popframe.models.town

Classes

Town(*, id, name, level, population, geometry)

A class representing a town with an ID, name, administrative level, population, and geometry.

class popframe.models.town.Town(*, id: int, name: str, level: str, population: int, geometry: Point)[source]

Bases: BaseModel

A class representing a town with an ID, name, administrative level, population, and geometry.

Attributes

idint

Unique identifier for the town.

namestr

Name of the town.

levelstr

Administrative level of the town (e.g., city, village).

populationint

Population of the town. Must be greater than zero.

geometryshapely.Point

Shapely Point object representing the town’s geographic location.

Methods

to_dict() -> dict

Converts the Town object to a dictionary format.

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

Class method to create a dictionary of Town instances from a GeoDataFrame.

id: int
name: str
level: str
population: int
geometry: Point
to_dict() dict[source]

Converts the Town instance into a dictionary.

Returns

dict

A dictionary containing the ‘id’, ‘name’, ‘population’, ‘level’, and ‘geometry’ of the town.

classmethod from_gdf(gdf: GeoDataFrame) dict[source]

Creates a dictionary of Town objects from a GeoDataFrame.

Parameters

gdfgpd.GeoDataFrame

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

Returns

dict

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

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

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