public class GraphHopper extends Object implements GraphHopperAPI
GraphHopperAPI
Constructor and Description |
---|
GraphHopper() |
Modifier and Type | Method and Description |
---|---|
List<Path> |
calcPaths(GHRequest request,
GHResponse ghRsp)
This method calculates the alternative path list using the low level Path objects.
|
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 LocationIndex |
createLocationIndex(Directory dir) |
protected DataReader |
createReader(GraphHopperStorage ghStorage) |
protected RoutingTemplate |
createRoutingTemplate(GHRequest request,
GHResponse ghRsp,
String algoStr,
Weighting weighting) |
Weighting |
createWeighting(Profile profile,
PMap hints) |
Weighting |
createWeighting(Profile profile,
PMap hints,
boolean disableTurnCosts) |
protected void |
ensureNotLoaded() |
protected void |
ensureWriteAccess() |
protected void |
flush() |
GraphHopper |
forDesktop()
Configures the underlying storage to be used on a Desktop computer or within another Java
application with enough RAM but no network latency.
|
GraphHopper |
forMobile()
Configures the underlying storage to be used on a less powerful machine like Android or
Raspberry Pi with only few MB of RAM.
|
GraphHopper |
forServer()
Configures the underlying storage and response to be used on a well equipped server.
|
RoutingAlgorithmFactory |
getAlgorithmFactory(String profile,
boolean disableCH,
boolean disableLM) |
CHPreparationHandler |
getCHPreparationHandler() |
String |
getDataReaderFile() |
ElevationProvider |
getElevationProvider() |
EncodedValueFactory |
getEncodedValueFactory() |
EncodingManager |
getEncodingManager() |
String |
getGraphHopperLocation() |
GraphHopperStorage |
getGraphHopperStorage()
The underlying graph used in algorithms.
|
LMPreparationHandler |
getLMPreparationHandler() |
LocationIndex |
getLocationIndex()
The location index created from the graph.
|
int |
getMaxVisitedNodes() |
PathDetailsBuilderFactory |
getPathDetailsBuilderFactory() |
Profile |
getProfile(String profileName)
Returns the profile for the given profile name, or null if it does not exist
|
List<Profile> |
getProfiles() |
TagParserFactory |
getTagParserFactory() |
TranslationMap |
getTranslationMap() |
protected double |
getWayPointMaxDistance()
Return maximum distance (in meter) to reduce points via douglas peucker while OSM import.
|
protected int |
getWorkerThreads()
Threads for data reading.
|
boolean |
hasElevation() |
void |
importAndClose()
Imports and processes data, storing it to disk when complete.
|
protected DataReader |
importData() |
GraphHopper |
importOrLoad()
Imports provided data from disc and creates graph.
|
protected void |
importPublicTransit() |
GraphHopper |
init(GraphHopperConfig ghConfig)
Reads the configuration from a
GraphHopperConfig object which can be manually filled, or more typically
is read from `config.yml`. |
protected DataReader |
initDataReader(DataReader reader) |
protected void |
initLocationIndex()
Initializes the location index after the import is done.
|
boolean |
isAllowWrites() |
boolean |
load(String graphHopperFolder)
Opens existing graph folder.
|
protected GraphHopper |
loadGraph(GraphHopperStorage g)
For testing only
|
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.
|
void |
postProcessing()
Does the preparation and creates the location index
|
protected void |
postProcessing(boolean closeEarly)
Does the preparation and creates the location index
|
protected void |
prepareCH(boolean closeEarly) |
protected void |
registerCustomEncodedValues(EncodingManager.Builder emBuilder) |
GHResponse |
route(GHRequest request) |
GraphHopper |
setAllowWrites(boolean allowWrites)
Specifies if it is allowed for GraphHopper to write.
|
GraphHopper |
setDataReaderFile(String dataReaderFileStr)
This file can be any file type supported by the DataReader.
|
GraphHopper |
setElevation(boolean includeElevation)
Enable storing and fetching elevation data.
|
GraphHopper |
setElevationProvider(ElevationProvider eleProvider) |
GraphHopper |
setEnableCalcPoints(boolean b)
This methods enables gps point calculation.
|
GraphHopper |
setEncodedValueFactory(EncodedValueFactory factory) |
GraphHopper |
setEncodingManager(EncodingManager em)
Specify which vehicles can be read by this GraphHopper instance.
|
GraphHopper |
setFlagEncoderFactory(FlagEncoderFactory factory) |
GraphHopper |
setGraphHopperLocation(String ghLocation)
Sets the graphhopper folder.
|
void |
setGraphHopperStorage(GraphHopperStorage ghStorage) |
GraphHopper |
setInMemory()
This method call results in an in-memory graph.
|
protected void |
setLocationIndex(LocationIndex locationIndex) |
void |
setMaxVisitedNodes(int maxVisitedNodes)
This methods stops the algorithm from searching further if the resulting path would go over
the specified node count, important if none-CH routing is used.
|
GraphHopper |
setMemoryMapped()
Enable memory mapped configuration if not enough memory is available on the target platform.
|
GraphHopper |
setMinNetworkSize(int minNetworkSize) |
void |
setNonChMaxWaypointDistance(int nonChMaxWaypointDistance) |
GraphHopper |
setPathDetailsBuilderFactory(PathDetailsBuilderFactory pathBuilderFactory) |
GraphHopper |
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.
|
GraphHopper |
setProfiles(List<Profile> profiles) |
GraphHopper |
setProfiles(Profile... profiles)
Sets the routing profiles that can be used for CH/LM preparation.
|
GraphHopper |
setSortGraph(boolean sortGraph)
Sorts the graph which requires more RAM while import.
|
GraphHopper |
setStoreOnFlush(boolean storeOnFlush)
Only valid option for in-memory graph and if you e.g.
|
GraphHopper |
setTagParserFactory(TagParserFactory factory) |
GraphHopper |
setWayPointMaxDistance(double wayPointMaxDistance)
This parameter specifies how to reduce points via douglas peucker while OSM import.
|
protected void |
validateRequest(GHRequest request) |
protected GraphHopper loadGraph(GraphHopperStorage g)
public EncodingManager getEncodingManager()
public GraphHopper setEncodingManager(EncodingManager em)
public ElevationProvider getElevationProvider()
public GraphHopper setElevationProvider(ElevationProvider eleProvider)
protected int getWorkerThreads()
protected double getWayPointMaxDistance()
public GraphHopper setWayPointMaxDistance(double wayPointMaxDistance)
public GraphHopper setPathDetailsBuilderFactory(PathDetailsBuilderFactory pathBuilderFactory)
public PathDetailsBuilderFactory getPathDetailsBuilderFactory()
public GraphHopper forServer()
public GraphHopper forDesktop()
public GraphHopper forMobile()
public GraphHopper setPreciseIndexResolution(int precision)
public GraphHopper setMinNetworkSize(int minNetworkSize)
public GraphHopper setInMemory()
public GraphHopper setStoreOnFlush(boolean storeOnFlush)
storeOnFlush
- true by defaultpublic GraphHopper setMemoryMapped()
public GraphHopper setProfiles(Profile... profiles)
Here is an example how to setup two CH profiles and one LM profile (via the Java API)
// make sure the encoding manager contains a "car" and a "bike" flag encoder
hopper.setProfiles(
new Profile("my_car").setVehicle("car").setWeighting("shortest"),
new Profile("your_bike").setVehicle("bike").setWeighting("fastest")
);
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.
public GraphHopper setProfiles(List<Profile> profiles)
public Profile getProfile(String profileName)
public int getMaxVisitedNodes()
public void setMaxVisitedNodes(int maxVisitedNodes)
public boolean hasElevation()
public GraphHopper setElevation(boolean includeElevation)
public GraphHopper setEnableCalcPoints(boolean b)
public String getGraphHopperLocation()
public GraphHopper setGraphHopperLocation(String ghLocation)
public String getDataReaderFile()
public GraphHopper setDataReaderFile(String dataReaderFileStr)
public GraphHopperStorage getGraphHopperStorage()
IllegalStateException
- if graph is not instantiated.public void setGraphHopperStorage(GraphHopperStorage ghStorage)
public LocationIndex getLocationIndex()
IllegalStateException
- if index is not initializedprotected void setLocationIndex(LocationIndex locationIndex)
public GraphHopper setSortGraph(boolean sortGraph)
public boolean isAllowWrites()
public GraphHopper setAllowWrites(boolean allowWrites)
public TranslationMap getTranslationMap()
public GraphHopper setFlagEncoderFactory(FlagEncoderFactory factory)
public EncodedValueFactory getEncodedValueFactory()
public GraphHopper setEncodedValueFactory(EncodedValueFactory factory)
public TagParserFactory getTagParserFactory()
public GraphHopper setTagParserFactory(TagParserFactory factory)
public GraphHopper init(GraphHopperConfig ghConfig)
GraphHopperConfig
object which can be manually filled, or more typically
is read from `config.yml`.public GraphHopper importOrLoad()
public void importAndClose()
protected DataReader importData() throws IOException
IOException
protected DataReader createReader(GraphHopperStorage ghStorage)
protected DataReader initDataReader(DataReader reader)
public boolean load(String graphHopperFolder)
load
in interface GraphHopperAPI
graphHopperFolder
- is the folder containing graphhopper files. Can be a compressed file
too ala folder-content.ghz.public RoutingAlgorithmFactory getAlgorithmFactory(String profile, boolean disableCH, boolean disableLM)
public final CHPreparationHandler getCHPreparationHandler()
public final LMPreparationHandler getLMPreparationHandler()
public final void postProcessing()
protected void postProcessing(boolean closeEarly)
closeEarly
- release resources as early as possibleprotected void registerCustomEncodedValues(EncodingManager.Builder emBuilder)
protected void importPublicTransit()
public Weighting createWeighting(Profile profile, PMap hints, boolean disableTurnCosts)
profile
- The profile for which the weighting shall be createdhints
- Additional hints that can be used to further specify the weighting that shall be createddisableTurnCosts
- Can be used to explicitly create the weighting without turn costs. This is sometimes needed when the
weighting shall be used by some algorithm that can only be run with node-based graph traversal, like
LM preparation or Isochronespublic GHResponse route(GHRequest request)
route
in interface GraphHopperAPI
public List<Path> calcPaths(GHRequest request, GHResponse ghRsp)
protected void validateRequest(GHRequest request)
protected RoutingTemplate createRoutingTemplate(GHRequest request, GHResponse ghRsp, String algoStr, Weighting weighting)
protected LocationIndex createLocationIndex(Directory dir)
protected void initLocationIndex()
protected void prepareCH(boolean closeEarly)
protected void loadOrPrepareLM(boolean closeEarly)
protected void cleanUp()
protected void flush()
public void close()
public void clean()
protected void ensureNotLoaded()
protected void ensureWriteAccess()
public void setNonChMaxWaypointDistance(int nonChMaxWaypointDistance)
Copyright © 2012–2020. All rights reserved.