[gdal-dev] OGR behaves differently after matplotlib call
Amaury Dehecq
v1adehec at staffmail.ed.ac.uk
Mon Aug 10 03:27:49 PDT 2015
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20150810/ea470e6a/attachment.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: not available
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20150810/ea470e6a/attachment.ksh>
More information about the gdal-dev
mailing list