[prev in list] [next in list] [prev in thread] [next in thread] 

List:       qgis-developer
Subject:    Re: [Qgis-developer] Help needed in accessing classified raster
From:       Barry Rowlingson <b.rowlingson () lancaster ! ac ! uk>
Date:       2010-03-30 13:37:28
Message-ID: d8ad40b51003300637w44f7687fp5a9047d320494b3 () mail ! gmail ! com
[Download RAW message or body]

On Tue, Mar 30, 2010 at 1:24 PM, Bishwarup Banerjee
<bishwarup.banerjee@gmail.com> wrote:
> Dear All,
>
> Is there any way to access the Category values of the raster layer through
> python in QGIS?
>
> I have a classified raster and I want to access the classes through python.
> For example : I have classified soil map of a partricular area, with
> different types of soil, now I want to access the soil types of that raster
> through python.
>
> It will be very kind of you, if can help me out.

 Easiest thing is to use the gdal API and get it into a numpy array.
Something like (taken from rastercalc):

import numpy
import osgeo.gdal as gdal

def layerAsArray( layer ):
  gdalData = gdal.Open( str( layer.source() ) )
  array = gdalData.ReadAsArray().astype( numpy.float32 )
  gdalData = None
  return array

numpy.float32 might not be the right type if you have a classification
raster, but hopefully you'll get the idea.

There's more useful-looking functions in rastercalc and other plugins.

Barry
_______________________________________________
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic