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))));
}
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);
}
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;
}
}
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);
}
}
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))));
}
Aggregations