2 Star 4 Fork 3

汉塞大叔/Geospatial_Analysis_By_Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
2.1 编辑shapefile.py 1.40 KB
一键复制 编辑 原始数据 按行查看 历史
汉塞大叔 提交于 2021-01-20 19:53 +08:00 . 上传 py
import shapefile
from datetime import date
# 文本字段使用'C'类型创建,第三个'size'参数可以自定义为文本值的预期长度以节省空间
# w = shapefile.Writer("shapefiles")
# w.field('TEXT', 'C')
# w.field('SHORT_TEXT', 'C', size=5)
# w.field('LONG_TEXT', 'C', size=250)
# w.null()
# w.record('Hello', 'World', 'World'*50)
# w.close()
#
# r = shapefile.Reader("shapefiles")
# print(len(r))
# print(r.shapeTypeName)
# r.close()
# 日期字段使用'D'类型创建,并且可以使用日期对象,列表或YYYYMMDD格式的字符串创建
w = shapefile.Writer('shapefiles')
w.field('DATE', 'D')
w.null()
w.null()
w.null()
w.null()
w.record(date(1898, 1, 29))
w.record([1998, 1, 30])
w.record('19980131')
w.record(None)
w.close()
r = shapefile.Reader('shapefiles')
shapeRecs = r.shapeRecords()
print(shapeRecs[0].record[0])
print(shapeRecs[1].record[0])
print(shapeRecs[2].record[0])
print(shapeRecs[3].record[0])
assert r.record(0) == [date(1898,1,29)]
assert r.record(1) == [date(1998,1,30)]
assert r.record(2) == [date(1998,1,31)]
assert r.record(3) == [None]
# 可以使用关键字参数添加属性,其中关键字是字段名称
# w = shapefile.Writer('shapefiles')
# w.field('FIRST_FLD','C','40')
# w.field('SECOND_FLD','C','40')
# w.null()
# w.null()
# w.record('First', 'Line')
# w.record(FIRST_FLD='First', SECOND_FLD='Line')
# w.close()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/fengfeng233/geospatial_-analysis_-by_-python.git
git@gitee.com:fengfeng233/geospatial_-analysis_-by_-python.git
fengfeng233
geospatial_-analysis_-by_-python
Geospatial_Analysis_By_Python
master

搜索帮助