Browse Source

v.net op=connect: new arcs need unique cat

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@57857 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 11 năm trước cách đây
mục cha
commit
d007f510b4
3 tập tin đã thay đổi với 18 bổ sung6 xóa
  1. 15 3
      vector/v.net/connect.c
  2. 2 2
      vector/v.net/main.c
  3. 1 1
      vector/v.net/proto.h

+ 15 - 3
vector/v.net/connect.c

@@ -18,14 +18,16 @@
  * \return number of new arcs
  */
 int connect_arcs(struct Map_info *In, struct Map_info *Pnts,
-		 struct Map_info *Out, int nfield, double thresh, int snap)
+		 struct Map_info *Out, int afield, int nfield,
+		 double thresh, int snap)
 {
     int narcs;
     int type, line, seg, i, ltype, broken;
     double px, py, pz, spdist, dist;
 
     struct line_pnts *Points, *Pline, *Pout;
-    struct line_cats *Cats, *Cline;
+    struct line_cats *Cats, *Cline, *Cnew;
+    int maxcat, findex, ncats;
 
     narcs = 0;
 
@@ -34,10 +36,16 @@ int connect_arcs(struct Map_info *In, struct Map_info *Pnts,
     Pout = Vect_new_line_struct();
     Cats = Vect_new_cats_struct();
     Cline = Vect_new_cats_struct();
+    Cnew = Vect_new_cats_struct();
 
     /* rewrite all primitives to output file */
     Vect_copy_map_lines(In, Out);
     Vect_build_partial(Out, GV_BUILD_BASE);
+    
+    findex = Vect_cidx_get_field_index(In, afield);
+    ncats = Vect_cidx_get_num_cats_by_index(In, findex);
+    Vect_cidx_get_cat_by_index(In, findex, ncats - 1, &maxcat, &type, &line);
+    
 
     /* go thorough all points in point map and write a new arcs if missing */
     while ((type = Vect_read_next_line(Pnts, Points, Cats)) >= 0) {
@@ -103,7 +111,10 @@ int connect_arcs(struct Map_info *In, struct Map_info *Pnts,
 		Vect_reset_line(Pout);
 		Vect_append_point(Pout, px, py, pz);
 		Vect_append_point(Pout, Points->x[0], Points->y[0], Points->z[0]);
-		Vect_write_line(Out, ltype, Pout, Cline);
+		maxcat++;
+		Vect_reset_cats(Cnew);
+		Vect_cat_set(Cnew, afield, maxcat);
+		Vect_write_line(Out, ltype, Pout, Cnew);
 
 		narcs++;
 	    }
@@ -122,6 +133,7 @@ int connect_arcs(struct Map_info *In, struct Map_info *Pnts,
     Vect_destroy_line_struct(Pout);
     Vect_destroy_cats_struct(Cats);
     Vect_destroy_cats_struct(Cline);
+    Vect_destroy_cats_struct(Cnew);
 
     return narcs;
 }

+ 2 - 2
vector/v.net/main.c

@@ -138,8 +138,8 @@ int main(int argc, char **argv)
 	    int narcs;
 
 	    if (act == TOOL_CONNECT)
-		narcs = connect_arcs(In, Points, Out, nfield, thresh,
-		                     opt.snap_flag->answer);
+		narcs = connect_arcs(In, Points, Out, afield, nfield,
+		                     thresh, opt.snap_flag->answer);
 	    else
 		narcs = create_arcs(file_arcs, Points, Out, afield, nfield);
 

+ 1 - 1
vector/v.net/proto.h

@@ -24,7 +24,7 @@ void parse_arguments(const struct opt *,
 
 /* connect.c */
 int connect_arcs(struct Map_info *, struct Map_info *,
-		 struct Map_info *, int, double, int);
+		 struct Map_info *, int, int, double, int);
 
 /* nodes.c */
 int nodes(struct Map_info *, struct Map_info *, int,