[GRASS-dev] Re: ctypes problem with Vect_open_old
Maris Nartiss
maris.gis at gmail.com
Tue Jan 4 11:50:34 EST 2011
This one should work. One has to be really carefull and track when
pointers are required. Working with pointers and ctypes is a tricky
thing.
from ctypes import byref
from grass.lib.vector import *
map = Map_info()
Vect_open_update(byref(map), "vector", "mapset")
p = Vect_new_line_struct()
c = Vect_new_cats_struct()
Vect_append_point(p, 10, 10, 0)
Vect_write_line(byref(map), GV_POINT, p, c)
Vect_build(byref(map))
Vect_close(byref(map))
Maris.
2011/1/4, Martin Landa <landa.martin at gmail.com>:
> Hi,
>
> 2011/1/4 Glynn Clements <glynn at gclements.plus.com>:
>>> p = line_pnts()
>>> Vect_append_point(byref(p), 1, 1, 0)
>>
>> You're passing an uninitialised line_pnts structure (i.e. with its
>> fields containing garbage), and probably trashing the heap. Use
>> Vect_new_line_struct() to allocate an empty line_pnts object.
>
> something like?
>
> map_obj = Map_info()
> map = pointer(map_obj)
>
> Vect_open_update(map, "a", "")
>
> p = Vect_new_line_struct()
> c = Vect_new_cats_struct()
>
> Vect_append_point(p, 1, 1, 0)
> Vect_cat_set(c, 1, 1)
> print p.contents.n_points
>
> Vect_write_line(map, GV_POINT, p, c)
>
> Vect_build(map)
> Vect_close(map)
>
> No success, btw
>
> p = line_pns()
> Vect_append_point(byref(p), 1, 1, 0)
> print p.n_points
>
> interestingly works.
>
> Martin
>
> --
> Martin Landa <landa.martin gmail.com> * http://geo.fsv.cvut.cz/~landa
>
More information about the grass-dev
mailing list