Prechádzať zdrojové kódy

v.mkgrid: added breaks for vertical lines (ticket https://trac.osgeo.org/grass/ticket/1686)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@61552 15284696-431f-4ddb-bdfa-cd5b030d7da7
Luca Delucchi 10 rokov pred
rodič
commit
ad76013bef
2 zmenil súbory, kde vykonal 37 pridanie a 29 odobranie
  1. 4 4
      vector/v.mkgrid/main.c
  2. 33 25
      vector/v.mkgrid/write_grid.c

+ 4 - 4
vector/v.mkgrid/main.c

@@ -6,9 +6,9 @@
  *               Upgrade to 5.7 Radim Blazek 10/2004
  *               Hamish Bowman <hamish_b yahoo.com>,
  *               Jachym Cepicky <jachym les-ejk.cz>, Markus Neteler <neteler itc.it>
- *               Ivan Shevlakov: points support -p                
- *               Luca Delucchi: lines support -l
- * PURPOSE:      
+ *               Ivan Shevlakov: points support -p
+ *               Luca Delucchi: lines support -l, vertical breaks
+ * PURPOSE:
  * COPYRIGHT:    (C) 1999-2014 by the GRASS Development Team
  *
  *               This program is free software under the GNU General
@@ -125,7 +125,7 @@ int main(int argc, char *argv[])
     breaks->type = TYPE_INTEGER;
     breaks->required = NO;
     breaks->description =
-	_("Number of horizontal vertex points per grid cell");
+	_("Number of vertex points per grid cell");
     breaks->options = "0-60";
     breaks->answer = "3";
 

+ 33 - 25
vector/v.mkgrid/write_grid.c

@@ -11,7 +11,7 @@ int write_grid(struct grid_description *grid_info, struct Map_info *Map, int nbr
     int i, k, j;
     int rows, cols;
     int num_v_rows, num_v_cols;
-    double x, y, x_len;
+    double x, y, x_len, y_len;
     double sx, sy;
     double width, length;
     double next_x, next_y;
@@ -36,10 +36,10 @@ int write_grid(struct grid_description *grid_info, struct Map_info *Map, int nbr
      * line is less than half way around the globe
      */
      x_len = length / (1. * nbreaks + 1);
+     y_len = width / (1. * nbreaks + 1);
 
     /* write out all the vector lengths (x vectors) of the entire grid  */
     G_verbose_message(_("Writing out vector rows..."));
-
     y = grid_info->origin_y;
     for (i = 0; i < num_v_rows; ++i) {
 	double startx;
@@ -79,29 +79,37 @@ int write_grid(struct grid_description *grid_info, struct Map_info *Map, int nbr
     /* write out all the vector widths (y vectors) of the entire grid  */
     G_verbose_message(_("Writing out vector columns..."));
     x = grid_info->origin_x;
-    for (k = 0; k < num_v_cols; ++k) {
-	y = grid_info->origin_y;
-	G_percent(k, num_v_cols, 2);
-
-	i = 0;
-        do {
-	    next_y = y + width;
-
-	    sx = x;
-	    sy = y;
-	    snext_y = next_y;
-	    dum = x;
-	    rotate(&x, &y, grid_info->origin_x, grid_info->origin_y, angle);
-	    rotate(&dum, &next_y, grid_info->origin_x, grid_info->origin_y,
-		   angle);
-
-	    write_vect(x, y, dum, next_y, Map, Points, out_type);
-
-	    x = sx;
-	    y = next_y = snext_y;
-            i++;
-	} while (i < rows);
-	/* To get exactly the same coordinates as above, x+=length is wrong */
+    for (i = 0; i < num_v_cols; ++i) {
+        double starty;
+	starty = grid_info->origin_y;
+	G_percent(i, num_v_cols, 2);
+
+	for (k = 0; k < rows; k++) {
+	  y = starty;
+	  j = 0;
+	  do {
+	      if (j < nbreaks)
+		  next_y = y + y_len;
+	      else
+		  next_y = starty + width;
+
+	      sx = x;
+	      sy = y;
+	      snext_y = next_y;
+	      dum = x;
+	      rotate(&x, &y, grid_info->origin_x, grid_info->origin_y, angle);
+	      rotate(&dum, &next_y, grid_info->origin_x, grid_info->origin_y,
+		    angle);
+
+	      write_vect(x, y, dum, next_y, Map, Points, out_type);
+
+	      x = sx;
+	      y = next_y = snext_y;
+	      j++;
+	  } while (j <= nbreaks);
+	  /* To get exactly the same coordinates as above, y+=width is wrong */
+	  starty += width;
+	}
 	x += length;
     }