use of com.graphhopper.routing.util.spatialrules.SpatialRuleLookupBuilder in project graphhopper by graphhopper.
the class DefaultModule method buildIndex.
static SpatialRuleLookup buildIndex(Reader reader, BBox graphBBox) {
GHJson ghJson = new GHJsonBuilder().create();
JsonFeatureCollection jsonFeatureCollection = ghJson.fromJson(reader, JsonFeatureCollection.class);
return new SpatialRuleLookupBuilder().build(Arrays.asList(new GermanySpatialRule(), new AustriaSpatialRule()), jsonFeatureCollection, graphBBox, 1, true);
}
use of com.graphhopper.routing.util.spatialrules.SpatialRuleLookupBuilder 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;
}
Aggregations