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