I am not sure why i am keep getting NA whenever I run the
Over function with Latitude and Longitude point on the polygon from shapefile. Please note that this is first time for me doing the spatial analysis, but I have done my research and replicated things, but didn't succeed. I need some points which are outside of the polygon to be NA, so I can focus on the real data.
I read these sources since these pertain to my cause but I can't work my problem out:
Checking if points fall within polygon Shapefile
R: Error in checking point inside polygon
Here is my code chunk
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.
The datafiles are here:
reading csv file: https://github.com/THsTestingGround/SO_readOGR_quest/blob/master/311_Service_Requests__myGNV_.csv