[GRASS-SVN] r74208 - grass/trunk/vector/v.mkgrid

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Mar 9 10:57:08 PST 2019


Author: mmetz
Date: 2019-03-09 10:57:08 -0800 (Sat, 09 Mar 2019)
New Revision: 74208

Modified:
   grass/trunk/vector/v.mkgrid/local_proto.h
   grass/trunk/vector/v.mkgrid/main.c
   grass/trunk/vector/v.mkgrid/write_grid.c
Log:
v.mkgrid: + -d flag to add diagonals to rectangular lines

Modified: grass/trunk/vector/v.mkgrid/local_proto.h
===================================================================
--- grass/trunk/vector/v.mkgrid/local_proto.h	2019-03-09 18:53:50 UTC (rev 74207)
+++ grass/trunk/vector/v.mkgrid/local_proto.h	2019-03-09 18:57:08 UTC (rev 74208)
@@ -3,7 +3,7 @@
 void rotate(double *, double *, double, double, double);
 
 /* write_grid.c */
-int write_grid(struct grid_description *, struct Map_info *, int, int);
+int write_grid(struct grid_description *, struct Map_info *, int, int, int);
 
 /* hexgrid.c */
 int hexgrid(struct grid_description *, struct Map_info *, int, int);

Modified: grass/trunk/vector/v.mkgrid/main.c
===================================================================
--- grass/trunk/vector/v.mkgrid/main.c	2019-03-09 18:53:50 UTC (rev 74207)
+++ grass/trunk/vector/v.mkgrid/main.c	2019-03-09 18:57:08 UTC (rev 74208)
@@ -51,8 +51,8 @@
     struct Option *vectname, *grid, *coord, *box, *angle, *position_opt,
                   *breaks, *type_opt;
     struct GModule *module;
-    struct Flag *hex_flag, *ha_flag;
-    int otype, ptype, ltype;
+    struct Flag *hex_flag, *ha_flag, *diag_flag;
+    int otype, ptype, ltype, diag;
     char *desc;
 
     struct line_pnts *Points;
@@ -145,6 +145,13 @@
     ha_flag->description =
 	_("Allow asymmetric hexagons");
 
+    diag_flag = G_define_flag();
+    diag_flag->key = 'd';
+    diag_flag->label =
+	_("EXPERIMENTAL: Add diagonals to rectangular lines");
+    diag_flag->description =
+	_("Applies only to lines for rectangles");
+
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
@@ -164,8 +171,14 @@
 
     ptype = (otype & GV_POINTS);
     ltype = (otype & GV_LINES);
-    
 
+    diag = (otype == GV_LINE && !hex_flag->answer && diag_flag->answer);
+    if (diag) {
+	ptype = 0;
+	ltype = GV_LINE;
+	hex_flag->answer = 0;
+    }
+
     /* get the current window  */
     G_get_window(&window);
 
@@ -366,6 +379,7 @@
 			      db_get_string(&sql));
 	    }
 	}
+	db_commit_transaction(Driver);
     }
     else {
 	if (grid_info.width != grid_info.height) {
@@ -410,7 +424,7 @@
 
 	if (ltype) {
 	    /* create areas */
-	    write_grid(&grid_info, &Map, nbreaks, ltype);
+	    write_grid(&grid_info, &Map, nbreaks, ltype, diag);
 	}
 
 	/* Create a grid of label points at the centres of the grid cells */
@@ -466,10 +480,10 @@
 		    attCount++;
 	        }
 	    }
+	    db_commit_transaction(Driver);
             G_percent(1, 1, 1);
 	}
     }
-    db_commit_transaction(Driver);
 
     db_close_database_shutdown_driver(Driver);
 

Modified: grass/trunk/vector/v.mkgrid/write_grid.c
===================================================================
--- grass/trunk/vector/v.mkgrid/write_grid.c	2019-03-09 18:53:50 UTC (rev 74207)
+++ grass/trunk/vector/v.mkgrid/write_grid.c	2019-03-09 18:57:08 UTC (rev 74208)
@@ -31,7 +31,8 @@
     return 0;
 }
 
-int write_grid(struct grid_description *grid_info, struct Map_info *Map, int nbreaks, int out_type)
+int write_grid(struct grid_description *grid_info, struct Map_info *Map,
+               int nbreaks, int out_type, int diag)
 {
 
     int i, k, j;
@@ -42,6 +43,7 @@
     double width, height;
     double next_x, next_y;
     double snext_x, snext_y;
+    double xdiag, ydiag;
     double angle, dum;
 
     struct line_pnts *Points;
@@ -61,8 +63,8 @@
      * to make sure that each section of the grid
      * line is less than half way around the globe
      */
-     x_len = width / (1. * nbreaks + 1);
-     y_len = height / (1. * nbreaks + 1);
+    x_len = width / (1. * nbreaks + 1);
+    y_len = height / (1. * nbreaks + 1);
 
     /* write out all the vector lengths (x vectors) of the entire grid  */
     G_message(_("Writing out vector rows..."));
@@ -92,7 +94,20 @@
 		rotate(&next_x, &dum, grid_info->xo, grid_info->yo, 
 		       angle);
 		write_vect(x, y, next_x, dum, Map, Points, out_type);
+		if (diag && i < num_v_rows - 1) {
+		    xdiag = snext_x;
+		    ydiag = sy + height;
+		    rotate(&xdiag, &ydiag, grid_info->xo, grid_info->yo, 
+			   angle);
+		    write_vect(x, y, xdiag, ydiag, Map, Points, out_type);
 
+		    xdiag = sx;
+		    ydiag = sy + height;
+		    rotate(&xdiag, &ydiag, grid_info->xo, grid_info->yo, 
+			   angle);
+		    write_vect(xdiag, ydiag, next_x, dum, Map, Points, out_type);
+		}
+
 		y = sy;
 		x = next_x = snext_x;
                 j++;
@@ -112,30 +127,30 @@
 	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 + height;
+	    y = starty;
+	    j = 0;
+	    do {
+	        if (j < nbreaks)
+		    next_y = y + y_len;
+	        else
+		    next_y = starty + height;
 
-	      sx = x;
-	      sy = y;
-	      snext_y = next_y;
-	      dum = x;
-	      rotate(&x, &y, grid_info->xo, grid_info->yo, angle);
-	      rotate(&dum, &next_y, grid_info->xo, grid_info->yo,
+		sx = x;
+		sy = y;
+		snext_y = next_y;
+		dum = x;
+		rotate(&x, &y, grid_info->xo, grid_info->yo, angle);
+		rotate(&dum, &next_y, grid_info->xo, grid_info->yo,
 		    angle);
 
-	      write_vect(x, y, dum, next_y, Map, Points, out_type);
+		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 += height;
+	        x = sx;
+	        y = next_y = snext_y;
+	        j++;
+	    } while (j <= nbreaks);
+	    /* To get exactly the same coordinates as above, y+=width is wrong */
+	    starty += height;
 	}
 	x += width;
     }



More information about the grass-commit mailing list