What does the error in the title mean? I'm fairly new to GIS and can't understand which negative length vectors R is talking about? Here is what I'm doing:
I have a csv of lat/long locations of certain points and a multiPolygon Shapefile of buildings in a particular city . I want to find the nearest polygon to each point. First I have converted the points and polygons to planar projections by the following code:
##BUILDINGS DATA buildings<-readOGR("buildings.shp") buildings<- spTransform(buildings, CRS("+proj=utm +zone=45 +a=6377299.151 +b=6356098.145120132 +towgs84=295,736,257,0,0,0,0 +units=m +no_defs ")) ##LATITUDES/LONGITUDES DATA locations<-read.csv("20190712033434-47083-data.csv") locations <- SpatialPointsDataFrame(coords = locations, data = locations, proj4string = CRS("+proj=longlat +datum=WGS84")) locations<- spTransform(locations, CRS("+proj=utm +zone=45 +a=6377299.151 +b=6356098.145120132 +towgs84=295,736,257,0,0,0,0 +units=m +no_defs "))
Then I find the minimum distance using the following formula:
minimum_distance<- apply(gDistance(locations, buildings,byid=TRUE),2,min)
But it gives me the error:
Error in RGEOSDistanceFunc(spgeom1, spgeom2, byid, "rgeos_distance") : negative length vectors are not allowed
What is going wrong?