本文整理汇总了Java中com.graphhopper.GraphHopper.importOrLoad方法的典型用法代码示例。如果您正苦于以下问题:Java GraphHopper.importOrLoad方法的具体用法?Java GraphHopper.importOrLoad怎么用?Java GraphHopper.importOrLoad使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.graphhopper.GraphHopper
的用法示例。
在下文中一共展示了GraphHopper.importOrLoad方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import com.graphhopper.GraphHopper; //导入方法依赖的package包/类
/**
*
* @param osmFile path to the osmFile to use
* @param workingDir if multiple GH instances are used, then each should have a different workingDir
* @return graphhopper instance
*/
public static GraphHopper get(String osmFile, String workingDir) {
GraphHopper hopper;
// create one GraphHopper instance
Map<String, String> env = System.getenv();
if(Boolean.valueOf(env.get("LOW_MEMORY"))) {
LOGGER.info("Using Graphhopper for mobile due to LOW_MEMORY env.");
hopper = new GraphHopper().forMobile();
hopper.setCHPrepareThreads(1);
} else {
hopper = new GraphHopper().forServer();
}
hopper.setOSMFile(osmFile);
hopper.setGraphHopperLocation(workingDir);
hopper.setEncodingManager(new EncodingManager("car"));
hopper.importOrLoad();
return hopper;
}
示例2: createHopper
import com.graphhopper.GraphHopper; //导入方法依赖的package包/类
public static GraphHopper createHopper(boolean memoryMapped, String graphFolder) {
GraphHopper ret = null;
ret = new GraphHopper().forDesktop();
// initialise the encoders ourselves as we can use multiple
// encoders for same vehicle type corresponding to different
// times of day (i.e. rush hours)
ret.setEncodingManager(createEncodingManager(graphFolder));
// don't need to write so disable the lock file (allows us to run out of program files)
ret.setAllowWrites(false);
if (memoryMapped) {
ret.setMemoryMapped();
}
ret.setGraphHopperLocation(graphFolder);
ret.importOrLoad();
return ret;
}
示例3: main
import com.graphhopper.GraphHopper; //导入方法依赖的package包/类
public static void main(String[] strArgs) throws Exception{
// GHServer.main(strArgs);
CmdArgs args = CmdArgs.read(strArgs);
args = CmdArgs.readFromConfigAndMerge(args, "config", "graphhopper.config");
GraphHopper hopper = new GraphHopper().forDesktop().init(args);
hopper.importOrLoad();
hopper.close();
}
示例4: loadInBackground
import com.graphhopper.GraphHopper; //导入方法依赖的package包/类
@Override
public Result loadInBackground() {
LOGI(TAG, "#loadInBackground; mStartLocation = " + mStartLocation + "; mEndLocation = " + mEndLocation);
try {
final GraphHopper hopper = new GraphHopper().forMobile();
hopper.setInMemory();
final File mapsforgeFile = AbstractMap.instance().getMapsforgeFile(getContext());
hopper.setOSMFile(mapsforgeFile.getAbsolutePath());
hopper.setGraphHopperLocation(mapsforgeFile.getParent());
hopper.setEncodingManager(new EncodingManager("car"));
hopper.importOrLoad();
final GHRequest req =
new GHRequest(
mStartLocation.getLatitude(),
mStartLocation.getLongitude(),
mEndLocation.getLatitude(),
mEndLocation.getLongitude())
.setAlgorithm(Parameters.Algorithms.DIJKSTRA_BI);
req.getHints().
put(Parameters.Routing.INSTRUCTIONS, "false");
// GHResponse resp = hopper.route(req);
final GHResponse rsp = hopper.route(req);
if (rsp.hasErrors()) {
LOGW(TAG, "GHResponse contains errors!");
List<Throwable> errors = rsp.getErrors();
for (int i = 0; i < errors.size(); i++) {
LOGE(TAG, "Graphhopper error #" + i, errors.get(i));
}
return Result.INTERNAL_ERROR;
}
// if (!rsp.isFound()) {
// LOGW(TAG, "Graphhopper cannot find route!");
// return Result.NO_ROUTE;
// }
else {
PathWrapper paths = rsp.getBest();
final List<GeoPoint> geoPoints = new LinkedList<>();
final PointList points = paths.getPoints();
double lati, longi, alti;
for (int i = 0; i < points.getSize(); i++) {
lati = points.getLatitude(i);
longi = points.getLongitude(i);
alti = points.getElevation(i);
geoPoints.add(new GeoPoint(lati, longi, alti));
}
return new Result(geoPoints);
}
} catch (OutOfMemoryError e) {
LOGE(TAG, "Graphhoper OOM", e);
return Result.INTERNAL_ERROR;
}
}
示例5: loadInBackground
import com.graphhopper.GraphHopper; //导入方法依赖的package包/类
@Override
public Result loadInBackground() {
LOGI(TAG, "#loadInBackground; mStartLocation = " + mStartLocation + "; mEndLocation = " + mEndLocation);
try {
final GraphHopper hopper = new GraphHopper().forMobile();
hopper.setInMemory(true);
final File mapsforgeFile = AbstractMap.instance().getMapsforgeFile(getContext());
hopper.setOSMFile(mapsforgeFile.getAbsolutePath());
hopper.setGraphHopperLocation(mapsforgeFile.getParent());
hopper.setEncodingManager(new EncodingManager("car"));
hopper.importOrLoad();
final GHRequest req =
new GHRequest(
mStartLocation.getLatitude(),
mStartLocation.getLongitude(),
mEndLocation.getLatitude(),
mEndLocation.getLongitude())
.setVehicle("car");
final GHResponse rsp = hopper.route(req);
if (rsp.hasErrors()) {
LOGW(TAG, "GHResponse contains errors!");
List<Throwable> errors = rsp.getErrors();
for (int i = 0; i < errors.size(); i++) {
LOGE(TAG, "Graphhopper error #" + i, errors.get(i));
}
return Result.INTERNAL_ERROR;
}
if (!rsp.isFound()) {
LOGW(TAG, "Graphhopper cannot find route!");
return Result.NO_ROUTE;
} else {
final List<GeoPoint> geoPoints = new LinkedList<>();
final PointList points = rsp.getPoints();
double lati, longi, alti;
for (int i = 0; i < points.getSize(); i++) {
lati = points.getLatitude(i);
longi = points.getLongitude(i);
alti = points.getElevation(i);
geoPoints.add(new GeoPoint(lati, longi, alti));
}
return new Result(geoPoints);
}
} catch (OutOfMemoryError e) {
LOGE(TAG, "Graphhoper OOM", e);
return Result.INTERNAL_ERROR;
}
}
示例6: writeGraphHopperBinaryNetwork
import com.graphhopper.GraphHopper; //导入方法依赖的package包/类
private static void writeGraphHopperBinaryNetwork(final String baseOutputFileName,
final File osmXmlFile) throws IOException
{
final long startTime = System.currentTimeMillis();
final String graphHopperOutputDirectoryName = baseOutputFileName + "-gh";
final String[] inputs = { "graph.flag_encoders=foot",
"graph.elevation.dataaccess=RAM_STORE",
"prepare.ch.weightings=no",
"graph.dataaccess=RAM_STORE",
"graph.location=" + graphHopperOutputDirectoryName, // where to store the results
"osmreader.osm=" + osmXmlFile // input osm
};
final GraphHopper graphHopper = new GraphHopper().init(CmdArgs.read(inputs));
try
{
final ElevationProvider tagElevationProvider = new TagElevationProvider();
tagElevationProvider.setBaseURL(osmXmlFile.getPath());
graphHopper.setElevation(true);
graphHopper.setElevationProvider(tagElevationProvider);
graphHopper.importOrLoad(); // Creates binary output
final File graphHopperOutputDirectory = new File(graphHopperOutputDirectoryName);
try
{
// Create Zip from binary folder output
zipDirectory(graphHopperOutputDirectory, 9);
}
finally
{
// Delete the temporary folder
if(graphHopperOutputDirectory.exists())
{
recursivelyDeleteDirectory(graphHopperOutputDirectory);
}
}
}
finally
{
graphHopper.close();
}
System.out.format(" ...finished! (%s)\n",
elapsedTime(System.currentTimeMillis() - startTime));
}
示例7: writeGraphHopperBinaryNetwork
import com.graphhopper.GraphHopper; //导入方法依赖的package包/类
private static void writeGraphHopperBinaryNetwork(final String baseOutputFileName,
final File osmXmlFile) throws IOException
{
final long startTime = System.currentTimeMillis();
final String graphHopperOutputDirectoryName = baseOutputFileName + "-gh";
final String[] inputs = { "graph.flag_encoders=foot",
"graph.elevation.dataaccess=RAM_STORE",
"prepare.ch.weightings=no",
"graph.dataaccess=RAM_STORE",
"graph.location=" + graphHopperOutputDirectoryName, // where to store the results
"osmreader.osm=" + osmXmlFile // input osm
};
final GraphHopper graphHopper = new GraphHopper().init(CmdArgs.read(inputs));
try
{
final ElevationProvider tagElevationProvider = new TagElevationProvider();
tagElevationProvider.setBaseURL(osmXmlFile.getPath());
graphHopper.setElevation(true);
graphHopper.setElevationProvider(tagElevationProvider);
graphHopper.importOrLoad(); // Creates binary output
final File graphHopperOutputDirectory = new File(graphHopperOutputDirectoryName);
try
{
// Create Zip from binary folder output
zipDirectory(graphHopperOutputDirectory, 9);
}
finally
{
// Delete the temporary folder
if(graphHopperOutputDirectory.exists())
{
recursivelyDeleteDirectory(graphHopperOutputDirectory);
}
}
}
finally
{
graphHopper.close();
}
}
示例8: writeGraphHopperBinaryNetwork
import com.graphhopper.GraphHopper; //导入方法依赖的package包/类
private static void writeGraphHopperBinaryNetwork(final String baseOutputFileName,
final File osmXmlFile) throws IOException
{
final long startTime = System.currentTimeMillis();
final String graphHopperOutputDirectoryName = baseOutputFileName + "-gh";
final String[] inputs = { "graph.flag_encoders=car",
"prepare.ch.weightings=fastest,shortest",
"routing.ch.disabling_allowed=true",
"graph.dataaccess=RAM_STORE",
"graph.location=" + graphHopperOutputDirectoryName, // where to store the results
"osmreader.osm=" + osmXmlFile // input osm
};
final GraphHopper graphHopper = new GraphHopper().init(CmdArgs.read(inputs));
try
{
graphHopper.importOrLoad(); // Creates binary output
final File graphHopperOutputDirectory = new File(graphHopperOutputDirectoryName);
try
{
// Create Zip from binary folder output
zipDirectory(graphHopperOutputDirectory, 9);
}
finally
{
// Delete the temporary folder
if(graphHopperOutputDirectory.exists())
{
recursivelyDeleteDirectory(graphHopperOutputDirectory);
}
}
}
finally
{
graphHopper.close();
}
}