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

Pierre Roudier pierre.roudier at gmail.com
Mon Dec 17 13:41:36 PST 2012


Thanks Pietro and Soeren,

That's really great!


I am looking forward to use this with v.surf.bspline to do on the fly
interpolation (interpolation with SciPy is quite slow and memory
hungry). I am coding an iterative process that calls the interpolation
routine a lot of times (~10 to 40 interpolation steps), so I would
like to make the most of GRASS interpolation power.

Cheers,

Pierre

2012/12/18 Pietro <peter.zamb at gmail.com>:
> 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



-- 
Scientist
Landcare Research, New Zealand


More information about the grass-dev mailing list