Friday, July 25, 2014

Week #10. Network analysis in GNM

The new GNM functionality came to GDAL with two new applications: gnmmanage and gnmanalyse. In this post I'll describe the new classes and methods of API by example of these apps, which I also implement on this week: this is my last commit.

Note: I've also renamed some classes (e.g. GNMConnectivity -> GNMNetwork) and moved some methods from one class to another, due to the better correspondence to my concept. I'll describe the final architecture appearance a bit later, but it hasn't been changed a lot.


The gnmmanage utility intends to provide all managing actions with networks: creating/deleting networks, creating/deleting features, setting/removing connections. For now it has the following usage:
>gnmmanage.exe --long-usage
Usage: gnmmanage [--help][-q][-quiet][--utility_version][--long-usage]
[create [-f format_name] [-t_srs srs_name] [-dsco NAME=VALUE]... ]
[import src_dataset_name] [-l layer_name]
[autoconnect tolerance]

create: create connectivity or the full network, depending on native format support (-nt)
-f format_name: output file format name, possible values are: [ESRI Shapefile]
-t_srs srs_name: spatial reference input
-dsco NAME=VALUE: dataset creation option (format specific) import src_dataset_name: dataset name to copy
-l layer_name: layer name in dataset (optional)
autoconnect tolerance: create topology automatically with the given double tolerance
remove: remove connectivity or network, depending on native format support (-nt)
-nt: use native network format (now unavailable)
So the way using utility is similar to my previous utility: gnminfo, which soon will be using only for getting info about the existing networks. All managing functionality will fully migrate to gnmmanage and it will be more close to the gdalmanage.

The new method GNMNetwork::AutoConnect() tries to build the topology of the network automatically, as I described in my previous post. Remember, that if you will try to build a topology on several layers two times in different spatial reference systems - the results will be different. For example in our case the common network's SRS is 'EPSG:4326'. If we create a network in 'EPSG:3857', import all layers as previous and AutoConnect them with the same tolerance again (for me it was 0.00005) - the topology will differ from previous case.


The gnmmanage utility intends to provide all analysing functionality of GNM. It has the following usage:
>gnmanalyse.exe --long-usage
Usage: gnmanalyse [--help][-q][-quiet][--utility_version][--long-usage]
[dijkstra start_gfid end_gfid [-ds ds_name][-f ds_format][-l layer_name]]

dijkstra start_gfid end_gfid: calculates the shortest path between two points
-ds ds_name: the name&path of the dataset to save the layer with shortest path. Not need to be existed dataset
-f ds_format: define this to set the fromat of newly created dataset
-l layer_name: the name of the resulting layer. If the layer exist already — it will be rewritten
For now it has the usage of only one method: GNMStdRoutingAnalyser::DijkstraShortestPath(). For example lets use it on the network, which had been built with the gnmmanage, the following way:
>gnmanalyse.exe dijkstra 718 1185 -ds ..\shortestpath.shp -f "ESRI Shapefile" -l shortestpath ..\network_data

Path between 718 and 1185 found and saved to the ..\shortestpath.shp successfully
So the path between features with 718 and 1185 GFIDs will be found and saved into the instantly created or opened Shapefile layer.

No comments:

Post a Comment