How to create a KML file using R

前端 未结 4 1952
梦如初夏
梦如初夏 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 16:55

    If you/your collegues know QGIS, this is a very good way to display data in Google Earth. QGIS has the feature of showing Google Earth as a base map and then you can open your spatial data and it will be displayed on the base map. Of course it requires your data to be correctly projected as rcs says.

    Here you need to export your points as a shape file using the maptools package and Spatial Points package:

    library(maptools)
    library(sp)
    
    ## define projection
    myProjection <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
    
    ## your points in format dataframe
    coordinates.df <- as.data.frame(MyCoordinates) 
    
    ## the number of points you have as dataframe
    number <- as.data.frame(NumberOfPoints)
    
    ## convert points to Spatial Points Dataframe
    myPoints.spdf <- SpatialPointsDataFrame(coordinates.df, number, proj4string = CRS(myProjection))
    
    ## save shapefile
    writeSpatialShape(myPoints.spdf, "MyPointsName")
    

    Your points can now be opened in QGIS and be displayed in Google Earth. In QGIS your data can also easily be saved as kmz file if necessary.

提交回复
热议问题