adamfranco / curvature

Find roads that are the most curvy or twisty based on Open Street Map (OSM) data.
http://roadcurvature.com/
225 stars 39 forks source link

TypeError: 'NoneType' object has no attribute '__getitem__' #18

Closed sgallese closed 8 years ago

sgallese commented 8 years ago

Using the osm file from here: http://download.geofabrik.de/north-america/us/california-latest.osm.pbf

And using the code from the Bay Area example here: https://github.com/adamfranco/curvature#examples

$ ./curvature.py -v --max_lat_bound 38.5 --min_lat_bound 36.5 --min_lon_bound -123.25 --max_lon_bound -121.0 --output_basename california-bay-area --min_curvature 1000 --add_kml colorize=1 california-latest.osm.pbf

Loading california-latest.osm.pbf
Loading ways, each '-' is 100 ways, each row is 10,000 ways
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
-----------------
0 ways matched in california-latest.osm.pbf 1754.0MB memory used,
6719156 coordinates will be loaded, each '.' is 1% complete
................
Coordinates loaded 1835.0MB memory used.
229503 routes will have bboxes calculated, each '.' is 1% complete
Traceback (most recent call last):
  File "./curvature.py", line 131, in <module>
    collector.load_file(file.name)
  File "/Users/sgallese/bmw/curvature-master/curvature/collector.py", line 73, in load_file
    self.calculate_bboxes()
  File "/Users/sgallese/bmw/curvature-master/curvature/collector.py", line 210, in calculate_bboxes
    self.store_way_region(way)
  File "/Users/sgallese/bmw/curvature-master/curvature/collector.py", line 214, in store_way_region
    way['max_lat'] = first[0]
TypeError: 'NoneType' object has no attribute '__getitem__'

$ brew list protobuf
/usr/local/Cellar/protobuf/2.6.1/bin/protoc
/usr/local/Cellar/protobuf/2.6.1/include/google/ (56 files)
/usr/local/Cellar/protobuf/2.6.1/lib/libprotobuf-lite.9.dylib
/usr/local/Cellar/protobuf/2.6.1/lib/libprotobuf.9.dylib
/usr/local/Cellar/protobuf/2.6.1/lib/libprotoc.9.dylib
/usr/local/Cellar/protobuf/2.6.1/lib/pkgconfig/ (2 files)
/usr/local/Cellar/protobuf/2.6.1/lib/python2.7/site-packages/homebrew-protobuf.pth
/usr/local/Cellar/protobuf/2.6.1/lib/ (6 other files)
/usr/local/Cellar/protobuf/2.6.1/libexec/lib/ (36 files)
/usr/local/Cellar/protobuf/2.6.1/share/doc/ (12 files)
$ pip list
imposm.parser (1.0.7)
adamfranco commented 8 years ago

@sgallese, do you get the same error when running Curvature without limiting it to a bounding-box? I haven't had a chance to test yet, but I'm guessing that the bounding box is causing the collection of coordinates to drop coordinates that later are being looked for because they are part of a way that includes some coordinates that are in the bounding box.

I can think of two ways this might be solved:

sgallese commented 8 years ago

Your assumption is correct, setting the bounding box produces an error while running the same command without a bounding box works without issue.

Spent an hour trying the first solution, couldn't get it to work (sorry, still not sure about all project terminology and new to Python).

I'll go ahead and use the entire state map for now and not limit to a bounding box.