I have a list of addresses that I have geocoded to get the corresponding longitude and latitude.
> AddressDetail <- geocode(match_address)
> coordinates(AddressDetail) <- c("lon", "lat")
Now I believe I should assign a projection so that R knows how the lon/lat coords are set up
> proj4string(AddressDetail) <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
Now I read in the shapefile that uses the NZMG projection
> Shape_MB = readOGR("/Work in progress/MB06_LV2/", "MB06_LV2")
Now this is where it starts to go wrong. I try transforming the projection of the lon/lat addresses into NZMG projection.
> AddressDetail <- spTransform(AddressDetail_v2, CRS("+proj=tmerc +lat_0=0 +lon_0=173 +k=0.9996 +x_0=1600000 +y_0=10000000 +ellps=GRS80 +units=m +no_defs")
non finite transformation detected:
lon lat
Error in spTransform(xSP, CRSobj, ...) : failure in points
In addition: Warning message:
In spTransform(xSP, CRSobj, ...) : 9 projected point(s) not finite
So when I continue on to use the over function to find the corresponding census meshblock index of the polygon that the address is within I get the following error.
> temp <- over(AddressDetail_v2,Shape_MB,MB06)
Error: identicalCRS(x, y) is not TRUE
I'm a bit of a novice with geospatial stuff in R so would appreciate any advice!