use of com.graphhopper.reader.osm.GraphHopperOSM in project graphhopper by graphhopper.
the class ShapeFileReaderTest method setupBeforeClass.
/**
* Build the graphs once only for the various tests
*/
@BeforeClass
public static void setupBeforeClass() {
try {
new File(tempOutputDirFromShp).mkdirs();
new File(tempOutputDirFromPbf).mkdirs();
hopperShp = initHopper(new GraphHopperSHP(), shapefile, tempOutputDirFromShp);
hopperPbf = initHopper(new GraphHopperOSM(), pbf, tempOutputDirFromPbf);
} catch (Exception e) {
// Junit silently fails if we get an exception in the setup before
// class,
// so we record it here and explicitly rethrow it
BEFORE_CLASS_EXCEPTION = e;
}
}
use of com.graphhopper.reader.osm.GraphHopperOSM in project graphhopper by graphhopper.
the class MiniGraphUI method main.
public static void main(String[] strs) throws Exception {
CmdArgs args = CmdArgs.read(strs);
GraphHopper hopper = new GraphHopperOSM().init(args).importOrLoad();
boolean debug = args.getBool("minigraphui.debug", false);
new MiniGraphUI(hopper, debug).visualize();
}
use of com.graphhopper.reader.osm.GraphHopperOSM 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.reader.osm.GraphHopperOSM in project graphhopper by graphhopper.
the class GraphHopperIT method beforeClass.
@BeforeClass
public static void beforeClass() {
// make sure we are using fresh graphhopper files with correct vehicle
Helper.removeDir(new File(graphFileFoot));
hopper = new GraphHopperOSM().setOSMFile(osmFile).setStoreOnFlush(true).setCHEnabled(false).setGraphHopperLocation(graphFileFoot).setEncodingManager(new EncodingManager(importVehicles)).importOrLoad();
}
use of com.graphhopper.reader.osm.GraphHopperOSM in project graphhopper by graphhopper.
the class GraphHopperIT method testMultipleVehiclesWithCH.
@Test
public void testMultipleVehiclesWithCH() {
String tmpOsmFile = DIR + "/monaco.osm.gz";
GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(tmpOsmFile).setStoreOnFlush(true).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager("bike,car")).importOrLoad();
assertEquals("bike", tmpHopper.getDefaultVehicle().toString());
checkMultiVehiclesWithCH(tmpHopper);
tmpHopper.close();
tmpHopper.clean();
// new instance, try different order, resulting only in different default vehicle
tmpHopper = new GraphHopperOSM().setOSMFile(tmpOsmFile).setStoreOnFlush(true).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager("car,bike")).importOrLoad();
assertEquals("car", tmpHopper.getDefaultVehicle().toString());
checkMultiVehiclesWithCH(tmpHopper);
tmpHopper.close();
}
Aggregations