cea.technologies.network_layout package

Submodules

cea.technologies.network_layout.connectivity_potential module

cea.technologies.network_layout.main module

cea.technologies.network_layout.minimum_spanning_tree module

cea.technologies.network_layout.steiner_spanning_tree module

cea.technologies.network_layout.substations_location module

cea.technologies.network_layout.utility module

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.

cea.technologies.network_layout.utility.edges_from_line(geom, attrs, simplify=True, geom_attrs=True)[source]

Generate edges for each line in geom Written as a helper for read_shp

geom: ogr line geometry

To be converted into an edge or edges

attrs: dict

Attributes to be associated with all geoms

simplify: bool

If True, simplify the line as in read_shp

geom_attrs: bool

If True, add geom attributes to edge as in read_shp

edges: generator of edges

each edge is a tuple of form (node1_coord, node2_coord, attribute_dict) suitable for expanding into a networkx Graph add_edge call

cea.technologies.network_layout.utility.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 (str) – 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 geometry 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:

the 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.

cea.technologies.network_layout.utility.write_shp(G, outdir)[source]

Writes a networkx.DiGraph to two shapefiles, edges and nodes. Nodes and edges are expected to have a Well Known Binary (Wkb) or Well Known Text (Wkt) key in order to generate geometries. Also acceptable are nodes with a numeric tuple key (x,y).

“The Esri Shapefile or simply a shapefile is a popular geospatial vector data format for geographic information systems software [2].”

:param str outdir : directory path, Output directory for the two shapefiles. :rtype: None

Examples:

nx.write_shp(digraph, '/shapefiles') # doctest +SKIP