22 #include <grass/gis.h>
23 #include <grass/Vect.h>
24 #include <grass/glocale.h>
93 struct line_pnts *BPoints, *Points;
94 struct line_cats *Cats;
95 int i, j, k, ret, ltype, broken, last, nlines;
98 int apoints, npoints, nallpoints, nmarks;
101 double dx, dy, a1 = 0, a2 = 0;
102 int closed, last_point, cross;
112 G_debug(3,
"nlines = %d", nlines);
124 for (i = 1; i <= nlines; i++) {
141 last_point = Points->n_points - 1;
142 if (Points->x[0] == Points->x[last_point] &&
143 Points->y[0] == Points->y[last_point])
148 for (j = 0; j < Points->n_points; j++) {
152 if (j == last_point && closed)
166 G_debug(3,
"fpoint = %d", fpoint);
168 if (Points->n_points <= 2 ||
169 (!closed && (j == 0 || j == last_point))) {
174 if (j == 0 && closed) {
175 dx = Points->x[last_point] - Points->x[0];
176 dy = Points->y[last_point] - Points->y[0];
178 dx = Points->x[1] - Points->x[0];
179 dy = Points->y[1] - Points->y[0];
183 dx = Points->x[j - 1] - Points->x[j];
184 dy = Points->y[j - 1] - Points->y[j];
186 dx = Points->x[j + 1] - Points->x[j];
187 dy = Points->y[j + 1] - Points->y[j];
193 if (XPnts[fpoint].cross == 1)
198 XPnts[fpoint].
cross = 1;
202 G_debug(3,
"a1 = %f xa1 = %f a2 = %f xa2 = %f", a1,
203 XPnts[fpoint].a1, a2, XPnts[fpoint].a2);
204 if ((a1 == XPnts[fpoint].a1 && a2 == XPnts[fpoint].a2) || (a1 == XPnts[fpoint].a2 && a2 == XPnts[fpoint].a1)) {
208 XPnts[fpoint].
cross = 1;
216 if (npoints >= apoints) {
219 (
XPNT *) G_realloc(XPnts,
220 (apoints + 1) *
sizeof(
XPNT));
222 XPnts[npoints].
x = Points->x[j];
223 XPnts[npoints].
y = Points->y[j];
224 XPnts[npoints].
used = 0;
225 if (j == 0 || j == (Points->n_points - 1) ||
226 Points->n_points < 3) {
227 XPnts[npoints].
a1 = 0;
228 XPnts[npoints].
a2 = 0;
229 XPnts[npoints].
cross = 1;
233 XPnts[npoints].
a1 = a1;
234 XPnts[npoints].
a2 = a2;
235 XPnts[npoints].
cross = 0;
252 for (i = 1; i <= nlines; i++) {
267 n_orig_points = Points->n_points;
272 G_debug(3,
"n_points = %d", Points->n_points);
273 for (j = 1; j < Points->n_points; j++) {
285 if (Points->n_points <= 1 ||
286 (j == (Points->n_points - 1) && !broken))
292 G_debug(3,
"fpoint = %d", fpoint);
294 if (XPnts[fpoint].cross) {
295 XPnts[fpoint].
used = 1;
299 if ((j == (Points->n_points - 1) && broken) ||
300 XPnts[fpoint].
cross) {
302 for (k = last; k <= j; k++) {
309 if (BPoints->n_points > 1) {
312 "Line %d written j = %d n_points(orig,pruned) = %d n_points(new) = %d",
313 ret, j, Points->n_points, BPoints->n_points);
324 if (!broken && n_orig_points > Points->n_points) {
325 if (Points->n_points > 1) {
327 G_debug(3,
"Line %d pruned, npoints = %d", i,
332 G_debug(3,
"Line %d was deleted", i);
336 G_debug(3,
"Line %d was not changed", i);
343 for (i = 1; i < npoints; i++) {
RectReal boundary[NUMSIDES]
void G_free(void *buf)
Free allocated memory.
void Vect_break_polygons(struct Map_info *Map, int type, struct Map_info *Err)
Break polygons in vector map.
struct line_pnts * Vect_new_line_struct()
Creates and initializes a struct line_pnts.
int RTreeSearch(struct Node *N, struct Rect *R, SearchHitCallback shcb, void *cbarg)
void RTreeDestroyNode(struct Node *)
int Vect_reset_line(struct line_pnts *Points)
Reset line.
int Vect_reset_cats(struct line_cats *Cats)
Reset category structure to make sure cats structure is clean to be re-used.
int RTreeInsertRect(struct Rect *R, int Tid, struct Node **Root, int Level)
int Vect_append_point(struct line_pnts *Points, double x, double y, double z)
Appends one point to the end of a line.
int G_percent(long n, long d, int s)
Print percent complete messages.
void G_verbose_message(const char *msg,...)
Print a message to stderr but only if module is in verbose mode.
int Vect_rewrite_line(struct Map_info *Map, int line, int type, struct line_pnts *points, struct line_cats *cats)
Rewrites feature info at the given offset.
int Vect_line_alive(struct Map_info *Map, int line)
Check if feature is alive or dead.
struct line_cats * Vect_new_cats_struct()
Creates and initializes line_cats structure.
int Vect_line_prune(struct line_pnts *Points)
Remove duplicate points, i.e. zero length segments.
int Vect_get_num_lines(struct Map_info *map)
Fetch number of features (points, lines, boundaries, centroids) in vector map.
int G_debug(int level, const char *msg,...)
Print debugging message.
int Vect_delete_line(struct Map_info *Map, int line)
Delete feature.
struct Node * RTreeNewIndex(void)
long Vect_write_line(struct Map_info *Map, int type, struct line_pnts *points, struct line_cats *cats)
Writes new feature to the end of file (table)
int srch(int id, int *arg)
int Vect_read_line(struct Map_info *Map, struct line_pnts *line_p, struct line_cats *line_c, int line)
Read vector feature.