您好,登錄后才能下訂單哦!
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é)習或者工作具有一定的參考學(xué)習價值,謝謝大家對億速云的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。