Error reading shape file
Closed this issue · 6 comments
Getting this error after reading in the shape file, any idea?
UnicodeDecodeError: 'utf8' codec can't decode byte 0xc5 in position 0: invalid continuation byte
What OS and Python versions are you using?
Please can you post the full error traceback?
Ubuntu 16.04 and I tried Python 2.7 and 3.7
Here is the full traceback:
File "/home/brads/projects/random-street-view/random_street_view.py", line 86, in <module>
for i, record in enumerate(sf.records()):
File "/home/brads/anaconda3/envs/cv/lib/python3.7/site-packages/shapefile.py", line 1012, in records
r = self.__record(oid=i)
File "/home/brads/anaconda3/envs/cv/lib/python3.7/site-packages/shapefile.py", line 987, in __record
value = u(value, self.encoding, self.encodingErrors)
File "/home/brads/anaconda3/envs/cv/lib/python3.7/site-packages/shapefile.py", line 104, in u
return v.decode(encoding, encodingErrors)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc5 in position 0: invalid continuation byte```
Aha, I didn't get the same error with an old version of pyshp, 1.2.12.
I can reproduce after upgrading to the latest 2.1.0.
Looks like they've changed the interface for pyshp 2.
Please install the latest pyshp 1 to use this script:
pip install "pyshp<2"
Awesome, thanks for looking into it
Checking https://github.com/GeospatialPython/pyshp#unicode-and-shapefile-encodings, looks like it should work with pyshp 2.1.0 and Python 3 with this change in random_street_view.py
:
-sf = shapefile.Reader(shape_file)
+sf = shapefile.Reader(shape_file, encoding="latin1")