graphhopper / map-matching

The map matching functionality is now located in the main repository https://github.com/graphhopper/graphhopper#map-matching
https://www.graphhopper.com/open-source/
Apache License 2.0
785 stars 274 forks source link

URL parameter points_encoded=false should not result in exception #118

Closed karussell closed 6 years ago

karussell commented 6 years ago

On master branch I get due to the empty snapped_waypoints:

2018-06-14 15:51:38.774 [dw-27 - POST /match?vehicle=car&points_encoded=false] ERROR i.d.j.errors.LoggingExceptionMapper - Error handling a request: 209f0336cdf5beb7
java.lang.UnsupportedOperationException: cannot access EMPTY PointList
        at com.graphhopper.util.PointList$1.toLineString(PointList.java:127)
        at com.graphhopper.http.WebHelper.jsonObject(WebHelper.java:175)
        at com.graphhopper.matching.http.MapMatchingResource.doGet(MapMatchingResource.java:148)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

The old behaviour was an empty string for points_encoded=true (already is) and {"coordinates":[],"type":"LineString"} for false.

karussell commented 6 years ago

The correct fix would be to remove overwriting this method in PointList.EMPTY:

public LineString toLineString(boolean includeElevation) {
    throw new UnsupportedOperationException("cannot access EMPTY PointList");
}

Then we would get the correct GeoJSON equivalent as before which is also according to the specification: GeoJSON processors MAY interpret Geometry objects with empty "coordinates" arrays as null objects

Fixed via https://github.com/graphhopper/graphhopper/commit/882d1e19954431a5b14b081fc8de068bf2eb7d49