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

Glynn Clements glynn at gclements.plus.com
Fri Mar 30 13:26:33 EDT 2012


peter.loewe at 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 at gclements.plus.com>


More information about the grass-user mailing list