我不确定为什么在shapefile上的多边形上运行纬度和经度点的Over
函数时,为什么我总是得到NA。请注意,这是我第一次进行空间分析,但是我已经完成了研究并复制了东西,但没有成功。我需要将多边形之外的一些点设为NA,因此我可以专注于实际数据。
我阅读了这些资料,因为它们与我的事业有关,但我无法解决我的问题:sp::over() for point in polygon analysishttps://gis.stackexchange.com/questions/133625/checking-if-points-fall-within-polygon-shapefilehttps://gis.stackexchange.com/questions/278723/r-error-in-checking-point-inside-polygon
这是我的代码块
library(sp) library(rgdal) library(readr) gainsville_df <- read_csv("311_Service_Requests__myGNV_.csv") gnv <- readOGR("~\\Downloads\\GIS_cgbound", layer = "cgbound") gnv_latlon <- spTransform(gnv, CRS("+proj=longlat +ellps=WGS84 +datum=WGS84")) gnv_raw <- data.frame(Longitude= gainsville_df$Longitude, Latitude= gainsville_df$Latitude) coordinates(gnv_raw) <- ~Longitude + Latitude proj4string(gnv_raw) <- proj4string(gnv) over(gnv_raw, as(gnv,"SpatialLinesDataFrame")) #Yeilds: # FID_cgboun Id Perimeter Area Acres Hectares Shape_Leng #1 NA NA NA NA NA NA NA # Desired Output: # Whereas I should have seen which gainesville Latitudes and Longitude are within the shpaefile # polygon so I can drop the outliers, that have the NA. According to this, none of my LatLon points # are inside the polygon.
数据文件在这里:形状文件:https://github.com/THsTestingGround/SO_readOGR_quest/tree/master/GIS_cgbound读取csv文件:https://github.com/THsTestingGround/SO_readOGR_quest/blob/master/311_Service_Requests__myGNV_.csv
如果有人可以帮助我,我将不胜感激。
我不确定为什么在shapefile中的多边形上使用纬度和经度点运行Over函数时,为什么我总是得到NA。请注意,这是我第一次进行空间...
我意识到您的点数据是一个sf对象,因为您具有POINT (-82.34323174 29.67058748)
作为字符。因此,我首先重建了您的数据。我也在这里分配了一个投影。