[GRASS-SVN] r70451 - grass/trunk/vector/v.to.db
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Jan 29 06:04:27 PST 2017
Author: mlennert
Date: 2017-01-29 06:04:26 -0800 (Sun, 29 Jan 2017)
New Revision: 70451
Modified:
grass/trunk/vector/v.to.db/areas.c
grass/trunk/vector/v.to.db/global.h
grass/trunk/vector/v.to.db/main.c
grass/trunk/vector/v.to.db/parse.c
grass/trunk/vector/v.to.db/report.c
grass/trunk/vector/v.to.db/update.c
grass/trunk/vector/v.to.db/v.to.db.html
Log:
v.to.db: added bounding box as additional measure (one suggestion of #2122)
Modified: grass/trunk/vector/v.to.db/areas.c
===================================================================
--- grass/trunk/vector/v.to.db/areas.c 2017-01-29 04:47:03 UTC (rev 70450)
+++ grass/trunk/vector/v.to.db/areas.c 2017-01-29 14:04:26 UTC (rev 70451)
@@ -19,6 +19,7 @@
int i, idx, found;
int area_num, nareas;
struct line_cats *Cats;
+ struct bound_box Bbox;
double area, perimeter;
Cats = Vect_new_cats_struct();
@@ -41,6 +42,9 @@
if (G_projection() != PROJECTION_LL && G_projection() != PROJECTION_XY)
perimeter = perimeter * G_database_units_to_meters_factor();
}
+ if (options.option == O_BBOX) {
+ Vect_get_area_box(Map, area_num, &Bbox);
+ }
found = 0;
if (Vect_get_area_cats(Map, area_num, Cats) == 0) {
@@ -61,6 +65,16 @@
case O_FD:
Values[idx].d1 = 2.0 * log(perimeter) / log(area);
break;
+ case O_BBOX:
+ if (Values[idx].d1 < Bbox.N)
+ Values[idx].d1 = Bbox.N;
+ if (Values[idx].d2 > Bbox.S)
+ Values[idx].d2 = Bbox.S;
+ if (Values[idx].d3 < Bbox.E)
+ Values[idx].d3 = Bbox.E;
+ if (Values[idx].d4 > Bbox.W)
+ Values[idx].d4 = Bbox.W;
+ break;
}
found = 1;
}
@@ -82,6 +96,16 @@
case O_FD:
Values[idx].d1 = 2.0 * log(perimeter) / log(area);
break;
+ case O_BBOX:
+ if (Values[idx].d1 < Bbox.N)
+ Values[idx].d1 = Bbox.N;
+ if (Values[idx].d2 > Bbox.S)
+ Values[idx].d2 = Bbox.S;
+ if (Values[idx].d3 < Bbox.E)
+ Values[idx].d3 = Bbox.E;
+ if (Values[idx].d4 > Bbox.W)
+ Values[idx].d4 = Bbox.W;
+ break;
}
}
}
Modified: grass/trunk/vector/v.to.db/global.h
===================================================================
--- grass/trunk/vector/v.to.db/global.h 2017-01-29 04:47:03 UTC (rev 70450)
+++ grass/trunk/vector/v.to.db/global.h 2017-01-29 14:04:26 UTC (rev 70451)
@@ -9,7 +9,7 @@
/* for sides set to 2, if more than 1 area category was found, */
/* including no category (cat = -1)! */
int i1, i2; /* values; i1: query (result int), sides; i2: sides */
- double d1, d2, d3; /* values (length, area, x/y/z, query) */
+ double d1, d2, d3, d4; /* values (length, area, x/y/z, bbox, query) */
char *str1; /* string value (query) */
int *qcat; /* array query categories */
int nqcats; /* number of query cats */
@@ -23,7 +23,7 @@
{
char *name;
int field;
- char *col[3];
+ char *col[4];
char *qcol;
int type;
int option;
@@ -72,6 +72,8 @@
#define O_AZIMUTH 15 /* line azimuth */
+#define O_BBOX 16 /* bounding box */
+
/* areas.c */
int read_areas(struct Map_info *);
Modified: grass/trunk/vector/v.to.db/main.c
===================================================================
--- grass/trunk/vector/v.to.db/main.c 2017-01-29 04:47:03 UTC (rev 70450)
+++ grass/trunk/vector/v.to.db/main.c 2017-01-29 14:04:26 UTC (rev 70451)
@@ -90,6 +90,14 @@
Values[i].i2 = -1;
Values[i].d1 = 0.0;
Values[i].d2 = 0.0;
+ Values[i].d3 = 0.0;
+ Values[i].d4 = 0.0;
+ if (options.option == O_BBOX) {
+ Values[i].d1 = -PORT_DOUBLE_MAX;
+ Values[i].d2 = PORT_DOUBLE_MAX;
+ Values[i].d3 = -PORT_DOUBLE_MAX;
+ Values[i].d4 = PORT_DOUBLE_MAX;
+ }
Values[i].qcat = NULL;
Values[i].nqcats = 0;
Values[i].aqcats = 0;
@@ -115,6 +123,14 @@
Values[i].i2 = -1;
Values[i].d1 = 0.0;
Values[i].d2 = 0.0;
+ Values[i].d3 = 0.0;
+ Values[i].d4 = 0.0;
+ if (options.option == O_BBOX) {
+ Values[i].d1 = -PORT_DOUBLE_MAX;
+ Values[i].d2 = PORT_DOUBLE_MAX;
+ Values[i].d3 = -PORT_DOUBLE_MAX;
+ Values[i].d4 = PORT_DOUBLE_MAX;
+ }
Values[i].qcat = NULL;
Values[i].nqcats = 0;
Values[i].aqcats = 0;
@@ -131,7 +147,8 @@
query(&Map);
}
else if ((options.option == O_AREA) || (options.option == O_COMPACT) ||
- (options.option == O_PERIMETER) || (options.option == O_FD)) {
+ (options.option == O_PERIMETER) || (options.option == O_FD) ||
+ (options.option == O_BBOX)) {
read_areas(&Map);
}
else {
Modified: grass/trunk/vector/v.to.db/parse.c
===================================================================
--- grass/trunk/vector/v.to.db/parse.c 2017-01-29 04:47:03 UTC (rev 70450)
+++ grass/trunk/vector/v.to.db/parse.c 2017-01-29 14:04:26 UTC (rev 70451)
@@ -50,7 +50,7 @@
parms.option->required = YES;
parms.option->multiple = NO;
parms.option->options =
- "cat,area,compact,fd,perimeter,length,count,coor,start,end,sides,query,slope,sinuous,azimuth";
+ "cat,area,compact,fd,perimeter,length,count,coor,start,end,sides,query,slope,sinuous,azimuth,bbox";
parms.option->description = _("Value to upload");
desc = NULL;
G_asprintf(&desc,
@@ -68,7 +68,8 @@
"query;%s;"
"slope;%s;"
"sinuous;%s;"
- "azimuth;%s;",
+ "azimuth;%s;"
+ "bbox;%s;",
_("insert new row for each category if doesn't exist yet"),
_("area size"),
_("compactness of an area, calculated as \n"
@@ -87,7 +88,8 @@
"(or geometries) from table specified by 'query_layer' option"),
_("slope steepness of vector line or boundary"),
_("line sinuousity, calculated as line length / distance between end points"),
- _("line azimuth, calculated as angle between North direction and endnode direction at startnode"));
+ _("line azimuth, calculated as angle between North direction and endnode direction at startnode"),
+ _("bounding box of area, N,S,E,W"));
parms.option->descriptions = desc;
parms.col = G_define_standard_option(G_OPT_DB_COLUMNS);
@@ -164,6 +166,7 @@
options.col[0] = NULL;
options.col[1] = NULL;
options.col[2] = NULL;
+ options.col[3] = NULL;
while (parms.col->answers && parms.col->answers[ncols]) {
options.col[ncols] = G_store(parms.col->answers[ncols]);
ncols++;
@@ -188,6 +191,12 @@
G_fatal_error(_("This option requires at least two columns"));
}
}
+ else if (options.option == O_BBOX) {
+ if (ncols != 4) {
+ G_fatal_error(_("This option requires four columns"));
+ }
+ }
+
}
if (options.option == O_QUERY && !parms.qcol->answers)
@@ -266,6 +275,8 @@
x = O_SINUOUS;
else if (strcmp(s, "azimuth") == 0)
x = O_AZIMUTH;
+ else if (strcmp(s, "bbox") == 0)
+ x = O_BBOX;
return x;
}
Modified: grass/trunk/vector/v.to.db/report.c
===================================================================
--- grass/trunk/vector/v.to.db/report.c 2017-01-29 04:47:03 UTC (rev 70450)
+++ grass/trunk/vector/v.to.db/report.c 2017-01-29 14:04:26 UTC (rev 70451)
@@ -77,6 +77,16 @@
fprintf(stdout, "%d%s%.15g\n", Values[i].cat, options.fs, Values[i].d1);
break;
+ case O_BBOX:
+ if (G_verbose() > G_verbose_min())
+ fprintf(stdout, "cat%sN%sS%sE%sW\n", options.fs, options.fs, options.fs,options.fs);
+ for (i = 0; i < vstat.rcat; i++) {
+ fprintf(stdout, "%d%s%.15g%s%.15g%s%.15g%s%.15g\n", Values[i].cat, options.fs,
+ Values[i].d1, options.fs, Values[i].d2, options.fs, Values[i].d3,
+ options.fs, Values[i].d4);
+ }
+ break;
+
case O_LENGTH:
if (options.print) {
if (G_verbose() > G_verbose_min())
Modified: grass/trunk/vector/v.to.db/update.c
===================================================================
--- grass/trunk/vector/v.to.db/update.c 2017-01-29 04:47:03 UTC (rev 70450)
+++ grass/trunk/vector/v.to.db/update.c 2017-01-29 14:04:26 UTC (rev 70451)
@@ -75,6 +75,7 @@
case O_START:
case O_END:
case O_SIDES:
+ case O_BBOX:
sprintf(buf1, "update %s set ", Fi->table);
break;
}
@@ -108,6 +109,14 @@
sprintf(buf2, "%s %f where %s = %d", buf1, Values[i].d1, Fi->key,
Values[i].cat);
break;
+
+ case O_BBOX:
+ sprintf(buf2,
+ "%s %s = %.15g, %s = %.15g, %s = %.15g, %s = %.15g where %s = %d",
+ buf1, options.col[0], Values[i].d1, options.col[1],
+ Values[i].d2, options.col[2], Values[i].d3, options.col[3],
+ Values[i].d4, Fi->key, Values[i].cat);
+ break;
case O_COOR:
case O_START:
Modified: grass/trunk/vector/v.to.db/v.to.db.html
===================================================================
--- grass/trunk/vector/v.to.db/v.to.db.html 2017-01-29 04:47:03 UTC (rev 70450)
+++ grass/trunk/vector/v.to.db/v.to.db.html 2017-01-29 14:04:26 UTC (rev 70451)
@@ -19,6 +19,9 @@
distance between the vertices is used.
<p>When using <em>option=coor</em> on a vector area map,
only coordinates of centroids with unique category will be reported.
+<p>When using <em>option=bbox</em> on a vector area map with more than one
+feature per category value, the results corresponds to the bounding box of
+all features of same category taken together.
<p>Line azimuth is calculated as angle from the North direction to the line endnode
direction at the line statnode. By default it's reported in decimal degrees (0-360, CW) but
it also may be repored in radians with <em>unit=radians</em>. Azimuth value
More information about the grass-commit
mailing list