瀏覽代碼

added flag to impose fixed length segments

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@65446 15284696-431f-4ddb-bdfa-cd5b030d7da7
Moritz Lennert 10 年之前
父節點
當前提交
bb2ef27e1f
共有 1 個文件被更改,包括 18 次插入3 次删除
  1. 18 3
      vector/v.split/main.c

+ 18 - 3
vector/v.split/main.c

@@ -36,13 +36,13 @@ int main(int argc, char *argv[])
     struct GModule *module;
     struct Option *in_opt, *layer_opt, *out_opt, *length_opt,
                   *units_opt, *vertices_opt;
-    struct Flag *nosplit_flag;
+    struct Flag *nosplit_flag, *fixedlength_flag;
     
     struct Map_info In, Out;
     struct line_pnts *Points, *Points2, *Points3;
     struct line_cats *Cats;
 
-    int line, nlines, layer, nosplit;
+    int line, nlines, layer, nosplit, fixedlength;
     double length = -1;
     int vertices = 0;
     double (*line_length) ();
@@ -92,6 +92,13 @@ int main(int argc, char *argv[])
     nosplit_flag->key = 'n';
     nosplit_flag->label = _("Add new vertices, but do not split");
     nosplit_flag->description = _("Applies only to 'length' option");
+
+    fixedlength_flag = G_define_flag();
+    fixedlength_flag->key = 'f';
+    fixedlength_flag->label = _("Force segments to be exactly of given length, except for last one");
+    fixedlength_flag->description = _("Applies only to 'length' option");
+
+
     
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
@@ -157,6 +164,7 @@ int main(int argc, char *argv[])
 	    G_fatal_error(_("Number of vertices must be at least 2"));
     }
     nosplit = nosplit_flag->answer;
+    fixedlength = fixedlength_flag->answer;
     
     Vect_set_open_level(2);
 
@@ -208,10 +216,17 @@ int main(int argc, char *argv[])
 		    G_debug(3, "l: %f, length: %f", l, length);
 
 		    n = ceil(l / length);
+
 		    if (geodesic)
 			l = Vect_line_length(Points);
 
-		    step = l / n;
+		    if (fixedlength) {
+			    step = length;
+		    }
+		    else {
+			    step = l / n;
+		    }
+
 		    from = 0.;
 		    
 		    G_debug(3, "n: %ld, step: %f", n, step);