ó ŸÃÒYc@sXdZddlZdZddgZeed„Zeed„Zd„Zd „Z dS( s² ********* Shapefile ********* Generates a networkx.DiGraph from point and line shapefiles. "The Esri Shapefile or simply a shapefile is a popular geospatial vector data format for geographic information systems software. It is developed and regulated by Esri as a (mostly) open specification for data interoperability among Esri and other software products." See https://en.wikipedia.org/wiki/Shapefile for additional information. iÿÿÿÿNs!Ben Reilly (benwreilly@gmail.com)tread_shpt write_shpcCsÇyddlm}Wntk r3tdƒ‚nXt|tƒsGdStjƒ}|j|ƒ}x^|D]V}g|jD]}|j ƒ^qy}x+|D]#} g|D]}| j | j |ƒƒ^q¥} | j ƒ} t t|| ƒƒ} |j ƒ| d<| jƒ|jkr+|j| jdƒ| ƒq˜| jƒ|j|jfkr xot| | ||ƒD]:} | \}}}|j||ƒ|||j|ƒq_Wq˜tdj| jƒƒƒ‚q˜WqiW|S(s®Generates a networkx.DiGraph from shapefiles. Point geometries are translated into nodes, lines into edges. Coordinate tuples are used as keys. Attributes are preserved, line geometries are simplified into start and end coordinates. Accepts a single shapefile or directory of many shapefiles. "The Esri Shapefile or simply a shapefile is a popular geospatial vector data format for geographic information systems software [1]_." Parameters ---------- path : file or string File, directory, or filename to read. simplify: bool If True, simplify line geometries to start and end coordinates. If False, and line feature geometry has multiple segments, the non-geometric attributes for that feature will be repeated for each edge comprising that feature. geom_attrs: bool If True, include the Wkb, Wkt and Json geometry attributes with each edge. NOTE: if these attributes are available, write_shp will use them to write the geometry. If nodes store the underlying coordinates for the edge geometry as well (as they do when they are read via this method) and they change, your geomety will be out of sync. Returns ------- G : NetworkX graph Examples -------- >>> G=nx.read_shp('test.shp') # doctest: +SKIP References ---------- .. [1] https://en.wikipedia.org/wiki/Shapefile iÿÿÿÿ(togrs+read_shp requires OGR: http://www.gdal.org/NtShpNameisGeometryType {} not supported(tosgeoRt ImportErrort isinstancetstrtnxtDiGraphtOpentschematGetNametGetFieldt GetFieldIndextgeometrytdicttziptGetGeometryTypetwkbPointtadd_nodet GetPoint_2Dt wkbLineStringtwkbMultiLineStringtedges_from_linetadd_edgetupdatetformat(tpathtsimplifyt geom_attrsRtnettshptlyrtxtfieldstftflddatatgt attributestedgete1te2tattr((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/readwrite/nx_shp.pyRs6+   " +   c csyddlm}Wntk r3tdƒ‚nX|jƒ|jkr¨|rÇ|jƒ}|jƒd}|r¤|jƒ|d<|jƒ|d<|j ƒ|d  #  cs{yddlm‰Wntk r3tdƒ‚nXˆjƒ‡fd†}d‡‡fd†}ˆjdƒ}|j|ƒ}y|jdƒWnnX|jddˆj ƒ}x7|D]/}|j |}|||ƒ‰|ˆ|ƒqºWy|jdƒWnnX|jddˆj ƒ} i} i} iˆj t 6ˆjt6ˆjt6} x|jd tƒD]} |j| Œ}|| |ƒ‰xÍ| d jƒD]»\}}|d kr˜|d kr˜|d kr˜|dkr˜|| krFt|ƒ| kr | t|ƒ| | s  M@