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.

Friday, June 20, 2014

Week #4 and #5

These two weeks were hard for me, because I had to spend additional time to prepare and defend my Master's thesis. Now it is successfully done and I fully concentrate on GSoC coding.
Nevertheless I have already done some important things:

* Made some main methods of a new GNM API: create and remove connectivity.
* Integrated it directly into GDAL 2.0dev (my fork https://github.com/MikhanGusev/gdal-svn/tree/cmake4gdal), built the library and tested with my old testing application, improving it a bit in order to use new GDAL 2.0.

So, according to my concept the following algorithm is actual for these methods just now:

Income: we have a set of spatial data. It can be void (without layers) or full of layers.
1. Initialize GDALDataset.
2. Create the GNMConnectivity over this dataset. The according system layers and fields will be created.
3. ... <here will be modifying, analysis and so on>
4. Remove the connectivity if it is necessary to restore an old "pure of network" dataset, so:
Outcome: we have the initial set of spatial data without any changes.

I continue to move old methods to the new API and to implement my concept.

Friday, June 6, 2014

Week #3. Some old methods completed

Some new methods have been added to an old API:
[commit]

* New decorator for connectivity behavior. It checks whether the features being connected have the according geometries: wkbPoint for source and target vertexes and wkbLine for edge. If this decorator hasn't been set any geometries must "lie under" the graph (even poligons).

* Delete feature method. Deletes the feature from data source, from the according system tables and from the graph.

* Remove edge, remove vertex methods. The removing methods of the graph.

All these methods will be moved to the new API in future.