[Qgis-user] Re: Raster Manipulation in the QGIS Python Console

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Tue Oct 27 04:30:40 PDT 2009


On Tue, Oct 27, 2009 at 12:26 PM, Agustin Lobo <alobolistas at gmail.com> wrote:
> According to
> http://www.maths.lancs.ac.uk/~rowlings/Qgis/Plugins/Documentation/rasterlang/python.html
> I've done:
>
>>>> layer1 = iface.mapCanvas().layer(0)
>>>> layer1.name()
>
> but get no answer, I was expecting getting the layer name, as indicated in
> the web page
> "This should show the names of your raster layers"
>
> Nevertheles, computing works because I've done:
>>>> from rasterlang.layers import layerAsArray
>>>> a1 = layerAsArray(layer1)
>>>> a1.shape
>>>> rsum = a1 + a1
>>>> from rasterlang.layers import writeGeoTiff
>>>> e = layer1.extent()
>>>> extent = [e.xMinimum(),e.yMinimum(),e.xMaximum(),e.yMaximum()]
>>>> writeGeoTiff(rsum, extent,
>>>> "/media/Transcend/Anyella/calib20090730/rsum.tiff")
>
> and I do get a correct rsum.tiff file that I can display in qgis.
>
> Why am I not getting any answer from the console? a1.shape does not return
> anything either

 The latest python console requires you to 'print' everything you want
to see. So:

print layer1.name()

 Nah, I don't like it either! I have written my own python console
plugin but it seemed to crash things quite a lot...

Barry



More information about the Qgis-user mailing list