Tools

Spatial Merge

spatial_graph_merge(base_graph, other_graph, inplace=False, merge_direction='both', node_filter=None, intersection_nodes_attr=None, discretization_tol=None)[source]

Operates spatial merge between two graphs. Spatial edge projection is used on merging nodes (see spatial_points_merge). The base_graph attributes have higher priority than the other_graph attributes ( i.e. if graphs have common graph attributes, nodes or edges, the base_graph attributes will be kept).

Parameters
  • base_graph (GeoGraph, GeoDiGraph, GeoMultiGraph or GeoMultiDiGraph) – Base graph on which the merge operation is done.

  • other_graph (GeoGraph, GeoDiGraph, GeoMultiGraph or GeoMultiDiGraph) – Input graph to merge. Modified graph if operation is done inplace.

  • inplace (bool) – If True, do operation inplace and return None. (Default value = False)

  • merge_direction (str) – See spatial_points_merge (Default value = “both”)

  • node_filter – Lambda returning if a given node (from the other_graph graph) has to be merged. (Default value = None)

  • intersection_nodes_attr (str) – A dictionary of attributes (constant for all added intersection nodes). (Default value = None)

  • discretization_tol (float) – A custom discretization tolerance for lines. If None, tolerance with the right order of magnitude is pre-defined for some CRS. For more details, see gnx.get_default_discretization_tolerance method. (Default value = None)

Returns

A new graph with the same type as base_graph if not inplace.

Return type

None or GeoGraph

spatial_points_merge(graph, points_gdf, inplace=False, merge_direction='both', node_filter=<function no_filter>, edge_filter=<function no_filter>, intersection_nodes_attr=None, discretization_tol=None)[source]

Merge given points as node with a spatial merge. Points are projected on the closest edge of the graph and an intersection node is added if necessary. If two nodes a given point and a node have the same name, with equal coordinates, then the node is considered as already in the graph. A discretization tolerance is used for indexing edges lines. New nodes created from the geodataframe have attributes described by other columns (except if an attribute value is nan). When a point is projected on an edge, this edge is removed and replaced by two others that connect the extremities to the intersection node. A reference to the original edge is kept on theses new edges with the attribute settings.ORIGINAL_EDGE_KEY. The original edge is the oldest parent of the new edge, to have the direct parent, the attribute has to be cleant first.

Parameters
  • graph (GeoGraph, GeoDiGraph, GeoMultiGraph or GeoMultiDiGraph) – A GeoGraph or derived class describing a spatial graph.

  • points_gdf (gpd.GeoDataFrame) – A list of point describing new nodes to add.

  • inplace (bool) – If True, do operation inplace and return None. (Default value = False)

  • merge_direction (str) –

    For directed graphs only:

    • 'both': 2 edges are added: graph -> new node and new node -> graph

    • 'in': 1 edge is added: new_node -> graph

    • 'out': 1 edge is added: graph -> new_node (Default value = “both”)

  • node_filter – A node filter (lambda) to exclude nodes (and by the way all concerned edges) from the projection operation. (Default value = no_filter)

  • edge_filter – An edge filter (lambda) to exclude edges on which the projection will not take place. (Default value = no_filter)

  • intersection_nodes_attr (dict) – A dictionary of attributes (constant for all added intersection nodes). (Default value = None)

  • discretization_tol (float) – A custom discretization tolerance for lines. If None, tolerance with the right order of magnitude is pre-defined for some CRS. For more details, see gnx.get_default_discretization_tolerance method. (Default value = None)

Returns

If not inplace, the created graph.

Return type

None or GeoGraph

Return type

GeoGraph

Isochrones

boundary_edge_buffer(line)[source]

Return the edge buffer polygon on the oriented line. This represented the area where all points are reachable starting from the line first extremity and using the closest edge projection rule.

Return type

Union[Polygon, MultiPolygon]

get_alpha_shape_polygon(points, quantile)[source]

Return the alpha-shape polygon formed by the given points. Alpha parameter is determined using a quantile of circumradius of Delaunay triangles.

Parameters
  • points (list) – List of input points (2D)

  • quantile (float) – Quantile on circumradius to determine alpha (100 returns the convex hull, 0 returns an empty polygon). 0 <= quantile <= 100.

Returns

The polygon formed by all triangles having a circumradius inferior or equal to \(1/\alpha\).

Note that this does not return the exhaustive alpha-shape for low quantiles, the minimum spanning tree LineString should be added to the returned polygon. This is adapted from Sean Gillies code.

Return type

Polygon or MultiPolygon

Return type

Union[Polygon, MultiPolygon]

get_edges_voronoi_cells(graph, tolerance=1e-07)[source]

Return edge voronoi cells as GeoSeries.

Return type

GeoSeries

get_point_boundary_buffer_polygon(point_coords, radius, segment_direction, resolution=16)[source]

Returns a half-disk centered on the given point, with the given radius and having the boundary edge orthogonal to the given segment direction. See boundary_edge_buffer.

Return type

Polygon

get_segment_boundary_buffer_polygon(segment_coords, radius, residual_radius)[source]

Return a segment boundary polygon using given radius. It represents all reachable points from the first extremity of the segment. The returned polygon is a trapeze. See boundary_edge_buffer.

Return type

Polygon

isochrone_polygon(graph, source, limit, weight='length', tolerance=1e-07)[source]

Return a polygon approximating the isochrone set in the geograph.

Parameters
  • graph (Geograph) – Graph representing possible routes.

  • source – Source node from where distance is computed

  • limit (float or int) – Isochrone limit (e.g. 100 meters, 5 minutes, depending on weight unit).

  • weight (str) – Weight attribute on edges to compute distances (edge weights should be non-negative). (Default value = “length”)

  • tolerance (float) – Tolerance to compute Voronoi cells. (Default value = 1e-7)

Returns

A polygon representing all reachable points within the given limit from the source node.

Return type

Polygon or MultiPolygon

Return type

Union[Polygon, MultiPolygon]

isochrone_polygon_with_alpha_shape(graph, source, limit, weight='length', alpha_quantile=99.0, remove_holes=True, tolerance=1e-07)[source]

Returns an approximation of the isochrone polygon using an alpha-shape of the Shortest Path Tree.

Parameters
  • graph (GeoGraph) – GeoGraph to browse

  • source – Source node from where distance is computed

  • limit (float or int) – Isochrone limit (e.g. 100 meters, 5 minutes, depending on weight unit).

  • weight (str) – Weight attribute on edges to compute distances (edge weights should be non-negative). (Default value = “length”)

  • alpha_quantile (float) – Quantile on circumradius to determine alpha (100 returns the convex hull, 0 returns an empty polygon). 0 <= quantile <= 100. (Default value = 99.0)

  • remove_holes (bool) – If True remove holes in the returned polygon. (Default value = True)

  • tolerance (float) – Buffering tolerance on polygon for rendering (Default value = 1e-7)

Returns

A polygon approximating the isochrone.

Return type

Polygon or MultiPolygon

Return type

Union[Polygon, MultiPolygon]