use of com.graphhopper.routing.util.spatialrules.SpatialRuleLookup in project graphhopper by graphhopper.
the class DefaultModule method createGraphHopper.
/**
* @return an initialized GraphHopper instance
*/
protected GraphHopper createGraphHopper(CmdArgs args) {
GraphHopper tmp = new GraphHopperOSM() {
@Override
protected void loadOrPrepareLM() {
if (!getLMFactoryDecorator().isEnabled() || getLMFactoryDecorator().getPreparations().isEmpty())
return;
try {
String location = args.get(Parameters.Landmark.PREPARE + "split_area_location", "");
Reader reader = location.isEmpty() ? new InputStreamReader(LandmarkStorage.class.getResource("map.geo.json").openStream()) : new FileReader(location);
JsonFeatureCollection jsonFeatureCollection = new GHJsonBuilder().create().fromJson(reader, JsonFeatureCollection.class);
if (!jsonFeatureCollection.getFeatures().isEmpty()) {
SpatialRuleLookup ruleLookup = new SpatialRuleLookupBuilder().build("country", new SpatialRuleLookupBuilder.SpatialRuleDefaultFactory(), jsonFeatureCollection, getGraphHopperStorage().getBounds(), 0.1, true);
for (PrepareLandmarks prep : getLMFactoryDecorator().getPreparations()) {
prep.setSpatialRuleLookup(ruleLookup);
}
}
} catch (IOException ex) {
logger.error("Problem while reading border map GeoJSON. Skipping this.", ex);
}
super.loadOrPrepareLM();
}
}.forServer().init(args);
String location = args.get("spatial_rules.location", "");
if (!location.isEmpty()) {
if (!tmp.getEncodingManager().supports(("generic"))) {
logger.warn("spatial_rules.location was specified but 'generic' encoder is missing to utilize the index");
} else
try {
SpatialRuleLookup index = buildIndex(new FileReader(location), tmp.getGraphHopperStorage().getBounds());
if (index != null) {
logger.info("Set spatial rule lookup with " + index.size() + " rules");
((DataFlagEncoder) tmp.getEncodingManager().getEncoder("generic")).setSpatialRuleLookup(index);
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
tmp.importOrLoad();
logger.info("loaded graph at:" + tmp.getGraphHopperLocation() + ", data_reader_file:" + tmp.getDataReaderFile() + ", flag_encoders:" + tmp.getEncodingManager() + ", " + tmp.getGraphHopperStorage().toDetailsString());
return tmp;
}
use of com.graphhopper.routing.util.spatialrules.SpatialRuleLookup in project graphhopper by graphhopper.
the class LandmarkStorageTest method testWithBorderBlocking.
@Test
public void testWithBorderBlocking() {
AbstractRoutingAlgorithmTester.initBiGraph(ghStorage);
LandmarkStorage storage = new LandmarkStorage(ghStorage, new RAMDirectory(), 2, new FastestWeighting(encoder), TraversalMode.NODE_BASED);
final SpatialRule ruleRight = new DefaultSpatialRule() {
@Override
public String getId() {
return "right";
}
};
final SpatialRule ruleLeft = new DefaultSpatialRule() {
@Override
public String getId() {
return "left";
}
};
final SpatialRuleLookup lookup = new SpatialRuleLookup() {
@Override
public SpatialRule lookupRule(double lat, double lon) {
if (lon > 0.00105)
return ruleRight;
return ruleLeft;
}
@Override
public SpatialRule lookupRule(GHPoint point) {
return lookupRule(point.lat, point.lon);
}
@Override
public void addRule(SpatialRule rule) {
}
@Override
public int getSpatialId(SpatialRule rule) {
throw new IllegalStateException();
}
@Override
public BBox getBounds() {
throw new IllegalStateException();
}
@Override
public int size() {
return 2;
}
};
storage.setSpatialRuleLookup(lookup);
storage.setMinimumNodes(2);
storage.createLandmarks();
assertEquals(3, storage.getSubnetworksWithLandmarks());
}
Aggregations