Search in sources :

Example 31 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 32 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 33 with BBox

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

the class GraphHopperAPITest method testConcurrentGraphChange.

@Test
public void testConcurrentGraphChange() throws InterruptedException {
    final GraphHopperStorage graph = new GraphBuilder(encodingManager).create();
    initGraph(graph);
    graph.edge(1, 2, 10, true);
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicInteger checkPointCounter = new AtomicInteger(0);
    final GraphHopper graphHopper = new GraphHopper() {

        @Override
        protected ChangeGraphHelper createChangeGraphHelper(Graph graph, LocationIndex locationIndex) {
            return new ChangeGraphHelper(graph, locationIndex) {

                @Override
                public long applyChanges(EncodingManager em, Collection<JsonFeature> features) {
                    // force sleep inside the lock and let the main thread run until the lock barrier
                    latch.countDown();
                    try {
                        Thread.sleep(400);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    checkPointCounter.incrementAndGet();
                    return super.applyChanges(em, features);
                }
            };
        }
    }.setStoreOnFlush(false).setEncodingManager(encodingManager).setCHEnabled(false).loadGraph(graph);
    GHResponse rsp = graphHopper.route(new GHRequest(42, 10.4, 42, 10));
    assertFalse(rsp.toString(), rsp.hasErrors());
    assertEquals(1800, rsp.getBest().getTime());
    final List<JsonFeature> list = new ArrayList<>();
    Map<String, Object> properties = new HashMap<>();
    properties.put("speed", 5);
    list.add(new JsonFeature("1", "bbox", new BBox(10.399, 10.4, 42.0, 42.001), null, properties));
    ExecutorService executorService = Executors.newFixedThreadPool(1);
    executorService.submit(new Runnable() {

        @Override
        public void run() {
            graphHopper.changeGraph(list);
            checkPointCounter.incrementAndGet();
        }
    });
    latch.await();
    assertEquals(0, checkPointCounter.get());
    rsp = graphHopper.route(new GHRequest(42, 10.4, 42, 10));
    assertFalse(rsp.toString(), rsp.hasErrors());
    assertEquals(8400, rsp.getBest().getTime());
    executorService.shutdown();
    executorService.awaitTermination(3, TimeUnit.SECONDS);
    assertEquals(2, checkPointCounter.get());
}
Also used : ChangeGraphHelper(com.graphhopper.storage.change.ChangeGraphHelper) GraphBuilder(com.graphhopper.storage.GraphBuilder) EncodingManager(com.graphhopper.routing.util.EncodingManager) CountDownLatch(java.util.concurrent.CountDownLatch) LocationIndex(com.graphhopper.storage.index.LocationIndex) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) JsonFeature(com.graphhopper.json.geo.JsonFeature) Graph(com.graphhopper.storage.Graph) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BBox(com.graphhopper.util.shapes.BBox) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Example 34 with BBox

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

the class LinearKeyAlgoTest method testInstantiation.

/*
    * Test if different constructors yield same results
     */
@Test
public void testInstantiation() {
    double minLon = 0;
    double minLat = 2;
    double maxLat = 6;
    double maxLon = 5;
    BBox bounds = new BBox(minLon, maxLon, minLat, maxLat);
    LinearKeyAlgo algo1 = new LinearKeyAlgo(4, 4).setBounds(bounds);
    LinearKeyAlgo algo2 = new LinearKeyAlgo(4, 4).setBounds(minLon, maxLon, minLat, maxLat);
    assertEquals(algo1.getLonDelta(), algo2.getLonDelta(), 1e-7);
    assertEquals(algo1.getLatDelta(), algo2.getLatDelta(), 1e-7);
}
Also used : BBox(com.graphhopper.util.shapes.BBox) Test(org.junit.Test)

Example 35 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)

Aggregations

BBox (com.graphhopper.util.shapes.BBox)38 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)11 GHPoint (com.graphhopper.util.shapes.GHPoint)7 GHJsonFactory (com.graphhopper.json.GHJsonFactory)4 JsonFeatureCollection (com.graphhopper.json.geo.JsonFeatureCollection)4 JsonFeature (com.graphhopper.json.geo.JsonFeature)3 Graph (com.graphhopper.storage.Graph)3 IntArrayList (com.carrotsearch.hppc.IntArrayList)2 IntHashSet (com.carrotsearch.hppc.IntHashSet)2 EdgeFilter (com.graphhopper.routing.util.EdgeFilter)2 SpatialRuleLookup (com.graphhopper.routing.util.spatialrules.SpatialRuleLookup)2 GraphBuilder (com.graphhopper.storage.GraphBuilder)2 PMap (com.graphhopper.util.PMap)2 PointList (com.graphhopper.util.PointList)2 Circle (com.graphhopper.util.shapes.Circle)2 Map (java.util.Map)2 IntIntHashMap (com.carrotsearch.hppc.IntIntHashMap)1 IntLongHashMap (com.carrotsearch.hppc.IntLongHashMap)1 GTFSFeed (com.conveyal.gtfs.GTFSFeed)1