Re: [Qgis-developer] update plugin to QGIS 2.0

2013-08-02 Thread Otto Dassau
Hi,

thanks for your hints, I think I am on the right track now. I had a look at
the value tool plugin and tried to adapt the method accordingly:

def sampleRaster20(self, layer, x, y):
   #success, data = layer.dataProvider().identify(QgsPoint(x,y))
   success, data = 
layer.dataProvider().identify(QgsPoint(x,y),QgsRaster.IdentifyFormatValue).results()
 
   for band, value in data.items(): 
  return value

But now I get another error message 

 File
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 448, in printValue self.showValues() File
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 454, in showValues self.plot() File
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 526, in plot w = float(self.sampleRaster(self.InRastW.currentText(),
 self.xCoord, self.yCoord))/10 File
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 300, in sampleRaster return self.sampleRaster20(layer, x, y) File
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 285, in sampleRaster20 success, data =
 layer.dataProvider().identify(QgsPoint(x,y), QgsRaster.IdentifyFormatValue
 ).results() ValueError: need more than 1 value to unpack

Do you have an idea for this, too?

Thanks 
Otto

Am Thu, 1 Aug 2013 16:00:08 -0300
schrieb Etienne Tourigny etourigny@gmail.com:

 Have a look at the source of the value tool plugin, it calls the identify()
 method and has been updated to 2.0 api.
 
 Etienne
 
 On Thu, Aug 1, 2013 at 1:58 PM, Otto Dassau das...@gbd-consult.de wrote:
 
  Hi,
 
  I want to update a plugin from 1.8 to QGIS 2.0 and it throws following
  error:
 
  Traceback (most recent call last):
  File
 
 
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 447, in printValue self.showValues() File
 
 
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 453, in showValues self.plot() File
 
 
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 514, in plot w = float(self.sampleRaster(self.InRastW.currentText(),
  self.xCoord, self.yCoord))/10 File
 
 
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 299, in sampleRaster return self.sampleRaster20(layer, x, y) File
 
 
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 284, in sampleRaster20 success, data =
  layer.dataProvider().identify(QgsPoint(x,y))
 
  TypeError:
  QgsRasterDataProvider.identify(QgsPoint, QgsRaster.IdentifyFormat,
  QgsRectangle theExtent=QgsRectangle(), int theWidth=0, int theHeight=0):
  not enough arguments
 
  I found at
  http://hub.qgis.org/wiki/quantum-gis/API_changes_for_version_20 the
  section QgsRasterDataProvider which should fit. And the Method, where I
  assume the error occurs should be this
 
  # get value at mouse position QGIS = 1.8 (working for 1.8)
  def sampleRaster18(self, layer, x, y):
 success, data = layer.identify(QgsPoint(x,y))
 for band, value in data.items():
   return value
 
  now what I tried but doesn't work (see error above)
 
  # get value at mouse position QGIS = 2.0 (not working yet :()
  def sampleRaster20(self, layer, x, y):
 success, data = layer.dataProvider().identify(QgsPoint(x,y))
 for band, value in data.items():
   return value
 
  my problem is, that I don't understand how to implement in sampleRaster20
  the new method from the API_changes_for_version_20 website which says:
 
  QMapint, QVariant identify( const QgsPoint  thePoint, IdentifyFormat
  theFormat, const QgsRectangle theExtent = QgsRectangle(), int theWidth =
  0, int theHeight = 0 )
 
  can anybody help?
 
  Thanks
 
  Otto
  ___
  Qgis-developer mailing list
  Qgis-developer@lists.osgeo.org
  http://lists.osgeo.org/mailman/listinfo/qgis-developer
 


-- 
Geoinformatik Büro Dassau - http://www.gbd-consult.de
FOSSGIS consulting , training , support  and analysis
Ackerstrasse 144c  ,  D - 40233 Düsseldorf  , Germany
Tel: +49-(0)211-47468178 , Mobil: +49-(0)171-4687540

--
Community Advisor - QGIS Project Steering Committee
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] update plugin to QGIS 2.0

2013-08-02 Thread Etienne Tourigny
from the api 
http://www.qgis.org/api/classQgsRasterIdentifyResult.html#a8537d25fdff215e7e9650b71a0a16783

results() returns a QMapint, QVariant (one item for each band), it
does not return a tuple, so you should actually call

ident = 
layer.dataProvider().identify(QgsPoint(x,y),QgsRaster.IdentifyFormatValue).results()

and then test that ident is not empty (i,e. ident is not None and
ident.iterkeys() is not None)

for each band, if the point is outside of the raster extent or is
nodata, the value will be a null QVariant (i.e. QVariant()) which in
python is None.


cheers
Etienne

On Fri, Aug 2, 2013 at 7:13 AM, Otto Dassau das...@gbd-consult.de wrote:

 Hi,

 thanks for your hints, I think I am on the right track now. I had a look at
 the value tool plugin and tried to adapt the method accordingly:

 def sampleRaster20(self, layer, x, y):
#success, data = layer.dataProvider().identify(QgsPoint(x,y))
success, data = 
 layer.dataProvider().identify(QgsPoint(x,y),QgsRaster.IdentifyFormatValue).results()
for band, value in data.items():
   return value

 But now I get another error message

  File
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 448, in printValue self.showValues() File
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 454, in showValues self.plot() File
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 526, in plot w = float(self.sampleRaster(self.InRastW.currentText(),
  self.xCoord, self.yCoord))/10 File
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 300, in sampleRaster return self.sampleRaster20(layer, x, y) File
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 285, in sampleRaster20 success, data =
  layer.dataProvider().identify(QgsPoint(x,y), QgsRaster.IdentifyFormatValue
  ).results() ValueError: need more than 1 value to unpack

 Do you have an idea for this, too?

 Thanks
 Otto

 Am Thu, 1 Aug 2013 16:00:08 -0300
 schrieb Etienne Tourigny etourigny@gmail.com:

  Have a look at the source of the value tool plugin, it calls the identify()
  method and has been updated to 2.0 api.
 
  Etienne
 
  On Thu, Aug 1, 2013 at 1:58 PM, Otto Dassau das...@gbd-consult.de wrote:
 
   Hi,
  
   I want to update a plugin from 1.8 to QGIS 2.0 and it throws following
   error:
  
   Traceback (most recent call last):
   File
  
  
   /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
   line 447, in printValue self.showValues() File
  
  
   /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
   line 453, in showValues self.plot() File
  
  
   /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
   line 514, in plot w = float(self.sampleRaster(self.InRastW.currentText(),
   self.xCoord, self.yCoord))/10 File
  
  
   /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
   line 299, in sampleRaster return self.sampleRaster20(layer, x, y) File
  
  
   /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
   line 284, in sampleRaster20 success, data =
   layer.dataProvider().identify(QgsPoint(x,y))
  
   TypeError:
   QgsRasterDataProvider.identify(QgsPoint, QgsRaster.IdentifyFormat,
   QgsRectangle theExtent=QgsRectangle(), int theWidth=0, int theHeight=0):
   not enough arguments
  
   I found at
   http://hub.qgis.org/wiki/quantum-gis/API_changes_for_version_20 the
   section QgsRasterDataProvider which should fit. And the Method, where I
   assume the error occurs should be this
  
   # get value at mouse position QGIS = 1.8 (working for 1.8)
   def sampleRaster18(self, layer, x, y):
  success, data = layer.identify(QgsPoint(x,y))
  for band, value in data.items():
