[GRASS-user] Python/Ctype interface: how to get coordinates for raster layer.

hi all,

for a GRASS 6.x script I'm using the ctype interface
to iterate over all lines (and cells) of a raster layer:

...

for rown in xrange(rows):
     G_get_raster_row(infd, inrast, rown, data_type)
     print rown, inrast[0:cols]
...
[taken from the ctypes raster example (http://fossies.org/dox/grass-6.4.2/example__ctypes_8py_source.html)]

Q:The (geographic) coordinates for each raster cell should be accessible via
coo_col = G_col_to_easting((thecolumn + 0.5), "REGION")
coo_row = G_row_to_northing((therow + 0.5), "REGION")

=> how is "REGION"-related information 1) derived and 2) referred to on this level ?

Peter
--
Dr. Peter Löwe
<peter.loewe@gmx.de>

Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de

peter.loewe@gmx.de wrote:

Q:The (geographic) coordinates for each raster cell should be accessible via
coo_col = G_col_to_easting((thecolumn + 0.5), "REGION")
coo_row = G_row_to_northing((therow + 0.5), "REGION")

=> how is "REGION"-related information 1) derived and 2) referred to on this level ?

The second argument to G_col_to_easting() and G_row_to_northing() is a
"const struct Cell_head *". The information can be obtained from
G_get_window(), e.g.:

  import sys
  import grass.lib.gis as gis
  from ctypes import *
  
  gis.G_gisinit(sys.argv[0])
  
  region = gis.Cell_head()
  G_get_window(byref(region))
  coo_col = gis.G_col_to_easting((thecolumn + 0.5), byref(region))
  coo_row = gis.G_row_to_northing((therow + 0.5), byref(region))

The ctypes interfaces are thin wrappers around the corresponding C
functions. Any script which uses them should have essentially the same
structure as a module written in C. Structures can be allocated by
using the structure name as a function, and passed by reference using
ctypes' byref() function.

--
Glynn Clements <glynn@gclements.plus.com>

On Fri, Mar 30, 2012 at 7:26 PM, Glynn Clements
<glynn@gclements.plus.com> wrote:

peter.loewe@gmx.de wrote:

Q:The (geographic) coordinates for each raster cell should be accessible via
coo_col = G_col_to_easting((thecolumn + 0.5), "REGION")
coo_row = G_row_to_northing((therow + 0.5), "REGION")

=> how is "REGION"-related information 1) derived and 2) referred to on this level ?

The second argument to G_col_to_easting() and G_row_to_northing() is a
"const struct Cell_head *".

[...]

... added to
http://grass.osgeo.org/wiki/Python_Ctypes_Examples

Markus