Opened 17 years ago
Closed 17 years ago
#8563 closed (invalid)
[gis] Current locale considered when converting a geometry to WKT
| Reported by: | Owned by: | jbronn | |
|---|---|---|---|
| Component: | GIS | Version: | dev |
| Severity: | Keywords: | geos locale | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
I'm getting a OGRGeometry Exception intermittently, when saving a form.
After debuging the code I noticed that the WKT string generated from
geometries were taking the current locale into account, thus raising
the Exceptions due to a bad WKT string representation. Here goes an
example:
>>> import locale
>>> from django.contrib.gis.geos import Point
>>> p = Point(-45.23, -23.15)
>>> p.wkt
'POINT (-45.2299999999999969 -23.1499999999999986)'
>>> locale.getlocale()
(None, None)
>>> locale.setlocale(locale.LC_ALL, ('pt_BR','UTF-8'))
'pt_BR.UTF8'
>>> p.wkt
'POINT (-45,2299999999999969 -23,1499999999999986)'
Notice de comma "," for decimal separator in the last output.
It must be something in the GEOS C library and in this case should be
fixed there, but maybe it should be avoided reseting de locale before
calling the C routine and restoring the locale to what it was just
after.
I think the reason this problem was not always happening is related to
the some setlocale thread safety issue.
I was using the wkt from the geometry in a custom form PointField to get the coordinate transformed to the desired srid.
Change History (4)
comment:1 by , 17 years ago
| Keywords: | geos locale added |
|---|---|
| Owner: | changed from to |
comment:2 by , 17 years ago
| Status: | new → assigned |
|---|
comment:3 by , 17 years ago
Well, I've got enough reasons not to use python locale.setlocale as per official docs point:
- http://docs.python.org/lib/module-locale.html
- http://docs.python.org/lib/node745.html "...it is generally a bad idea to call setlocale() in some library routine..."
But is still can be an issue to unattented users (like me), so I filed a ticket in the GEOS trac http://trac.osgeo.org/geos/ticket/201
comment:4 by , 17 years ago
| Resolution: | → invalid |
|---|---|
| Status: | assigned → closed |
| Triage Stage: | Unreviewed → Accepted |
Because this is an underlying bug in GEOS I'm closing this ticket. Thanks to Luiz for filing a ticket with the GEOS folks (#201).
Confirmed. To add the locale on Ubuntu do:
sudo locale-gen pt_BR.UTF-8.