Python中shapefile转换geojson的示例
shapefile转换geojson
importshapefile
importcodecs
fromjsonimportdumps
#readtheshapefile
defshp2geo(file="line出产.shp"):
reader=shapefile.Reader(file)
fields=reader.fields[1:]
field_names=[field[0]forfieldinfields]
buffer=[]
forsrinreader.shapeRecords():
record=sr.record
record=[r.decode('gb2312','ignore')ifisinstance(r,bytes)
elserforrinrecord]
atr=dict(zip(field_names,record))
geom=sr.shape.__geo_interface__
buffer.append(dict(type="Feature",geometry=geom,properties=atr))
#writetheGeoJSONfile
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__':
#importos
#forz,x,cinos.walk('.'):
#forzzinc:
#ifzz.endswith(".shp"):
#shp2geo(zz)
#shp2geo(file='D.shp')
shp2geo(file='ttttttttttt.shp')
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对毛票票的支持。如果你想了解更多相关内容请查看下面相关链接
热门推荐
10 毛笔哥哥结婚祝福语简短
11 向国庆送祝福语简短
12 建队节祝福语简短
13 朋友喜得外孙简短祝福语
14 小店营业的祝福语简短
15 餐饮生日祝福语简短独特
16 鲜花英语祝福语卡片简短
17 男朋友暴富祝福语简短
18 婶婶拜年祝福语大全简短