【发布时间】:2017-06-27 12:17:21
【问题描述】:
我是第一次处理 R 和空间数据的 R 初学者。所以我希望我说清楚。
我有一个意大利地区的 shapefile,分为几个人口普查部门。 另一方面,我有一个 csv 文件,其中包含每个案例的案例列表和地址。 我想绘制点和 shapefile 并计算每个人口普查部门中有多少点。
从现在开始我做了什么:
#get cases file
cases <- read.csv("cases.csv", sep =';', header = TRUE)
names(cases)
[1] "name" "address"
#geocode addresses from Google Maps
library(GISTools)
library(rgeos)
library(ggmap)
geolocalize <- geocode(as.character(cases$address))
# bind latitude and longitude to the previous cases data frame
cases <- data.frame(cases, geolocalize)
names(cases)
[1] "name" "address" "lon" "lat"
#make cases a SpatialPointDataFrame
#since addresses were retrieved using GoogleMaps, I set proj4string as follows
cases.points <- SpatialPointsDataFrame(cases[,3:4], cases, proj4string = CRS("+init=EPSG:3857"))
#get the shapefile
region <- readOGR("R02_11_WGS84.shp")
现在,我可以分别绘制 case.points 和 shapefile,但不能将它们添加到同一个图中。除此之外,正如我所说,我想计算每个多边形中有多少点(即“区域”的人口普查划分)。
我必须承认我对地理不是很感兴趣。我怀疑不同的坐标和/或投影参考系统可能是问题,因此我检查了。
head(coordinates(region))
[,1] [,2]
0 364509.0 5065900
1 363916.3 5056629
2 372585.0 5068078
3 360692.3 5048321
4 356029.7 5062399
5 360012.1 5065663
coordinates(cases)
lon lat
[1,] 7.323667 45.73664
proj4string(region)
[1] "+proj=utm +zone=32 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0"
proj4string(cases.points)
[1] "+init=EPSG:3857 +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs"
形状文件坐标是否可能以度为单位,而案例坐标为十进制?如果是,如何转换?
谢谢, 萨罗
【问题讨论】:
-
shapefile 中列的名称是什么?还是他们没有名字?
-
暂时不能试,所以不回答,看
sp::spTransform吧。
标签: r geospatial spatial