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

StreetProfile shall warn if CRS is geographic #369

Open
adhamenaya opened this issue Jul 7, 2022 · 5 comments
Open

StreetProfile shall warn if CRS is geographic #369

adhamenaya opened this issue Jul 7, 2022 · 5 comments
Labels

Comments

@adhamenaya
Copy link

Describe the problem

I am following the sample source code on this link: Simplified detection of urban types . And after updating GeoPandas (0.11.0) and GDAL (3.5.0) packages, I started getting this error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [4], in <cell line: 1>()
----> 1 profile = momepy.StreetProfile(streets, buildings)

File ~/opt/anaconda3/envs/PythonEnv/lib/python3.9/site-packages/momepy/dimension.py:590, in StreetProfile.__init__(self, left, right, heights, distance, tick_length, verbose)
    587         ticks.append([line_end_1, pt])
    588         ticks.append([line_end_2, pt])
--> 590 ticks = pygeos.linestrings(ticks)
    592 inp, res = right.sindex.query_bulk(ticks, predicate="intersects")
    593 intersections = pygeos.intersection(ticks[inp], right.geometry.values.data[res])

File ~/opt/anaconda3/envs/PythonEnv/lib/python3.9/site-packages/pygeos/decorators.py:80, in multithreading_enabled.<locals>.wrapped(*args, **kwargs)
     78     for arr in array_args:
     79         arr.flags.writeable = False
---> 80     return func(*args, **kwargs)
     81 finally:
     82     for arr, old_flag in zip(array_args, old_flags):

File ~/opt/anaconda3/envs/PythonEnv/lib/python3.9/site-packages/pygeos/creation.py:119, in linestrings(coords, y, z, indices, out, **kwargs)
    117 coords = _xyz_to_coords(coords, y, z)
    118 if indices is None:
--> 119     return lib.linestrings(coords, out=out, **kwargs)
    120 else:
    121     return simple_geometries_1d(coords, indices, GeometryType.LINESTRING, out=out)

ValueError: linestrings: Input operand 0 does not have enough dimensions (has 1, gufunc core with signature (i, d)->() requires 2)

Steps to reproduce

import geopandas
import libpysal
import momepy
import osmnx
import pandas

place = 'Znojmo, Czechia'

buildings = osmnx.geometries.geometries_from_place(place, tags={'building':True})

osm_graph = osmnx.graph_from_place(place, network_type='drive')
#osm_graph = osmnx.projection.project_graph(osm_graph, to_crs=local_crs)
streets = osmnx.graph_to_gdfs(
    osm_graph, 
    nodes=False, 
    edges=True,
    node_geometry=False, 
    fill_edge_geometry=True
)

profile = momepy.StreetProfile(streets, buildings)

Versions of your packages

GeoPandas=0.11.0
GDAL=3.5.0
momepy=0.5.3
libpysal=4.6.2
osmnx=1.2.1

Your operating system

macOS Monterey 12.4

Additional context

No response

@adhamenaya adhamenaya added the bug Something isn't working label Jul 7, 2022
@martinfleis
Copy link
Member

Thanks for the report. I see the same behaviour on my side. Not sure what is causing it though, will need to dig.

@adhamenaya
Copy link
Author

adhamenaya commented Jul 13, 2022

Thanks for the report. I see the same behaviour on my side. Not sure what is causing it though, will need to dig.

Thanks @martinfleis - I need to work on this library for my uni research as soon as possible. Could you please advise what version of GeoPandas and GDAL is compatible with this library?

@martinfleis
Copy link
Member

@adhamenaya I figured out the issue. It is not a bug in momepy or any of the dependencies but in your code above.

I didn't notice that you commented out osmnx.projection.project_graph. Without this step, your geometry is in EPSG:4326, which means that the units are degrees. Since we create perpendicular lines along each segment in StreetProfile every 10 units by default, those 10 units are in your case 10 degrees. As a result, no lines is created. The code expects meters (or feet), so you need to project your data before using almost any function in momepy.

What we can do here on the momepy side is to raise a warning if the GeoDataFrame is in geographic CRS as geopandas does with buffer and similar and raise an informative error if the resulting set of perpendicular lines is empty. But those are just user convenience messages, there is no bug to fix.

@martinfleis martinfleis added good first issue Good for newcomers and removed bug Something isn't working labels Jul 13, 2022
@adhamenaya
Copy link
Author

@martinfleis Thanks a lot for the clarification, and sorry about my misuse of library functions.

@martinfleis
Copy link
Member

I'll keep it open to add those warnings.

@martinfleis martinfleis changed the title StreetProfile: linestrings: Input operand 0 does not have enough dimensions (has 1, gufunc core with signature (i, d)->() requires 2) StreetProfile shall warn if CRS is geographic May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants