wkt icon indicating copy to clipboard operation
wkt copied to clipboard

Support rounding for `.wkt_string()`

Open IndigoCurnick opened this issue 1 year ago • 4 comments

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!

IndigoCurnick avatar Dec 03 '24 12:12 IndigoCurnick

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.

lnicola avatar Dec 03 '24 14:12 lnicola

Another option could be a builder pattern:

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

frewsxcv avatar Dec 03 '24 23:12 frewsxcv

@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!

IndigoCurnick avatar Dec 06 '24 11:12 IndigoCurnick

@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)

urschrei avatar Dec 06 '24 13:12 urschrei