Reputation: 23
I'm relatively new to GIS and R, and I'm do a project to map crime data to specific neighborhoods in cities. The data file is in CSV format, with incident ID, longitude and latitude. The neighborhood polygons are defined by shapefile. Here is my code in R:
require(sp)
require(rgdal)
require(maps)
crime<-read.csv("crime sample.csv")
crime<-subset(crime,!is.na(crime$Latitude))
coordinates(crime)<-c("Longitude","Latitude")
Neigh <- readOGR(".", "Neighborhoods_2012b")
proj4string(crime)<-proj4string(Neigh)
inside.Neigh <- !is.na(over(crime, as(Neigh, "SpatialPolygons")))
however, the result shows that there are no points that falls within any of the polygons.
proj4string(Neigh)
gives
[1] "+proj=tmerc +lat_0=36.66666666666666 +lon_0=-88.33333333333333 +k=0.999975
+x_0=300000 +y_0=0 +datum=NAD83 +units=us-ft +no_defs +ellps=GRS80 +towgs84=0,0,0
The data files used are available at this link: file
thanks for any help.
Upvotes: 2
Views: 2428
Reputation: 68849
You have to re-project one data set. The spTransform
methods provide transformation between datum(s) and conversion between projections:
Neigh_wgs84 <- spTransform(Neigh, CRS("+proj=longlat +datum=WGS84"))
proj4string(crime) <- proj4string(Neigh_wgs84)
plot(Neigh_wgs84)
plot(crime, add=TRUE, col="red")
R> over(crime, Neigh_wgs84)
PRI_NEIGH SEC_NEIGH SHAPE_AREA SHAPE_LEN
1 Gage Park MARQUETTE PARK,GAGE PARK 61284896 32294
2 Humboldt Park HUMBOLDT PARK 125010426 46127
3 Grand Boulevard BRONZEVILLE 48492503 28197
4 Garfield Ridge MIDWAY AIRPORT 117890778 60080
5 Auburn Gresham AUBURN GRESHAM 105065354 46758
Upvotes: 5