1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#include <grass/vector.h>
#include <grass/glocale.h>
void write_lines(struct Map_info *In, struct field_info *IFi, int *ALines,
int *AAreas, struct Map_info *Out, int table_flag,
int reverse_flag, int nfields, int *fields, int *ncats,
int **cats)
{
int i, f, j, aline, nalines;
int atype;
struct line_pnts *APoints;
struct line_cats *ACats;
APoints = Vect_new_line_struct();
ACats = Vect_new_cats_struct();
for (i = 0; i < nfields; i++) {
ncats[i] = 0;
cats[i] = (int *)G_malloc(Vect_cidx_get_num_cats_by_index(&(In[0]), i) *
sizeof(int));
fields[i] = Vect_cidx_get_field_number(&(In[0]), i);
}
nalines = Vect_get_num_lines(In);
G_message(_("Writing selected features..."));
for (aline = 1; aline <= nalines; aline++) {
G_debug(3, "aline = %d ALines[aline] = %d", aline, ALines[aline]);
G_percent(aline, nalines, 2);
if ((!reverse_flag && !(ALines[aline])))
continue;
atype = Vect_read_line(&(In[0]), APoints, ACats, aline);
if ((reverse_flag && ALines[aline])) {
if (atype == GV_BOUNDARY && AAreas) {
int left, right, skipme;
skipme = 1;
Vect_get_line_areas(&(In[0]), aline, &left, &right);
if (left < 0)
left = Vect_get_isle_area(&(In[0]), abs(left));
if (left > 0 && !AAreas[left])
skipme = 0;
if (right < 0)
right = Vect_get_isle_area(&(In[0]), abs(right));
if (right > 0 && !AAreas[right])
skipme = 0;
if (skipme)
continue;
}
else
continue;
}
Vect_write_line(Out, atype, APoints, ACats);
if (!table_flag && (IFi != NULL)) {
for (i = 0; i < ACats->n_cats; i++) {
f = -1;
for (j = 0; j < nfields; j++) { /* find field */
if (fields[j] == ACats->field[i]) {
f = j;
break;
}
}
if (f >= 0) {
cats[f][ncats[f]] = ACats->cat[i];
ncats[f]++;
}
}
}
}
Vect_destroy_line_struct(APoints);
Vect_destroy_cats_struct(ACats);
}
|