popframe.models.territory

Classes

Territory(*, id, name, geometry)

A class representing a geographic territory with an ID, name, and geometry.

class popframe.models.territory.Territory(*, id: int, name: str, geometry: Polygon)[source]

Bases: BaseModel

A class representing a geographic territory with an ID, name, and geometry.

Attributes

idint

Unique identifier for the territory.

namestr

Name of the territory.

geometryshapely.Polygon

A Shapely Polygon object representing the territory’s geometry.

Methods

to_dict() -> dict

Converts the Territory object to a dictionary format.

from_gdf(cls, gdf: gpd.GeoDataFrame) -> list

Class method to create a list of Territory instances from a GeoDataFrame.

id: int
name: str
geometry: Polygon
to_dict() dict[source]

Converts the Territory instance to a dictionary.

Returns

dict

A dictionary containing the ‘id’, ‘name’, and ‘geometry’ of the territory.

classmethod from_gdf(gdf: GeoDataFrame) list[source]

Creates a dictionary of Territory objects from a GeoDataFrame.

Parameters

gdfgpd.GeoDataFrame

GeoDataFrame containing data to initialize Territory instances. The GeoDataFrame should have ‘id’, ‘name’, and ‘geometry’ columns.

Returns

dict

A dictionary where the keys are indices of the GeoDataFrame and the values are Territory instances.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.