return value
  
   now what I tried but doesn't work (see error above)
  
   # get value at mouse position QGIS = 2.0 (not working yet :()
   def sampleRaster20(self, layer, x, y):
  success, data = layer.dataProvider().identify(QgsPoint(x,y))
  for band, value in data.items():
return value
  
   my problem is, that I don't understand how to implement in sampleRaster20
   the new method from the API_changes_for_version_20 website which says:
  
   QMapint, QVariant identify( const QgsPoint  thePoint, IdentifyFormat
   theFormat, const QgsRectangle theExtent = QgsRectangle(), int theWidth =
   0, int theHeight = 0 )
  
   can anybody help?
  
   Thanks
  
   Otto
   ___
   Qgis-developer mailing list
   Qgis-developer@lists.osgeo.org
   http://lists.osgeo.org/mailman/listinfo/qgis-developer
  


 --
 Geoinformatik Büro Dassau - http://www.gbd-consult.de
 FOSSGIS consulting , training , support  and analysis
 Ackerstrasse 144c  ,  D - 40233 Düsseldorf  , Germany
 Tel: +49-(0)211-47468178 , Mobil: +49-(0)171-4687540

 --
 Community Advisor - QGIS Project 

Re: [Qgis-developer] update plugin to QGIS 2.0

2013-08-02 Thread Matthias Kuhn
Hi

On Fre 02 Aug 2013 13:50:08 CEST, Etienne Tourigny wrote:

 for each band, if the point is outside of the raster extent or is
 nodata, the value will be a null QVariant (i.e. QVariant()) which in
 python is None.

It will be a QPyNullVariant so doing

value = QPyNullVariant( int )
if not value:
print 'Is NULL'
else:
print 'Is not NULL'

if value is None:
print 'Is None'
else:
print 'Is NOT None'

will print:
Is NULL
Is NOT None

Sorry for the smart-arsing ;)

-- Matthias



 cheers
 Etienne

 On Fri, Aug 2, 2013 at 7:13 AM, Otto Dassau das...@gbd-consult.de wrote:

 Hi,

 thanks for your hints, I think I am on the right track now. I had a look at
 the value tool plugin and tried to adapt the method accordingly:

 def sampleRaster20(self, layer, x, y):
#success, data = layer.dataProvider().identify(QgsPoint(x,y))
success, data = 
 layer.dataProvider().identify(QgsPoint(x,y),QgsRaster.IdentifyFormatValue).results()
for band, value in data.items():
   return value

 But now I get another error message

  File
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 448, in printValue self.showValues() File
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 454, in showValues self.plot() File
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 526, in plot w = float(self.sampleRaster(self.InRastW.currentText(),
  self.xCoord, self.yCoord))/10 File
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 300, in sampleRaster return self.sampleRaster20(layer, x, y) File
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 285, in sampleRaster20 success, data =
  layer.dataProvider().identify(QgsPoint(x,y), QgsRaster.IdentifyFormatValue
  ).results() ValueError: need more than 1 value to unpack

 Do you have an idea for this, too?

 Thanks
 Otto

 Am Thu, 1 Aug 2013 16:00:08 -0300
 schrieb Etienne Tourigny etourigny@gmail.com:

 Have a look at the source of the value tool plugin, it calls the identify()
 method and has been updated to 2.0 api.

 Etienne

 On Thu, Aug 1, 2013 at 1:58 PM, Otto Dassau das...@gbd-consult.de wrote:

 Hi,

 I want to update a plugin from 1.8 to QGIS 2.0 and it throws following
 error:

 Traceback (most recent call last):
 File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 447, in printValue self.showValues() File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 453, in showValues self.plot() File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 514, in plot w = float(self.sampleRaster(self.InRastW.currentText(),
 self.xCoord, self.yCoord))/10 File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 299, in sampleRaster return self.sampleRaster20(layer, x, y) File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 284, in sampleRaster20 success, data =
 layer.dataProvider().identify(QgsPoint(x,y))

 TypeError:
 QgsRasterDataProvider.identify(QgsPoint, QgsRaster.IdentifyFormat,
 QgsRectangle theExtent=QgsRectangle(), int theWidth=0, int theHeight=0):
 not enough arguments

 I found at
 http://hub.qgis.org/wiki/quantum-gis/API_changes_for_version_20 the
 section QgsRasterDataProvider which should fit. And the Method, where I
 assume the error occurs should be this

 # get value at mouse position QGIS = 1.8 (working for 1.8)
 def sampleRaster18(self, layer, x, y):
success, data = layer.identify(QgsPoint(x,y))
for band, value in data.items():
  return value

 now what I tried but doesn't work (see error above)

 # get value at mouse position QGIS = 2.0 (not working yet :()
 def sampleRaster20(self, layer, x, y):
success, data = layer.dataProvider().identify(QgsPoint(x,y))
for band, value in data.items():
  return value

 my problem is, that I don't understand how to implement in sampleRaster20
 the new method from the API_changes_for_version_20 website which says:

 QMapint, QVariant identify( const QgsPoint  thePoint, IdentifyFormat
 theFormat, const QgsRectangle theExtent = QgsRectangle(), int theWidth =
 0, int theHeight = 0 )

 can anybody help?

 Thanks

 Otto
 ___
 Qgis-developer mailing list
 Qgis-developer@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/qgis-developer



 --
 Geoinformatik Büro Dassau - http://www.gbd-consult.de
 FOSSGIS consulting , training , support  and analysis
 Ackerstrasse 144c  ,  D - 40233 Düsseldorf  , Germany
 Tel: +49-(0)211-47468178 , Mobil: +49-(0)171-4687540

 --
 Community Advisor - QGIS Project Steering Committee
 ___
 Qgis-developer mailing list
 Qgis-developer@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/qgis-developer



