twpayne / go-geom

Package geom implements efficient geometry types for geospatial applications.
BSD 2-Clause "Simplified" License
839 stars 104 forks source link

Simplify GeoJSON + Rewrite FlatCoords #219

Closed Mendes11 closed 1 year ago

Mendes11 commented 1 year ago

First of all, thanks for the library, it's really great and it's helping me a lot!

I'm trying to create an API that is going to load GeoJSON files, simplify them and then send this simplified version to the caller. From what I understand, I can do the simplification using xy.SimplifyFlatCoords(feature.Geometry.FlatCoords(), .5, feature.Geometry.Stride()). My problem is since it's returning the indexes that I should use, I would need to recreate the Feature, or replace the existing FlatCoords, but I don't seem to find a way to do this.

What's the best approach here?

twpayne commented 1 year ago

You should create a new geometry with the simplified coordinates. Replacing the existing FlatCoords break the existing geometry.

Note that xy.SimplifyFlatCoords is a line simplification algorithm and is only suitable for simplifying LineString geomtries.