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

WKT writer precision #375

Closed
jaakkor2 opened this issue Dec 30, 2020 · 2 comments
Closed

WKT writer precision #375

jaakkor2 opened this issue Dec 30, 2020 · 2 comments

Comments

@jaakkor2
Copy link

Using the Julia interface to GEOS, a non-consistent behavior of WKTWriter with rounding precision was observed. Original issue JuliaGeo/LibGEOS.jl#86. Used versions are LibGEOS v0.6.6 and GEOS_jll v3.9.0+0.

using LibGEOS
p = readgeom("POINT (654321.12345 0.1)");
writer = LibGEOS.WKTWriter(LibGEOS._context, trim=false, roundingprecision=3);
writegeom(p, writer)

gives

"POINT (654321.123 0.100)"

whereas

writer = LibGEOS.WKTWriter(LibGEOS._context, trim=true, roundingprecision=3);
writegeom(p, writer)

gives

"POINT (6.54e+05 0.1)"

Relevant libgeos code here

geos/src/io/WKTWriter.cpp

Lines 358 to 369 in 5b722cf

WKTWriter::writeNumber(double d)
{
std::stringstream ss;
if(! trim) {
ss << std::fixed;
}
ss << std::setprecision(decimalPlaces >= 0 ? decimalPlaces : 0) << d;
return ss.str();
}

Judging from http://www.cplusplus.com/reference/iomanip/setprecision/ , if std::fixed is not in the stream, std::setprecision sets the significant digits.

@jaakkor2
Copy link
Author

jaakkor2 commented Jan 5, 2021

Same as above, now using pygeos

>>> import pygeos
>>> p = pygeos.Geometry("POINT (654321.12345 0.1)")
>>> pygeos.io.to_wkt(p, trim=False, rounding_precision=3)
'POINT (654321.123 0.100)'
>>> pygeos.io.to_wkt(p, trim=True, rounding_precision=3)
'POINT (6.54e+05 0.1)'                    
geos               conda-forge/win-64::geos-3.8.1-he025d50_0
pygeos             conda-forge/win-64::pygeos-0.8-py38h9764186_1

@pramsey
Copy link
Member

pramsey commented Jan 7, 2021

Output in "trim" mode should be closer to "expectations" in master, as of 2376cd6

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

2 participants