The ShapeFileParser class#

What it does#

The ShapeFileParser class is used to extract and structure the geometric and topological information from vector data such as shapefiles or GeoDataFrames. It processes points, lines, zones, boundaries, regions, and associated resolutions, preparing the data for downstream tasks such as mesh generation with Gmsh. ShapeFileParser automates the conversion of geospatial vector information into a structured, indexed format compatible with finite element meshing workflows.

Documentation#

class watlab.utils.ShapeFileParser(shapefile: str | GeoDataFrame, type: str = 'shp')#

Extracts and structures the elements of geospatial vector informations into an indexed format compatible with MeshMaker.

This parser reads a shapefile (.shp) or a geopandas.GeoDataFrame and extracts all geometric and topological information required for mesh construction. It identifies points, resolutions, lines, boundaries, zones, and regions. Duplicate geometries are automatically removed.

Parameters:
  • shapefile (str | geopandas.GeoDataFrame) – Path to the shapefile, or a GeoDataFrame containing the data. The shapefile ‘data.shp’ must be placed in the same folder as the associated files ‘data.cpg’, ‘data.dbf’, ‘data.prj’, and ‘data.shx’.

  • type (str) – Defines how the input should be interpreted. Use “shp” for shapefiles or “csv” for CSV geometry files. Defaults to “shp”.

Example

from watlab.utils.shapeFileParser import ShapeFileParser

parser = ShapeFileParser("topology/data.shp")

print(parser.points)
print(parser.boundaries)
print(parser.zones)
print(parser.regions)
property boundaries: dict#

A dictionary of boundaries names and boundary line indices.

Each key is a boundary name extracted from the shapefile, and each value is a list of line indices that compose that boundary. This allows referencing the topology according to its physical boundary definitions.

Getter:

Dictionary mapping boundary names to lists of line indices.

Return type:

dict[str, list[int]]

property data: GeoDataFrame#

geopandas.GeoDataframe that stores the geospatial vectored data.

Getter:

returns the GeoDataFrame containing the original geospatial vectored data.

Return type:

geopandas.GeoDataFrame

property internal_boundaries: dict#

A dictionary of internal boundaries names and internal boundary line indices.

Each key is an internal boundary name extracted from the shapefile, and each value is a list of line indices that compose that internal boundary. This allows referencing the topology according to its physical boundary definitions. An internal boundary is a line within a unique zone, which does not separate two different zones.

Getter:

Dictionary mapping internal boundary names to lists of line indices.

Return type:

dict[str, list[int]]

property lines: list#

A list of unique line segments extracted from all linestrings.

Unlike linestrings—which preserves the grouping by polylines—this property returns a flat collection of distinct line segments, each represented as a tuple (i, j) of point indices. Duplicate segments are removed, and the list is sorted to ensure consistent ordering.

Getter:

The sorted list of unique line segments.

Return type:

list[tuple[int, int]]

property linestrings: list#

A list of line segments extracted from the shapefile.

Each element corresponds to a polyline and is represented as a list of tuples (i, j), where each tuple denotes a line segment between two consecutive point tags in the geometry.

Getter:

The collection of line segments grouped by their originating polylines.

Return type:

list of list[tuple[int, int]]

property points: list#

List of unique point coordinates extracted from the shapefile (sorted by increasing coordinates).

Getter:

A sorted list of unique point coordinates.

Return type:

list of tuple(float, float)

property points_tags: list#

List of sequential identifiers associated with each extracted point.

Tags are generated after point extraction and correspond to the index (starting at 1) of each point in the sorted points list.

Getter:

A list of integer tags for all points.

Return type:

list of int

property polylines: list#

A sequence of line indices representing the polylines.

Each polyline corresponds to a linestring from the shapefile and is represented as a list of integer indices pointing to the global lines list. This allows reconstructing each polyline in terms of its constituent line segments.

Getter:

A list of polylines, where each polyline is a list of indices referring to line segments in lines.

Return type:

list of list[int]

property polypoints: list#

Sequence of point-index lists describing each polyline. Each element corresponds to a LineString and contains the ordered point identifiers (tags) that compose it.

Getter:

A list where each element is a list of point tags forming a polyline.

Return type:

list of list[int]

property regions: dict#

A dictionary of regions and zones names.

Each key is a region name extracted from the shapefile, and each value is a set of zone names that compose that region. Zones are included in a region if all their line segments are part of the region’s lines.

Getter:

Dictionary mapping region names to sets of zone names.

Return type:

dict[str, set[str]]

property resolutions: list#

Resolution value associated with each point on the geospatial vectored data.

Getter:

A list of resolution for all points.

Return type:

list of double

property zones: dict#

A dictionary of zones and line indices.

Each key is a zone name extracted from the shapefile, and each value is a list of line indices that compose the boundary of that zone. By convention, the first point of the first line matches the last point of the last line, forming a closed loop.

Getter:

Dictionary mapping zone names to lists of line indices forming the zone boundaries.

Return type:

dict[str, list[int]]