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

Hema Yeedunuri hema.yeedunuri at amigooptima.in
Tue Nov 11 02:48:32 PST 2014


hello Mikhail Gusev ,

Thank u for the reply .I want to find  the shortest distance between
features .But the road layer I am using is having 10055 features. without
creating graph it is not possible to find shortest distance.And to my
understanding I think it is difficult to manually connect features to
create graph. The algorithm is using only the features that are connected
manually and that are present in _gnm_graph.dbf file.Is there any other
simple solution to solve this.

thanks,
hema

On Tue, Nov 11, 2014 at 3:59 PM, Mikhail Gusev <gusevmihs at gmail.com> wrote:

> Hello, hema.
> The current default implementation of GNMNetwork::AutoConnect() can work
> only if the passing array of layers contains at least one point and one
> line layer (i.e. GetGeomType() for the layers equals wkbPoint and
> wkbLineString accordingly). For each line feature the algorithm takes the
> start and end snapping area formed around the start and end point of the
> line and searches the points from point layers which are situated inside
> these two areas. So there is no way for now to connect features of only one
> line layer automatically. You can use ConnectFeatures() to connect
> manually, but you will need the features (with any geometry!) to be the
> source and the target for the connection, while the gnm_roads_line feature
> will be the connector.
>
> 2014-11-11 11:26 GMT+04:00 yhema <hema.yeedunuri at amigooptima.in>:
>
>> 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.
>> _______________________________________________
>> gdal-dev mailing list
>> gdal-dev at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20141111/ca5a8959/attachment.html>


More information about the gdal-dev mailing list