Search in sources :

Example 21 with GraphHopperOSM

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;
    }
}
Also used : GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM) File(java.io.File) URISyntaxException(java.net.URISyntaxException) BeforeClass(org.junit.BeforeClass)

Example 22 with GraphHopperOSM

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();
}
Also used : GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM) GraphHopper(com.graphhopper.GraphHopper)

Example 23 with GraphHopperOSM

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;
}
Also used : GHJsonBuilder(com.graphhopper.json.GHJsonBuilder) InputStreamReader(java.io.InputStreamReader) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) FileReader(java.io.FileReader) GraphHopper(com.graphhopper.GraphHopper) SpatialRuleLookup(com.graphhopper.routing.util.spatialrules.SpatialRuleLookup) IOException(java.io.IOException) LandmarkStorage(com.graphhopper.routing.lm.LandmarkStorage) PrepareLandmarks(com.graphhopper.routing.lm.PrepareLandmarks) JsonFeatureCollection(com.graphhopper.json.geo.JsonFeatureCollection) FileReader(java.io.FileReader) SpatialRuleLookupBuilder(com.graphhopper.routing.util.spatialrules.SpatialRuleLookupBuilder)

Example 24 with GraphHopperOSM

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();
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM) File(java.io.File)

Example 25 with GraphHopperOSM

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();
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM)

Aggregations

GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)26 EncodingManager (com.graphhopper.routing.util.EncodingManager)18 GraphHopper (com.graphhopper.GraphHopper)7 SRTMProvider (com.graphhopper.reader.dem.SRTMProvider)4 GHPoint (com.graphhopper.util.shapes.GHPoint)4 File (java.io.File)4 IOException (java.io.IOException)3 AlgoHelperEntry (com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry)2 OneRun (com.graphhopper.routing.util.TestAlgoCollector.OneRun)2 Weighting (com.graphhopper.routing.weighting.Weighting)2 LocationIndex (com.graphhopper.storage.index.LocationIndex)2 Provides (com.google.inject.Provides)1 GHBitSet (com.graphhopper.coll.GHBitSet)1 GHJsonBuilder (com.graphhopper.json.GHJsonBuilder)1 JsonFeatureCollection (com.graphhopper.json.geo.JsonFeatureCollection)1 DataReader (com.graphhopper.reader.DataReader)1 LandmarkStorage (com.graphhopper.routing.lm.LandmarkStorage)1 PrepareLandmarks (com.graphhopper.routing.lm.PrepareLandmarks)1 SpatialRuleLookup (com.graphhopper.routing.util.spatialrules.SpatialRuleLookup)1 SpatialRuleLookupBuilder (com.graphhopper.routing.util.spatialrules.SpatialRuleLookupBuilder)1