Python中shapefile转换geojson的示例
更新时间:2019年01月03日 11:46:16 作者:staHuri
今天小编就为大家分享一篇关于Python中shapefile转换geojson的示例,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
shapefile转换geojson
import shapefile import codecs from json import dumps # read the shapefile def shp2geo(file="line出产.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')
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对脚本之家的支持。如果你想了解更多相关内容请查看下面相关链接
相关文章
解读torch.cuda.amp自动混合精度训练之节省显存并加快推理速度
这篇文章主要介绍了torch.cuda.amp自动混合精度训练之节省显存并加快推理速度问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教2023-08-08python+pytest自动化测试函数测试类测试方法的封装
这篇文章主要介绍了python+pytest自动化测试函数测试类测试方法的封装,文章围绕主题展开详细的内容介绍,具有一定的参考价值,需要的小伙伴可以参考一下2022-06-06Python编程ContextManager上下文管理器讲解
这篇文章主要介绍了Python编程中对Context Manager上下文管理器的详解说明,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步2021-09-09
最新评论