Re: [Qgis-developer] update plugin to QGIS 2.0

2013-08-02 Thread Etienne Tourigny
On Fri, Aug 2, 2013 at 9:37 AM, Matthias Kuhn matthias.k...@gmx.ch wrote:
 Hi

 On Fre 02 Aug 2013 13:50:08 CEST, Etienne Tourigny wrote:

 for each band, if the point is outside of the raster extent or is
 nodata, the value will be a null QVariant (i.e. QVariant()) which in
 python is None.

 It will be a QPyNullVariant so doing

 value = QPyNullVariant( int )
 if not value:
 print 'Is NULL'
 else:
 print 'Is not NULL'

 if value is None:
 print 'Is None'
 else:
 print 'Is NOT None'

 will print:
 Is NULL
 Is NOT None

Hi,

I was not referring to the value of QPyNullVariant( int ), but the
value that results() would return in the case of nodata (which is
QVariant() in the c++ code)

unless mistaken, that would be converted to None by Sip - or am I wrong?


 Sorry for the smart-arsing ;)

 -- Matthias



 cheers
 Etienne

 On Fri, Aug 2, 2013 at 7:13 AM, Otto Dassau das...@gbd-consult.de wrote:

 Hi,

 thanks for your hints, I think I am on the right track now. I had a look at
 the value tool plugin and tried to adapt the method accordingly:

 def sampleRaster20(self, layer, x, y):
#success, data = layer.dataProvider().identify(QgsPoint(x,y))
success, data = 
 layer.dataProvider().identify(QgsPoint(x,y),QgsRaster.IdentifyFormatValue).results()
for band, value in data.items():
   return value

 But now I get another error message

  File
  
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 448, in printValue self.showValues() File
  
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 454, in showValues self.plot() File
  
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 526, in plot w = float(self.sampleRaster(self.InRastW.currentText(),
  self.xCoord, self.yCoord))/10 File
  
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 300, in sampleRaster return self.sampleRaster20(layer, x, y) File
  
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 285, in sampleRaster20 success, data =
  layer.dataProvider().identify(QgsPoint(x,y), QgsRaster.IdentifyFormatValue
  ).results() ValueError: need more than 1 value to unpack

 Do you have an idea for this, too?

 Thanks
 Otto

 Am Thu, 1 Aug 2013 16:00:08 -0300
 schrieb Etienne Tourigny etourigny@gmail.com:

 Have a look at the source of the value tool plugin, it calls the identify()
 method and has been updated to 2.0 api.

 Etienne

 On Thu, Aug 1, 2013 at 1:58 PM, Otto Dassau das...@gbd-consult.de wrote:

 Hi,

 I want to update a plugin from 1.8 to QGIS 2.0 and it throws following
 error:

 Traceback (most recent call last):
 File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 447, in printValue self.showValues() File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 453, in showValues self.plot() File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 514, in plot w = float(self.sampleRaster(self.InRastW.currentText(),
 self.xCoord, self.yCoord))/10 File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 299, in sampleRaster return self.sampleRaster20(layer, x, y) File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 284, in sampleRaster20 success, data =
 layer.dataProvider().identify(QgsPoint(x,y))

 TypeError:
 QgsRasterDataProvider.identify(QgsPoint, QgsRaster.IdentifyFormat,
 QgsRectangle theExtent=QgsRectangle(), int theWidth=0, int theHeight=0):
 not enough arguments

 I found at
 http://hub.qgis.org/wiki/quantum-gis/API_changes_for_version_20 the
 section QgsRasterDataProvider which should fit. And the Method, where I
 assume the error occurs should be this

 # get value at mouse position QGIS = 1.8 (working for 1.8)
 def sampleRaster18(self, layer, x, y):
success, data = layer.identify(QgsPoint(x,y))
for band, value in data.items():
  return value

 now what I tried but doesn't work (see error above)

 # get value at mouse position QGIS = 2.0 (not working yet :()
 def sampleRaster20(self, layer, x, y):
success, data = layer.dataProvider().identify(QgsPoint(x,y))
for band, value in data.items():
  return value

 my problem is, that I don't understand how to implement in sampleRaster20
 the new method from the API_changes_for_version_20 website which says:

 QMapint, QVariant identify( const QgsPoint  thePoint, IdentifyFormat
 theFormat, const QgsRectangle theExtent = QgsRectangle(), int theWidth =
 0, int theHeight = 0 )

 can anybody help?

 Thanks

 Otto
 ___
 Qgis-developer mailing list
 Qgis-developer@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/qgis-developer



 --
 Geoinformatik Büro Dassau - http://www.gbd-consult.de
 FOSSGIS consulting , training , support  and analysis
 Ackerstrasse 144c  ,  D - 

Re: [Qgis-developer] update plugin to QGIS 2.0

2013-08-02 Thread Matthias Kuhn
On Fre 02 Aug 2013 15:13:04 CEST, Etienne Tourigny wrote:
 On Fri, Aug 2, 2013 at 9:37 AM, Matthias Kuhn matthias.k...@gmx.ch wrote:
 Hi

 On Fre 02 Aug 2013 13:50:08 CEST, Etienne Tourigny wrote:

 for each band, if the point is outside of the raster extent or is
 nodata, the value will be a null QVariant (i.e. QVariant()) which in
 python is None.

 It will be a QPyNullVariant so doing

 value = QPyNullVariant( int )
 if not value:
 print 'Is NULL'
 else:
 print 'Is not NULL'

 if value is None:
 print 'Is None'
 else:
 print 'Is NOT None'

 will print:
 Is NULL
 Is NOT None

 Hi,

 I was not referring to the value of QPyNullVariant( int ), but the
 value that results() would return in the case of nodata (which is
 QVariant() in the c++ code)

 unless mistaken, that would be converted to None by Sip - or am I wrong?


The SIP API v2 for QVariant defines:

An Invalid QVariant will be represented as None
A Null QVariant will be represented as QPyNullVariant [1]

Except for feature attributes (e.g. for a vectorlayer: feature['attr']) 
which is patched by QGIS to become None in case of a Null value.

Matthias

[1]
http://pyqt.sourceforge.net/Docs/PyQt4/python_v3.html#qvariant


 Sorry for the smart-arsing ;)

 -- Matthias



 cheers
 Etienne

 On Fri, Aug 2, 2013 at 7:13 AM, Otto Dassau das...@gbd-consult.de wrote:

 Hi,

 thanks for your hints, I think I am on the right track now. I had a look at
 the value tool plugin and tried to adapt the method accordingly:

 def sampleRaster20(self, layer, x, y):
#success, data = layer.dataProvider().identify(QgsPoint(x,y))
success, data = 
 layer.dataProvider().identify(QgsPoint(x,y),QgsRaster.IdentifyFormatValue).results()
for band, value in data.items():
   return value

 But now I get another error message

  File
  
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 448, in printValue self.showValues() File
  
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 454, in showValues self.plot() File
  
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 526, in plot w = float(self.sampleRaster(self.InRastW.currentText(),
  self.xCoord, self.yCoord))/10 File
  
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 300, in sampleRaster return self.sampleRaster20(layer, x, y) File
  
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 285, in sampleRaster20 success, data =
  layer.dataProvider().identify(QgsPoint(x,y), QgsRaster.IdentifyFormatValue
  ).results() ValueError: need more than 1 value to unpack

 Do you have an idea for this, too?

 Thanks
 Otto

 Am Thu, 1 Aug 2013 16:00:08 -0300
 schrieb Etienne Tourigny etourigny@gmail.com:

 Have a look at the source of the value tool plugin, it calls the 
 identify()
 method and has been updated to 2.0 api.

 Etienne

 On Thu, Aug 1, 2013 at 1:58 PM, Otto Dassau das...@gbd-consult.de wrote:

 Hi,

 I want to update a plugin from 1.8 to QGIS 2.0 and it throws following
 error:

 Traceback (most recent call last):
 File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 447, in printValue self.showValues() File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 453, in showValues self.plot() File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 514, in plot w = float(self.sampleRaster(self.InRastW.currentText(),
 self.xCoord, self.yCoord))/10 File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 299, in sampleRaster return self.sampleRaster20(layer, x, y) File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 284, in sampleRaster20 success, data =
 layer.dataProvider().identify(QgsPoint(x,y))

 TypeError:
 QgsRasterDataProvider.identify(QgsPoint, QgsRaster.IdentifyFormat,
 QgsRectangle theExtent=QgsRectangle(), int theWidth=0, int theHeight=0):
 not enough arguments

 I found at
 http://hub.qgis.org/wiki/quantum-gis/API_changes_for_version_20 the
 section QgsRasterDataProvider which should fit. And the Method, where I
 assume the error occurs should be this

 # get value at mouse position QGIS = 1.8 (working for 1.8)
 def sampleRaster18(self, layer, x, y):
success, data = layer.identify(QgsPoint(x,y))
for band, value in data.items():
  return value

 now what I tried but doesn't work (see error above)

 # get value at mouse position QGIS = 2.0 (not working yet :()
 def sampleRaster20(self, layer, x, y):
success, data = layer.dataProvider().identify(QgsPoint(x,y))
for band, value in data.items():
  return value

 my problem is, that I don't understand how to implement in sampleRaster20
 the new method from the API_changes_for_version_20 website which says:

 QMapint, QVariant identify( const QgsPoint  thePoint, IdentifyFormat
 theFormat, const 

Re: [Qgis-developer] update plugin to QGIS 2.0

2013-08-02 Thread Etienne Tourigny
On Fri, Aug 2, 2013 at 10:22 AM, Matthias Kuhn matthias.k...@gmx.ch wrote:
 On Fre 02 Aug 2013 15:13:04 CEST, Etienne Tourigny wrote:
 On Fri, Aug 2, 2013 at 9:37 AM, Matthias Kuhn matthias.k...@gmx.ch wrote:
 Hi

 On Fre 02 Aug 2013 13:50:08 CEST, Etienne Tourigny wrote:

 for each band, if the point is outside of the raster extent or is
 nodata, the value will be a null QVariant (i.e. QVariant()) which in
 python is None.

 It will be a QPyNullVariant so doing

 value = QPyNullVariant( int )
 if not value:
 print 'Is NULL'
 else:
 print 'Is not NULL'

 if value is None:
 print 'Is None'
 else:
 print 'Is NOT None'

 will print:
 Is NULL
 Is NOT None

 Hi,

 I was not referring to the value of QPyNullVariant( int ), but the
 value that results() would return in the case of nodata (which is
 QVariant() in the c++ code)

 unless mistaken, that would be converted to None by Sip - or am I wrong?


 The SIP API v2 for QVariant defines:

 An Invalid QVariant will be represented as None
 A Null QVariant will be represented as QPyNullVariant [1]

 Except for feature attributes (e.g. for a vectorlayer: feature['attr'])
 which is patched by QGIS to become None in case of a Null value.

thanks for the clarification

Although it seems that testing for None does the trick,,. In the case
of nodata pixels this test does seem to work:

  bandvalue = ident[iband]
  if bandvalue is None:
  bandvalue = no data

and in c++ nodata pixels are defined as QVariant() (i.e. a null QVariant)


 Matthias

 [1]
 http://pyqt.sourceforge.net/Docs/PyQt4/python_v3.html#qvariant


 Sorry for the smart-arsing ;)

 -- Matthias



 cheers
 Etienne

 On Fri, Aug 2, 2013 at 7:13 AM, Otto Dassau das...@gbd-consult.de wrote:

 Hi,

 thanks for your hints, I think I am on the right track now. I had a look 
 at
 the value tool plugin and tried to adapt the method accordingly:

 def sampleRaster20(self, layer, x, y):
#success, data = layer.dataProvider().identify(QgsPoint(x,y))
success, data = 
 layer.dataProvider().identify(QgsPoint(x,y),QgsRaster.IdentifyFormatValue).results()
