Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with isochrone example script #9

Open
tuschla opened this issue May 6, 2024 · 0 comments
Open

Error with isochrone example script #9

tuschla opened this issue May 6, 2024 · 0 comments

Comments

@tuschla
Copy link

tuschla commented May 6, 2024

Executing the isochrone example script produces the following error

TypeError                                 Traceback (most recent call last)
Cell In[1], [line 24](vscode-notebook-cell:?execution_count=1&line=24)
     [22](vscode-notebook-cell:?execution_count=1&line=22) polygons = []
     [23](vscode-notebook-cell:?execution_count=1&line=23) for l in limits:
---> [24](vscode-notebook-cell:?execution_count=1&line=24)     p = gnx.isochrone_polygon(graph, source, l, weight="length")
     [25](vscode-notebook-cell:?execution_count=1&line=25)     polygons.append(p)

File [~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/tools/isochrones.py:102](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/tools/isochrones.py:102), in isochrone_polygon(graph, source, limit, weight, tolerance)
    [100](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/tools/isochrones.py:100) ego_graph = gnx.extended_ego_graph(working_graph, source, limit, distance=weight)
    [101](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/tools/isochrones.py:101) # Compute edges voronoi cells
--> [102](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/tools/isochrones.py:102) edge_voronoi_cells = get_edges_voronoi_cells(working_graph, tolerance)
    [103](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/tools/isochrones.py:103) # Set ego-graph edges cells
    [104](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/tools/isochrones.py:104) isochrone_polygons = []

File [~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/tools/isochrones.py:21](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/tools/isochrones.py:21), in get_edges_voronoi_cells(graph, tolerance)
     [19](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/tools/isochrones.py:19) edge_as_lines = graph.get_edges_as_line_series()
     [20](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/tools/isochrones.py:20) lines = list(edge_as_lines)
---> [21](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/tools/isochrones.py:21) edge_cells = gnx.compute_voronoi_cells_from_lines(lines, tolerance)
     [22](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/tools/isochrones.py:22) edge_cells_as_series = gpd.GeoSeries({e: cell for e, cell in zip(edge_as_lines.index, edge_cells)})
     [23](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/tools/isochrones.py:23) edge_cells_as_series.crs = graph.crs

File [~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:243](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:243), in compute_voronoi_cells_from_lines(lines, tolerance)
    [226](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:226) def compute_voronoi_cells_from_lines(lines: list, tolerance=1e-7) -> list:
    [227](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:227)     """Compute the voronoi cells of given generic lines. Input linestrings can be not simple.
    [228](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:228) 
    [229](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:229)     Parameters
   (...)
    [241](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:241) 
    [242](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:242)     """
--> [243](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:243)     simple_segments_mapping = split_as_simple_segments(lines, tolerance)
    [244](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:244)     all_segments = [list(s.coords) for i in range(len(lines)) for s in simple_segments_mapping[i]]
    [245](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:245)     bounds = MultiLineString(lines).bounds

File [~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:208](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:208), in split_as_simple_segments(lines, tol)
    [191](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:191) """Split a list of lines to simple segments (linestring composed by two points). All returned segments do not
    [192](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:192) cross themselves except at extremities.
    [193](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:193) 
   (...)
    [205](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:205) 
    [206](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:206) """
    [207](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:207) split_lines_mapping = defaultdict(list)
--> [208](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:208) all_split_lines = split_linestring_as_simple_linestrings(MultiLineString(lines))
    [209](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:209) j = 0
    [210](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:210) sub_line = all_split_lines[j]

File [~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:186](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:186), in split_linestring_as_simple_linestrings(line)
    [184](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:184)     if line.geom_type == 'LineString' and mls.geom_type == 'MultiLineString':
    [185](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:185)         mls = linemerge(mls)
--> [186](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:186)     return list(mls)
    [187](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:187) else:
    [188](https://file+.vscode-resource.vscode-cdn.net/home/lt/kamaro/oepnv/~/kamaro/oepnv/.venv/lib/python3.8/site-packages/geonetworkx/utils/voronoi_utils.py:188)     return [line]

TypeError: 'MultiLineString' object is not iterable```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant