1. Introduction (you may skip this if you like)
In order to implement a road snapping feature in R for recorded positioning data, I first searched the internet for possible solutions to the problem:
While it seems this can be solved with fuzzyMM (using fuzzy logic), the project using that approach is unfortunately not active any more and, thus, the documentation does not include the kind of information that would be required to get started with the package itself.
Another solution could be using online geospatial APIs, e.g. Google's. However, the current database already includes way more datasets than what's included in the free package.
At last, I found
snapPointsToLines (short introduction about how the function works can be found here) and attempted to snap a couple of coordinates to lines provided by a shapefile.
Note: Because the GPS-data was recorded on cars mostly driving on major roads in Germany, I downloaded the respective shapefile (of Bavaria, i.e. Bayern) here (
2. The specific problem
Road snapping with
snapPointsToLines() generates quite confusing values with this code. The following picture shows a list of recorded longitude / latitude values (see
roadsBavaria = readOGR("~/roads.shp", "roads") pointsCoord = getValuesFromPicture() pointsSpatial = SpatialPoints(pointsCoord) pointsSpatialCorrected = snapPointsToLines(pointsSpatial, roadsBavaria)
Although this reduced test case sets the value
pointsSpatialCorrected (see result at the end), it fails (code after that is not executed) with
Warning messages: 1: In RGEOSDistanceFunc(spgeom1, spgeom2, byid, "rgeos_distance") : Spatial object 1 is not projected; GEOS expects planar coordinates 2: In RGEOSDistanceFunc(spgeom1, spgeom2, byid, "rgeos_distance") : Spatial object 2 is not projected; GEOS expects planar coordinates
Note that this error occurs even when I apply the shapefile's projection on the
spatialPoints manually via
pointsSpatial = SpatialPoints(pointsCoord, proj4string = CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"))
What am I doing wrong here?
3. Additional information
The resulting value of
spatialPointsCorrected as displayed by