for band, value in data.items():
   return value

 But now I get another error message

  File
  
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 448, in printValue self.showValues() File
  
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 454, in showValues self.plot() File
  
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 526, in plot w = float(self.sampleRaster(self.InRastW.currentText(),
  self.xCoord, self.yCoord))/10 File
  
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 300, in sampleRaster return self.sampleRaster20(layer, x, y) File
  
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 285, in sampleRaster20 success, data =
  layer.dataProvider().identify(QgsPoint(x,y), 
 QgsRaster.IdentifyFormatValue
  ).results() ValueError: need more than 1 value to unpack

 Do you have an idea for this, too?

 Thanks
 Otto

 Am Thu, 1 Aug 2013 16:00:08 -0300
 schrieb Etienne Tourigny etourigny@gmail.com:

 Have a look at the source of the value tool plugin, it calls the 
 identify()
 method and has been updated to 2.0 api.

 Etienne

 On Thu, Aug 1, 2013 at 1:58 PM, Otto Dassau das...@gbd-consult.de 
 wrote:

 Hi,

 I want to update a plugin from 1.8 to QGIS 2.0 and it throws following
 error:

 Traceback (most recent call last):
 File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 447, in printValue self.showValues() File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 453, in showValues self.plot() File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 514, in plot w = 
 float(self.sampleRaster(self.InRastW.currentText(),
 self.xCoord, self.yCoord))/10 File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 299, in sampleRaster return self.sampleRaster20(layer, x, y) File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 284, in sampleRaster20 success, data =
 layer.dataProvider().identify(QgsPoint(x,y))

 TypeError:
 QgsRasterDataProvider.identify(QgsPoint, QgsRaster.IdentifyFormat,
 QgsRectangle theExtent=QgsRectangle(), int theWidth=0, int theHeight=0):
 not enough arguments

 I found at
 http://hub.qgis.org/wiki/quantum-gis/API_changes_for_version_20 the
 section QgsRasterDataProvider which should fit. And the Method, where I
 assume the error occurs should be this

 # get value at mouse position QGIS = 1.8 (working for 1.8)
 def sampleRaster18(self, layer, x, y):
success, data = layer.identify(QgsPoint(x,y))
for band, value in data.items():
  return value

 now what I tried but doesn't work (see error above)

 # get value at mouse 

Re: [Qgis-developer] update plugin to QGIS 2.0

2013-08-02 Thread Matthias Kuhn
On Fre 02 Aug 2013 15:52:19 CEST, Etienne Tourigny wrote:
 On Fri, Aug 2, 2013 at 10:22 AM, Matthias Kuhn matthias.k...@gmx.ch wrote:
 On Fre 02 Aug 2013 15:13:04 CEST, Etienne Tourigny wrote:
 On Fri, Aug 2, 2013 at 9:37 AM, Matthias Kuhn matthias.k...@gmx.ch wrote:
 Hi

 On Fre 02 Aug 2013 13:50:08 CEST, Etienne Tourigny wrote:

 for each band, if the point is outside of the raster extent or is
 nodata, the value will be a null QVariant (i.e. QVariant()) which in
 python is None.

 It will be a QPyNullVariant so doing

 value = QPyNullVariant( int )
 if not value:
 print 'Is NULL'
 else:
 print 'Is not NULL'

 if value is None:
 print 'Is None'
 else:
 print 'Is NOT None'

 will print:
 Is NULL
 Is NOT None

 Hi,

 I was not referring to the value of QPyNullVariant( int ), but the
 value that results() would return in the case of nodata (which is
 QVariant() in the c++ code)

 unless mistaken, that would be converted to None by Sip - or am I wrong?


 The SIP API v2 for QVariant defines:

 An Invalid QVariant will be represented as None
 A Null QVariant will be represented as QPyNullVariant [1]

 Except for feature attributes (e.g. for a vectorlayer: feature['attr'])
 which is patched by QGIS to become None in case of a Null value.

 thanks for the clarification

 Although it seems that testing for None does the trick,,. In the case
 of nodata pixels this test does seem to work:

   bandvalue = ident[iband]
   if bandvalue is None:
   bandvalue = no data


Ah, now I see.

QVariant() constructs an invalid QVariant and not a NULL QVariant. [1]

Glad we could sort this out :-)

Kind Regards
Matthias

[1] http://qt-project.org/doc/qt-4.8/qvariant.html#QVariant

 and in c++ nodata pixels are defined as QVariant() (i.e. a null QVariant)


 Matthias

 [1]
 http://pyqt.sourceforge.net/Docs/PyQt4/python_v3.html#qvariant


 Sorry for the smart-arsing ;)

 -- Matthias



 cheers
 Etienne

 On Fri, Aug 2, 2013 at 7:13 AM, Otto Dassau das...@gbd-consult.de wrote:

 Hi,

 thanks for your hints, I think I am on the right track now. I had a look 
 at
 the value tool plugin and tried to adapt the method accordingly:

 def sampleRaster20(self, layer, x, y):
#success, data = layer.dataProvider().identify(QgsPoint(x,y))
success, data = 
 layer.dataProvider().identify(QgsPoint(x,y),QgsRaster.IdentifyFormatValue).results()
for band, value in data.items():
   return value

 But now I get another error message

  File
  
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 448, in printValue self.showValues() File
  
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 454, in showValues self.plot() File
  
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 526, in plot w = 
 float(self.sampleRaster(self.InRastW.currentText(),
  self.xCoord, self.yCoord))/10 File
  
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 300, in sampleRaster return self.sampleRaster20(layer, x, y) File
  
 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 285, in sampleRaster20 success, data =
  layer.dataProvider().identify(QgsPoint(x,y), 
 QgsRaster.IdentifyFormatValue
  ).results() ValueError: need more than 1 value to unpack

 Do you have an idea for this, too?

 Thanks
 Otto

 Am Thu, 1 Aug 2013 16:00:08 -0300
 schrieb Etienne Tourigny etourigny@gmail.com:

 Have a look at the source of the value tool plugin, it calls the 
 identify()
 method and has been updated to 2.0 api.

 Etienne

 On Thu, Aug 1, 2013 at 1:58 PM, Otto Dassau das...@gbd-consult.de 
 wrote:

 Hi,

 I want to update a plugin from 1.8 to QGIS 2.0 and it throws following
 error:

 Traceback (most recent call last):
 File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 447, in printValue self.showValues() File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 453, in showValues self.plot() File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 514, in plot w = 
 float(self.sampleRaster(self.InRastW.currentText(),
 self.xCoord, self.yCoord))/10 File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 299, in sampleRaster return self.sampleRaster20(layer, x, y) File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 284, in sampleRaster20 success, data =
 layer.dataProvider().identify(QgsPoint(x,y))

 TypeError:
 QgsRasterDataProvider.identify(QgsPoint, QgsRaster.IdentifyFormat,
 QgsRectangle theExtent=QgsRectangle(), int theWidth=0, int 
 theHeight=0):
 not enough arguments

 I found at
 http://hub.qgis.org/wiki/quantum-gis/API_changes_for_version_20 the
 section QgsRasterDataProvider which should fit. And the Method, where I
 assume the error occurs should be this

 # get 

