Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support rounding for .wkt_string() #131

Open
IndigoCurnick opened this issue Dec 3, 2024 · 4 comments
Open

Support rounding for .wkt_string() #131

IndigoCurnick opened this issue Dec 3, 2024 · 4 comments

Comments

@IndigoCurnick
Copy link

Hi! A feature I'd really like is supporting rounding to X decimal places in the .wkt_string() function.

For example I can force the output to be POINT (2.32 5.45).

Maybe a second function like wkt_string_rounded(prec: i32)?

I'm happy to work on this myself and PR but wanted to check if this would be something of interest first that would get merged in! Thanks!

@lnicola
Copy link
Member

lnicola commented Dec 3, 2024

Note that this can turn valid polygons into invalid ones (with self-intersections). As prior art, PostGIS has a maxdecimaldigits parameter, but suggets using ST_ReducePrecision first, which calls GEOSGeom_setPrecision.

@frewsxcv
Copy link
Member

frewsxcv commented Dec 3, 2024

Another option could be a builder pattern:

wkt::Formatter::new()
   .with_pretty_print()
   .with_max_decimal_digits(5)
   .format(my_wkt)

@IndigoCurnick
Copy link
Author

@lnicola Yes, I see the problem with just rounding naively, has georust already implemented something like ST_ReducePrecision? I haven't been able to find it yet if it has

@frewsxcv I think a builder is actually a much more sensible idea for this interface!

@urschrei
Copy link
Member

urschrei commented Dec 6, 2024

@lnicola Yes, I see the problem with just rounding naively, has georust already implemented something like ST_ReducePrecision? I haven't been able to find it yet if it has

No, and my understanding is that its implementation is non-trivial so it's unlikely to be available in the short term (but PRs are very welcome)

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

No branches or pull requests

4 participants