networkx.readwrite.nx_shp.read_shp¶
-
read_shp
(path, simplify=True, geom_attrs=True, strict=True)[source]¶ 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.
strict (bool) – If True, raise NetworkXError when feature geometry is missing or GeometryType is not supported. If False, silently ignore missing or unsupported geometry in features.
Returns: G
Return type: NetworkX graph
Raises: ImportError
– If ogr module is not available.RuntimeError
– If file cannot be open or read.NetworkXError
– If strict=True and feature is missing geometry or GeometryType is not supported.
Examples
>>> G=nx.read_shp('test.shp') # doctest: +SKIP
References
[1] https://en.wikipedia.org/wiki/Shapefile