Geometry
cdse.geometry
Geometry utilities for CDSE Client.
This module provides functions for working with geographic data, including GeoJSON parsing, WKT conversion, and geometry operations. These functions are designed to be compatible with sentinelsat's API.
read_geojson(path: Union[str, Path]) -> dict[str, Any]
Read a GeoJSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Union[str, Path]
|
Path to the GeoJSON file |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Parsed GeoJSON dictionary |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If file cannot be read or parsed |
Example
geojson = read_geojson("area.geojson") footprint = geojson_to_wkt(geojson)
geojson_to_wkt(geojson: dict[str, Any]) -> str
Convert GeoJSON geometry to WKT format.
Supports GeoJSON Feature, FeatureCollection, and raw geometry objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geojson
|
dict[str, Any]
|
GeoJSON dictionary (Feature, FeatureCollection, or geometry) |
required |
Returns:
| Type | Description |
|---|---|
str
|
WKT string representation of the geometry |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If GeoJSON is invalid or unsupported |
Example
wkt = geojson_to_wkt({ ... "type": "Polygon", ... "coordinates": [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]] ... }) print(wkt) POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))
wkt_to_geojson(wkt: str) -> dict[str, Any]
Convert WKT to GeoJSON geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wkt
|
str
|
WKT string |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
GeoJSON geometry dictionary |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If WKT is invalid |
Example
geojson = wkt_to_geojson("POINT (1 2)") print(geojson) {'type': 'Point', 'coordinates': [1.0, 2.0]}
bbox_to_geojson(bbox: list[float]) -> dict[str, Any]
Convert bounding box to GeoJSON Polygon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
list[float]
|
Bounding box [min_lon, min_lat, max_lon, max_lat] |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
GeoJSON Polygon geometry |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If bbox is invalid |
Example
geojson = bbox_to_geojson([9.0, 45.0, 9.5, 45.5])
geojson_to_bbox(geojson: dict[str, Any]) -> list[float]
Extract bounding box from GeoJSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geojson
|
dict[str, Any]
|
GeoJSON dictionary |
required |
Returns:
| Type | Description |
|---|---|
list[float]
|
Bounding box [min_lon, min_lat, max_lon, max_lat] |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If GeoJSON is invalid |
simplify_geometry(geojson: dict[str, Any], tolerance: float = 0.01) -> dict[str, Any]
Simplify a GeoJSON geometry using Douglas-Peucker algorithm.
This is a basic implementation. For production use, consider using shapely with the 'geo' optional dependency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geojson
|
dict[str, Any]
|
GeoJSON geometry |
required |
tolerance
|
float
|
Simplification tolerance in degrees |
0.01
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Simplified GeoJSON geometry |
validate_geometry(geojson: dict[str, Any]) -> bool
Validate a GeoJSON geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geojson
|
dict[str, Any]
|
GeoJSON dictionary |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if valid, raises ValidationError otherwise |