国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python中shapefile轉(zhuǎn)換geojson的示例

2020-01-04 13:37:32
字體:
供稿:網(wǎng)友

shapefile轉(zhuǎn)換geojson

import shapefileimport codecsfrom json import dumps# read the shapefiledef shp2geo(file="line出產(chǎn).shp"):  reader = shapefile.Reader(file)  fields = reader.fields[1:]  field_names = [field[0] for field in fields]  buffer = []  for sr in reader.shapeRecords():    record = sr.record    record = [r.decode('gb2312', 'ignore') if isinstance(r, bytes)         else r for r in record]    atr = dict(zip(field_names, record))    geom = sr.shape.__geo_interface__    buffer.append(dict(type="Feature", geometry=geom, properties=atr))    # write the GeoJSON file  geojson = codecs.open(file.split('.')[0] + "-geo.json", "w", encoding="gb2312")  geojson.write(dumps({"type": "FeatureCollection", "features": buffer}, indent=2) + "/n")  geojson.close()if __name__ == '__main__':  # import os  # for z,x,c in os.walk('.'):  #   for zz in c:  #     if zz.endswith(".shp"):  #       shp2geo(zz)  # shp2geo(file='D.shp')  shp2geo(file='ttttttttttt.shp')

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對VEVB武林網(wǎng)的支持。


注:相關(guān)教程知識閱讀請移步到python教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 娱乐| 玉山县| 洮南市| 九龙坡区| 洛川县| 宾阳县| 石首市| 东台市| 普兰店市| 尚义县| 青岛市| 双峰县| 南召县| 城市| 崇信县| 望城县| 罗城| 阳新县| 黑龙江省| 巴里| 正阳县| 金坛市| 阿荣旗| 平舆县| 宜州市| 班戈县| 喀喇沁旗| 滁州市| 河源市| 莱州市| 喜德县| 新化县| 铁力市| 时尚| 东莞市| 石家庄市| 红原县| 阿鲁科尔沁旗| 武平县| 保靖县| 抚州市|