MCPcopy Create free account
hub / github.com/OSGeo/gdal / GetPath

Method GetPath

gnm/gnmgenericnetwork.cpp:769–864  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

767}
768
769OGRLayer *GNMGenericNetwork::GetPath(GNMGFID nStartFID, GNMGFID nEndFID,
770 GNMGraphAlgorithmType eAlgorithm,
771 CSLConstList papszOptions)
772{
773
774 if (!m_bIsGraphLoaded && LoadGraph() != CE_None)
775 {
776 return nullptr;
777 }
778
779 GDALDriver *poMEMDrv =
780 OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName("Memory");
781 if (poMEMDrv == nullptr)
782 {
783 CPLError(CE_Failure, CPLE_AppDefined, "Cannot load 'Memory' driver");
784 return nullptr;
785 }
786
787 GDALDataset *poMEMDS =
788 poMEMDrv->Create("dummy_name", 0, 0, 0, GDT_Unknown, nullptr);
789 OGRSpatialReference oDstSpaRef(GetProjectionRef());
790 OGRLayer *poMEMLayer =
791 poMEMDS->CreateLayer(GetAlgorithmName(eAlgorithm, true), &oDstSpaRef,
792 wkbGeometryCollection, nullptr);
793
794 OGRGNMWrappedResultLayer *poResLayer =
795 new OGRGNMWrappedResultLayer(poMEMDS, poMEMLayer);
796
797 const bool bReturnEdges =
798 CPLFetchBool(papszOptions, GNM_MD_FETCHEDGES, true);
799 const bool bReturnVertices =
800 CPLFetchBool(papszOptions, GNM_MD_FETCHVERTEX, true);
801
802 switch (eAlgorithm)
803 {
804 case GATDijkstraShortestPath:
805 {
806 GNMPATH path = m_oGraph.DijkstraShortestPath(nStartFID, nEndFID);
807
808 // fill features in result layer
809 FillResultLayer(poResLayer, path, 1, bReturnVertices, bReturnEdges);
810 }
811 break;
812 case GATKShortestPath:
813 {
814 int nK =
815 atoi(CSLFetchNameValueDef(papszOptions, GNM_MD_NUM_PATHS, "1"));
816
817 CPLDebug("GNM", "Search %d path(s)", nK);
818
819 std::vector<GNMPATH> paths =
820 m_oGraph.KShortestPaths(nStartFID, nEndFID, nK);
821
822 // fill features in result layer
823 for (size_t i = 0; i < paths.size(); ++i)
824 {
825 FillResultLayer(poResLayer, paths[i], static_cast<int>(i + 1),
826 bReturnVertices, bReturnEdges);

Callers 5

CPL_STDCALL GNMGetPathFunction · 0.45
test_gnm_graph_dijkstraFunction · 0.45
test_gnm_graph_kshortestFunction · 0.45
MAIN_STARTFunction · 0.45

Calls 13

CPLErrorFunction · 0.85
CSLFetchNameValueDefFunction · 0.85
CPLDebugFunction · 0.85
DijkstraShortestPathMethod · 0.80
KShortestPathsMethod · 0.80
ConnectedComponentsMethod · 0.80
CPLFetchBoolFunction · 0.50
GetDriverByNameMethod · 0.45
CreateMethod · 0.45
CreateLayerMethod · 0.45
sizeMethod · 0.45

Tested by 3

test_gnm_graph_dijkstraFunction · 0.36
test_gnm_graph_kshortestFunction · 0.36