如何使用R创建KML文件 [英] How to create a KML file using R

查看:201
本文介绍了如何使用R创建KML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个R脚本来获取一些地图点数据(纬度和经度值).我能够在R中绘制它们并对其进行可视化.但是,现在我想根据这些数据生成一个KML文件,并使用Google Earth进行查看.这样我就可以与同事共享,他们也可以在Google Earth上看到它.

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 this data and view using Google Earth. So that I can share it with colleagues and they can see it on Google Earth too.

执行此操作的最佳方法/软件包是什么?

What is the best method / package to do this ?

推荐答案

检查rgdal包中的writeOGR函数.这是一个简单的示例:

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") 

导出的对象是sp软件包中定义的SpatialPointsDataFrameSpatialLinesDataFrameSpatialPolygonsDataFrame对象.

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

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

要使用KML驱动程序进行编写,请注意,几何形状应在原点为WGS84的地理坐标中.

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

这篇关于如何使用R创建KML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