我正试着把形状文件读入地理数据框。在
通常我只需要这样做,它就会起作用:
import pandas as pd
import geopandas as gpd
from shapely.geometry import Point
df = gpd.read_file("wild_fires/nbac_2016_r2_20170707_1114.shp")
但这一次它给了我一个错误:b'Recode from ANSI 1252 to UTF-8 failed with the error: "Invalid argument".'
完全错误:
^{pr2}$我一直想弄清楚为什么有一段时间会出错,但似乎找不到答案。在
数据是从这个网页获得的我只下载了2016年的链接:http://cwfis.cfs.nrcan.gc.ca/datamart/download/nbac?token=78e9bd6af67f71204e18cb6fa4e47515
有人能帮我吗?谢谢您。在
为我工作。在
作为this answer的扩展,可以通过geopandas read_file传递fiona参数:
似乎您的SuffEFILE包含非UTF字符,这些字符导致^ {CD1>}调用失败(GeopDaas使用菲奥娜打开文件)。在
解决这个错误的方法是打开Shapefile(例如使用QGis),然后选择
save as
,并将Encoding
选项指定为“UTF-8”:这样做之后,我在调用
df = gpd.read_file("convertedShape.shp")
时没有出错。在另一种不必使用QGis或类似工具的方法是再次读取并保存Shapefile(有效地转换为所需的格式)。使用OGR,您可以执行以下操作:
这也使得在转换后可以用
df = gpd.read_file("convertedShape.shp")
成功打开。希望这有帮助。在相关问题 更多 >
编程相关推荐