[gdal-dev] creating graph for single line shape layer using gdal gnm

yhema hema.yeedunuri at amigooptima.in
Mon Nov 10 23:26:44 PST 2014


Hello all,

I am trying to create a graph for network analysis using gdalgnm.The feature
auto connect is working if we provide more than one layer.How can we connect
features of a single layer so that graph is created automatically. We can
connect features using connect features but automatically it is not
conncting using auto connect .Here is the code.

 char **options = NULL;
    options = CSLAddNameValue(options,GNM_INIT_OPTIONPAIR_NAME,
"roads_network");
   
   
    GNMGdalNetwork *poNet;
   
    poNet =
GNMManager::GdalCreateNetwork("/home/shiva/Desktop/network/network_data",
"ESRI Shapefile", "EPSG:4326", options);
    CSLDestroy(options);
    if (poNet == NULL)
    {
        printf("Failed to create network\n");
        exit(1);
    }
   
    GDALDataset *poSrcDS = (GDALDataset*)
GDALOpenEx("/home/shiva/Desktop/network/data",
                                                     GDAL_OF_VECTOR |
GDAL_OF_READONLY, NULL, NULL, NULL );
    if(poSrcDS == NULL)
    {
        printf("Can not open source dataset at\n");
        exit(1);
    }
   
    OGRLayer *poSrcLayer2 = poSrcDS->GetLayerByName("roads");
    if (poSrcLayer2 == NULL)
    {
        printf("layer is null\n");
        printf("Can not process layers of source dataset\n");
        exit(1);
    }
   
    GNMErr err2 = poNet->CopyLayer(poSrcLayer2, "roads");
    if (err2 != GNMERR_NONE)
    {
        printf("Can not import layers from source dataset\n");
        exit(1);
    }
   
    GDALClose(poSrcDS);
   
   
    if (poNet->CreateRule("CLASS gnm_roads_line COSTS TIGER_ID") !=
GNMERR_NONE)
    {
        printf("Can not create rule\n");
    }
   
    if (poNet->CreateRule("NETWORK CONNECTS gnm_roads_line WITH
gnm_roads_line  ") != GNMERR_NONE)
    {
        printf("Can not create rule\n");
    }
   
   
    printf("\nBuilding network topology ...\n");
    GDALDataset *poNetDS = poNet->GetDataset();
    OGRLayer **layers = new OGRLayer*[3];
   
    layers[0] = poNetDS->GetLayerByName("gnm_roads_line");
    layers[2] = NULL;
    layers[1] = NULL;
   
   
    if (poNet->AutoConnect(layers,0.05, NULL) != GNMERR_NONE)
    {
        printf("Building topology failed\n");
        exit(1);
    }
    else
    {
        printf("Topology has been built successfully\n");
    }
   
    delete[] layers;
   
   
        GNMManager::GdalCloseNetwork(poNet);




thanks,
hema



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/creating-graph-for-single-line-shape-layer-using-gdal-gnm-tp5172326.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.


More information about the gdal-dev mailing list