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