Discussion:
[Community] how to access "rouding_precision" in WKTWriter?
Harasty, Daniel J
2016-06-23 12:36:44 UTC
Permalink
I have an application where the full WKT representation of double-precision floats is undesirable.

It seems that WKTWriter has an optional, keyword argument to set the "rounding_precision". Great! Just what I need!

However... I can't figure out the calling convention; the ".wkt" method of the shapely object is a PROPERTY... so although the "kwargs" is defined, I can't figure out the right Python syntax to USE them.
from shapely.geometry import Polygon
p1 = Polygon([(0,0), (10.1, 0), (31./3, 10), (0, 10)])
print p1.wkt
POLYGON ((0 0, 10.1 0, 10.33333333333333 10, 0 10, 0 0))
# as expected
print p1.wkt(rounding_precision=8)
TypeError: 'str' object is not callable
# bummer: I'd like to use something this concise
from shapely.geos import lgeos, WKTWriter
writer = WKTWriter(lgeos, rounding_precision=8)
print writer.write(p1)
POLYGON ((0 0, 10.1 0, 10.333333 10, 0 10, 0 0))
# this is the result what I want; can it be done without expressly
# creating a WKTWriter()?


How can I pass the "rounding_precision" kwarg to the property getter?

Thanks,
Dan
Mike Toews
2016-06-23 21:08:51 UTC
Permalink
Post by Harasty, Daniel J
I have an application where the full WKT representation of double-precision
floats is undesirable.
It seems that WKTWriter has an optional, keyword argument to set the
“rounding_precision”. Great! Just what I need!
...
How can I pass the “rounding_precision” kwarg to the property getter?
Hi Dan,

Easy, set this in the 'defaults' dict:

WKTWriter.defaults['rounding_precision'] = 8
print(p1) # POLYGON ((0 0, 10.1 0, 10.333333 10, 0 10, 0 0))

Loading...