Search in sources :

Example 21 with BBox

use of com.graphhopper.util.shapes.BBox in project graphhopper by graphhopper.

the class SpatialRuleLookupBuilderTest method testBounds.

@Test
public void testBounds() {
    Reader reader = new InputStreamReader(SpatialRuleLookupBuilderTest.class.getResourceAsStream("countries.geo.json"));
    SpatialRuleLookup spatialRuleLookup = DefaultModule.buildIndex(reader, new BBox(-180, 180, -90, 90));
    BBox almostWorldWide = new BBox(-179, 179, -89, 89);
    // Might fail if a polygon is defined outside the above coordinates
    assertTrue("BBox seems to be not contracted", almostWorldWide.contains(spatialRuleLookup.getBounds()));
}
Also used : BBox(com.graphhopper.util.shapes.BBox) Test(org.junit.Test)

Example 22 with BBox

use of com.graphhopper.util.shapes.BBox in project graphhopper by graphhopper.

the class SpatialRuleLookupBuilderTest method testIntersection.

@Test
public void testIntersection() {
    /*
            We are creating a BBox smaller than Germany. We have the German Spatial rule activated by default.
            So the BBox should not contain a Point lying somewhere close in Germany.
         */
    Reader reader = new InputStreamReader(SpatialRuleLookupBuilderTest.class.getResourceAsStream("countries.geo.json"));
    SpatialRuleLookup spatialRuleLookup = DefaultModule.buildIndex(reader, new BBox(9, 10, 51, 52));
    assertFalse("BBox seems to be incorrectly contracted", spatialRuleLookup.getBounds().contains(49.9, 8.9));
}
Also used : BBox(com.graphhopper.util.shapes.BBox) Test(org.junit.Test)

Example 23 with BBox

use of com.graphhopper.util.shapes.BBox in project graphhopper by graphhopper.

the class FeatureJsonDeserializer method parseBBox.

private BBox parseBBox(JsonArray arr) {
    // The axes order of a bbox follows the axes order of geometries => lon,lat,ele
    if (arr.size() == 6) {
        double minLon = arr.get(0).getAsDouble();
        double minLat = arr.get(1).getAsDouble();
        double minEle = arr.get(2).getAsDouble();
        double maxLon = arr.get(3).getAsDouble();
        double maxLat = arr.get(4).getAsDouble();
        double maxEle = arr.get(5).getAsDouble();
        return new BBox(minLon, maxLon, minLat, maxLat, minEle, maxEle);
    } else if (arr.size() == 4) {
        double minLon = arr.get(0).getAsDouble();
        double minLat = arr.get(1).getAsDouble();
        double maxLon = arr.get(2).getAsDouble();
        double maxLat = arr.get(3).getAsDouble();
        return new BBox(minLon, maxLon, minLat, maxLat);
    } else {
        throw new IllegalArgumentException("Illegal array dimension (" + arr.size() + ") of bbox " + arr.toString());
    }
}
Also used : BBox(com.graphhopper.util.shapes.BBox)

Example 24 with BBox

use of com.graphhopper.util.shapes.BBox in project graphhopper by graphhopper.

the class GraphicsWrapper method setBounds.

public BBox setBounds(int minX, int maxX, int minY, int maxY) {
    double minLon = getLon(minX);
    double maxLon = getLon(maxX);
    double maxLat = getLat(minY);
    double minLat = getLat(maxY);
    bounds = new BBox(minLon, maxLon, minLat, maxLat);
    return bounds;
}
Also used : BBox(com.graphhopper.util.shapes.BBox)

Example 25 with BBox

use of com.graphhopper.util.shapes.BBox in project graphhopper by graphhopper.

the class Measurement method printLocationIndexQuery.

private void printLocationIndexQuery(Graph g, final LocationIndex idx, int count) {
    count *= 2;
    final BBox bbox = g.getBounds();
    final double latDelta = bbox.maxLat - bbox.minLat;
    final double lonDelta = bbox.maxLon - bbox.minLon;
    final Random rand = new Random(seed);
    MiniPerfTest miniPerf = new MiniPerfTest() {

        @Override
        public int doCalc(boolean warmup, int run) {
            double lat = rand.nextDouble() * latDelta + bbox.minLat;
            double lon = rand.nextDouble() * lonDelta + bbox.minLon;
            int val = idx.findClosest(lat, lon, EdgeFilter.ALL_EDGES).getClosestNode();
            return val;
        }
    }.setIterations(count).start();
    print("location_index", miniPerf);
}
Also used : Random(java.util.Random) BBox(com.graphhopper.util.shapes.BBox)

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