Search in sources :

Example 1 with BBox

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;
}
Also used : Circle(com.graphhopper.util.shapes.Circle) GHIntHashSet(com.graphhopper.coll.GHIntHashSet) Shape(com.graphhopper.util.shapes.Shape) BBox(com.graphhopper.util.shapes.BBox) ArrayList(java.util.ArrayList) GHPoint(com.graphhopper.util.shapes.GHPoint)

Example 2 with BBox

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)
}
Also used : BBox(com.graphhopper.util.shapes.BBox) LinearKeyAlgo(com.graphhopper.geohash.LinearKeyAlgo)

Example 3 with BBox

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);
}
Also used : BBox(com.graphhopper.util.shapes.BBox) Test(org.junit.Test)

Example 4 with BBox

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));
}
Also used : BBox(com.graphhopper.util.shapes.BBox) Test(org.junit.Test)

Example 5 with BBox

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);
    }
}
Also used : BBox(com.graphhopper.util.shapes.BBox) Map(java.util.Map)

Aggregations

BBox (com.graphhopper.util.shapes.BBox)28 Test (org.junit.Test)13 GHPoint (com.graphhopper.util.shapes.GHPoint)5 JsonFeature (com.graphhopper.json.geo.JsonFeature)3 GermanySpatialRule (com.graphhopper.routing.util.spatialrules.countries.GermanySpatialRule)3 ArrayList (java.util.ArrayList)3 IntArrayList (com.carrotsearch.hppc.IntArrayList)2 Geometry (com.graphhopper.json.geo.Geometry)2 Graph (com.graphhopper.storage.Graph)2 GraphBuilder (com.graphhopper.storage.GraphBuilder)2 IntHashSet (com.carrotsearch.hppc.IntHashSet)1 PathWrapper (com.graphhopper.PathWrapper)1 GHIntHashSet (com.graphhopper.coll.GHIntHashSet)1 LinearKeyAlgo (com.graphhopper.geohash.LinearKeyAlgo)1 SpatialKeyAlgo (com.graphhopper.geohash.SpatialKeyAlgo)1 GeoJsonPolygon (com.graphhopper.json.geo.GeoJsonPolygon)1 JsonFeatureCollection (com.graphhopper.json.geo.JsonFeatureCollection)1 ReaderWay (com.graphhopper.reader.ReaderWay)1 TarjansSCCAlgorithm (com.graphhopper.routing.subnetwork.TarjansSCCAlgorithm)1 EdgeFilter (com.graphhopper.routing.util.EdgeFilter)1