Hi all,

I noticed that osgeo.ogr.Feature.GetField behaves differently when a matplotlib function is called. In particular, fields of type "Real" don't return the same value when called before or after the use of matplotlib functions. See for example the script below that extract the fields values from an ESRI shapefile :

"""
import matplotlib.pyplot as plt
from osgeo import ogr

#Read ESRI shapefile
filename='/disk/L0data/GLIMS/RGI_5.0/all_asia.shp'
ds = ogr.Open(filename,0)
layer = ds.GetLayer()

#Comment/uncomment this line
#plt.figure()
#plt.show()

#Extract field number 5 information (central longitude)
index=5
layerDefinition = layer.GetLayerDefn()
name= layerDefinition.GetFieldDefn(index).GetName()
print "Name : %s " %name
fieldTypeCode = layerDefinition.GetFieldDefn(index).GetType()
print "Type : %s" %layerDefinition.GetFieldDefn(index).GetFieldTypeName(fieldTypeCode)
print "Width : %i" %layerDefinition.GetFieldDefn(index).GetWidth()

#Extract feature field values
for i in xrange(5):
    feat = layer.GetNextFeature()
    print feat.GetField(name)
"""

This script returns :

/Name : CenLon //
//Type : Real//
//Width : 14//
//79.4939//
//77.9513//
//77.9295//
//77.9237//
//77.9141/


But when the 2 matplotlib lines are uncommented, it returns :

/Name : CenLon //
//Type : Real//
//Width : 14//
//79.0//
//77.0//
//77.0//
//77.0//
//77.0//
/
It seems that the values are truncated. Has anyone observed the same problem? Are there any incompatibilities between matplotlib and OGR?
I use :
Python 2.6.6
osgeo 1.6.3
matplotlib 1.3.1

Thank you,
Amaury
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to