(source code at <gdal root>/gnm)
In general the approach is like in one of my first posts, but now we have the API, which integrated into GDAL library (for the moment only in my fork of GDAL repo) and this API has a key change: it is no longer the OGR driver, not only because in GDAL 2.0 all migrates to GDAL drivers but also because of my concept which I described earlier. So now it is the separate set of classes.
(source code in <gdal root>/apps/gnminfo.cpp)
This console utility is similar to those like gdalinfo.exe or ogrinfo.exe and was made to provide the use of several GNM API methods. Type this in command line:
>gnminfo.exe --long-usageand you will see its usage:
Usage: gnminfo [--help-general] [-progress] [-quiet]So with this utility you can now do the following. Note: we assume that the "connectivity" is a set of special system layers which store the network data (contrary to the set of layers with spatial data on which the connectivity though is based).
[-create [-f format_name] [-t_srs srs_name] [-dsco NAME=VALUE]...]
[-cp src_dataset_name] [-l layer_name]
-f format_name: output file format name, possible values are:
-progress: Display progress on terminal. Only works if input layers have the "fast feature count" capability
-dsco NAME=VALUE: Dataset creation option (format specific)
-cp src_datasource_name: Datasource to copy
-l layer_name: Layer name in datasource (optional)
1. Create a connectivity:
>gnminfo.exe -create -f "ESRI Shapefile" -t_srs "EPSG:3857" -dsco "con_name=my_connectivity_1" ..\data\my_conThe connectivity will be created in the Shapefile format at the given path and with the passed parameters. Technically there will be created several system layers (in our case several .dbf files for Shapefile dataset).
2. Import layers with spatial data:
>gnminfo.exe -cp ..\data -l kolodci ..\data\my_conThese 3 layers will be copied with all features from an external dataset to a given connectivity with special names. The according changes will be made in system layers and also the system fields will be added to this data in order to maintain the work with future network.
>gnminfo.exe -cp ..\data -l lines ..\data\my_con
>gnminfo.exe -cp ..\data -l reshetki \..\data\my_con
3. Give an info about connectivity:
>gnminfo.exe -i ..\data\my_conThe info will be printed:
Connectivity opened successfully at ..\data\my_conWe see the system and simple layers, and also the contents of _gnm_meta - the network metadata.
1: _gnm_meta (None)
2: _gnm_graph (None)
3: _gnm_classes (None)
4: gnm_kolodci_point (Point)
5: gnm_lines_line (Line String)
6: gnm_reshetki_point (Point)
Connectivity metadata [Name=Value]:
PROJCS["WGS 84 / Pseudo-Mercator",
<... Additional info about SRS ...>
The connect, disconnect, reconnect methods were not used in the gnminfo utility. If we want to make some connections in the created connectivity we can just call ConnectFeatures() and pass the global identifiers (which were set automatically when the layers were imported) to it. The graph layer (_gnm_graph) will be modified. As I planed my next steps will be to widen the GNM API and particularly to add an automatic graph building (so not to use ConnectFeatures() manually on the big sets of spatial data). Maybe I also make a similar utility to test this functionality.