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 FileCurrently we use this for a few tests where the dataReaderFile is loaded from the classpathprotected EncodingManagerbuildEncodingManager(Map<String, PMap> encodedValuesWithProps, Map<String, ImportUnit> activeImportUnits, Map<String, List<String>> restrictionVehicleTypesByProfile) protected OSMParsersbuildOSMParsers(Map<String, PMap> encodedValuesWithProps, Map<String, ImportUnit> activeImportUnits, Map<String, List<String>> restrictionVehicleTypesByProfile, List<String> ignoredHighways) voidvoidclean()Removes the on-disc routing files.protected voidcleanUp()Internal method to clean up the graph.voidclose()Releases all associated resources like memory or files.protected voidprotected LocationIndexprotected List<BooleanEncodedValue> final WeightingcreateWeighting(Profile profile, PMap hints) final WeightingcreateWeighting(Profile profile, PMap hints, boolean disableTurnCosts) protected WeightingFactoryprotected RouterdoCreateRouter(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 voidprotected voidprotected voidflush()The underlying graph used in algorithms.final CHPreparationHandlergetEVSortIndex(Map<String, Profile> profilesByName) booleanfinal LMPreparationHandlerThe location index created from the graph.getNavigationMode(String profileName) getProfile(String profileName) Returns the profile for the given profile name, or null if it does not existprotected intgetProfileHash(Profile profile) booleanvoidImports and processes data, storing it to disk when complete.Imports provided data from disc and creates graph.protected voidprotected voidinit(GraphHopperConfig ghConfig) Reads the configuration from aGraphHopperConfigobject which can be manually filled, or more typically is read from `config.yml`.protected voidInitializes the location index after the import is done.booleanstatic longlatLonToHilbertIndex(double lat, double lon, int order) booleanload()Load from existing graph folder.protected voidloadOrPrepareCH(boolean closeEarly) protected voidloadOrPrepareLM(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 voidprotected voidpostProcessing(boolean closeEarly) Runs both after the import and when loading an existing Graphprotected Map<String, PrepareContractionHierarchies.Result> protected voidprotected List<PrepareLandmarks> protected voidprocess(boolean closeEarly) Creates the graph from OSM data.static JsonFeatureCollectionresolveCustomAreas(String customAreasDirectory) resolveCustomModelFiles(String customModelFolder, List<Profile> profiles, JsonFeatureCollection globalAreas) setAllowWrites(boolean allowWrites) Specifies if it is allowed for GraphHopper to write.voidsetBaseGraph(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 voidsetLocationIndex(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) setSortGraph(boolean sortGraph) 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.static voidstatic voidsortGraphForGivenOrdering(BaseGraph baseGraph, com.carrotsearch.hppc.IntArrayList newNodesByOldNodes, com.carrotsearch.hppc.IntArrayList newEdgesByOldEdges) static longxy2d(int n, long x, long y)
-
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.
- See Also:
-
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
-
setSortGraph
-
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 aGraphHopperConfigobject 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
-
createSubnetworkEncodedValues
-
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() -
sortGraphAlongHilbertCurve
-
sortGraphForGivenOrdering
public static void sortGraphForGivenOrdering(BaseGraph baseGraph, com.carrotsearch.hppc.IntArrayList newNodesByOldNodes, com.carrotsearch.hppc.IntArrayList newEdgesByOldEdges) -
latLonToHilbertIndex
public static long latLonToHilbertIndex(double lat, double lon, int order) -
xy2d
public static long xy2d(int n, long x, long y) -
_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. -
getProfileHash
-
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
-