reading shp file with pyshp jupyter

474 Views Asked by At
import numpy as np
import pandas as pd

import shapefile as shp

import matplotlib.pyplot as plt
import seaborn as sns
shp_path = 'seoul\seoul.shp'
sf = shp.Reader(shp_path)
sf.records()[1]

and then finally I got this error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xba in position 0: invalid start byte

I wanna how to solve this problem

1

There are 1 best solutions below

0
RicHincapie On

You need to try different encodings options. The documentation shows a way to do it for the shapefile's method Reader:

shp_path = "Barrios_Cali/Barrios.shp"
sf = shp.Reader(shp_path, encoding="latin1") # Notice the encoding option

So go ahead and look for the .shp probable encoding type and give it a try.