当前位置:首页 » 编程语言 » shapefilepython

shapefilepython

发布时间: 2023-04-05 19:54:36

python readshapefile读取.shp报错

帮你搜

python readshapefile

找到了

'utf-8' codec can't decode when using readshapefile on python basemap - Stack Overflow

其中提到的,或许对你有用:

去把你的要导入的文件 bou2_4p.shp 去(比如用VSCode)转换为UTF-8编码

估计就可以了。


关于VSCode,详见:

文件编码 · 史上最好用的编辑器:VSCode

㈡ 如何用python读取arcgis中shapefile文件的属性表

可以,如果arcgis是10版本,可以用arcpy模块中的SearchCursor读取shp的属性表;用python读写excel需要安装pythonWin或者安装comtypes都可以,你可以上网找一下这样的资料。

㈢ 如何利用Python读入shapefile文件 Python如果读入非TXT文件

# filename: test.py
import os

users = [] # 用来保存从文件中读取的数据

for item in os.listdir('.'): # 遍历指定目录
if os.path.isfile(item) and item.endswith('.txt'): # 判断是否为.txt文件
f = open(item) # 打开文件

for line in f: # 读入文件的每一行
if line.startswith('用户名'): # 变量初始化
uid = age = sex = None
elif line.startswith("用户id"): # 根据每行开始内容获取数据
uid = line.split()[1]
elif line.startswith("年龄"):
age = line.split()[1]
elif line.startswith("性别"):
sex = line.split()[1]
users.append([uid, age, sex]) # 将所获得的数据以列表的形式追加到数组中

f.close() # 关闭文件

print(users) # 打印数组内容

# [['12345', '23', '男'], ['12346', '23', '男'], ['12347', '23', '男'], ['12348', '23', '男']]

使用的数据文件:
1.txt
------------
用户名 abc
------------
用户id 12345

年龄 23

性别 男

------------
用户名 小张
------------
用户id 12346

年龄 23

性别 男

2.txt
------------
用户名 张三
------------
用户id 12347

年龄 23

性别 男

------------
用户名 李四
------------
用户id 12348

年龄 23

性别 男

热点内容
androiddagger2 发布:2025-09-16 04:38:38 浏览:120
javahttp编程 发布:2025-09-16 04:33:44 浏览:300
压缩安装器 发布:2025-09-16 03:47:17 浏览:178
特产网源码 发布:2025-09-16 03:42:24 浏览:328
安卓faceplay怎么付款 发布:2025-09-16 03:32:34 浏览:583
安卓rom包里有什么 发布:2025-09-16 03:07:57 浏览:353
sql2005无法连接 发布:2025-09-16 03:04:21 浏览:681
预埋件算法 发布:2025-09-16 02:55:45 浏览:93
php取差集 发布:2025-09-16 02:46:58 浏览:974
ah脚本扫货 发布:2025-09-16 02:44:53 浏览:73