[R] Generating kml lines output

fbielejec fbielejec at gmail.com
Fri Nov 26 19:13:51 CET 2010


Dnia 2010-11-26, o godz. 17:11:22
Barry Rowlingson <b.rowlingson at lancaster.ac.uk> napisał(a):

> On Fri, Nov 26, 2010 at 5:03 PM, fbielejec <fbielejec at gmail.com>
> wrote:
> > Dear,
> >
> > I would like to generate kml file with lines (<LineString>) of
> > different style (definitely color, but width would also be nice to
> > see). However with kmlLine from maptools package I am able only to
> > output the single first Lines object (first row of
> > SpatialLinesDataFrame)
> >
> > I guess the option would be to have single Lines object (instead of
> > list of them), but then also the style wouldn't vary among them...
> > My code so far:
> 
>  If you cant get what you want from package code, and you know a bit
> about the KML format you are trying to produce, then try using the R
> 'brew' package, which lets your write a template which can have loops,
> variable substitutions, and other bits of R code in it.
> 
>  For example, here creating a simple set of KML points from a data
> frame called 'cpts':
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <kml xmlns="http://earth.google.com/kml/2.1">
> <Document>
> <% for(i in 1:nrow(cpts)){ %>
> <Placemark>
> <Name><%=paste("pt-",i,sep="")%></Name>
> <Point>
> <coordinates><%=cpts[i,]$Xt%>,<%=cpts[i,]$Yt%>,0</coordinates>
> </Point>
> </Placemark>
> <% } %>
> </Document>
> </kml>
> 
> 
> results in a KML with lots of these:
> 
> <Placemark>
> <Name>pt-4</Name>
> <Point>
> <coordinates>-43.93769,-19.92065,0</coordinates>
> </Point>
> </Placemark>
> 
>  - its a lot easier than writing lots of cat() and other formatting
> nonsense in R code!
> 
>  But if you can get package code to do it, that's the way to go. But
> for outside-the-box solutions, install.packages("brew")!
> 
> Barry

Dear,

Many thanks, that indeed is an option. However we already have a
software in our lab that works in a similar way, writing lines of kml
code to files, I was hoping to write something more generic...

-- 
while(!succeed) { try(); }



More information about the R-help mailing list