-
Notifications
You must be signed in to change notification settings - Fork 368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'utf-8' codec can't decode #1282
Comments
I reworked a lot of the shapefile reading this past year, but there hasn't ever been any encoding parameters on Cartopy's side. It looks like both pyshp and Fiona contain an encoding keyword, so if you wanted to make a pull request with that added to the readers that would be a worthwhile addition I think. Reading pyshp's latest release notes: https://github.com/GeospatialPython/pyshp/releases I would also suggest installing Fiona to do the shapefile reading if possible, it is much faster and perhaps that library can detect the file encoding better. It looks like you're on an Anaconda environment, so: |
Thanks for advices. I find a way to convert my It's a nice experience to use Cartopy to handle projection and add Really thanks for all you guys' works! |
|
Add a argument to Reader class maybe a better choice. The most lazy way is add class BasicReader(object):
"""
Provide an interface for accessing the contents of a shapefile.
The primary methods used on a Reader instance are
:meth:`~Reader.records` and :meth:`~Reader.geometries`.
"""
def __init__(self, filename, **kwargs):
# Validate the filename/shapefile
self._reader = reader = shapefile.Reader(filename, **kwargs) And class FionaReader(object):
"""
Provides an interface for accessing the contents of a shapefile
with the fiona library, which has a much faster reader than pyshp.
The primary methods used on a Reader instance are
:meth:`~Reader.records` and :meth:`~Reader.geometries`.
"""
def __init__(self, filename, bbox=None, **kwargs):
self._data = []
with fiona.open(filename, **kwargs) as f:
if bbox is not None:
assert len(bbox) == 4
features = f.filter(bbox=bbox)
else:
features = f |
@wqshen do you want to open a PR with your proposed change? |
@wqshen It really works, awesome! |
Passing encoding to pyshp/fiona is now added with #2236. |
Description
Same codes worked well last year, but not now.
Code to reproduce
Traceback
Full environment definition
Operating system
Win10 1809 64bit
Cartopy version
Now is 0.17.0, don't remember witch version when it worked.
conda list
When I
there's no Error.
What happened to
shapefile
orcartopy
? Can I passencoding="gbk"
tocartopy.io.shapereader.Reader()
?The text was updated successfully, but these errors were encountered: