Search in sources :

Example 6 with JsonFeatureCollection

use of com.graphhopper.util.JsonFeatureCollection in project graphhopper by graphhopper.

the class IsochroneResourceTest method requestByTimeLimitNoTurnRestrictions.

@Test
public void requestByTimeLimitNoTurnRestrictions() {
    Response rsp = clientTarget(app, "/isochrone").queryParam("profile", "fast_car_no_turn_restrictions").queryParam("point", "42.531073,1.573792").queryParam("time_limit", 5 * 60).queryParam("buckets", 2).queryParam("type", "geojson").request().buildGet().invoke();
    JsonFeatureCollection featureCollection = rsp.readEntity(JsonFeatureCollection.class);
    assertEquals(2, featureCollection.getFeatures().size());
    Geometry polygon0 = featureCollection.getFeatures().get(0).getGeometry();
    Geometry polygon1 = featureCollection.getFeatures().get(1).getGeometry();
    assertTrue(polygon0.contains(geometryFactory.createPoint(new Coordinate(1.587224, 42.5386))));
    assertFalse(polygon0.contains(geometryFactory.createPoint(new Coordinate(1.589756, 42.558012))));
    assertTrue(polygon1.contains(geometryFactory.createPoint(new Coordinate(1.589756, 42.558012))));
    assertFalse(polygon1.contains(geometryFactory.createPoint(new Coordinate(1.635246, 42.53841))));
}
Also used : Response(javax.ws.rs.core.Response) Geometry(org.locationtech.jts.geom.Geometry) Coordinate(org.locationtech.jts.geom.Coordinate) JsonFeatureCollection(com.graphhopper.util.JsonFeatureCollection) Test(org.junit.jupiter.api.Test)

Example 7 with JsonFeatureCollection

use of com.graphhopper.util.JsonFeatureCollection in project graphhopper by graphhopper.

the class IsochroneResourceTest method requestReverseFlow.

@Test
public void requestReverseFlow() {
    Response rsp = clientTarget(app, "/isochrone").queryParam("profile", "fast_car").queryParam("point", "42.531073,1.573792").queryParam("reverse_flow", true).queryParam("time_limit", 5 * 60).queryParam("buckets", 2).queryParam("type", "geojson").request().buildGet().invoke();
    JsonFeatureCollection featureCollection = rsp.readEntity(JsonFeatureCollection.class);
    assertEquals(2, featureCollection.getFeatures().size());
    Geometry polygon0 = featureCollection.getFeatures().get(0).getGeometry();
    Geometry polygon1 = featureCollection.getFeatures().get(1).getGeometry();
    assertTrue(polygon0.contains(geometryFactory.createPoint(new Coordinate(1.587224, 42.5386))));
    assertFalse(polygon0.contains(geometryFactory.createPoint(new Coordinate(1.589756, 42.558012))));
    assertTrue(polygon1.contains(geometryFactory.createPoint(new Coordinate(1.589756, 42.558012))));
    assertFalse(polygon1.contains(geometryFactory.createPoint(new Coordinate(1.635246, 42.53841))));
    int bucketNumber = (Integer) featureCollection.getFeatures().get(0).getProperties().get("bucket");
    assertEquals(0, bucketNumber);
}
Also used : Response(javax.ws.rs.core.Response) Geometry(org.locationtech.jts.geom.Geometry) Coordinate(org.locationtech.jts.geom.Coordinate) JsonFeatureCollection(com.graphhopper.util.JsonFeatureCollection) Test(org.junit.jupiter.api.Test)

Example 8 with JsonFeatureCollection

use of com.graphhopper.util.JsonFeatureCollection in project graphhopper by graphhopper.

the class LMPreparationHandler method loadLandmarkSplittingFeatureCollection.

private JsonFeatureCollection loadLandmarkSplittingFeatureCollection(String splitAreaLocation) {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(new JtsModule());
    URL builtinSplittingFile = LandmarkStorage.class.getResource("map.geo.json");
    try (Reader reader = splitAreaLocation.isEmpty() ? new InputStreamReader(builtinSplittingFile.openStream(), UTF_CS) : new InputStreamReader(new FileInputStream(splitAreaLocation), UTF_CS)) {
        JsonFeatureCollection result = objectMapper.readValue(reader, JsonFeatureCollection.class);
        if (splitAreaLocation.isEmpty()) {
            LOGGER.info("Loaded built-in landmark splitting collection from {}", builtinSplittingFile);
        } else {
            LOGGER.info("Loaded landmark splitting collection from {}", splitAreaLocation);
        }
        return result;
    } catch (IOException e) {
        LOGGER.error("Problem while reading border map GeoJSON. Skipping this.", e);
        return null;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) JsonFeatureCollection(com.graphhopper.util.JsonFeatureCollection) JtsModule(com.bedatadriven.jackson.datatype.jts.JtsModule) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) URL(java.net.URL) FileInputStream(java.io.FileInputStream)

