[gdal-dev] Changing precision of coordinates in Python OGR API

Roger André randre at gmail.com
Wed Aug 17 02:49:38 EDT 2011


Works brilliantly, thanks again.

- Set env var:
export OGR_WKT_PRECISION=4

- In Python interpreter:
from osgeo import ogr
datasource = ogr.Open('World_Admin_2.shp')
layer = datasource.GetLayer(0)
feat = layer.GetNextFeature()
geom = feat.geometry()
wkt = geom.ExportToWkt()

was:
151.857685024000034 -32.613605699642989,151.857672992 -32.613692002142983))
now:
151.8577 -32.6136,151.8577 -32.6137))

Roger
---

On Tue, Aug 16, 2011 at 10:53 PM, Roger André <randre at gmail.com> wrote:

> Thanks Chaitanya,
>
> I like the look of that second option.  If I understand correctly what Even
> says, I should then be able to call the *ExportToWKT() *method with a
> precision parameter?
>
> Roger
> --
>
> On Tue, Aug 16, 2011 at 10:36 PM, Chaitanya kumar CH <
> chaitanya.ch at gmail.com> wrote:
>
>> Roger,
>>
>> OGR doesn't support control of coordinate precision. You need to do this
>> yourselves.
>> You can get the WKT of the geometry and and edit the string. If you are
>> willing to recompile GDAL/OGR, you can modify the code that creates the WKT.
>> Even wrote how to do this in this mailing list [1].
>>
>> [1]: http://lists.osgeo.org/pipermail/gdal-dev/2011-April/028306.html
>>
>> On Wed, Aug 17, 2011 at 5:21 AM, Roger André <randre at gmail.com> wrote:
>>
>>> Hi All,
>>>
>>> I have an assignment that requires me to truncate the precision of all my
>>> polygon coordinates to 6 decimal places.  Is there an easy way to do this
>>> while I have the feature opened with OGR and can access its ogr.Geometry
>>> directly?  If not, can someone recommend a good way to iterate through each
>>> coordinate in a feature in such a way that I can treat it as a string and
>>> format it?
>>>
>>> Thanks,
>>>
>>> Roger
>>>
>>> _______________________________________________
>>> gdal-dev mailing list
>>> gdal-dev at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>>>
>>
>>
>>
>> --
>> Best regards,
>> Chaitanya kumar CH.
>>
>> +91-9494447584
>> 17.2416N 80.1426E
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20110816/b30b38a0/attachment.html


More information about the gdal-dev mailing list