1

I am trying the following:

After downloading http://eric.clst.org/assets/wiki/uploads/Stuff/gz_2010_us_050_00_20m.json

In [2]: import geopandas
In [3]: geopandas.read_file('./gz_2010_us_050_00_20m.json')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-83a1d4a0fc1f> in <module>
----> 1 geopandas.read_file('./gz_2010_us_050_00_20m.json')

~/miniconda3/envs/ml3/lib/python3.6/site-packages/geopandas/io/file.py in read_file(filename, **kwargs)
     24         else:
     25             f_filt = f
---> 26         gdf = GeoDataFrame.from_features(f_filt, crs=crs)
     27 
     28         # re-order with column order from metadata, with geometry last

~/miniconda3/envs/ml3/lib/python3.6/site-packages/geopandas/geodataframe.py in from_features(cls, features, crs)
    207 
    208         rows = []
--> 209         for f in features_lst:
    210             if hasattr(f, "__geo_interface__"):
    211                 f = f.__geo_interface__

fiona/ogrext.pyx in fiona.ogrext.Iterator.__next__()

fiona/ogrext.pyx in fiona.ogrext.FeatureBuilder.build()

TypeError: startswith first arg must be bytes or a tuple of bytes, not str

On the page http://eric.clst.org/tech/usgeojson/ with 4 geojson files under the 20m column, the above file corresponds to the US Counties row, and is the only one that cannot be read out of the 4. The error message isn't very informative, I wonder what's the reason, please?

zyxue
  • 7,904
  • 5
  • 48
  • 74
  • Can e.g., QGIS read the file? – Paul H Dec 24 '18 at 16:08
  • yes, QGIS can open the file – zyxue Dec 24 '18 at 16:54
  • Does the error message looks anything like "Polygons and MultiPolygons should follow the right-hand rule"? Because if so, it means you should sort the coordinates in the Polygons/MultiPolygons. – oriash Dec 25 '18 at 17:07
  • @oriash, I am not sure if this is the problem. But how do you sort coordinates, by lat or by lng? – zyxue Dec 25 '18 at 17:15
  • 1
    Clockwise. https://mapster.me/right-hand-rule-geojson-fixer/ should work. – oriash Dec 25 '18 at 17:18
  • @oriash, it turns out you're right, thank you! Do you know a more scalable fixer, the web-based one mapster almost freezes when I paste the geojson. Also, if you'd like reply it as an answer, I'd be happy to choose it as an answer. – zyxue Dec 25 '18 at 19:11

2 Answers2

1

If your error message looks anything like "Polygons and MultiPolygons should follow the right-hand rule", it means the order of the coordinates in those GeoObjects should be clock-wise.

Here's an online tool to "fix" your objects, with a short explanation:

https://mapster.me/right-hand-rule-geojson-fixer/

oriash
  • 149
  • 5
1

Possibly an answer for people arriving at this page, I received the same error and the error was thrown due to encoding issues.

Try encoding the initial file with utf-8 or try opening the file with an encoding which you think is applied to the file. This fixed my error.

More info here