Package com.graphhopper
Class GraphHopper
java.lang.Object
com.graphhopper.GraphHopper
Easy to use access point to configure import and (offline) routing.
- Author:
- Peter Karich
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected File
Currently we use this for a few tests where the dataReaderFile is loaded from the classpathprotected EncodingManager
buildEncodingManager
(Map<String, PMap> encodedValuesWithProps, Map<String, ImportUnit> activeImportUnits, Map<String, List<String>> restrictionVehicleTypesByProfile) protected OSMParsers
buildOSMParsers
(Map<String, PMap> encodedValuesWithProps, Map<String, ImportUnit> activeImportUnits, Map<String, List<String>> restrictionVehicleTypesByProfile, List<String> ignoredHighways, String dateRangeParserString) void
void
clean()
Removes the on-disc routing files.protected void
cleanUp()
Internal method to clean up the graph.void
close()
Releases all associated resources like memory or files.protected void
protected LocationIndex
final Weighting
createWeighting
(Profile profile, PMap hints) final Weighting
createWeighting
(Profile profile, PMap hints, boolean disableTurnCosts) protected WeightingFactory
protected Router
doCreateRouter
(BaseGraph baseGraph, EncodingManager encodingManager, LocationIndex locationIndex, Map<String, Profile> profilesByName, PathDetailsBuilderFactory pathBuilderFactory, TranslationMap trMap, RouterConfig routerConfig, WeightingFactory weightingFactory, Map<String, RoutingCHGraph> chGraphs, Map<String, LandmarkStorage> landmarks) protected void
protected void
protected void
flush()
The underlying graph used in algorithms.final CHPreparationHandler
getEVSortIndex
(Map<String, Profile> profilesByName) boolean
final LMPreparationHandler
The location index created from the graph.getProfile
(String profileName) Returns the profile for the given profile name, or null if it does not existboolean
void
Imports and processes data, storing it to disk when complete.Imports provided data from disc and creates graph.protected void
protected void
init
(GraphHopperConfig ghConfig) Reads the configuration from aGraphHopperConfig
object which can be manually filled, or more typically is read from `config.yml`.protected void
Initializes the location index after the import is done.boolean
boolean
load()
Load from existing graph folder.protected void
loadOrPrepareCH
(boolean closeEarly) protected void
loadOrPrepareLM
(boolean closeEarly) For landmarks it is required to always call this method: either it creates the landmark data or it loads it.parseEncodedValueString
(String encodedValuesStr) protected void
protected void
postProcessing
(boolean closeEarly) Runs both after the import and when loading an existing Graphprotected Map<String,
PrepareContractionHierarchies.Result> protected void
protected List<PrepareLandmarks>
protected void
process
(boolean closeEarly) Creates the graph from OSM data.static JsonFeatureCollection
resolveCustomAreas
(String customAreasDirectory) resolveCustomModelFiles
(String customModelFolder, List<Profile> profiles, JsonFeatureCollection globalAreas) setAllowWrites
(boolean allowWrites) Specifies if it is allowed for GraphHopper to write.void
setBaseGraph
(BaseGraph baseGraph) setCountryRuleFactory
(CountryRuleFactory countryRuleFactory) Sets the factory used to create country rules.setCustomAreasDirectory
(String customAreasDirectory) setElevation
(boolean includeElevation) Enable storing and fetching elevation data.setElevationProvider
(ElevationProvider eleProvider) setEncodedValuesString
(String encodedValuesString) setGraphHopperLocation
(String ghLocation) Sets the graphhopper folder.setImportRegistry
(ImportRegistry importRegistry) protected void
setLocationIndex
(LocationIndex locationIndex) setMaxSpeedCalculator
(MaxSpeedCalculator maxSpeedCalculator) setMinNetworkSize
(int minNetworkSize) setOSMFile
(String osmFile) This file can be an osm xml (.osm), a compressed xml (.osm.zip or .osm.gz) or a protobuf file (.pbf).setPathDetailsBuilderFactory
(PathDetailsBuilderFactory pathBuilderFactory) setPreciseIndexResolution
(int precision) Precise location resolution index means also more space (disc/RAM) could be consumed and probably slower query times, which would be e.g.setProfiles
(Profile... profiles) Sets the routing profiles that shall be supported by this GraphHopper instance.setProfiles
(List<Profile> profiles) setStoreOnFlush
(boolean storeOnFlush) Only valid option for in-memory graph and if you e.g.setUrbanDensityCalculation
(double residentialAreaRadius, double residentialAreaSensitivity, double cityAreaRadius, double cityAreaSensitivity, int threads) Configures the urban density classification.
-
Field Details
-
encodingManager
-
-
Constructor Details
-
GraphHopper
public GraphHopper()
-
-
Method Details
-
setEncodedValuesString
-
getEncodedValuesString
-
getEncodingManager
-
getOSMParsers
-
getElevationProvider
-
setElevationProvider
-
setPathDetailsBuilderFactory
-
getPathDetailsBuilderFactory
-
setPreciseIndexResolution
Precise location resolution index means also more space (disc/RAM) could be consumed and probably slower query times, which would be e.g. not suitable for Android. The resolution specifies the tile width (in meter). -
setMinNetworkSize
-
setUrbanDensityCalculation
public GraphHopper setUrbanDensityCalculation(double residentialAreaRadius, double residentialAreaSensitivity, double cityAreaRadius, double cityAreaSensitivity, int threads) Configures the urban density classification. Each edge will be classified as 'rural','residential' or 'city',UrbanDensity
- Parameters:
residentialAreaRadius
- in meters. The higher this value the longer the calculation will take and the bigger the area for which the road density used to identify residential areas is calculated.residentialAreaSensitivity
- Use this to find a trade-off between too many roads being classified as residential (too high values) and not enough roads being classified as residential (too small values)cityAreaRadius
- in meters. The higher this value the longer the calculation will take and the bigger the area for which the road density used to identify city areas is calculated. Set this to zero to skip the city classification.cityAreaSensitivity
- Use this to find a trade-off between too many roads being classified as city (too high values) and not enough roads being classified as city (too small values)threads
- the number of threads used for the calculation. If this is zero the urban density calculation is skipped entirely
-
setStoreOnFlush
Only valid option for in-memory graph and if you e.g. want to disable store on flush for unit tests. Specify storeOnFlush to true if you want that existing data will be loaded FROM disc and all in-memory data will be flushed TO disc after flush is called e.g. while OSM import.- Parameters:
storeOnFlush
- true by default
-
setProfiles
Sets the routing profiles that shall be supported by this GraphHopper instance. The (and only the) given profiles can be used for routing without preparation and for CH/LM preparation.Here is an example how to setup two CH profiles and one LM profile (via the Java API)
hopper.setProfiles( new Profile("my_car"), new Profile("your_bike") ); hopper.getCHPreparationHandler().setCHProfiles( new CHProfile("my_car"), new CHProfile("your_bike") ); hopper.getLMPreparationHandler().setLMProfiles( new LMProfile("your_bike") );
See also https://github.com/graphhopper/graphhopper/pull/1922.
-
setProfiles
-
getProfiles
-
getProfile
Returns the profile for the given profile name, or null if it does not exist -
hasElevation
public boolean hasElevation()- Returns:
- true if storing and fetching elevation data is enabled. Default is false
-
setElevation
Enable storing and fetching elevation data. Default is false -
getGraphHopperLocation
-
setGraphHopperLocation
Sets the graphhopper folder. -
getOSMFile
-
setOSMFile
This file can be an osm xml (.osm), a compressed xml (.osm.zip or .osm.gz) or a protobuf file (.pbf). -
setMaxSpeedCalculator
-
getBaseGraph
The underlying graph used in algorithms.- Throws:
IllegalStateException
- if graph is not instantiated.
-
setBaseGraph
-
getProperties
-
getCHGraphs
- Returns:
- a mapping between profile names and according CH preparations. The map will be empty before loading or import.
-
getLandmarks
- Returns:
- a mapping between profile names and according landmark preparations. The map will be empty before loading or import.
-
getLocationIndex
The location index created from the graph.- Throws:
IllegalStateException
- if index is not initialized
-
setLocationIndex
-
isAllowWrites
public boolean isAllowWrites() -
setAllowWrites
Specifies if it is allowed for GraphHopper to write. E.g. for read only filesystems it is not possible to create a lock file and so we can avoid write locks. -
getTranslationMap
-
setImportRegistry
-
getImportRegistry
-
setCustomAreasDirectory
-
getCustomAreasDirectory
-
setCountryRuleFactory
Sets the factory used to create country rules. Use `null` to disable country rules -
getCountryRuleFactory
-
init
Reads the configuration from aGraphHopperConfig
object which can be manually filled, or more typically is read from `config.yml`.Important note: Calling this method overwrites the configuration done in some of the setter methods of this class, so generally it is advised to either use this method to configure GraphHopper or the different setter methods, but not both. Unfortunately, this still does not cover all cases and sometimes you have to use both, but then you should make sure there are no conflicts. If you need both it might also help to call the init before calling the setters, because this way the init method won't apply defaults to configuration options you already chose using the setters.
-
buildEncodingManager
-
getEVSortIndex
-
buildOSMParsers
-
parseEncodedValueString
-
importOrLoad
Imports provided data from disc and creates graph. Depending on the settings the resulting graph will be stored to disc so on a second call this method will only load the graph from disc which is usually a lot faster. -
importAndClose
public void importAndClose()Imports and processes data, storing it to disk when complete. -
process
protected void process(boolean closeEarly) Creates the graph from OSM data. -
prepareImport
protected void prepareImport() -
postImportOSM
protected void postImportOSM() -
importOSM
protected void importOSM() -
createBaseGraphAndProperties
protected void createBaseGraphAndProperties() -
_getOSMFile
Currently we use this for a few tests where the dataReaderFile is loaded from the classpath -
load
public boolean load()Load from existing graph folder. -
checkProfilesConsistency
public void checkProfilesConsistency() -
getCHPreparationHandler
-
getLMPreparationHandler
-
postProcessing
protected void postProcessing(boolean closeEarly) Runs both after the import and when loading an existing Graph- Parameters:
closeEarly
- release resources as early as possible
-
importPublicTransit
protected void importPublicTransit() -
createWeighting
-
createWeighting
-
createWeightingFactory
-
route
-
doCreateRouter
protected Router doCreateRouter(BaseGraph baseGraph, EncodingManager encodingManager, LocationIndex locationIndex, Map<String, Profile> profilesByName, PathDetailsBuilderFactory pathBuilderFactory, TranslationMap trMap, RouterConfig routerConfig, WeightingFactory weightingFactory, Map<String, RoutingCHGraph> chGraphs, Map<String, LandmarkStorage> landmarks) -
createLocationIndex
-
initLocationIndex
protected void initLocationIndex()Initializes the location index after the import is done. -
loadOrPrepareCH
protected void loadOrPrepareCH(boolean closeEarly) -
prepareCH
protected Map<String,PrepareContractionHierarchies.Result> prepareCH(boolean closeEarly, List<CHConfig> configsToPrepare) -
loadOrPrepareLM
protected void loadOrPrepareLM(boolean closeEarly) For landmarks it is required to always call this method: either it creates the landmark data or it loads it. -
prepareLM
-
cleanUp
protected void cleanUp()Internal method to clean up the graph. -
flush
protected void flush() -
close
public void close()Releases all associated resources like memory or files. But it does not remove them. To remove the files created in graphhopperLocation you have to call clean(). -
clean
public void clean()Removes the on-disc routing files. Call only after calling close or before importOrLoad or load -
ensureNotLoaded
protected void ensureNotLoaded() -
ensureWriteAccess
protected void ensureWriteAccess() -
getFullyLoaded
public boolean getFullyLoaded() -
getRouterConfig
-
getReaderConfig
-
resolveCustomAreas
-
resolveCustomModelFiles
-