use of com.graphhopper.util.shapes.BBox in project graphhopper by graphhopper.
the class GraphEdgeIdFinder method parseStringHints.
/**
* This method reads string values from the hints about blocked areas and fills the configMap with either the
* created shapes or the found edges if area is small enough.
*/
public ConfigMap parseStringHints(ConfigMap configMap, HintsMap hints, EdgeFilter filter) {
final String objectSeparator = ";";
final String innerObjSep = ",";
// use shapes if bigger than 1km^2
final double shapeArea = 1000 * 1000;
final GHIntHashSet blockedEdges = new GHIntHashSet();
final List<Shape> blockedShapes = new ArrayList<>();
// Add blocked circular areas or points
String blockedCircularAreasStr = hints.get(BLOCK_AREA, "");
if (!blockedCircularAreasStr.isEmpty()) {
String[] blockedCircularAreasArr = blockedCircularAreasStr.split(objectSeparator);
for (int i = 0; i < blockedCircularAreasArr.length; i++) {
String objectAsString = blockedCircularAreasArr[i];
String[] splittedObject = objectAsString.split(innerObjSep);
if (splittedObject.length == 4) {
final BBox bbox = BBox.parseTwoPoints(objectAsString);
if (bbox.calculateArea() > shapeArea)
blockedShapes.add(bbox);
else
findEdgesInShape(blockedEdges, bbox, filter);
} else if (splittedObject.length == 3) {
double lat = Double.parseDouble(splittedObject[0]);
double lon = Double.parseDouble(splittedObject[1]);
int radius = Integer.parseInt(splittedObject[2]);
Circle circle = new Circle(lat, lon, radius);
if (circle.calculateArea() > shapeArea) {
blockedShapes.add(circle);
} else {
findEdgesInShape(blockedEdges, circle, filter);
}
} else if (splittedObject.length == 2) {
double lat = Double.parseDouble(splittedObject[0]);
double lon = Double.parseDouble(splittedObject[1]);
findClosestEdge(blockedEdges, lat, lon, filter);
} else {
throw new IllegalArgumentException(objectAsString + " at index " + i + " need to be defined as lat,lon " + "or as a circle lat,lon,radius or rectangular lat1,lon1,lat2,lon2");
}
}
}
configMap.put(BLOCKED_EDGES, blockedEdges);
configMap.put(BLOCKED_SHAPES, blockedShapes);
return configMap;
}
use of com.graphhopper.util.shapes.BBox in project graphhopper by graphhopper.
the class Location2IDQuadtree method initAlgo.
void initAlgo(int lat, int lon) {
this.latSize = lat;
this.lonSize = lon;
BBox b = graph.getBounds();
keyAlgo = new LinearKeyAlgo(lat, lon).setBounds(b);
double max = Math.max(distCalc.calcDist(b.minLat, b.minLon, b.minLat, b.maxLon), distCalc.calcDist(b.minLat, b.minLon, b.maxLat, b.minLon));
maxRasterWidth2InMeterNormed = distCalc.calcNormalizedDist(max / Math.sqrt(getCapacity()) * 2);
// as long as we have "dist < PI*R/2" it is save to compare the normalized distances instead of the real
// distances. because sin(x) is only monotonic increasing for x <= PI/2 (and positive for x >= 0)
}
use of com.graphhopper.util.shapes.BBox in project graphhopper by graphhopper.
the class SpatialRuleLookupBuilderTest method testNoIntersection.
@Test
public void testNoIntersection() {
Reader reader = new InputStreamReader(SpatialRuleLookupBuilderTest.class.getResourceAsStream("countries.geo.json"));
SpatialRuleLookup spatialRuleLookup = DefaultModule.buildIndex(reader, new BBox(-180, -179, -90, -89));
assertNull(spatialRuleLookup);
}
use of com.graphhopper.util.shapes.BBox in project graphhopper by graphhopper.
the class SpatialRuleLookupBuilderTest method testIndex.
@Test
public void testIndex() {
Reader reader = new InputStreamReader(SpatialRuleLookupBuilderTest.class.getResourceAsStream("countries.geo.json"));
SpatialRuleLookup spatialRuleLookup = DefaultModule.buildIndex(reader, new BBox(-180, 180, -90, 90));
// Berlin
assertEquals(AccessValue.EVENTUALLY_ACCESSIBLE, spatialRuleLookup.lookupRule(52.5243700, 13.4105300).getAccessValue("track", TransportationMode.MOTOR_VEHICLE, AccessValue.ACCESSIBLE));
assertEquals(AccessValue.ACCESSIBLE, spatialRuleLookup.lookupRule(52.5243700, 13.4105300).getAccessValue("primary", TransportationMode.MOTOR_VEHICLE, AccessValue.ACCESSIBLE));
// Paris -> empty rule
assertEquals(AccessValue.ACCESSIBLE, spatialRuleLookup.lookupRule(48.864716, 2.349014).getAccessValue("track", TransportationMode.MOTOR_VEHICLE, AccessValue.ACCESSIBLE));
assertEquals(AccessValue.ACCESSIBLE, spatialRuleLookup.lookupRule(48.864716, 2.349014).getAccessValue("primary", TransportationMode.MOTOR_VEHICLE, AccessValue.ACCESSIBLE));
// Vienna
assertEquals(AccessValue.ACCESSIBLE, spatialRuleLookup.lookupRule(48.210033, 16.363449).getAccessValue("track", TransportationMode.MOTOR_VEHICLE, AccessValue.ACCESSIBLE));
assertEquals(AccessValue.ACCESSIBLE, spatialRuleLookup.lookupRule(48.210033, 16.363449).getAccessValue("primary", TransportationMode.MOTOR_VEHICLE, AccessValue.ACCESSIBLE));
assertEquals(AccessValue.EVENTUALLY_ACCESSIBLE, spatialRuleLookup.lookupRule(48.210033, 16.363449).getAccessValue("living_street", TransportationMode.MOTOR_VEHICLE, AccessValue.ACCESSIBLE));
}
use of com.graphhopper.util.shapes.BBox in project graphhopper by graphhopper.
the class FeatureJsonDeserializer method deserialize.
@Override
public JsonFeature deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
try {
JsonObject obj = json.getAsJsonObject();
String id, strType = null;
Map<String, Object> properties = null;
BBox bbox = null;
Geometry geometry = null;
// TODO ensure uniqueness
if (obj.has("id"))
id = obj.get("id").getAsString();
else
id = UUID.randomUUID().toString();
if (obj.has("properties")) {
properties = context.deserialize(obj.get("properties"), Map.class);
}
if (obj.has("bbox"))
bbox = parseBBox(obj.get("bbox").getAsJsonArray());
if (obj.has("geometry")) {
JsonObject geometryJson = obj.get("geometry").getAsJsonObject();
if (geometryJson.has("coordinates")) {
if (!geometryJson.has("type"))
throw new IllegalArgumentException("No type for non-empty coordinates specified");
strType = context.deserialize(geometryJson.get("type"), String.class);
if ("Point".equals(strType)) {
JsonArray arr = geometryJson.get("coordinates").getAsJsonArray();
double lon = arr.get(0).getAsDouble();
double lat = arr.get(1).getAsDouble();
if (arr.size() == 3)
geometry = new Point(lat, lon, arr.get(2).getAsDouble());
else
geometry = new Point(lat, lon);
} else if ("MultiPoint".equals(strType)) {
geometry = parseLineString(geometryJson);
} else if ("LineString".equals(strType)) {
geometry = parseLineString(geometryJson);
} else if ("Polygon".equals(strType)) {
geometry = parsePolygonString(geometryJson);
} else if ("MultiPolygon".equals(strType)) {
geometry = parsePolygonString(geometryJson);
} else {
throw new IllegalArgumentException("Coordinates type " + strType + " not yet supported");
}
}
}
return new JsonFeature(id, strType, bbox, geometry, properties);
} catch (Exception ex) {
throw new JsonParseException("Problem parsing JSON feature " + json, ex);
}
}
Aggregations