0

I'm trying to open a geojson file into geopandas but getting the following error message:

 Traceback (most recent call last):
 File "C:\Users\arobe\Anaconda3\envs\test_env\lib\site-packages\geopandas\io\file.py", line 95, in read_file
 gdf = GeoDataFrame.from_features(f_filt, crs=crs, columns=columns)
 File "C:\Users\arobe\Anaconda3\envs\test_env\lib\site-packages\geopandas\geodataframe.py", line 283, in from_features
 for f in features_lst:
 File "fiona/ogrext.pyx", line 1369, in fiona.ogrext.Iterator.__next__
 File "fiona/ogrext.pyx", line 232, in fiona.ogrext.FeatureBuilder.build
 TypeError: startswith first arg must be bytes or a tuple of bytes, not str

The solutions here geopandas cannot read a geojson properly_ have not worked for me and I've tried all manner of encodings. The data is from UK MSOA dataset (https://geoportal.statistics.gov.uk/datasets/f341dcfd94284d58aba0a84daf2199e9_2/geoservice?page=720).

The data downloads fine and works ok in Tableau. It also looks to be ok when opened in Notepad++ so it doesn't appear to be a data issue but I'm new to this so really don't know what I'm doing!

Any help would be much appreciated.

Code snippet:

 gdf=gpd.read_file("https://opendata.arcgis.com/datasets/f341dcfd94284d58aba0a84daf2199e9_2.geojson")
 print(gdf.head(10))

 gdf.to_file("msoa.geojson", driver='GeoJSON')

 gdf2=gpd.read_file("msoa.geojson"
             ,driver='GeoJSON'
             )

 print(gdf2.head(10))
A Rob4
  • 1,278
  • 3
  • 17
  • 35

2 Answers2

1

I run your code on Linux using geopandas v0.8.1, fiona v1.8.17. All OK. The simple plot is as follows.

gb-plot

swatchai
  • 17,400
  • 3
  • 39
  • 58
  • thanks so much. This seems to be a windows/ anaconda issue perhaps as a few people seem to have had trouble, I'm starting to think it might be to do with Fiona and have built a fresh environment and followed the steps here https://stackoverflow.com/questions/50876702/cant-install-fiona-on-windows?rq=1 but so far to no benefit as still having the same issue. – A Rob4 Dec 07 '20 at 14:52
  • you are right - issue is some strange characters see my answer above – A Rob4 Dec 16 '20 at 07:37
0

It transpires that there was, for some reason, some strange characters in the downloaded data. I manually removed them as they were for an area I wasn't interested in and it now works. The solution was found here https://github.com/geopandas/geopandas/issues/621

A Rob4
  • 1,278
  • 3
  • 17
  • 35