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