[GRASS-dev] GRASS-Python Interface: Vector API added

Hi,

I have added the Vector API to the GRASS-SWIG-Python interface.
Now w have to figure out how to use it :slight_smile:

I am struggling there (don't know much about Python yet):

#### snip #####
import python_grass6 as g6lib

input = 'soils'
mapset = 'PERMANENT'

g6lib.G_gisinit('')
g6lib.Vect_set_open_level (2)

## how to set Map?
g6lib.Vect_open_old_head (Map, input, mapset)
print 'Vect is 3D:'
print g6lib.Vect_is_3d (Map)

g6lib.Vect_open_old(input, mapset)
print 'Vect DB links'
print g6lib.Vect_get_num_dblinks(Map)

g6lib.Vect_close(Map)

#### snap #####

Markus

Hello,

To get the Map_info structure we have to wrap also dig_structs.h (so
we must add dig_struct.i to the interfaces dir by adding a line in the
Makefile there).

I also added some lines to the python-swig interface file to provide
access to int/float/double arrays. Find attached the patch to
python_grass.i and below the updates to the script proposed by Markus
that now works with the new Map_info object.

#!/usr/bin/python
import python_grass6 as g6lib

input = 'soils'
mapset = 'PERMANENT'

g6lib.G_gisinit('')
g6lib.Vect_set_open_level (2)

map = g6lib.Map_info()

g6lib.Vect_open_old_head (map, input, mapset)
print 'Vect is 3D: ', g6lib.Vect_is_3d (map)

g6lib.Vect_open_old(map, input, mapset)
print 'Vect DB links: ', g6lib.Vect_get_num_dblinks(map)

g6lib.Vect_close(map)
## end of the python script

Regards,

Alessandro

2006/9/24, Markus Neteler <neteler@itc.it>:

Hi,

I have added the Vector API to the GRASS-SWIG-Python interface.
Now w have to figure out how to use it :slight_smile:

I am struggling there (don't know much about Python yet):

#### snip #####
import python_grass6 as g6lib

input = 'soils'
mapset = 'PERMANENT'

g6lib.G_gisinit('')
g6lib.Vect_set_open_level (2)

## how to set Map?
g6lib.Vect_open_old_head (Map, input, mapset)
print 'Vect is 3D:'
print g6lib.Vect_is_3d (Map)

g6lib.Vect_open_old(input, mapset)
print 'Vect DB links'
print g6lib.Vect_get_num_dblinks(Map)

g6lib.Vect_close(Map)

#### snap #####

Markus

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

--
Alessandro Frigeri, PhD

(attachments)

python_grass6.i.patch (449 Bytes)

Thanks, Alessandro.

I have submitted the patches and added
rasteraccess.py and
vectoraccess.py
as examples in CVS. The latter, slightly extended, now reports:

python vectoraccess.py
Vect is 3D: 0
Vect DB links: 1
Map Scale: 1: 24000
Number of lines: 2876

Markus

On Sun, Sep 24, 2006 at 10:43:04PM +0200, Alessandro Frigeri wrote:

Hello,

To get the Map_info structure we have to wrap also dig_structs.h (so
we must add dig_struct.i to the interfaces dir by adding a line in the
Makefile there).

I also added some lines to the python-swig interface file to provide
access to int/float/double arrays. Find attached the patch to
python_grass.i and below the updates to the script proposed by Markus
that now works with the new Map_info object.

#!/usr/bin/python
import python_grass6 as g6lib

input = 'soils'
mapset = 'PERMANENT'

g6lib.G_gisinit('')
g6lib.Vect_set_open_level (2)

map = g6lib.Map_info()

g6lib.Vect_open_old_head (map, input, mapset)
print 'Vect is 3D: ', g6lib.Vect_is_3d (map)

g6lib.Vect_open_old(map, input, mapset)
print 'Vect DB links: ', g6lib.Vect_get_num_dblinks(map)

g6lib.Vect_close(map)
## end of the python script

Regards,

Alessandro

--
Alessandro Frigeri, PhD