Vector attributes

Hi

I'm creating a program that creates vector areas. When such an area is
written to disk with 'Vect_write_line(map,AREA,pnts)' I also want to give
that area an attribute. The problem is that I don't know how to achieve
this. Is there a function to create attributes or can I give the area
attribute to vect_write_line? The Grass Programming Guide wasn't very
clear on this (or I missed it :wink:

Grtz, Job

----------------------------------------------------------------------
Job Spijker
Faculty of Geographical Sciences, Utrecht University
P.O. Box 80115, 3508 TC Utrecht, The Netherlands
T: 030-253 2758 F: 030-253 1145
----------------------------------------------------------------------
Life is cheap. It's the accessories that kill you.

spijker@geo.uu.nl wrote:

I'm creating a program that creates vector areas. When such an area is
written to disk with 'Vect_write_line(map,AREA,pnts)' I also want to give
that area an attribute. The problem is that I don't know how to achieve
this. Is there a function to create attributes or can I give the area
attribute to vect_write_line? The Grass Programming Guide wasn't very
clear on this (or I missed it :wink:

Grtz, Job

Hi
I have been working on similar tasks recently with shapefile
import.

I don't think there is a particular function for this. You must create a
dig_att file with G_fopen_new, or open an already existing with
G_fopen_append. Then a line like

fprintf( attribute_file, "L %-12f %-12f %-8d \n",
         x_co_ordinate, y_co_ordinate, some_int_attribute );

writes the line. It will look something like

L 123456.876543 919828.477583 13

in an ascii file of the map's name under ${MAPSET}/dig_att

The problem is - you must assign a label point to the polygon,
which must be on the interior of the polygon (but outside any
islands the polygon might have). This is far from trivial
to work out in the general case. But depending on the way you
are building polygons you might the advantage of information that
allows you to assign a suitable point.

Hope this helps

David

spijker@geo.uu.nl wrote:

I'm creating a program that creates vector areas. When such an area is
written to disk with 'Vect_write_line(map,AREA,pnts)' I also want to give
that area an attribute. The problem is that I don't know how to achieve
this. Is there a function to create attributes or can I give the area
attribute to vect_write_line? The Grass Programming Guide wasn't very
clear on this (or I missed it :wink:

There is no function for that, but it's easy to manage without.
Use :

f = G_fopen_new( "dig_att", name); /* opening attribute file for name vector
file */
...
fprintf( f, "L %-12lf %-12lf %-8d \n", xc, yc, cov_id); /* for each line */

where xc and yc are the coordinate of a point located on your vector
(the usual rule in grass programs are to take the mid of the vector,
i.e. with a n points vector, (x[n/2]+x[n/2+1])/2 and (y[n/2]+y[n/2+1])/2
cov_id is the value of the line attribute.

fprintf( f, "A %-12lf %-12lf %-8d \n", xc, yc, cov_id); /* for each area */

where xc and yc are a file *inside* the area, and cov_id the attribute for
this area. The main problem is "how to find a point inside the area ?"
If you don't have a centroid determination algorithm, i suggest you to find
the mean x , then look at the segments interseted, class them by y intersection
and take y as the middle between the first two intersections :the point is
inside and that should work.

fclose( f); /* at the end */

My 0.02$ (grass tax ?:slight_smile:
--
Michel Wurtz ENGEES - CEREG
                1, quai Koch - BP 1039, F-67070 STRASBOURG cedex
                Tel: +33 03.88.24.82.45 Fax: +33 03.88.37.04.97