[GRASS-dev] Fwd: different region if looking using ctypes or g.region

Vaclav Petras wenzeslaus at gmail.com
Thu Feb 27 14:44:02 PST 2014


Hi,

I'm glad you opened that topic. If you change region in C or using ctypes
in Python, it is affecting only the current process. While g.region
reads/writes the file with region but obviously will not change your
process region in Python (when using ctypes). And then there are the
temporary regions. To design an API for it is a challenge. I think I even
wrote something about it to documentation but it needs to be completely
rewritten to be actually readable.

Vaclav


On Thu, Feb 27, 2014 at 5:02 PM, Pietro <peter.zamb at gmail.com> wrote:

> Dear devs,
>
> I got different results if I use ctypes or the module g.region, I wrote:
>
> import ctypes import grass.lib.gis as libgis from grass import script
>
> SEP = '\n\n'
>
> c_region = ctypes.pointer(libgis.Cell_head())
> ## read current region
> libgis.G_get_set_window(c_region)
>
> print('original')
> print(c_region.contents.ns_res)
> print(c_region.contents.rows)
> print(c_region.contents.ew_res)
> print(c_region.contents.cols)
> print(SEP)
> ## change resolution
> c_region.contents.ns_res = 100.
> c_region.contents.ew_res = 100.
> ## adjust
> libgis.G_adjust_Cell_head(c_region, 0, 0)
>
> print('changed')
> print(c_region.contents.ns_res)
> print(c_region.contents.rows)
> print(c_region.contents.ew_res)
> print(c_region.contents.cols)
> print(SEP)
> ## save current
> libgis.G_set_window(c_region)
>
> print(script.read_command("g.region", flags="p"))
> print(SEP)
> ## read current region
> libgis.G_get_set_window(c_region)
> print('after')
> print(c_region.contents.ns_res)
> print(c_region.contents.rows)
> print(c_region.contents.ew_res)
> print(c_region.contents.cols)
> print(SEP)
>
> The output is:
>
> original10.0135010.01500
>
> changed100.0135100.0150
>
> projection: 99 (Lambert Conformal Conic)
> zone:       0
> datum:      nad83
> ellipsoid:  a=6378137 es=0.006694380022900787
> north:      228500
> south:      215000
> west:       630000
> east:       645000
> nsres:      10
> ewres:      10
> rows:       1350
> cols:       1500
> cells:      2025000
>
> after100.0135100.0150
>
> Any Ideas?
>
> Pietro
>
> _______________________________________________
> grass-dev mailing list
> grass-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20140227/1b8c8ce8/attachment-0001.html>


More information about the grass-dev mailing list