Skip to content

Shapefiles

siapy.entities.shapefiles

Coordinates

Bases: NamedTuple

X class-attribute instance-attribute

X: str = 'x'

Y class-attribute instance-attribute

Y: str = 'y'

Shapefile dataclass

Shapefile(_data: GeoDataFrame)

coords class-attribute

df property

df: GeoDataFrame

geometry_type property

geometry_type: str

Return the geometry type of the first feature in the shapefile.

geometry_types property

geometry_types: list[str]

Return a list of all geometry types in the shapefile.

from_path classmethod

from_path(filepath: str | Path) -> Shapefile
Source code in siapy/entities/shapefiles.py
29
30
31
32
33
34
@classmethod
def from_path(cls, filepath: str | Path) -> "Shapefile":
    if not Path(filepath).exists():
        raise InvalidFilepathError(filepath)
    shapefile = gpd.read_file(filepath)
    return cls(shapefile)

has_consistent_geometry_type

has_consistent_geometry_type() -> bool

Check if all features have the same geometry type.

Source code in siapy/entities/shapefiles.py
55
56
57
58
def has_consistent_geometry_type(self) -> bool:
    """Check if all features have the same geometry type."""
    types = set(self.geometry_types)
    return len(types) == 1

to_numpy

to_numpy() -> ndarray
Source code in siapy/entities/shapefiles.py
60
61
def to_numpy(self) -> np.ndarray:
    return self.df.to_numpy()