我想使用GraphHopper来创建我自己的路由API。我已经研究了GraphHopper.java来创建我自己的类。我将一个OSM文件放入API中,得到一个包含边、节点等的目录。这似乎运行良好。
我的问题是,如何加载此数据,以便可以调用route-Method?我试图理解GraphHopper.java类,但我的示例不起作用。我尝试使用以下命令加载图形
GHDirectory l_dir = new GHDirectory( m_graphlocation.getAbsolutePath(), DAType.RAM);
m_graph = new LevelGraphStorage( l_dir, m_EncodingManager );
我是否需要再次使用OSM文件进行路由,或者我是否可以仅使用具有边和节点的目录?我需要一个电话
OSMReader l_reader = new OSMReader( l_graph, CConfiguration.getInstance().get().ExpectedCapacity).setWorkerThreads(-1).setEncodingManager(m_EncodingManager).setWayPointMaxDistance(CConfiguration.getInstance().get().WaypointMaxDistance).setEnableInstructions(false);
l_reader.doOSM2Graph(p_osm);
l_graph.optimize();
为了创建我的图形,那么创建我的GraphHopperAPI类,重载方法,然后用上面的代码加载数据,然后可以调用路由,这样做正确吗?
非常感谢菲尔
发布于 2014-03-05 23:15:50
您只需要导入一次OSM。在GraphHopper类中,一个新的存储被实例化,然后调用loadExisting。如果失败,您就知道需要导入OSM文件并创建新的graphhopper文件。例如,在我的脑海中,它应该是这样的:
g = new LevelGraphStorage(dir, encodingManager);
if(!g.loadExisting()) {
reader = new OSMReader(g).setLotsOfThings
reader.doOSM2Graph..
}
问题是,如果禁用CH,则只能使用GraphHopperStorage。然后,您需要在正确的位置正确加载或创建LocationIndex,等等。看看现有的单元测试,在这些单元测试中,我也只是使用原始的东西,而不是GraphHopper包装器类。
但是为什么不创建一个GraphHopper的子类并使用现有的钩子(postProcessing、createWeighting等)呢?来根据你的需求进行定制?
发布于 2014-03-07 09:23:06
我使用以下代码:
GHDirectory l_dir = new GHDirectory( l_graphlocation.getAbsolutePath(), DAType.RAM_STORE);
m_graph = new LevelGraphStorage( l_dir, m_EncodingManager );
m_graph.setSegmentSize( CConfiguration.getInstance().get().SegmentSize );
if (!m_graph.loadExisting())
{
File l_osm = this.downloadOSMData();
OSMReader l_reader = new OSMReader( m_graph, CConfiguration.getInstance().get().ExpectedCapacity).setWorkerThreads(-1).setEncodingManager(m_EncodingManager).setWayPointMaxDistance(CConfiguration.getInstance().get().WaypointMaxDistance).setEnableInstructions(false);
l_reader.doOSM2Graph(l_osm);
m_graph.optimize();
m_graph.flush();
// do I need this?
PrepareRoutingSubnetworks l_preparation = new PrepareRoutingSubnetworks(m_graph, m_EncodingManager);
l_preparation.setMinNetworkSize( CConfiguration.getInstance().get().MinNetworkSize );
l_preparation.doWork();
}
// is this correct?
m_index = new LocationIndexTree(m_graph, l_dir);
m_index.setResolution( CConfiguration.getInstance().get().IndexResolution );
m_index.setSearchRegion(true);
if (!m_index.loadExisting())
throw new IOException("unable to load graph index file");
// does not work without the graph
m_graphhopper = new GraphHopper().setEncodingManager(m_EncodingManager).forDesktop();
我不能创建一个工作结构。我已经查看了测试示例,例如https://github.com/graphhopper/graphhopper/blob/master/core/src/test/java/com/graphhopper/GraphHopperAPITest.java,但是loadGraph方法不能在包外调用。
我想从OSM文件创建一个正确的图形数据库,这似乎是工作。然后我想找出与地理位置最接近的边:
m_index.findClosest( p_position.getLatitude(), p_position.getLongitude(), EdgeFilter.ALL_EDGES );
但是这会返回一个空指针异常,所以我的索引应该是错误的。如何创建正确的工作索引?
在此之后,我想通过图表创建一条快速/最短路径
GHRequest l_request = new GHRequest( p_start.getLatitude(), p_start.getLongitude(), p_end.getLatitude(), p_end.getLongitude() );
l_request.setAlgorithm( CConfiguration.getInstance().get().RoutingAlgorithm );
return m_graphhopper.route(l_request);
但是我不能为调用route-method创建一个工作的graphhopper实例。
https://stackoverflow.com/questions/22208416
复制相似问题