Michel Wurtz - ENGEES/CEREG
mw at engees.u-strasbg.fr
Mon Apr 3 09:30:26 EDT 2000
spijker at 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 ;-)
There is no function for that, but it's easy to manage without.
f = G_fopen_new( "dig_att", name); /* opening attribute file for name vector
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 ?:-)
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
More information about the grass-user