繁体   English   中英

将纬度/经度或URM坐标添加到R中的shapefile

[英]Add lat/long or URM coordinates to shapefiles in R

我是R语言中的GIS的新手,我正尝试将lat / long或UTM坐标添加到shapefile。 我从这里下载了芝加哥市的边界(City_Boundaries.shp): http : //www.cityofchicago.org/city/en/depts/doit/supp_info/gis_data.html

我加载了maptools和rgeos库:

library(maptools)
library(rgeos)
library(rgdal)

我将数据导入R&并尝试为区域16T添加UTM代码:

city<- readShapeSpatial("C:/Users/Luke.Gerdes/Documents/GIS Files/Chicago/City_Boundary.shp")
proj4string(city) <- CRS("+proj=utm +north +zone=16T + datum=WGS84")

但是,结果数据对我来说没有意义。 当我查看“城市”内的“坐标”插槽时,坐标值为例如X = 1092925和Y = 1944820。 我使用外部工具( http://home.hiwaay.net/~taylorc/toolbox/geography/geoutm.html )查找GPS坐标。 结果是:lat = 17.511,long = -81.42。 介于牙买加和洪都拉斯海岸之间。 在我看来,shapefile坐标存在于自己的宇宙中。 就像shapefile的名称所暗示的那样,坐标提供了城市形状的准确描述,但是这些坐标不会自动映射到地球上。

我的最终目标是确定在芝加哥是否发生了一些带有地理标记的事件。 我很乐意将经纬度列出的点转换为UTM,如下所示:

  SP <- SpatialPoints(cbind(-87.63044, 41.79625), proj4string=CRS("+proj=longlat +datum=WGS84"))
  SP <- spTransform(SP, CRS("+proj=utm +north +zone=16T +datum=WGS84"))

如果更有意义,我也愿意尝试使用原始格式的事件数据。 最终,我需要帮助将芝加哥城市边界变成一个多边形,可以对照事件数据进行检查。 像这样:

  gContains(city, SP)

如何将我的shapefile和事件数据放入一个通用(准确)的参照系中,以便可以检查点是否在城市中? 您可以提供的任何帮助将不胜感激。

一般建议是使用rgdal::readOGR读取shapefile,如

library(rgdal)
city = readOGR(".", "City_Boundary")

这不仅会给city适当的CRS:

proj4string(city)
[1] "+proj=tmerc +lat_0=36.66666666666666 +lon_0=-88.33333333333333 +k=0.9999749999999999 +x_0=300000 +y_0=0 +datum=NAD83 +units=us-ft +no_defs +ellps=GRS80 +towgs84=0,0,0"

但也要警告您是否要更改它而不重新投影:

proj4string(city) <- CRS("+proj=utm +north +zone=16T + datum=WGS84")
Warning message:
In `proj4string<-`(`*tmp*`, value = <S4 object of class "CRS">) :
  A new CRS was assigned to an object with an existing CRS:
+proj=tmerc +lat_0=36.66666666666666 +lon_0=-88.33333333333333 +k=0.9999749999999999 +x_0=300000 +y_0=0 +datum=NAD83 +units=us-ft +no_defs +ellps=GRS80 +towgs84=0,0,0
without reprojecting.
For reprojection, use function spTransform in package rgdal

意味着这样做之后, city错误的 您可以使用spTransform重新投影city ,如

city = spTransform(city, CRS("+proj=utm +north +zone=16T + datum=WGS84"))

您的rgeos::gContains调用可能会失败,因为utm的两个CRS字符串不同。 删除前面的+ datum=WGS84中的空格,就可以了( TRUE )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM