[GRASS-dev] RE: [GRASS-user] Question with Python-SWIG example [SEC=UNCLASSIFIED]

Glynn Clements glynn at gclements.plus.com
Tue May 18 14:51:35 EDT 2010


Martin Landa wrote:

> > Odd. Can you try it under GDB and check what arguments
> > G_find_raster2() is getting?
> >
> > Also, are you calling G_gisinit() first?
> 
> sample script below
> 
> ---
> #!/usr/bin/env python
> import os, sys
> from grass.lib import grass, raster
> from ctypes import *
> 
> input = sys.argv[1]
> 
> grass.G_gisinit(sys.argv[0])
> 
> mapset = grass.G_find_raster2(input, "")
> print mapset
> ---
> 
> Running
> 
> python example.py elevation
> 
> I get
> 
> D1/5: G_find_raster2(): name=?  ??? mapset=elevation
> WARNING: Illegal filename <? ???>. Character <� not allowed.
> ?

The script works fine for me.

I'm assuming that you added the G_debug() statement, because there
isn't one at present.

What platform, Python version, ctypesgen version?

The G_find_raster2() definition should look like:

# /usr/local/src/grass/7.0/dist.i686-pc-linux-gnu/include/grass/gisdefs.h: 220
if hasattr(_libs['grass_gis'], 'G_find_raster2'):
    G_find_raster2 = _libs['grass_gis'].G_find_raster2
    G_find_raster2.restype = ReturnString
    G_find_raster2.argtypes = [String, String]

Does it work if you use ctypes manually, e.g.:

---
#!/usr/bin/env python
import os, sys
from grass.script import read_command
from ctypes import *
input = sys.argv[1]
grass = CDLL("libgrass_gis.so")
version = read_command("g.version", flags = "r").splitlines()[1].strip().split()[1]
grass.G__gisinit("$Revision: %s $" % version, sys.argv[0])
mapset = grass.G_find_raster2(input, "")
print c_char_p(mapset).value
---

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


More information about the grass-dev mailing list