use of com.graphhopper.json.GHJsonFactory in project graphhopper by graphhopper.
the class SpatialRuleLookupBuilderTest method testIndex.
@Test
public void testIndex() throws FileNotFoundException {
final FileReader reader = new FileReader(COUNTRIES_FILE);
SpatialRuleLookup spatialRuleLookup = SpatialRuleLookupBuilder.buildIndex(new GHJsonFactory().create().fromJson(reader, JsonFeatureCollection.class), "ISO_A3", new CountriesSpatialRuleFactory());
// Berlin
Assert.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));
}
use of com.graphhopper.json.GHJsonFactory in project graphhopper by graphhopper.
the class SpatialRuleLookupHelper method buildAndInjectSpatialRuleIntoGH.
public static void buildAndInjectSpatialRuleIntoGH(GraphHopper graphHopper, CmdArgs args) {
String spatialRuleLocation = args.get("spatial_rules.location", "");
if (!spatialRuleLocation.isEmpty()) {
try {
final BBox maxBounds = BBox.parseBBoxString(args.get("spatial_rules.max_bbox", "-180, 180, -90, 90"));
final InputStreamReader reader = new InputStreamReader(new FileInputStream(spatialRuleLocation), UTF_CS);
final SpatialRuleLookup index = SpatialRuleLookupBuilder.buildIndex(new GHJsonFactory().create().fromJson(reader, JsonFeatureCollection.class), "ISO_A3", new CountriesSpatialRuleFactory(), .1, maxBounds);
logger.info("Set spatial rule lookup with " + index.size() + " rules");
final FlagEncoderFactory oldFEF = graphHopper.getFlagEncoderFactory();
graphHopper.setFlagEncoderFactory(new FlagEncoderFactory() {
@Override
public FlagEncoder createFlagEncoder(String name, PMap configuration) {
if (name.equals(GENERIC)) {
return new DataFlagEncoder(configuration).setSpatialRuleLookup(index);
}
return oldFEF.createFlagEncoder(name, configuration);
}
});
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
use of com.graphhopper.json.GHJsonFactory in project graphhopper by graphhopper.
the class SpatialRuleLookupBuilderTest method testNoIntersection.
@Test
public void testNoIntersection() throws FileNotFoundException {
final FileReader reader = new FileReader(COUNTRIES_FILE);
SpatialRuleLookup spatialRuleLookup = SpatialRuleLookupBuilder.buildIndex(new GHJsonFactory().create().fromJson(reader, JsonFeatureCollection.class), "ISO_A3", new CountriesSpatialRuleFactory(), .1, new BBox(-180, -179, -90, -89));
assertEquals(SpatialRuleLookup.EMPTY, spatialRuleLookup);
}
use of com.graphhopper.json.GHJsonFactory in project graphhopper by graphhopper.
the class SpatialRuleLookupBuilderTest method testBounds.
@Test
public void testBounds() throws FileNotFoundException {
final FileReader reader = new FileReader(COUNTRIES_FILE);
SpatialRuleLookup spatialRuleLookup = SpatialRuleLookupBuilder.buildIndex(new GHJsonFactory().create().fromJson(reader, JsonFeatureCollection.class), "ISO_A3", new CountriesSpatialRuleFactory(), .1, 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.json.GHJsonFactory in project graphhopper by graphhopper.
the class SpatialRuleLookupBuilderTest method testIntersection.
@Test
public void testIntersection() throws FileNotFoundException {
/*
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.
*/
final FileReader reader = new FileReader(COUNTRIES_FILE);
SpatialRuleLookup spatialRuleLookup = SpatialRuleLookupBuilder.buildIndex(new GHJsonFactory().create().fromJson(reader, JsonFeatureCollection.class), "ISO_A3", new CountriesSpatialRuleFactory(), .1, new BBox(9, 10, 51, 52));
assertFalse("BBox seems to be incorrectly contracted", spatialRuleLookup.getBounds().contains(49.9, 8.9));
}
Aggregations