Example 9 with JsonFeatureCollection

use of com.graphhopper.util.JsonFeatureCollection in project graphhopper by graphhopper.

the class LMPreparationHandler method init.

public void init(GraphHopperConfig ghConfig) {
    // throw explicit error for deprecated configs
    if (ghConfig.has("prepare.lm.weightings")) {
        throw new IllegalStateException("Use profiles_lm instead of prepare.lm.weightings, see #1922 and docs/core/profiles.md");
    }
    setPreparationThreads(ghConfig.getInt(Parameters.Landmark.PREPARE + "threads", getPreparationThreads()));
    setLMProfiles(ghConfig.getLMProfiles());
    landmarkCount = ghConfig.getInt(Parameters.Landmark.COUNT, landmarkCount);
    logDetails = ghConfig.getBool(Landmark.PREPARE + "log_details", false);
    minNodes = ghConfig.getInt(Landmark.PREPARE + "min_network_size", -1);
    for (String loc : ghConfig.getString(Landmark.PREPARE + "suggestions_location", "").split(",")) {
        if (!loc.trim().isEmpty())
            lmSuggestionsLocations.add(loc.trim());
    }
    if (!isEnabled())
        return;
    String splitAreaLocation = ghConfig.getString(Landmark.PREPARE + "split_area_location", "");
    JsonFeatureCollection landmarkSplittingFeatureCollection = loadLandmarkSplittingFeatureCollection(splitAreaLocation);
    if (landmarkSplittingFeatureCollection != null && !landmarkSplittingFeatureCollection.getFeatures().isEmpty()) {
        List<SplitArea> splitAreas = landmarkSplittingFeatureCollection.getFeatures().stream().map(SplitArea::fromJsonFeature).collect(Collectors.toList());
        areaIndex = new AreaIndex<>(splitAreas);
    }
}
Also used : JsonFeatureCollection(com.graphhopper.util.JsonFeatureCollection)

Example 10 with JsonFeatureCollection

use of com.graphhopper.util.JsonFeatureCollection in project graphhopper by graphhopper.

the class IsochroneResourceTest method requestWithBlockArea.

@Test
public void requestWithBlockArea() {
    Response rsp = clientTarget(app, "/isochrone").queryParam("profile", "fast_car").queryParam("point", "42.531073,1.573792").queryParam("time_limit", 5 * 60).queryParam("buckets", 2).queryParam("type", "geojson").queryParam(BLOCK_AREA, "42.558067,1.589429,100").request().buildGet().invoke();
    JsonFeatureCollection featureCollection = rsp.readEntity(JsonFeatureCollection.class);
    assertEquals(2, featureCollection.getFeatures().size());
    Geometry polygon0 = featureCollection.getFeatures().get(0).getGeometry();
    Geometry polygon1 = featureCollection.getFeatures().get(1).getGeometry();
    assertTrue(polygon0.contains(geometryFactory.createPoint(new Coordinate(1.587224, 42.5386))));
    assertFalse(polygon0.contains(geometryFactory.createPoint(new Coordinate(1.589756, 42.558012))));
    assertFalse(polygon1.contains(geometryFactory.createPoint(new Coordinate(1.589756, 42.558012))));
    assertFalse(polygon1.contains(geometryFactory.createPoint(new Coordinate(1.635246, 42.53841))));
    assertTrue(polygon1.contains(geometryFactory.createPoint(new Coordinate(1.58864, 42.554582))));
}
Also used : Response(javax.ws.rs.core.Response) Geometry(org.locationtech.jts.geom.Geometry) Coordinate(org.locationtech.jts.geom.Coordinate) JsonFeatureCollection(com.graphhopper.util.JsonFeatureCollection) Test(org.junit.jupiter.api.Test)

Aggregations

JsonFeatureCollection (com.graphhopper.util.JsonFeatureCollection)12 Test (org.junit.jupiter.api.Test)10 Response (javax.ws.rs.core.Response)8 Coordinate (org.locationtech.jts.geom.Coordinate)8 Geometry (org.locationtech.jts.geom.Geometry)7 JsonFeature (com.graphhopper.util.JsonFeature)2 JtsModule (com.bedatadriven.jackson.datatype.jts.JtsModule)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 WebTarget (javax.ws.rs.client.WebTarget)1 Envelope (org.locationtech.jts.geom.Envelope)1 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)1 LineString (org.locationtech.jts.geom.LineString)1