[GRASS-dev] Extracting coordinates of RasterNumpy objects (pygrass)

Pietro peter.zamb at gmail.com
Mon Dec 17 13:24:57 PST 2012


Hi Pierre,

On Mon, Dec 17, 2012 at 9:44 PM, Pierre Roudier
<pierre.roudier at gmail.com> wrote:
> Thanks Pietro,
>
> Yes that answers the question, but just partly: I was actually
> wondering whether it would be possible to get the extracted x and y
> coordinates in geographic space (as opposed to the Numpy array space)?

aah sorry, I forgot to say that you can use pixel2coord... see the
example below:

>>> from grass import pygrass
>>> from pygrass.raster import RasterNumpy
>>> from pygrass.region import Region
>>> from pygrass.functions import pixel2coor
>>> elev = RasterNumpy("elevation")
>>> elev.open()
>>> a = elev > 144
>>> reg = Region()
>>> xcoords, ycoords = a.nonzero()
>>> for pixel in zip(list(xcoords), list(ycoords))[:5]:
...     print pixel
...
(0, 6)
(0, 7)
(0, 8)
(0, 9)
(0, 10)
>>> for pixel in zip(list(xcoords), list(ycoords))[:5]:
...    print pixel2coor(pixel, reg)
...
(228440.0, 630000.0)
(228430.0, 630000.0)
(228420.0, 630000.0)
(228410.0, 630000.0)
(228400.0, 630000.0)

Best regards

Pietro


More information about the grass-dev mailing list