[GRASS-SVN] r58361 - sandbox/martinl/v.merge

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Dec 2 11:01:05 PST 2013


Author: martinl
Date: 2013-12-02 11:01:05 -0800 (Mon, 02 Dec 2013)
New Revision: 58361

Modified:
   sandbox/martinl/v.merge/local_proto.h
   sandbox/martinl/v.merge/main.c
   sandbox/martinl/v.merge/merge.c
Log:
v.merge (sandbox): experiments


Modified: sandbox/martinl/v.merge/local_proto.h
===================================================================
--- sandbox/martinl/v.merge/local_proto.h	2013-12-02 19:00:05 UTC (rev 58360)
+++ sandbox/martinl/v.merge/local_proto.h	2013-12-02 19:01:05 UTC (rev 58361)
@@ -1,2 +1,4 @@
+int merge_line(struct Map_info *, int, double,
+               struct Map_info *);
 int merge_map_lines(struct Map_info *, double,
                     struct Map_info *);

Modified: sandbox/martinl/v.merge/main.c
===================================================================
--- sandbox/martinl/v.merge/main.c	2013-12-02 19:00:05 UTC (rev 58360)
+++ sandbox/martinl/v.merge/main.c	2013-12-02 19:01:05 UTC (rev 58361)
@@ -82,7 +82,8 @@
     Vect_build(&Out);
     
     /* read and patch features from patch map */
-    merge_map_lines(&Patch, thresh, &Out);
+    /* merge_map_lines(&Patch, thresh, &Out); */
+    merge_line(&Patch, 59, thresh, &Out);
 
     Vect_close(&Patch);
 

Modified: sandbox/martinl/v.merge/merge.c
===================================================================
--- sandbox/martinl/v.merge/merge.c	2013-12-02 19:00:05 UTC (rev 58360)
+++ sandbox/martinl/v.merge/merge.c	2013-12-02 19:01:05 UTC (rev 58361)
@@ -1,5 +1,98 @@
 #include <grass/vector.h>
 
+int merge_line(struct Map_info *Patch, int line, double thresh,
+               struct Map_info *Out)
+{
+    int i, j, with_z, nearest_line, last_line;
+    int iseg, pseg, nseg; /* current/previous/next segment */
+    int last_modified, last_type;
+    double dist;
+    
+    struct line_pnts *Points, *Points_ref;
+    struct line_cats *Cats_ref;
+    
+    Points = Vect_new_line_struct();
+    Points_ref = Vect_new_line_struct();
+    Cats_ref   = Vect_new_cats_struct();
+    
+    with_z = Vect_is_3d(Out) && Vect_is_3d(Patch);
+    
+    /* read features from patch map */
+    Vect_read_line(Patch, Points, NULL, line);
+    G_debug(0, "line: %d, n_points: %d", line, Points->n_points);
+    
+    last_line = -1;
+    last_modified = FALSE;
+    /* read line verteces */
+    for (i = 0; i < Points->n_points; i++) {
+        /* find nearest features from reference map */
+        nearest_line = Vect_find_line(Out, Points->x[i], Points->y[i], Points->z[i],
+                                      GV_LINES, thresh, with_z, -1);
+        G_debug(0, "line: %d, vertex: %d -> nearest: %d", line, i, nearest_line);
+        
+        if (nearest_line > 0) {
+            if (nearest_line != last_line) {
+                if (last_modified) {
+                    Vect_rewrite_line(Out, last_line, last_type, Points_ref, Cats_ref);
+                    last_modified = FALSE;
+                }
+                
+                last_type = Vect_read_line(Out, Points_ref, Cats_ref, nearest_line);
+                last_line = nearest_line;
+                
+            }
+            Vect_line_distance(Points_ref, Points->x[i], Points->y[i], Points->z[i],
+                               with_z, NULL, NULL, NULL, &dist, NULL, NULL);
+            G_debug(0, "\t-> dist: %f", dist);
+        }
+        else {
+            if (last_line != -1) {
+                /* modify cached line, insert new point */
+                iseg = Vect_line_distance(Points_ref, Points->x[i], Points->y[i], Points->z[i],
+                                          with_z, NULL, NULL, NULL, &dist, NULL, NULL);
+                G_debug(0, "\t-> dist: %f, iseg: %d", dist, iseg);
+                pseg = nseg = 0;
+                if (i > 0) {
+                    /* find previous vertex */
+                    pseg = Vect_line_distance(Points_ref, Points->x[i-1], Points->y[i-1],
+                                              Points->z[i-1],
+                                              with_z, NULL, NULL, NULL, &dist, NULL, NULL);
+                    G_debug(0, "\t(previous) -> dist: %f, pseg: %d", dist, pseg);
+                }
+                
+                if (i < Points->n_points-1) {
+                    /* find last vertex */
+                    nseg = Vect_line_distance(Points_ref, Points->x[i+1], Points->y[i+1],
+                                              Points->z[i+1],
+                                              with_z, NULL, NULL, NULL, &dist, NULL, NULL);
+                    G_debug(0, "\t(next) -> dist: %f, nseg: %d", dist, nseg);
+                }
+                
+                for (j = 1; j < nseg-pseg; j++) {
+                    G_debug(0, "%d", pseg);
+                    Vect_line_delete_point(Points_ref, pseg+1);
+                }
+                
+                Vect_line_insert_point(Points_ref, pseg > 0 ? pseg+1 : iseg,
+                                       Points->x[i], Points->y[i], Points->z[i]);
+                
+                last_modified = TRUE;
+            }
+        }
+    }
+    
+    if (last_modified) {
+        Vect_rewrite_line(Out, last_line, last_type, Points_ref, Cats_ref);
+        last_modified = FALSE;
+    }        
+
+    Vect_destroy_line_struct(Points);
+    Vect_destroy_line_struct(Points_ref);
+    Vect_destroy_cats_struct(Cats_ref);
+
+    return 0;
+}
+  
 int merge_map_lines(struct Map_info *Patch, double thresh,
                     struct Map_info *Out)
 {



More information about the grass-commit mailing list