Skip to content

'utf-8' codec can't decode #1282

@Mo-Dabao

Description

@Mo-Dabao

Description

Same codes worked well last year, but not now.

Code to reproduce

import cartopy.io.shapereader as shpreader


def __extract():
    shpname = r".\map\China_province"
    provinces_records = list(shpreader.Reader(shpname).records())
    provinces_geometrys = [x.geometry for x in provinces_records]
    provinces_attributes = [x.attributes for x in provinces_records]
    return provinces_geometrys, provinces_attributes

provinces_shapes, provinces_records = __extract()

Traceback

Traceback (most recent call last):

  File "<ipython-input-51-fc14594e3fb3>", line 1, in <module>
    from China_map import provinces_geometrys

  File "E:\Python\pyNMIC\FY4A\China_map.py", line 24, in <module>
    provinces_geometrys, provinces_attributes = __extract()

  File "E:\Python\pyNMIC\FY4A\China_map.py", line 18, in __extract
    provinces_records = list(shpreader.Reader(shpname).records())

  File "D:\Anaconda3\lib\site-packages\cartopy\io\shapereader.py", line 249, in records
    shape_record = self._reader.shapeRecord(i)

  File "D:\Anaconda3\lib\site-packages\shapefile.py", line 992, in shapeRecord
    return ShapeRecord(shape=self.shape(i), record=self.record(i))

  File "D:\Anaconda3\lib\site-packages\shapefile.py", line 961, in record
    return self.__record(oid=i)

  File "D:\Anaconda3\lib\site-packages\shapefile.py", line 946, in __record
    value = u(value, self.encoding, self.encodingErrors)

  File "D:\Anaconda3\lib\site-packages\shapefile.py", line 104, in u
    return v.decode(encoding, encodingErrors)

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb0 in position 0: invalid start byte
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

pyshp                     2.0.1
shapely                   1.6.4
python                    3.7.2
......

When I

from shapefile import Reader as shpReader

shpname = r".\map\China_province"
file = shpReader(shpname, encoding="gbk")
provinces_records = file.records()
provinces_shapes = file.shapes()

there's no Error.

What happened to shapefile or cartopy? Can I pass encoding="gbk" to cartopy.io.shapereader.Reader()?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions