Shared models
Building blocks shared by the domain models. Domain-specific models are documented
next to their client: Observed groundwater levels, Modeled groundwater levels and Groundwater chemistry.
Collections and features
Every collection model inherits from
FeatureCollection, which owns the GeoJSON fields
and the conversion to a DataFrame. Collections with a date per feature (measurements,
modeled levels and analysis results) inherit from
TimeSeriesCollection, which adds sorting by date
and to_series(). See Working with pandas for how the collections’
DataFrames differ.
GeoJSON features and feature collections, and their conversion to pandas.
-
pydantic model Feature[source]
One feature of a collection (GeoJSON Feature).
-
field type:
Literal['Feature'] = 'Feature'
-
field id:
str [Required]
Feature id, e.g. stationer.4086
-
field geometry:
Point | MultiPoint | LineString | Polygon | MultiPolygon | None = None
Feature geometry
-
field properties:
TypeVar(P, bound= SGUBaseModel) [Required]
Feature properties
-
pydantic model FeatureCollection[source]
A collection of features (GeoJSON FeatureCollection).
to_dataframe() gives one row per feature: feature_id first, then the
collection’s geometry columns (if any), then every property under its English
name.
-
field type:
Literal['FeatureCollection'] = 'FeatureCollection'
-
field features:
list[TypeVar(F, bound= Feature)] [Optional]
Features
-
field totalFeatures:
int | None = None
Total number of features
-
field numberMatched:
int | None = None
Number of features matching query
-
field numberReturned:
int | None = None
Number of features returned
-
field timeStamp:
Annotated[datetime | None] = None
Response timestamp (UTC)
- Constraints:
-
-
field links:
list[Link] | None = None
Related links
-
field crs:
CRS | None = None
Coordinate reference system
-
to_dataframe()[source]
Convert to a pandas DataFrame with one row per feature.
The index is each row’s position in the API response.
- Return type:
DataFrame
- Returns:
DataFrame with feature_id, the geometry columns and the properties.
-
pydantic model TimeSeriesCollection[source]
A feature collection with a date per feature.
Adds sorting by date to to_dataframe(), and to_series().
-
to_dataframe(sort_by_date=True)[source]
Convert to a pandas DataFrame with one row per feature.
- Parameters:
sort_by_date (bool) – Sort the rows by date. Either way the index is each
row’s position in the API response, so pass False (or call
sort_index()) to get the rows in API order.
- Return type:
DataFrame
- Returns:
DataFrame with feature_id, the geometry columns and the properties.
-
to_series(index=None, data=None, sort_by_date=True)[source]
Convert to a pandas Series, by default the collection’s main value by date.
- Parameters:
index (str | None) – Column to use as index. Defaults to the collection’s date column.
data (str | None) – Column to use as values. Defaults to the collection’s main value.
sort_by_date (bool) – Sort by date before creating the Series. Pass False
to keep the API response order.
- Return type:
Series
- Returns:
Series named after the data column.
- Raises:
ValueError – If index or data is not a column.
Base classes
Models accept both the English field names and the Swedish API aliases, and keep any
extra fields SGU adds in the future.
Base model classes for SGU Client.
-
pydantic model SGUBaseModel[source]
Base model for all SGU data structures.
-
pydantic model SGUResponse[source]
Base response wrapper for SGU API responses.
-
to_dict()[source]
Convert to dictionary.
- Return type:
dict[str, Any]
GeoJSON types
Shared types (like GeoJSON objects)
-
pydantic model Link[source]
A link in a GeoJSON response.
-
field href:
str [Required]
Link URL
-
field rel:
str | None = None
Link relation
-
field type:
str | None = None
Link media type
-
field title:
str | None = None
Link title
-
pydantic model CRS[source]
Coordinate Reference System.
-
field type:
str [Required]
CRS type
-
field properties:
dict[str, Any] [Required]
CRS properties
-
pydantic model Point[source]
GeoJSON Point geometry.
-
field type:
Literal['Point'] = 'Point'
-
field coordinates:
list[float] [Required]
- Constraints:
min_length = 2
max_length = 3
-
pydantic model MultiPoint[source]
GeoJSON MultiPoint geometry.
-
field type:
Literal['MultiPoint'] = 'MultiPoint'
-
field coordinates:
list[list[float]] [Required]
-
pydantic model LineString[source]
GeoJSON LineString geometry.
-
field type:
Literal['LineString'] = 'LineString'
-
field coordinates:
list[list[float]] [Required]
- Constraints:
-
-
pydantic model Polygon[source]
GeoJSON Polygon geometry.
-
field type:
Literal['Polygon'] = 'Polygon'
-
field coordinates:
list[list[list[float]]] [Required]
-
pydantic model MultiPolygon[source]
GeoJSON MultiPolygon geometry.
-
field type:
Literal['MultiPolygon'] = 'MultiPolygon'
-
field coordinates:
list[list[list[list[float]]]] [Required]