Skip to content

Comments

fix: Allow simplifying geometries in OGC Tiles API#249

Open
guillemc23 wants to merge 6 commits intodevelopmentseed:mainfrom
guillemc23:fix/simplify
Open

fix: Allow simplifying geometries in OGC Tiles API#249
guillemc23 wants to merge 6 commits intodevelopmentseed:mainfrom
guillemc23:fix/simplify

Conversation

@guillemc23
Copy link

@guillemc23 guillemc23 commented Feb 5, 2026

Hi everybody!

I believe there is a bug on the OGC Tiles API when simplifying the geometry. This possibility is documented in the official docs (https://developmentseed.org/tipg/user_guide/endpoints/#vector-tiles) but the behavior does not seem to be implemented.

I implemented the feature with small changes on the codebase, but I'm not sure if this is your ideal solution, though it works flawlessly. The only thing I haven't managed is to be coherent with the units, since in the other endpoints this simplify magnitude is given in degrees, but in this case it gets applied in meters (might be related with order of operations).

I would appreciate some input if on this feature :)

PS: I have noticed that bbox_only is also documented but not implemented.

@vincentsarago
Copy link
Member

Those parameters were implemented only on the features API and maybe I forgot to port them to the tile api. It predate the creation of TiPG and came from tifeatures (ee76362)

The only thing I haven't managed is to be coherent with the units, since in the other endpoints this simplify magnitude is given in degrees

Well it should be in the unit of the output CRS, we just need to make it clear in the documentation.

PS: I have noticed that bbox_only is also documented but not implemented.

might be interesting to add it as well

@guillemc23
Copy link
Author

Well it should be in the unit of the output CRS, we just need to make it clear in the documentation.

Yeah, you're right! I modified the docstring to match the behavior as well.

might be interesting to add it as well

I might open a new PR if I have the time to test it 😄

@guillemc23
Copy link
Author

guillemc23 commented Feb 9, 2026

Hey @vincentsarago

I was wondering, why is ST_Simplify used instead of ST_SimplifyPreserveTopology? We could maybe set up another optional argument to decide whether to use one or the other, not sure what do you think about something like this:

    def _select_mvt(
        self,
        properties: Optional[List[str]],
        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,
            )
        ...

If you think it's too specific for my use case, I can keep these in a custom collection

@vincentsarago vincentsarago requested a review from bitner February 9, 2026 17:09
@vincentsarago
Copy link
Member

@guillemc23 Let's see what @bitner has to say but using ST_SimplifyPreserveTopology seems a better choice IMO

@bitner
Copy link
Contributor

bitner commented Feb 9, 2026

Generally, you shouldn't need to run simplify when creating vector tiles as st_asmvt already will reduce the data based on the resolution of the tile. That being said, if something is necessary to control simplification even further, I'm certainly not opposed including this, and yeah, st_simplifypreservetopology is likely safer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants