[GRASS-dev] v.mkgrid: New `-p' option to suppress areas

Ivan Shmakov ivan at theory.asu.ru
Tue Feb 19 03:18:58 EST 2008


	In order to use `v.what.rast' a vector of points is needed.
	Surely one could use `v.type' to turn the centroids into points
	after creating the grid, but the following seems to be a cleaner
	solution.

vector/v.mkgrid/main.c (main): New `-p' option to generate points
instead of centroids and to skip the creation of areas as well.

	Alternatively, there could be an `-a' flag to turn areas off,
	and then `-p' would allow to switch between GV_CENTROID and
	GV_CENTROID | GV_POINT (or is that supported?), so that
	`v.what.rast' would be possible with otherwise ordinary vector
	grids.

	Suggestions for a documentation update?

	BTW, the `v.what.rast' module (along with `v.mkgrid',
	`v.random', `v.overlay', `v.edit' and `v.db.select') seems to
	allow quite sophisticated queries on the rasters.  Perhaps this
	should be mentioned on the wiki.

diff --git a/vector/v.mkgrid/main.c b/vector/v.mkgrid/main.c
index 49c0047..500bfc7 100644
--- a/vector/v.mkgrid/main.c
+++ b/vector/v.mkgrid/main.c
@@ -45,6 +45,8 @@ main (int argc, char *argv[])
   struct Map_info Map;
   struct Option *vectname, *grid, *coord, *box, *angle, *position_opt;
   struct Flag *q;
+  struct Flag *points_fl;
+  int points_p;
   struct GModule *module;
 
   struct line_pnts *Points;
@@ -107,6 +109,12 @@ main (int argc, char *argv[])
   angle->description = _("Angle of rotation (in degrees counter-clockwise)");
   angle->answer = "0";
 
+  points_fl = G_define_flag ();
+  points_fl->key = 'p';
+  points_fl->description = _("Create grid of points"
+                            " instead of areas and centroids");
+  points_fl->answer = 0;
+
   /* please, remove before GRASS 7 released */
   q = G_define_flag ();
   q->key = 'q';
@@ -123,6 +131,7 @@ main (int argc, char *argv[])
 		    "in future. Please use '--quiet' instead."));
     }
 
+  points_p = points_fl->answer;
 
   /* get the current window  */
   G_get_window (&window);
@@ -226,7 +235,10 @@ main (int argc, char *argv[])
   if (db_grant_on_table (Driver, Fi->table, DB_PRIV_SELECT, DB_GROUP|DB_PUBLIC ) != DB_OK )
       G_fatal_error (_("Unable to grant privileges on table <%s>"), Fi->table );
 
-  write_grid (&grid_info, &Map);
+  if (! points_p) {
+    /* create areas */
+    write_grid (&grid_info, &Map);
+  }
 
   /* Create a grid of label points at the centres of the grid cells */
   G_verbose_message ( _("Creating centroids...") );
@@ -235,6 +247,7 @@ main (int argc, char *argv[])
   attCount = 0;
   for( i = 0; i < grid_info.num_rows; ++i ) {
       for( j = 0; j < grid_info.num_cols; ++j ) {
+	  const int point_type = points_p ? GV_POINT : GV_CENTROID;
 	  double x, y;
 
 	  x = grid_info.origin_x + ( 0.5 + j ) * grid_info.length;
@@ -247,7 +260,7 @@ main (int argc, char *argv[])
 
 	  Vect_append_point ( Points, x, y, 0.0 );
 	  Vect_cat_set ( Cats, 1, attCount+1 );
-	  Vect_write_line ( &Map, GV_CENTROID, Points, Cats );
+	  Vect_write_line ( &Map, point_type, Points, Cats );
 
           if ( grid_info.num_rows < 27 && grid_info.num_cols < 27 ) {
 	      sprintf ( buf, "insert into %s values ( %d, %d, %d, '%c', '%c' )", Fi->table, attCount+1, 



More information about the grass-dev mailing list