[R] Generating kml lines output

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Fri Nov 26 18:11:22 CET 2010

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">
<% for(i in 1:nrow(cpts)){ %>
<% } %>

results in a KML with lots of these:


 - 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")!


More information about the R-help mailing list