Python中shapefile轉(zhuǎn)換geojson的示例
shapefile轉(zhuǎn)換geojson
import shapefile
import codecs
from json import dumps
# read the shapefile
def 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)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接
相關(guān)文章
Python+?Flask實(shí)現(xiàn)Mock?Server詳情
這篇文章主要介紹了Python+?Flask實(shí)現(xiàn)Mock?Server詳情,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-09-09
python實(shí)現(xiàn)代碼審查自動(dòng)回復(fù)消息
這篇文章主要介紹了python實(shí)現(xiàn)代碼審查回復(fù)消息生成的示例,幫助大家更好的理解和學(xué)習(xí)python,感興趣的朋友可以了解下2021-02-02
python通過elixir包操作mysql數(shù)據(jù)庫實(shí)例代碼
這篇文章主要介紹了python通過elixir包操作mysql數(shù)據(jù)庫,分享了相關(guān)代碼示例,小編覺得還是挺不錯(cuò)的,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-01-01
詳解使用pymysql在python中對(duì)mysql的增刪改查操作(綜合)
本篇文章主要介紹了使用pymysql在python中對(duì)mysql的增刪改查操作,通過pymysql向數(shù)據(jù)庫進(jìn)行查刪增改,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-01-01
Windows 下更改 jupyterlab 默認(rèn)啟動(dòng)位置的教程詳解
這篇文章主要介紹了Windows 下更改 jupyterlab 默認(rèn)啟動(dòng)位置,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-05-05
Python 高級(jí)教程之線程進(jìn)程和協(xié)程的代碼解析
這篇文章主要介紹了Python 高級(jí)教程之線程進(jìn)程和協(xié)程的代碼解析,包括使用線程模塊的簡(jiǎn)單示例,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-05-05
python 實(shí)現(xiàn)簡(jiǎn)易的記事本
這篇文章主要介紹了python 實(shí)現(xiàn)簡(jiǎn)易的記事本的示例代碼,幫助大家更好的理解和學(xué)習(xí)python,感興趣的朋友可以了解下2020-11-11
Python+matplotlib實(shí)現(xiàn)填充螺旋實(shí)例
這篇文章主要介紹了Python+matplotlib實(shí)現(xiàn)填充螺旋實(shí)例,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-01-01

