since nobody really complained, I commited the patch. v.to.db has new
option "slope" now
Index: vector/v.to.db/global.h
RCS file: /grassrepository/grass6/vector/v.to.db/global.h,v
retrieving revision 1.8
diff -u -r1.8 global.h
--- vector/v.to.db/global.h 9 Feb 2006 03:09:07 -0000 1.8
+++ vector/v.to.db/global.h 7 Dec 2006 16:21:18 -0000
@@ -13,7 +13,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, query, slope) */
char *str1; /* string value (query) */
int *qcat; /* array query categories */
int nqcats; /* number of query cats */
@@ -65,6 +65,8 @@
#define O_START 10 /* line/boundary starting point */
#define O_END 11 /* line/boundary end point */
+
+#define O_SLOPE 12 /* Line slope */
#define U_ACRES 1
#define U_HECTARES 2
Index: vector/v.to.db/lines.c
RCS file: /grassrepository/grass6/vector/v.to.db/lines.c,v
retrieving revision 1.8
diff -u -r1.8 lines.c
--- vector/v.to.db/lines.c 9 Feb 2006 03:09:07 -0000 1.8
+++ vector/v.to.db/lines.c 7 Dec 2006 16:21:18 -0000
@@ -48,7 +48,7 @@
/*
* Read: - points/centroids : cat,count,coor
- * - lines/boundaries : cat,count,length
+ * - lines/boundaries : cat,count,length,slope
*/
int
@@ -58,7 +58,7 @@
register int line_num;
struct line_pnts *Points;
struct line_cats *Cats, *LCats, *RCats;
- double len;
+ double len,slope;
/* Initialize the Point struct */
Points = Vect_new_line_struct();
@@ -137,7 +137,13 @@
read_side_cats ( LCats, &(Values[idx].i1), &(Values[idx].count1) );
read_side_cats ( RCats, &(Values[idx].i2), &(Values[idx].count2) );
+ } else if ( options.option == O_SLOPE && (type & GV_LINES) ) {
+ /* Calculate line slope */
+ len = length (Points->n_points, Points->x, Points->y);
+ slope = (Points->z[Points->n_points-1] - Points->z[0])/len;
+ Values[idx].d1 += slope;
}
+
found = 1;
}
}
@@ -167,7 +173,13 @@
} else if ( options.option == O_SIDES && type == GV_BOUNDARY ) {
read_side_cats ( LCats, &(Values[idx].i1), &(Values[idx].count1) );
read_side_cats ( RCats, &(Values[idx].i2), &(Values[idx].count2) );
- }
+ } else if ( options.option == O_SLOPE && (type & GV_LINES) ) {
+ /* Calculate line slope */
+ len = length (Points->n_points, Points->x, Points->y);
+ slope = (Points->z[Points->n_points-1] - Points->z[0])/len;
+ Values[idx].d1 += slope;
+ }
+
}
}
Index: vector/v.to.db/parse.c
RCS file: /grassrepository/grass6/vector/v.to.db/parse.c,v
retrieving revision 1.19
diff -u -r1.19 parse.c
--- vector/v.to.db/parse.c 21 Sep 2006 12:50:39 -0000 1.19
+++ vector/v.to.db/parse.c 7 Dec 2006 16:21:18 -0000
@@ -48,7 +48,7 @@
parms.option->type = TYPE_STRING;
parms.option->required = YES;
parms.option->multiple = NO;
- parms.option->options = "cat,area,compact,perimeter,length,count,coor,start,end,sides,query";
+ parms.option->options = "cat,area,compact,perimeter,length,count,coor,start,end,sides,query,slope";
parms.option->description = _("Value to upload");
parms.option->descriptions =
"cat;insert new row for each category if doesn't exist yet;"
@@ -64,7 +64,8 @@
"sides;categories of areas on the left and right side of the boundary, "
"'qlayer' is used for area category;"
"query;result of a database query for all records of the geometry"
- "(or geometries) from table specified by 'qlayer' option";
+ "(or geometries) from table specified by 'qlayer' option;"
+ "slope;slope steepness of vector line or boundary";
parms.units = G_define_option();
parms.units->key = "units";
@@ -100,7 +101,7 @@
flags.t = G_define_flag();
flags.t->key = 'c';
- flags.t->description = _("In print mode prints totals for options: length,area,count");
+ flags.t->description = _("In print mode prints totals for options: length,area");
if (G_parser(argc,argv)) exit(EXIT_FAILURE);
@@ -132,7 +133,7 @@
}
if ( options.option == O_AREA || options.option == O_LENGTH || options.option == O_COUNT
- || options.option == O_QUERY || options.option == O_COMPACT || options.option == O_PERIMETER) /* one column required */
+ || options.option == O_QUERY || options.option == O_COMPACT || options.option == O_PERIMETER || options.option == O_SLOPE ) /* one column required */
{
if ( ncols != 1 ) {
G_fatal_error ( _("This option requires one column") );
@@ -187,6 +188,7 @@
else if (strcmp (s, "query") == 0) x = O_QUERY;
else if (strcmp (s, "compact") == 0) x = O_COMPACT;
else if (strcmp (s, "perimeter") == 0) x = O_PERIMETER;
+ else if (strcmp (s, "slope") == 0) x = O_SLOPE;
return x;
}
Index: vector/v.to.db/report.c
RCS file: /grassrepository/grass6/vector/v.to.db/report.c,v
retrieving revision 1.11
diff -u -r1.11 report.c
--- vector/v.to.db/report.c 9 Feb 2006 03:09:07 -0000 1.11
+++ vector/v.to.db/report.c 7 Dec 2006 16:21:18 -0000
@@ -66,6 +66,13 @@
for ( i = 0; i < vstat.rcat; i++ )
fprintf (stdout, "%d|%.15g\n", Values[i].cat, Values[i].d1);
}
+ break;
+ case O_SLOPE:
+ fprintf (stdout,"cat|slope\n");
+ for ( i = 0; i < vstat.rcat; i++ )
+ fprintf (stdout, "%d|%.15g\n", Values[i].cat, Values[i].d1);
+
+
break;
case O_COOR:
Index: vector/v.to.db/update.c
RCS file: /grassrepository/grass6/vector/v.to.db/update.c,v
retrieving revision 1.17
diff -u -r1.17 update.c
--- vector/v.to.db/update.c 9 Feb 2006 03:09:07 -0000 1.17
+++ vector/v.to.db/update.c 7 Dec 2006 16:21:18 -0000
@@ -49,6 +49,7 @@
case O_QUERY:
case O_COMPACT:
case O_PERIMETER:
+ case O_SLOPE:
sprintf (buf1, "update %s set %s =", Fi->table, options.col[0]);
break;
case O_COOR:
@@ -79,6 +80,7 @@
case O_AREA:
case O_COMPACT:
case O_PERIMETER:
+ case O_SLOPE:
sprintf (buf2, "%s %f where %s = %d", buf1, Values[i].d1, Fi->key, Values[i].cat);
break;
_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev