Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Note: Minor version `0.X.0` update might break the API, It's recommended to pin

## [unreleased]

* fix geometry simplification on OGC Tiles endpoints (author @guillemc23, https://github.com/developmentseed/tipg/pull/249)


## [1.3.0] - 2025-11-17

* switch to official python docker image from `bitnami`
Expand Down
13 changes: 13 additions & 0 deletions tipg/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,19 @@ def _select_mvt(
geometry_column: Column,
tms: TileMatrixSet,
tile: Tile,
simplify: Optional[float],
preserve_topology: Optional[bool],
):
"""Create MVT from intersecting geometries."""
geom = pg_funcs.cast(logic.V(geometry_column.name), "geometry")

if simplify:
geom = logic.Func(
"ST_SnapToGrid",
logic.Func("ST_SimplifyPreserveTopology" if preserve_topology else "ST_Simplify", geom, simplify),
simplify,
)

# make sure the geometries do not overflow the TMS bbox
if not tms.is_valid(tile):
geom = logic.Func(
Expand Down Expand Up @@ -866,6 +875,8 @@ async def get_tile(
geom: Optional[str] = None,
dt: Optional[str] = None,
limit: Optional[int] = None,
simplify: Optional[float] = None,
preserve_topology: Optional[bool] = None,
):
"""Build query to get Vector Tile."""
limit = limit or mvt_settings.max_features_per_tile
Expand All @@ -885,6 +896,8 @@ async def get_tile(
geometry_column=geometry_column,
tms=tms,
tile=tile,
simplify=simplify,
preserve_topology=preserve_topology,
),
self._from(function_parameters),
self._where(
Expand Down
14 changes: 14 additions & 0 deletions tipg/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,18 @@ async def collection_get_tile(
description="Limits the number of features in the response. Defaults to 10000 or TIPG_MAX_FEATURES_PER_TILE environment variable."
),
] = None,
simplify: Annotated[
Optional[float],
Query(
description="Simplify the output geometry to given threshold in the units of the output CRS.",
),
] = None,
preserve_topology: Annotated[
Optional[bool],
Query(
description="Whether to preserve the same topology as the original data when simplifying.",
),
] = None,
):
"""Return Vector Tile."""
tms = self.supported_tms.get(tileMatrixSetId)
Expand All @@ -1688,6 +1700,8 @@ async def collection_get_tile(
limit=limit,
geom=geom_column,
dt=datetime_column,
simplify=simplify,
preserve_topology=preserve_topology,
)

return Response(tile, media_type=MediaType.mvt.value)
Expand Down
Loading