Util
geom
Geometry, WKT and SRS helpers.
Everything in this package that talks to GDAL. A geometry reaches xmas_core as a WKT
string beside an SRS reference, and these are the three things every reader and writer needs
from that pair: what kind of geometry it is, how to move between a single geometry and its
multi variant, and what the SRS reference actually says about the coordinates - which is an
EPSG code and an axis order, because CRS84 and EPSG:4326 differ in exactly the latter while
sharing the former.
SRS
Bases: NamedTuple
What an SRS reference says about a geometry's coordinates.
cast_geom_to_multi
Cast a single geometry to its multi variant.
Source code in xmas_core/util/geom.py
cast_geom_to_single
Cast a multi geometry to its single variant.
Source code in xmas_core/util/geom.py
format_srs
Formats an EPSG SRID as an SRS string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
srid
|
int
|
The EPSG SRID. |
required |
fmt
|
Literal['short', 'url']
|
|
'url'
|
Returns:
| Type | Description |
|---|---|
str
|
The formatted SRS string. |
Source code in xmas_core/util/geom.py
get_envelope
Return a BBOX for a list of geometries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geoms
|
list[str]
|
A list of WKT strings. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple[float, float, float, float]
|
The BBOX coordinates in the format min_X, max_X, min_Y, max_Y. |
Source code in xmas_core/util/geom.py
get_geometry_type_from_wkt
get_geometry_type_from_wkt(geom: str) -> type[GeometryType] | None
Derives the geometry type from a WKT string.
Source code in xmas_core/util/geom.py
parse_srs
parse_srs(srs: str | dict[str, Any] | None) -> SRS
Resolves an SRS reference to an EPSG SRID and an axis order.
Accepts any notation OGR's SetFromUserInput understands (EPSG:25832,
urn:ogc:def:crs:EPSG::25832, the OGC URL form, WKT) as well as the JSON-FG
coordRefSys object form ({"type": "Reference", "href": ...}). CRS84 and
its OGC URI/URN aliases resolve to 4326. The JSON-FG array (compound CRS) form
is not supported.
swap_axes says whether the reference orders latitude or northing first, so a geometry
read under it has to be swapped to reach the x/y a Geometry field stores - and
swapped back on the way out. Two things decide it: EPSG defines 4326 and 4258
latitude-first and the Gauß-Krüger zones 31466-31469 northing-first, where the UTM zones
and CRS84 are x/y already; and only the URN and OGC URL notations carry that order at
all. CRS84 and EPSG:4326 differ in exactly this while sharing an SRID, which is why the
answer cannot come from srid alone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
srs
|
str | dict[str, Any] | None
|
The SRS reference, as a string, a JSON-FG |
required |
Returns:
| Type | Description |
|---|---|
SRS
|
The EPSG SRID, or None if it could not be determined, and whether coordinates read |
SRS
|
under this reference need swapping to reach x/y. |
Source code in xmas_core/util/geom.py
identifier
UUID parsing and serialization.
is_uuid
Check whether a given string is - or, unless exact, contains - a valid UUID.
parse_uuid
Return the UUID a given string is - or, unless exact, contains - or None.