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.
This PR contains all the loading code for geograph.py. You can load the graph from:
a raster image, either passing a path to a GeoTiff file or a numpy array containing the data. This will polygonise using a function in rasterio_utils.py, using connectivity=4 and buffer(0). Then the vector data will be saved to a GPKG or Shapefile and loaded into a graph.
a GPKG or Shapefile
a GeoPandas dataframe
a saved graph + rtree object, saved as a pickle file or compressed pickle file (bz2 and gzip are supported)
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:
a "representative point" for the polygon (see here)
the polygon area
the polygon perimeter
the class label (when converting from raster)
the polygon object itself, under node['geometry']
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.
This PR contains all the loading code for
geograph.py
. You can load the graph from:rasterio_utils.py
, usingconnectivity=4
andbuffer(0)
. Then the vector data will be saved to a GPKG or Shapefile and loaded into a graph.bz2
andgzip
are supported)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 atolerance
parameter, which will create edges between all polygons which are withintolerance
metres of each other. This is done by expanding the original polygon using.buffer(tolerance)
and checkingintersects()
.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
andgeometry
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.