question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError Reading a GeoJSON file

See original GitHub issue

Python version: Python 3.6.3 OS: Mac OSX 10.12.6

I’m wondering if anyone could help me with this error? I’m trying to load a Geojson file into a dataframe with OSM2PGSQL data downloaded from https://mapzen.com/data/metro-extracts/metro/birmingham_england/

When calling gpd.read_file with the points datafile I get the below error. I’m on a new Mac for work so perhaps I havn’t got a dependency installed? Any help would be great.

TypeError                                 Traceback (most recent call last)
<ipython-input-17-e215e87f454f> in <module>()
----> 1 gpd.read_file(points_datafile)

/usr/local/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

/usr/local/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```

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
koneshgitcommented, Mar 11, 2021

I did the following and it’s working

sFile = open(r"myFile.geojson","rb")
gdf = gpd.read_file(sFile)
data = json.loads(gdf.to_json())
1reaction
jschitocommented, Jun 1, 2019

I had the same issue an in my case it was an encoding error while reading the GeoJSON. I expected that the encoding of the input GeoJSON was UTF-8, but instead, it was ANSI. After I encoded the GeoJSON to UTF-8, everything worked properly. I noticed the error on the first occurrence of a special case in the properties (e.g. the German Umlaut ä, Ä, ö, Ö, ü, Ü), thus, I thought it could have something to do with the encoding.

Read more comments on GitHub >

github_iconTop Results From Across the Web

geopandas cannot read a geojson properly
TypeError : unhashable type: 'numpy.ndarray' when I use Series.str.len() in pandas query? Hot Network Questions · What was ...
Read more >
Reading geojson into Leaflet results in error?
I'm trying to read a geojson file into leaflet. Everything works out when I copy the text from the geojson file and paste...
Read more >
SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
JSON.parse() parses a string as JSON. This string has to be valid JSON and will throw this error if incorrect syntax was encountered....
Read more >
Cannot read properties of undefined (reading 'json') : r/node
Getting error -> TypeError: Cannot read properties of undefined (reading 'json'). Update: No need to use ".then" since I am using "async ...
Read more >
JSON encoder and decoder — Python 3.11.1 documentation
Be cautious when parsing JSON data from untrusted sources. ... Let the base class default method raise the TypeError ... return json.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found