Zillow 为美国主要城市的不同社区提供了一组shapefile。我想使用R检查某些社区中是否存在某些建筑物:
library(rgeos)
library(sp)
library(rgdal)
df <- data.frame(Latitude =c(47.591351, 47.62212,47.595152),
Longitude = c(-122.332271,-122.353985,-122.331639),
names = c("Safeco Field", "Key Arena", "Century Link"))
coordinates(df) <- ~ Latitude + Longitude
wa.map <- readOGR("ZillowNeighborhoods-WA.shp", layer="ZillowNeighborhoods-WA")
sodo <- wa.map[wa.map$CITY == "Seattle" & wa.map$NAME == "Industrial District", ]
我可以毫无问题地绘图
plot(sodo)
points(df$Latitude ~ df$Longitude, col = "red", cex = 1)
我proj4
将shapefile 中的字符串匹配到我的data.frame
CRSobj <- CRS("+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0 ")
df@proj4string <- CRSobj
over(df, sodo)
这给了我很多NA
价值。我已经试过这个答案
spp <- SpatialPoints(df)
spp@proj4string <- CRSobj
over(spp, sodo)
但仍然只获得NA
值。有什么想法我还应该尝试吗?