util
Convenience functions for the preparation and conversion of networkX graphs to and from cityseer data structures. Note that the cityseer network data structures can be created and manipulated directly, if so desired.
validate_cityseer_networkx_graph
Validates a networkX MultiGraph for use with cityseer.
Parameters
A networkX MultiGraph with a crs attribute denoting a projected coordinate system, containing x and y node attributes, and geom edge attributes containing LineString geoms.
Returns
A networkX MultiGraph with nodes of degree=2 removed. Adjacent edges will be combined into a unified new edge with associated geom attributes spliced together.
measure_bearing
Measures the angular bearing between two coordinate pairs.
measure_coords_angle
Measures angle between three coordinate pairs. Angular change is from one line segment to the next, across the intermediary coord.
measure_angle_diff_betw_linestrings
Measures the angular difference between the bearings of two sets of linestring coords.
measure_cumulative_angle
Measures the cumulative angle along a LineString geom’s coords.
measure_max_angle
Measures the maximum angle along a LineString geom’s coords.
snap_linestring_startpoint
Snaps a LineString’s start-point coordinate to a specified x_y coordinate.
Parameters
A list, tuple, or numpy array of x, y coordinate tuples.
A tuple of floats representing the target x, y coordinates against which to align the linestring start point.
Returns
A list of linestring coords aligned to the specified starting point.
snap_linestring_endpoint
Snaps a LineString’s end-point coordinate to a specified x_y coordinate.
Parameters
A list, tuple, or numpy array of x, y coordinate tuples.
A tuple of floats representing the target x, y coordinates against which to align the linestring end point.
Returns
A list of linestring coords aligned to the specified ending point.
align_linestring_coords
Align a LineString’s coordinate order to either start or end at a specified x_y coordinate within a given tolerance.
Parameters
A list, tuple, or numpy array of x, y coordinate tuples.
A tuple of floats representing the target x, y coordinates against which to align the linestring coords.
If reverse=False the coordinate order will be aligned to start from the given x_y coordinate. If reverse=True the coordinate order will be aligned to end at the given x_y coordinate.
Distance tolerance in metres for matching the x_y coordinate to the linestring_coords.
Returns
A list of linestring coords aligned to the specified endpoint.
snap_linestring_endpoints
Snaps edge geom coordinate sequence to the nodes on either side.
Parameters
A networkX MultiGraph with x and y node attributes and edge geom attributes.
A node key corresponding to the edge’s start node.
A node key corresponding to the edge’s end node.
A list, tuple, or numpy array of x, y coordinate tuples.
Distance tolerance in metres for matching the x_y coordinate to the linestring_coords.
Returns
A list of linestring coords aligned to the specified ending point.
weld_linestring_coords
Welds two linestrings. Finds a matching start / end point combination and merges the coordinates accordingly. If the optional force_xy is provided then the weld will be performed at the x_y end of the LineStrings. The force_xy parameter is useful for looping geometries or overlapping geometries where it can happen that welding works from either of the two ends, thus potentially mis-aligning the start point unless explicit.
add_node
Add a node to a networkX MultiGraph. Assembles a new name from source node names. Checks for duplicates. Returns new name and is_dupe
create_nodes_strtree
Create a nodes-based STRtree spatial index.
create_edges_strtree
Create an edges-based STRtree spatial index.
project_geom
Projects an input shapely geometry.
Parameters
A GeoDataFrame containing building polygons.
The EPSG code from which to convert the projection.
The EPSG code into which to convert the projection.
Returns
A shapely geometry in the specified to_crs_code projection.
extract_utm_epsg_code
Finds the UTM coordinate reference system for a given longitude and latitude.
Parameters
The longitude for which to find the appropriate UTM EPSG code.
The latitude for which to find the appropriate UTM EPSG code.
Returns
The EPSG coordinate reference code for the UTM projection.