<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Hi all,<br>
<br>
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 :<br>
<br>
"""<br>
import matplotlib.pyplot as plt<br>
from osgeo import ogr<br>
<br>
#Read ESRI shapefile<br>
filename='/disk/L0data/GLIMS/RGI_5.0/all_asia.shp'<br>
ds = ogr.Open(filename,0)<br>
layer = ds.GetLayer()<br>
<br>
#Comment/uncomment this line<br>
#plt.figure()<br>
#plt.show()<br>
<br>
#Extract field number 5 information (central longitude)<br>
index=5<br>
layerDefinition = layer.GetLayerDefn()<br>
name= layerDefinition.GetFieldDefn(index).GetName()<br>
print "Name : %s " %name<br>
fieldTypeCode = layerDefinition.GetFieldDefn(index).GetType()<br>
print "Type : %s"
%layerDefinition.GetFieldDefn(index).GetFieldTypeName(fieldTypeCode)<br>
print "Width : %i" %layerDefinition.GetFieldDefn(index).GetWidth()<br>
<br>
#Extract feature field values<br>
for i in xrange(5):<br>
feat = layer.GetNextFeature()<br>
print feat.GetField(name)<br>
"""<br>
<br>
This script returns :<br>
<br>
<i>Name : CenLon </i><i><br>
</i><i>Type : Real</i><i><br>
</i><i>Width : 14</i><i><br>
</i><i>79.4939</i><i><br>
</i><i>77.9513</i><i><br>
</i><i>77.9295</i><i><br>
</i><i>77.9237</i><i><br>
</i><i>77.9141</i><br>
<br>
<br>
But when the 2 matplotlib lines are uncommented, it returns :<br>
<br>
<i>Name : CenLon </i><i><br>
</i><i>Type : Real</i><i><br>
</i><i>Width : 14</i><i><br>
</i><i>79.0</i><i><br>
</i><i>77.0</i><i><br>
</i><i>77.0</i><i><br>
</i><i>77.0</i><i><br>
</i><i>77.0</i><i><br>
</i><br>
It seems that the values are truncated. Has anyone observed the same
problem? Are there any incompatibilities between matplotlib and OGR?<br>
I use :<br>
Python 2.6.6<br>
osgeo 1.6.3<br>
matplotlib 1.3.1<br>
<br>
Thank you,<br>
Amaury<br>
</body>
</html>