How to create a KML file using R

前端 未结 4 1994
梦如初夏
梦如初夏 2021-02-02 16:35

I have written a R script to get some map point data (Latitude and Longitude values). I am able to plot them in R and visualize them. But now I want to generate a KML file from

4条回答
  •  轮回少年
    2021-02-02 17:01

    Check the writeOGR function in the rgdal package. Here is a simple example:

    library("sp")
    library("rgdal")
    data(meuse)
    coordinates(meuse) <- c("x", "y")
    proj4string(meuse) <- CRS("+init=epsg:28992")
    meuse_ll <- spTransform(meuse, CRS("+proj=longlat +datum=WGS84"))
    writeOGR(meuse_ll["zinc"], "meuse.kml", layer="zinc", driver="KML") 
    

    The objects exported are SpatialPointsDataFrame, SpatialLinesDataFrame, or SpatialPolygonsDataFrame objects as defined in the sp package.

    R> class(meuse)
    [1] "SpatialPointsDataFrame"
    attr(,"package")
    [1] "sp"
    

    For writing with the KML driver, note that the geometries should be in geographical coordinates with datum WGS84.

提交回复
热议问题