Re: [Qgis-developer] update plugin to QGIS 2.0

2013-08-02 Thread Otto Dassau
Hi,

thanks for the hint. And if I need the value of the raster? If I understand
correctly, ident will always be 1, if I have a 1 band raster layer. But how
can I get the value at QgsPoint(x,y) of the raster? I don't understand that
from the value tool plugin.

In QGIS 1.8 I use :

success, data = layer.identify(QgsPoint(x,y))
   for band, value in data.items():
   return value

and in QGIS 2.0:

ident = 
layer.dataProvider().identify(QgsPoint(x,y),QgsRaster.IdentifyFormatValue).results()
   ?

Thanks again

Otto


Am Fri, 2 Aug 2013 08:50:08 -0300
schrieb Etienne Tourigny etourigny@gmail.com:

 from the api
 http://www.qgis.org/api/classQgsRasterIdentifyResult.html#a8537d25fdff215e7e9650b71a0a16783
 
 results() returns a QMapint, QVariant (one item for each band), it
 does not return a tuple, so you should actually call
 
 ident =
 layer.dataProvider().identify(QgsPoint(x,y),QgsRaster.IdentifyFormatValue).results()
 
 and then test that ident is not empty (i,e. ident is not None and
 ident.iterkeys() is not None)
 
 for each band, if the point is outside of the raster extent or is
 nodata, the value will be a null QVariant (i.e. QVariant()) which in
 python is None.
 
 
 cheers
 Etienne
 
 On Fri, Aug 2, 2013 at 7:13 AM, Otto Dassau das...@gbd-consult.de wrote:
 
  Hi,
 
  thanks for your hints, I think I am on the right track now. I had a look
  at the value tool plugin and tried to adapt the method accordingly:
 
  def sampleRaster20(self, layer, x, y):
 #success, data = layer.dataProvider().identify(QgsPoint(x,y))
 success, data =
  layer.dataProvider().identify(QgsPoint(x,y),QgsRaster.IdentifyFormatValue).results()
  for band, value in data.items(): return value
 
  But now I get another error message
 
   File
   
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
   line 448, in printValue self.showValues() File
   
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
   line 454, in showValues self.plot() File
   
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
   line 526, in plot w =
  float(self.sampleRaster(self.InRastW.currentText(), self.xCoord,
  self.yCoord))/10 File
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 300, in sampleRaster return self.sampleRaster20(layer, x, y) File
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 285, in sampleRaster20 success, data =
  layer.dataProvider().identify(QgsPoint(x,y),
  QgsRaster.IdentifyFormatValue ).results() ValueError: need more than 1
  value to unpack
 
  Do you have an idea for this, too?
 
  Thanks
  Otto
 
  Am Thu, 1 Aug 2013 16:00:08 -0300
  schrieb Etienne Tourigny etourigny@gmail.com:
 
   Have a look at the source of the value tool plugin, it calls the
   identify() method and has been updated to 2.0 api.
  
   Etienne
  
   On Thu, Aug 1, 2013 at 1:58 PM, Otto Dassau das...@gbd-consult.de
   wrote:
  
Hi,
   
I want to update a plugin from 1.8 to QGIS 2.0 and it throws
following error:
   
Traceback (most recent call last):
File
   
   
/home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
line 447, in printValue self.showValues() File
   
   
/home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
line 453, in showValues self.plot() File
   
   
/home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
line 514, in plot w =
float(self.sampleRaster(self.InRastW.currentText(), self.xCoord,
self.yCoord))/10 File
   
   
/home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
line 299, in sampleRaster return self.sampleRaster20(layer, x, y)
File
   
   
/home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
line 284, in sampleRaster20 success, data =
layer.dataProvider().identify(QgsPoint(x,y))
   
TypeError:
QgsRasterDataProvider.identify(QgsPoint, QgsRaster.IdentifyFormat,
QgsRectangle theExtent=QgsRectangle(), int theWidth=0, int
theHeight=0): not enough arguments
   
I found at
http://hub.qgis.org/wiki/quantum-gis/API_changes_for_version_20 the
section QgsRasterDataProvider which should fit. And the Method,
where I assume the error occurs should be this
   
# get value at mouse position QGIS = 1.8 (working for 1.8)
def sampleRaster18(self, layer, x, y):
   success, data = layer.identify(QgsPoint(x,y))
   for band, value in data.items():
 return value
   
now what I tried but doesn't work (see error above)
   
# get value at mouse position QGIS = 2.0 (not working yet :()
def sampleRaster20(self, layer, x, y):
   success, data = layer.dataProvider().identify(QgsPoint(x,y))
   for band, value in data.items():
 return value
   
my problem is, that I don't understand how to implement in
sampleRaster20 the new 

Re: [Qgis-developer] update plugin to QGIS 2.0

2013-08-02 Thread Etienne Tourigny
On Fri, Aug 2, 2013 at 11:58 AM, Otto Dassau das...@gbd-consult.de wrote:
 Hi,

 thanks for the hint. And if I need the value of the raster? If I understand
 correctly, ident will always be 1, if I have a 1 band raster layer. But how
 can I get the value at QgsPoint(x,y) of the raster? I don't understand that
 from the value tool plugin.

no,  ident will be a dict with an element of key 1

you get exactly the fist band's value at the point with ident[1] .

the key of the map is the band number, and the value is the value (or
None if nodata/out of bounds)

so without any error checking you would do

ident = 
layer.dataProvider().identify(QgsPoint(x,y),QgsRaster.IdentifyFormatValue).results()
return ident[1]

cheers
Etienne


 In QGIS 1.8 I use :

 success, data = layer.identify(QgsPoint(x,y))
for band, value in data.items():
return value

 and in QGIS 2.0:

 ident = 
 layer.dataProvider().identify(QgsPoint(x,y),QgsRaster.IdentifyFormatValue).results()
?

 Thanks again

 Otto


 Am Fri, 2 Aug 2013 08:50:08 -0300
 schrieb Etienne Tourigny etourigny@gmail.com:

 from the api
 http://www.qgis.org/api/classQgsRasterIdentifyResult.html#a8537d25fdff215e7e9650b71a0a16783

 results() returns a QMapint, QVariant (one item for each band), it
 does not return a tuple, so you should actually call

 ident =
 layer.dataProvider().identify(QgsPoint(x,y),QgsRaster.IdentifyFormatValue).results()

 and then test that ident is not empty (i,e. ident is not None and
 ident.iterkeys() is not None)

 for each band, if the point is outside of the raster extent or is
 nodata, the value will be a null QVariant (i.e. QVariant()) which in
 python is None.


 cheers
 Etienne

 On Fri, Aug 2, 2013 at 7:13 AM, Otto Dassau das...@gbd-consult.de wrote:
 
  Hi,
 
  thanks for your hints, I think I am on the right track now. I had a look
  at the value tool plugin and tried to adapt the method accordingly:
 
  def sampleRaster20(self, layer, x, y):
 #success, data = layer.dataProvider().identify(QgsPoint(x,y))
 success, data =
  layer.dataProvider().identify(QgsPoint(x,y),QgsRaster.IdentifyFormatValue).results()
  for band, value in data.items(): return value
 
  But now I get another error message
 
   File
   
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
   line 448, in printValue self.showValues() File
   
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
   line 454, in showValues self.plot() File
   
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
   line 526, in plot w =
  float(self.sampleRaster(self.InRastW.currentText(), self.xCoord,
  self.yCoord))/10 File
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 300, in sampleRaster return self.sampleRaster20(layer, x, y) File
  /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
  line 285, in sampleRaster20 success, data =
  layer.dataProvider().identify(QgsPoint(x,y),
  QgsRaster.IdentifyFormatValue ).results() ValueError: need more than 1
  value to unpack
 
  Do you have an idea for this, too?
 
  Thanks
  Otto
 
  Am Thu, 1 Aug 2013 16:00:08 -0300
  schrieb Etienne Tourigny etourigny@gmail.com:
 
   Have a look at the source of the value tool plugin, it calls the
   identify() method and has been updated to 2.0 api.
  
   Etienne
  
   On Thu, Aug 1, 2013 at 1:58 PM, Otto Dassau das...@gbd-consult.de
   wrote:
  
Hi,
   
I want to update a plugin from 1.8 to QGIS 2.0 and it throws
following error:
   
Traceback (most recent call last):
File
   
   
/home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
line 447, in printValue self.showValues() File
   
   
/home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
line 453, in showValues self.plot() File
   
   
/home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
line 514, in plot w =
float(self.sampleRaster(self.InRastW.currentText(), self.xCoord,
self.yCoord))/10 File
   
   
/home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
line 299, in sampleRaster return self.sampleRaster20(layer, x, y)
File
   
   
/home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
line 284, in sampleRaster20 success, data =
layer.dataProvider().identify(QgsPoint(x,y))
   
TypeError:
QgsRasterDataProvider.identify(QgsPoint, QgsRaster.IdentifyFormat,
QgsRectangle theExtent=QgsRectangle(), int theWidth=0, int
theHeight=0): not enough arguments
   
I found at
http://hub.qgis.org/wiki/quantum-gis/API_changes_for_version_20 the
section QgsRasterDataProvider which should fit. And the Method,
where I assume the error occurs should be this
   
# get value at mouse position QGIS = 1.8 (working for 1.8)
def sampleRaster18(self, layer, x, y):
   success, data = 

Re: [Qgis-developer] update plugin to QGIS 2.0

2013-08-02 Thread Otto Dassau
Hi Etienne and Matthias,

fine - that was missing.

Thanks a lot
Otto

Am Fri, 2 Aug 2013 12:04:09 -0300
schrieb Etienne Tourigny etourigny@gmail.com:

 On Fri, Aug 2, 2013 at 11:58 AM, Otto Dassau das...@gbd-consult.de wrote:
  Hi,
 
  thanks for the hint. And if I need the value of the raster? If I
  understand correctly, ident will always be 1, if I have a 1 band raster
  layer. But how can I get the value at QgsPoint(x,y) of the raster? I
  don't understand that from the value tool plugin.
 
 no,  ident will be a dict with an element of key 1
 
 you get exactly the fist band's value at the point with ident[1] .
 
 the key of the map is the band number, and the value is the value (or
 None if nodata/out of bounds)
 
 so without any error checking you would do
 
 ident =
 layer.dataProvider().identify(QgsPoint(x,y),QgsRaster.IdentifyFormatValue).results()
 return ident[1]
 
 cheers
 Etienne
 
 
  In QGIS 1.8 I use :
 
  success, data = layer.identify(QgsPoint(x,y))
 for band, value in data.items():
 return value
 
  and in QGIS 2.0:
 
  ident =
  layer.dataProvider().identify(QgsPoint(x,y),QgsRaster.IdentifyFormatValue).results()
   ?
 
  Thanks again
 
  Otto
 
 
  Am Fri, 2 Aug 2013 08:50:08 -0300
  schrieb Etienne Tourigny etourigny@gmail.com:
 
  from the api
  http://www.qgis.org/api/classQgsRasterIdentifyResult.html#a8537d25fdff215e7e9650b71a0a16783
 
  results() returns a QMapint, QVariant (one item for each band), it
  does not return a tuple, so you should actually call
 
  ident =
  layer.dataProvider().identify(QgsPoint(x,y),QgsRaster.IdentifyFormatValue).results()
 
  and then test that ident is not empty (i,e. ident is not None and
  ident.iterkeys() is not None)
 
  for each band, if the point is outside of the raster extent or is
  nodata, the value will be a null QVariant (i.e. QVariant()) which in
  python is None.
 
 
  cheers
  Etienne
 
  On Fri, Aug 2, 2013 at 7:13 AM, Otto Dassau das...@gbd-consult.de
  wrote:
  
   Hi,
  
   thanks for your hints, I think I am on the right track now. I had a
   look at the value tool plugin and tried to adapt the method
   accordingly:
  
   def sampleRaster20(self, layer, x, y):
  #success, data = layer.dataProvider().identify(QgsPoint(x,y))
  success, data =
   layer.dataProvider().identify(QgsPoint(x,y),QgsRaster.IdentifyFormatValue).results()
   for band, value in data.items(): return value
  
   But now I get another error message
  
File

   /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
line 448, in printValue self.showValues() File

   /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
line 454, in showValues self.plot() File

   /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
line 526, in plot w =
   float(self.sampleRaster(self.InRastW.currentText(), self.xCoord,
   self.yCoord))/10 File
   /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
   line 300, in sampleRaster return self.sampleRaster20(layer, x, y) File
   /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
   line 285, in sampleRaster20 success, data =
   layer.dataProvider().identify(QgsPoint(x,y),
   QgsRaster.IdentifyFormatValue ).results() ValueError: need more than 1
   value to unpack
  
   Do you have an idea for this, too?
  
   Thanks
   Otto
  
   Am Thu, 1 Aug 2013 16:00:08 -0300
   schrieb Etienne Tourigny etourigny@gmail.com:
  
Have a look at the source of the value tool plugin, it calls the
identify() method and has been updated to 2.0 api.
   
Etienne
   
On Thu, Aug 1, 2013 at 1:58 PM, Otto Dassau das...@gbd-consult.de
wrote:
   
 Hi,

 I want to update a plugin from 1.8 to QGIS 2.0 and it throws
 following error:

 Traceback (most recent call last):
 File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 447, in printValue self.showValues() File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 453, in showValues self.plot() File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 514, in plot w =
 float(self.sampleRaster(self.InRastW.currentText(), self.xCoord,
 self.yCoord))/10 File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 299, in sampleRaster return self.sampleRaster20(layer, x, y)
 File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 284, in sampleRaster20 success, data =
 layer.dataProvider().identify(QgsPoint(x,y))

 TypeError:
 QgsRasterDataProvider.identify(QgsPoint, QgsRaster.IdentifyFormat,
 QgsRectangle theExtent=QgsRectangle(), int theWidth=0, int
 theHeight=0): not enough arguments

 I found at
 

Re: [Qgis-developer] update plugin to QGIS 2.0

2013-08-01 Thread Marc Jansen
Hi otto,

A super wild guess: whats the value of IdentifyFormat in your call?

Hth,
Marc



Otto Dassau das...@gbd-consult.de schrieb:
Hi,

I want to update a plugin from 1.8 to QGIS 2.0 and it throws following
error:

Traceback (most recent call last):
File
  
/home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 
line 447, in printValue self.showValues() File
  
/home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 
line 453, in showValues self.plot() File
  
/home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 
line 514, in plot w =
float(self.sampleRaster(self.InRastW.currentText(),
self.xCoord, self.yCoord))/10 File
  
/home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 
line 299, in sampleRaster return self.sampleRaster20(layer, x, y) File
  
/home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 
line 284, in sampleRaster20 success, data =
layer.dataProvider().identify(QgsPoint(x,y))

TypeError:
QgsRasterDataProvider.identify(QgsPoint, QgsRaster.IdentifyFormat,
QgsRectangle theExtent=QgsRectangle(), int theWidth=0, int
theHeight=0):
not enough arguments

I found at
http://hub.qgis.org/wiki/quantum-gis/API_changes_for_version_20
the section QgsRasterDataProvider which should fit. And the Method,
where I
assume the error occurs should be this

# get value at mouse position QGIS = 1.8 (working for 1.8)
def sampleRaster18(self, layer, x, y):
   success, data = layer.identify(QgsPoint(x,y))
   for band, value in data.items():
 return value

now what I tried but doesn't work (see error above)

# get value at mouse position QGIS = 2.0 (not working yet :()
def sampleRaster20(self, layer, x, y):
   success, data = layer.dataProvider().identify(QgsPoint(x,y))
   for band, value in data.items():
 return value

my problem is, that I don't understand how to implement in
sampleRaster20
the new method from the API_changes_for_version_20 website which says:

QMapint, QVariant identify( const QgsPoint  thePoint, IdentifyFormat
theFormat, const QgsRectangle theExtent = QgsRectangle(), int theWidth
=
0, int theHeight = 0 )

can anybody help?

Thanks 

Otto
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] update plugin to QGIS 2.0

2013-08-01 Thread Etienne Tourigny
Have a look at the source of the value tool plugin, it calls the identify()
method and has been updated to 2.0 api.

Etienne

On Thu, Aug 1, 2013 at 1:58 PM, Otto Dassau das...@gbd-consult.de wrote:

 Hi,

 I want to update a plugin from 1.8 to QGIS 2.0 and it throws following
 error:

 Traceback (most recent call last):
 File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 447, in printValue self.showValues() File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 453, in showValues self.plot() File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 514, in plot w = float(self.sampleRaster(self.InRastW.currentText(),
 self.xCoord, self.yCoord))/10 File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 299, in sampleRaster return self.sampleRaster20(layer, x, y) File


 /home/dassau/.qgis2/python/plugins/weibullanalyse/weibullanalysedialog.py,
 line 284, in sampleRaster20 success, data =
 layer.dataProvider().identify(QgsPoint(x,y))

 TypeError:
 QgsRasterDataProvider.identify(QgsPoint, QgsRaster.IdentifyFormat,
 QgsRectangle theExtent=QgsRectangle(), int theWidth=0, int theHeight=0):
 not enough arguments

 I found at http://hub.qgis.org/wiki/quantum-gis/API_changes_for_version_20
 the section QgsRasterDataProvider which should fit. And the Method, where I
 assume the error occurs should be this

 # get value at mouse position QGIS = 1.8 (working for 1.8)
 def sampleRaster18(self, layer, x, y):
success, data = layer.identify(QgsPoint(x,y))
for band, value in data.items():
  return value

 now what I tried but doesn't work (see error above)

 # get value at mouse position QGIS = 2.0 (not working yet :()
 def sampleRaster20(self, layer, x, y):
success, data = layer.dataProvider().identify(QgsPoint(x,y))
for band, value in data.items():
  return value

 my problem is, that I don't understand how to implement in sampleRaster20
 the new method from the API_changes_for_version_20 website which says:

 QMapint, QVariant identify( const QgsPoint  thePoint, IdentifyFormat
 theFormat, const QgsRectangle theExtent = QgsRectangle(), int theWidth =
 0, int theHeight = 0 )

 can anybody help?

 Thanks

 Otto
 ___
 Qgis-developer mailing list
 Qgis-developer@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/qgis-developer

___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer