Clay
Clay

Reputation: 2726

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", 
         driver="KML", 
         dataset_options=c("NameField=name", "DescriptionField=THIS IS A TEST"),
         overwrite_layer=TRUE)

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/>

Upvotes: 0

Views: 1217

Answers (1)

Clay
Clay

Reputation: 2726

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.

Where:
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)

Upvotes: 2

Related Questions