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 出阁宴祝福语姐姐简短