Reading KML files into R

只愿长相守 提交于 2019-12-01 08:45:13

This R function should extract Placemark information (name, description and Point coordinates) from KML exported from Google Maps.

It works fine for the two maps I have at hand and supports NA values in names and descriptions (which explains why the internal get_field function is coded how it is).

Improvements very welcome.

Add. I have added a function to deal with Polygons. The code now allows you to plot KML Points and Polygons as in

ggplot(kml_points(map),
       aes(x = longitude, y = latitude)) +
  geom_polygon(data = kml_polygons(map), fill = "red", alpha = 0.5) +
  geom_point()

where map holds the path to a KML file.

WARNING: no support for multi-geometries (e.g. multi-polygons with holes).

This R-sig-geo thread also refers. It seems the only way to approach this would be to write a custom function to parse the KML as XML and build individual spatialPoints and spatialPolygons objects from the respective geometries. On balance probably more effective to just try and stick to single geometry KMLs..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!