esrijson的绑定和实用程序
esrijson的Python项目详细描述
艾斯里森
简介
此模块旨在通过Shapely在gdal__geo_interface__
属性之间建立一个桥。
esrijson语法中没有GeometryCollection
的概念,因此对这个概念的支持有限。目前,我们只取第一个几何图形,其余的则删除。
这个图书馆深受python-geojson的启发。
用法
importesrijsonfromshapelyimportgeometry# Create an esrijson featurefeat=esrijson.Feature(geometry=geometry.Point(1,4),attributes={'name':'dummy','val':1},wkid=2056)# Dump to jsondumped=esrijson.dumps(feat)# Load to Feature back againloaded=esrijson.loads(dumped)print(loaded)print(type(loaded))>>>{'geometry':{'y':4.0,'x':1.0},'spatialReference':{u'wkid':2056}},'attributes':{u'name':u'dummy',u'val':1}}>>><class'esrijson.feature.Feature'># You can also transform an esri json like object into a shapely objectgeom=esrijson.to_shape({"paths":[[[0.0,0.0],[1.0,1.0]],[[-1.0,0.0],[1.0,0.0]]]})print(getattr(geom,'__geo_interface__')>>>{'type':'MultiLineString','coordinates':(((0.0,0.0),(1.0,1.0)),((-1.0,0.0),(1.0,0.0)))}# And of your do the same operation back againesri_geom=esrijson.from_shape(geom)print(esri_geom)>>>{'paths':(((0.0,0.0),(1.0,1.0)),((-1.0,0.0),(1.0,0.0)))}