[GRASS-user] Question with Python-SWIG example

Markus Neteler neteler at osgeo.org
Sat Apr 17 08:30:55 EDT 2010


On Sat, Apr 17, 2010 at 1:57 PM, Glynn Clements
<glynn at gclements.plus.com> wrote:
> Markus Neteler wrote:
>
>> On Thu, Apr 15, 2010 at 1:22 PM, Glynn Clements
>> <glynn at gclements.plus.com> wrote:
>> ...
>> > But I wouldn't recommend trying to use the SWIG interface. It's not
>> > particularly robust and not widely understood. If you really need to
>> > use GRASS library functions from Python, use the ctypes module
>> > instead.
>>
>> How would
>>  http://grass.osgeo.org/wiki/GRASS_and_Python#Python-SWIG_examples
>> look like with ctypes? Perhaps the SWIG interface should not be advertised
>> to much in the Wiki...
>
> I've attached versions using ctypes for 6.x and 7.x; only the latter
> has been tested.

Thanks for this. For the easy of management, I have put them into SVN
into doc/python/ (all 6.4, 6.5 and 7) along with a simple argument parsing.
Perhaps it should be doxygenized and put elsewhere.

Test results:

GRASS 6.4.0svn (nc_spm_08):~ > g.region rast=elevation
GRASS 6.4.0svn (nc_spm_08):~ > python example_ctypes.py elevation
0 [141.99613952636719, 141.27848815917969, 141.37904357910156
...

GRASS 6.4.0svn (nc_spm_08):~ > r.mapcalc "one = 1"
GRASS 6.4.0svn (nc_spm_08):~ > python example_ctypes.py one
0 [1, 1, ...

-> looks both good.

I get the same results in GRASS 6.5 and 7

Thanks for your examples,
Markus


More information about the grass-user mailing list