Extending lines does not reduce subgraph/connected component counts w/ primal approach? #356
-
I have a series of linestrings that I read in using a GeoPandas GeoDataFrame. The geography linestrings have minor disconnects at several places. I am testing the Example code: gdf = gpd.read_file('filename',driver='GeoJSON').explode(index_parts=False)
tol = 1.e-3*min([
abs(gdf.geometry.total_bounds[0] - gdf.geometry.total_bounds[2]),
abs(gdf.geometry.total_bounds[1] - gdf.geometry.total_bounds[3])])
gdf2 = momepy.extend_lines(gdf, tolerance=tol, extension = 1/10 * tol)
G = momepy.gdf_to_nx(
gdf2.to_crs('EPSG:4087'), #originally in EPSG:4326
approach='primal'
)
nodes, edges = momepy.nx_to_gdf(G) Checking Additional notes
Is there something in this process I am missing that would make the graph connect together with the primal approach? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
@tomrod is the data source OpenStreetMap? Depending on the query you'll often end up with disconnected components from things like random walking paths in parks etc. Are you able to see on plots what the nature of the disconnected components might be? |
Beta Was this translation helpful? Give feedback.
-
Hi, This is an expected behaviour. When creating networkx graph using I don't really have a universal solution for this case you are dealing with now. Snapping may be one option. |
Beta Was this translation helpful? Give feedback.
Hi,
This is an expected behaviour. When creating networkx graph using
gdf_to_nx
, momepy infers topology of the network from the endpoints of the line strings. Which means that to create an intersection, endpoints of all line strings need to coincide at that point. If you just extend the lines to visually intersect the others, it does not create nodes there and treats such an intersection as non-planar, as if it was a bridge for example.I don't really have a universal solution for this case you are dealing with now. Snapping may be one option.