Search in sources :

Example 56 with LineString

use of org.locationtech.jts.geom.LineString in project graphhopper by graphhopper.

the class MapMatchingResourceTurnCostsTest method runCar.

private void runCar(String urlParams) {
    final Response response = app.client().target("http://localhost:8080/match?" + urlParams).request().buildPost(Entity.xml(getClass().getResourceAsStream("another-tour-with-loop.gpx"))).invoke();
    JsonNode json = response.readEntity(JsonNode.class);
    assertFalse(json.has("message"), json.toString());
    assertEquals(200, response.getStatus());
    JsonNode path = json.get("paths").get(0);
    LineString expectedGeometry = readWktLineString("LINESTRING (12.3607 51.34365, 12.36418 51.34443, 12.36379 51.34538, 12.36082 51.34471, 12.36188 51.34278)");
    LineString actualGeometry = ResponsePathDeserializer.decodePolyline(path.get("points").asText(), 10, false).toLineString(false);
    assertEquals(DiscreteHausdorffDistance.distance(expectedGeometry, actualGeometry), 0.0, 1E-4);
    assertEquals(106.15, path.get("time").asLong() / 1000f, 0.1);
    assertEquals(106.15, json.get("map_matching").get("time").asLong() / 1000f, 0.1);
    assertEquals(811.56, path.get("distance").asDouble(), 1);
    assertEquals(811.56, json.get("map_matching").get("distance").asDouble(), 1);
}
Also used : Response(javax.ws.rs.core.Response) LineString(org.locationtech.jts.geom.LineString) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 57 with LineString

use of org.locationtech.jts.geom.LineString in project graphhopper by graphhopper.

the class MapMatchingResourceTurnCostsTest method readWktLineString.

private LineString readWktLineString(String wkt) {
    WKTReader wktReader = new WKTReader();
    LineString expectedGeometry = null;
    try {
        expectedGeometry = (LineString) wktReader.read(wkt);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return expectedGeometry;
}
Also used : LineString(org.locationtech.jts.geom.LineString) ParseException(org.locationtech.jts.io.ParseException) WKTReader(org.locationtech.jts.io.WKTReader)

Example 58 with LineString

use of org.locationtech.jts.geom.LineString in project graphhopper by graphhopper.

the class MapMatchingResourceTurnCostsTest method runBike.

private void runBike(String urlParams) {
    final Response response = app.client().target("http://localhost:8080/match?" + urlParams).request().buildPost(Entity.xml(getClass().getResourceAsStream("another-tour-with-loop.gpx"))).invoke();
    JsonNode json = response.readEntity(JsonNode.class);
    assertFalse(json.has("message"), json.toString());
    assertEquals(200, response.getStatus());
    JsonNode path = json.get("paths").get(0);
    LineString expectedGeometry = readWktLineString("LINESTRING (12.3607 51.34365, 12.36418 51.34443, 12.36379 51.34538, 12.36082 51.34471, 12.36188 51.34278)");
    LineString actualGeometry = ResponsePathDeserializer.decodePolyline(path.get("points").asText(), 10, false).toLineString(false);
    assertEquals(DiscreteHausdorffDistance.distance(expectedGeometry, actualGeometry), 0.0, 1E-4);
    assertEquals(162.31, path.get("time").asLong() / 1000f, 0.1);
    assertEquals(162.31, json.get("map_matching").get("time").asLong() / 1000f, 0.1);
    assertEquals(811.56, path.get("distance").asDouble(), 1);
    assertEquals(811.56, json.get("map_matching").get("distance").asDouble(), 1);
}
Also used : Response(javax.ws.rs.core.Response) LineString(org.locationtech.jts.geom.LineString) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 59 with LineString

use of org.locationtech.jts.geom.LineString in project graphhopper by graphhopper.

the class MapMatchingResourceTest method testGPX.

@Test
public void testGPX() {
    final Response response = app.client().target("http://localhost:8080/match?profile=fast_car").request().buildPost(Entity.xml(getClass().getResourceAsStream("/tour2-with-loop.gpx"))).invoke();
    assertEquals(200, response.getStatus());
    JsonNode json = response.readEntity(JsonNode.class);
    JsonNode path = json.get("paths").get(0);
    LineString expectedGeometry = readWktLineString("LINESTRING (12.3607 51.34365, 12.36418 51.34443, 12.36379 51.34538, 12.36082 51.34471, 12.36188 51.34278)");
    LineString actualGeometry = ResponsePathDeserializer.decodePolyline(path.get("points").asText(), 10, false).toLineString(false);
    assertEquals(DiscreteHausdorffDistance.distance(expectedGeometry, actualGeometry), 0.0, 1E-4);
    assertEquals(106.15, path.get("time").asLong() / 1000f, 0.1);
    assertEquals(106.15, json.get("map_matching").get("time").asLong() / 1000f, 0.1);
    assertEquals(811.56, path.get("distance").asDouble(), 1);
    assertEquals(811.56, json.get("map_matching").get("distance").asDouble(), 1);
}
Also used : Response(javax.ws.rs.core.Response) LineString(org.locationtech.jts.geom.LineString) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.jupiter.api.Test)

Example 60 with LineString

use of org.locationtech.jts.geom.LineString in project graphhopper by graphhopper.

the class MapMatchingResourceTest method readWktLineString.

private LineString readWktLineString(String wkt) {
    WKTReader wktReader = new WKTReader();
    LineString expectedGeometry = null;
    try {
        expectedGeometry = (LineString) wktReader.read(wkt);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return expectedGeometry;
}
Also used : LineString(org.locationtech.jts.geom.LineString) ParseException(org.locationtech.jts.io.ParseException) WKTReader(org.locationtech.jts.io.WKTReader)

Aggregations

LineString (org.locationtech.jts.geom.LineString)120 MultiLineString (org.locationtech.jts.geom.MultiLineString)48 Coordinate (org.locationtech.jts.geom.Coordinate)38 Geometry (org.locationtech.jts.geom.Geometry)35 Point (org.locationtech.jts.geom.Point)32 Test (org.junit.Test)24 Polygon (org.locationtech.jts.geom.Polygon)21 MultiPoint (org.locationtech.jts.geom.MultiPoint)19 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)14 WKTReader (org.locationtech.jts.io.WKTReader)13 ArrayList (java.util.ArrayList)12 CustomCoordinateSequence (org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)12 HashMap (java.util.HashMap)10 DimensionInfo (org.apache.jena.geosparql.implementation.DimensionInfo)9 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)9 ParseException (org.locationtech.jts.io.ParseException)9 DefaultGeometryProperty (eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty)8 GeometryNotSupportedException (eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException)7 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6