Django

Code

Ticket #8563 (closed: invalid)

Opened 1 year ago

Last modified 1 year ago

[gis] Current locale considered when converting a geometry to WKT

Reported by: luizvital <luiz.vital@gmail.com> Assigned to: jbronn
Milestone: Component: GIS
Version: SVN Keywords: geos locale
Cc: Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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.

Attachments

Change History

08/26/08 14:06:05 changed by jbronn

  • keywords set to geos locale.
  • needs_better_patch changed.
  • owner changed from nobody to jbronn.
  • needs_tests changed.
  • needs_docs changed.

Confirmed. To add the locale on Ubuntu do: sudo locale-gen pt_BR.UTF-8.

08/26/08 14:07:35 changed by jbronn

  • status changed from new to assigned.

08/27/08 10:11:02 changed by luizvital <luiz.vital@gmail.com>

Well, I've got enough reasons not to use python locale.setlocale as per official docs point:

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

08/27/08 12:03:01 changed by jbronn

  • status changed from assigned to closed.
  • resolution set to invalid.
  • stage changed from Unreviewed to 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).


Add/Change #8563 ([gis] Current locale considered when converting a geometry to WKT)




Change Properties
Action