1 Star 0 Fork 0

cq383768026/Learn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
zipshape.py 1.04 KB
一键复制 编辑 原始数据 按行查看 历史
geospatialpython 提交于 2015-06-19 01:37 +08:00 . Consolidated repositories
"""
Example of saving a shapefile to a file-like
object using a zip file as the target. Uses
the individual save methods for each type
of file instead of the general pyshp
save method.
"""
import zipfile
import StringIO
import shapefile
# Set up buffers for saving
shp = StringIO.StringIO()
shx = StringIO.StringIO()
dbf = StringIO.StringIO()
# Make a point shapefile
w = shapefile.Writer(shapefile.POINT)
w.point(90.3, 30)
w.point(92, 40)
w.point(-122.4, 30)
w.point(-90, 35.1)
w.field('FIRST_FLD')
w.field('SECOND_FLD','C','40')
w.record('First','Point')
w.record('Second','Point')
w.record('Third','Point')
w.record('Fourth','Point')
# Save shapefile components to buffers
w.saveShp(shp)
w.saveShx(shx)
w.saveDbf(dbf)
# Save shapefile buffers to zip file
# Note: zlib must be available for
# ZIP_DEFLATED to compress. Otherwise
# just use ZIP_STORED.
z = zipfile.ZipFile("myshape.zip", "w", zipfile.ZIP_DEFLATED)
z.writestr("myshape.shp", shp.getvalue())
z.writestr("myshape.shx", shx.getvalue())
z.writestr("myshape.dbf", dbf.getvalue())
z.close()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cq383768026/Learn.git
[email protected]:cq383768026/Learn.git
cq383768026
Learn
Learn
master

搜索帮助