filepath = '/tmp/test_datatypes/test_datatypes.TAB'
# Using Django
import django
print django.VERSION
from django.contrib.gis.gdal import DataSource
ds = DataSource(filepath)
lyr = ds[0]
for feat in lyr:
print '----------'
print 'Feature ID: ', feat.fid
for field_name in feat.fields:
print 'Field Name: ', field_name
print 'Field Data:', type(feat.get(field_name)), feat.get(field_name)
# Using OGR
import ogr
ds = ogr.Open(filepath)
lyr = ds[0]
for feat in lyr:
feat.items()
Hi Everybody,
I noticed what appeared to be a truncation issue today while attempting to retrieve decimal fields from a Map Info TAB file using the GeoDjango datasource.
I'd like to find out if
1) This is replicable for other people (I have replicated it successfully on two machines)
2) If this is a known issue and
3) If there are any workarounds besides falling back to 'normal' OGR.
I have attached a sample TAB file and a python file to test the problem. The output on my machine is as follows,
Python 2.7.2+ (default, Oct 4 2011, 20:06:09)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> filepath = '/tmp/test_datatypes/test_datatypes.TAB'
>>>
>>> # Using Django
>>> import django
>>> print django.VERSION
(1, 4, 1, 'final', 0)
>>> from django.contrib.gis.gdal import DataSource
>>> ds = DataSource(filepath)
>>> lyr = ds[0]
>>> for feat in lyr:
... print '----------'
... print 'Feature ID: ', feat.fid
... for field_name in feat.fields:
... print 'Field Name: ', field_name
... print 'Field Data:', type(feat.get(field_name)), feat.get(field_name)
... print
...
----------
Feature ID: 1
Field Name: char
Field Data: <type 'str'> test
Field Name: deci
Field Data: <type 'float'> 1.234
Field Name: int
Field Data: <type 'int'> 5
Field Name: date
Field Data: <type 'datetime.date'> 2012-08-24
Field Name: float
Field Data: <type 'int'> 987
----------
Feature ID: 2
Field Name: char
Field Data: <type 'str'> abc
Field Name: deci
Field Data: <type 'float'> 987.6
Field Name: int
Field Data: <type 'int'> 3
Field Name: date
Field Data: <type 'datetime.date'> 2012-08-26
Field Name: float
Field Data: <type 'int'> 12345
>>> # Using OGR
>>> import ogr
>>> ds = ogr.Open(filepath)
>>> lyr = ds[0]
>>> for feat in lyr:
... feat.items()
...
{'char': 'test', 'int': 5, 'float': 987.65, 'date': '2012/08/24', 'deci': 1.234}
{'char': 'abc', 'int': 3, 'float': 12345.6789, 'date': '2012/08/26', 'deci': 987.6}
>>>
The problem is that for the field named "float" the expected value is 987.65 for the first feature and 12345.6789 for the second field. Using geodjango however I am getting 987 and 12345 respectively. This is of course a truncation of some sort making the number into an int.
Has anyone else experienced this problem? Is this a known issue and is the appropriate work around simply to fall back to 'normal' OGR?
On a separate note purely for my own edification, does anyone know why the design decision was made to wrap OGR and GDAL and not simply reuse the python bindings that they provide?
Thanks in advance for any help that you can provide.
Ben
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/59ZJawSlTVkJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment