ai4er-cdt / geograph

GeoGraph provides a tool for analysing habitat fragmentation and related problems in landscape ecology. GeoGraph builds a geospatially referenced graph from land cover or field survey data and enables graph-based landscape ecology analysis as well as interactive visualizations.
https://geograph.readthedocs.io
MIT License
39 stars 10 forks source link

Feature/graph analysis loading #24

Closed herbiebradley closed 3 years ago

herbiebradley commented 3 years ago

This PR contains all the loading code for geograph.py. You can load the graph from:

After any of these,, the graph and rtree will be saved (by default to a bz2 file since it has the highest compression).

The _dataframe_to_graph() function now also supports a tolerance parameter, which will create edges between all polygons which are within tolerance metres of each other. This is done by expanding the original polygon using .buffer(tolerance) and checking intersects().

Each node's name is the integer index it had in the dataframe. By default, the node attributes are:

Additional attributes can be added by including them in a dataframe column (when passing a dataframe or when loading from a vector file). However, I strongly recommend we always use column names of class_label and geometry for the labels and polygons to keep things simple.

This PR also contains a merge_nodes function which accepts a list of nodes - this will create a new node with a neighbour list and polygon attribute which is the union of the nodes in the node list, while deleting all the old nodes.