Friday, June 27, 2014

Week #6. GNM in GDAL 2.0

Take a look at my repo to see the source code with comments and methods description.

GNM API
(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.

Application
(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-usage
and you will see its usage:
Usage: gnminfo [--help-general] [-progress] [-quiet]
               [-create [-f format_name] [-t_srs srs_name] [-dsco NAME=VALUE]...]
               [-i]
               [-cp src_dataset_name] [-l layer_name]
               gnm_name

 -f format_name: output file format name, possible values are:
    [ESRI Shapefile]
 -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)
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).

1. Create a connectivity:
>gnminfo.exe -create -f "ESRI Shapefile" -t_srs "EPSG:3857" -dsco "con_name=my_connectivity_1" ..\data\my_con
The 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_con
>gnminfo.exe -cp ..\data -l lines ..\data\my_con
>gnminfo.exe -cp ..\data -l reshetki \..\data\my_con
These 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.

3. Give an info about connectivity:
>gnminfo.exe -i ..\data\my_con
 The info will be printed:
Connectivity opened successfully at ..\data\my_con
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]:
    [common_srs=EPSG:3857]
    [gnm_version=1.0.0]
    [gfid_counter=1350]
    [con_name=my_connectivity_1]
SRS WKT:
PROJCS["WGS 84 / Pseudo-Mercator",
    GEOGCS["WGS 84",
        DATUM["WGS_1984",
    <... Additional info about SRS ...>
    AUTHORITY["EPSG","3857"]]
We see the system and simple layers, and also the contents of _gnm_meta - the network metadata.

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.

No comments:

Post a Comment