AmericanRedCross / street-view-green-view

BSD 3-Clause "New" or "Revised" License
8 stars 9 forks source link

"ValueError: Input GeoDataFrame must contain only LineString features." #26

Closed danbjoseph closed 2 months ago

danbjoseph commented 3 months ago

can't get the create_points process to work with a different sample dataset. i can't find a difference that would lead to the failure.

the file: jakarta_road_sample_small.zip

the error message:

python -m src.create_points data/raw/jakarta_road_sample_small.zip data/interim/jakarta_road_sample_small.gpkg
Traceback (most recent call last):

  File "<frozen runpy>", line 198, in _run_module_as_main

  File "<frozen runpy>", line 88, in _run_code

  File "/Users/danbjoseph/GitHub/americanredcross/street-view-green-view/src/create_points.py", line 141, in <module>
    app()

  File "/Users/danbjoseph/GitHub/americanredcross/street-view-green-view/src/create_points.py", line 136, in main
    gdf = create_points(gdf, mini_dist=mini_dist)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/Users/danbjoseph/GitHub/americanredcross/street-view-green-view/src/create_points.py", line 97, in create_points
    raise ValueError("Input GeoDataFrame must contain only LineString features.")

ValueError: Input GeoDataFrame must contain only LineString features.

(not working) Jakarta sample details

Screenshot 2024-03-21 at 12 18 04 PM Screenshot 2024-03-21 at 12 18 51 PM

(working) Three Rivers sample details

Screenshot 2024-03-21 at 12 18 16 PM Screenshot 2024-03-21 at 12 18 35 PM
ioalexei commented 3 months ago

Quick look in geopandas suggests there are features with None as geom type, which seems weird but which I assume is what causes create_points to fail.

>>> gpd.read_file("./jakarta_road_sample_small.zip")

          highway          osm_id                                           geometry
0        tertiary   way/155964624  LINESTRING (106.85513 -6.32937, 106.85518 -6.3...
1        tertiary   way/157974609                                               None
2     residential   way/157974611                                               None
3     residential   way/158979934                                               None
4     residential   way/158979937  LINESTRING (106.85874 -6.32874, 106.85866 -6.3...
..            ...             ...                                                ...
78  living_street  way/1228079958                                               None
79  living_street  way/1240606898  LINESTRING (106.85774 -6.32645, 106.85772 -6.3...
80  living_street  way/1240606900                                               None
81    residential  way/1245158482  LINESTRING (106.85653 -6.32900, 106.85631 -6.3...
82       tertiary  way/1259596877                                               None

Adding a geomtry type column in QGIS shows something similar: image

... and from an eyeball it doesn't look like QGIS is displaying 83 features: image

How did you generate the dataset?

Regardless, would be a good idea to add a check to check_points to check that geom_type is not null. (I can have a go at this when I have some time)

danbjoseph commented 3 months ago

I used the vertex tool to remove some of the roads and segments from the overpass query/export that I didn't want for the sample. Must have only deleted the vertices and not the feature itself. Interesting!

danbjoseph commented 3 months ago

If testing before a check for this is implemented, you can delete features with null geometry following: https://gis.stackexchange.com/a/276800

ioalexei commented 3 months ago

I've made a check to detect this and will make a pull request.

if (gdf.geometry.isna()).any(): 
        raise ValueError("Input GeoDataFrame contains null geometries.")

But checking first - is it desireable to add an argument to create_points to optionally drop null geometries? Or is it better to just raise and error and let users fix the dataset before using it?

danbjoseph commented 3 months ago

I think it would be nice to have the raised error message and then have an option to deal with it inside the program (instead of having to go back to QGIS). What do you think? Something like... Input GeoDataFrame contains null geometries. Rerun with --dropNull to drop these geometries.

dragonejt commented 2 months ago

Has this been resolved? Looks to be that way so closing for now...

danbjoseph commented 2 months ago

it has. if you run python -m src.create_points --help it will include details on --drop-null the --help command is mentioned in the readme, do you think we need to mention each flag in the readme or is mentioning how to get details through the help flag enough?