Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions examples/expression.ipynb

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions geoengine/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,12 +603,14 @@ def from_response(cls, response: geoengine_openapi_client.Layer) -> Layer:
if response.symbology is not None:
symbology = Symbology.from_response(response.symbology)

workflow_dict = cast(dict[str, Any], response.workflow.to_dict()) # silence mypy here

return Layer(
name=response.name,
description=response.description,
layer_id=LayerId(response.id.layer_id),
provider_id=LayerProviderId(response.id.provider_id),
workflow=response.workflow.to_dict(),
workflow=workflow_dict,
symbology=symbology,
properties=cast(list[Any], response.properties),
metadata=cast(dict[Any, Any], response.metadata),
Expand Down Expand Up @@ -852,7 +854,10 @@ def _add_layer_to_collection(
response = layers_api.add_layer(
collection_id,
geoengine_openapi_client.AddLayer(
name=name, description=description, workflow=workflow, symbology=symbology_dict
name=name,
description=description,
workflow=geoengine_openapi_client.Workflow.from_dict(workflow),
symbology=symbology_dict,
),
_request_timeout=timeout,
)
Expand Down
23 changes: 15 additions & 8 deletions geoengine/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from abc import abstractmethod
from datetime import datetime, timezone
from enum import Enum
from typing import Any, Literal, cast
from typing import Any, Literal, TypedDict, cast
from uuid import UUID

import geoengine_openapi_client
Expand Down Expand Up @@ -248,6 +248,13 @@ def __eq__(self, other: Any) -> bool:
return self.start == other.start and self.end == other.end


class SpatialResolutionDict(TypedDict):
"""A spatial resolution as a dictionary"""

x: float
y: float


class SpatialResolution:
"""'A spatial resolution."""

Expand All @@ -262,16 +269,16 @@ def __init__(self, x_resolution: float, y_resolution: float) -> None:
self.x_resolution = x_resolution
self.y_resolution = y_resolution

def to_api_dict(self) -> geoengine_openapi_client.SpatialResolution:
return geoengine_openapi_client.SpatialResolution(
x=self.x_resolution,
y=self.y_resolution,
)
def to_api_dict(self) -> SpatialResolutionDict:
return {
"x": self.x_resolution,
"y": self.y_resolution,
}

@staticmethod
def from_response(response: geoengine_openapi_client.SpatialResolution) -> SpatialResolution:
def from_response(response: SpatialResolutionDict) -> SpatialResolution:
"""create a `SpatialResolution` from an API response"""
return SpatialResolution(x_resolution=response.x, y_resolution=response.y)
return SpatialResolution(x_resolution=response["x"], y_resolution=response["y"])

def as_tuple(self) -> tuple[float, float]:
return (self.x_resolution, self.y_resolution)
Expand Down
11 changes: 8 additions & 3 deletions geoengine/workflow_builder/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,10 @@ def name(self) -> str:

def to_dict(self) -> dict[str, Any]:
output_column_dict = None
if isinstance(self.output_column, GeoVectorDataType):

if isinstance(self.output_column, dict):
output_column_dict = self.output_column
elif isinstance(self.output_column, GeoVectorDataType):
output_column_dict = {
"type": "geometry",
"value": self.output_column.value,
Expand Down Expand Up @@ -880,7 +883,7 @@ def to_dict(self) -> dict[str, Any]:

@classmethod
def from_operator_dict(cls, operator_dict: dict[str, Any]) -> VectorExpression:
if operator_dict["type"] != "Expression":
if operator_dict["type"] != "VectorExpression":
raise ValueError("Invalid operator type")

geometry_column_name = None
Expand All @@ -889,7 +892,9 @@ def from_operator_dict(cls, operator_dict: dict[str, Any]) -> VectorExpression:

output_measurement = None
if "outputMeasurement" in operator_dict["params"]:
output_measurement = Measurement.from_response(operator_dict["params"]["outputMeasurement"])
output_measurement = Measurement.from_response(
geoengine_openapi_client.Measurement.from_dict(operator_dict["params"]["outputMeasurement"])
)

return VectorExpression(
source=VectorOperator.from_operator_dict(operator_dict["sources"]["vector"]),
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ readme = { file = "README.md", content-type = "text/markdown" }
license-files = ["LICENSE"]
requires-python = ">=3.10"
dependencies = [
"geoengine-openapi-client == 0.0.31",
"geoengine-openapi-client @ git+https://github.com/geo-engine/openapi-client.git@rust2#subdirectory=python",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update

"geopandas >=1.0,<2.0",
"matplotlib >=3.6,<3.11",
"numpy >=1.23,<2.5",
Expand All @@ -27,7 +27,7 @@ dependencies = [
"rasterio >=1.3,<2",
"requests >= 2.26,<3",
"rioxarray >=0.9.1, <0.23",
"StrEnum >=0.4.6,<0.5", # TODO: use from stdlib when `python_requires = >=3.11`
"StrEnum >=0.4.6,<0.5", # TODO: use from stdlib when `python_requires = >=3.11`
"vega >= 3.5,<4.2",
"websockets >= 14.2,<17",
"xarray >=0.19,<2026.3",
Expand Down
Loading