Home Ask Login Register

Developers Planet

Your answer is one click away!

Clay February 2016

R export to kml with custom DescriptionField

How can I add a custom description field to a kml file exported from R?

Where Coords_wgs is a SpatialPointsDataFrame class object.

  writeOGR(Coords_wgs, dsn = GEfilename, 
         layer = "layer", 
         dataset_options=c("NameField=name", "DescriptionField=THIS IS A TEST"),

The Name shows up, but the description balloon only shows the other attribute data.

I really am looking to add an image to the description balloon by setting the "DescriptionField=" the following text

 <img src='file:///c:\temp\IMG_1234.jpg' width='400' /><br/&gt;  
 Photo example!<br/>


Clay February 2016

I ended up going a different route with the html.table= parameter of the plotKML function within the plotKML package to get the image into the description balloon.

Coords_wgs is a SpatialPointsDataFrame class object; and
"image1.png" must be in the same folder as the generated kml file, or the full path needs to be specified.

  # Description for kml file.
  desc <- paste0('<img src="image1.png"', 
                 "  width='400'  /><br/&gt; ", 
                 "Caption", '<br/>')
  # create kml file.
  plotKML(coords_wgs, html.table =  desc, 
          file.name = "filename.kml"),
          folder.name = "foldername",
          subfolder.name = "subfoldername",
          points_names = "pointnames", LabelScale = 0.8)

Post Status

Asked in February 2016
Viewed 3,037 times
Voted 7
Answered 1 times


Leave an answer

Quote of the day: live life