[GRASS-SVN] r29692 - grass/trunk/vector/v.to.db
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Jan 13 07:05:46 EST 2008
Author: wolf
Date: 2008-01-13 07:05:46 -0500 (Sun, 13 Jan 2008)
New Revision: 29692
Modified:
grass/trunk/vector/v.to.db/areas.c
grass/trunk/vector/v.to.db/global.h
grass/trunk/vector/v.to.db/lines.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
Log:
Added option=sinuous
Modified: grass/trunk/vector/v.to.db/areas.c
===================================================================
--- grass/trunk/vector/v.to.db/areas.c 2008-01-13 07:57:27 UTC (rev 29691)
+++ grass/trunk/vector/v.to.db/areas.c 2008-01-13 12:05:46 UTC (rev 29692)
@@ -51,7 +51,7 @@
case O_COMPACT:
Values[idx].d1 = perimeter / (2.0 * sqrt(M_PI * area));
break;
- case O_FD:
+ case O_FD:
Values[idx].d1 = 2.0 * log(perimeter) / log(area) ;
break;
}
Modified: grass/trunk/vector/v.to.db/global.h
===================================================================
--- grass/trunk/vector/v.to.db/global.h 2008-01-13 07:57:27 UTC (rev 29691)
+++ grass/trunk/vector/v.to.db/global.h 2008-01-13 12:05:46 UTC (rev 29692)
@@ -70,6 +70,8 @@
#define O_FD 13 /* fractal dimension */
+#define O_SINUOUS 14 /* sinuousity of a line (length / <distance between end points>) */
+
#define U_ACRES 1
#define U_HECTARES 2
#define U_KILOMETERS 3
Modified: grass/trunk/vector/v.to.db/lines.c
===================================================================
--- grass/trunk/vector/v.to.db/lines.c 2008-01-13 07:57:27 UTC (rev 29691)
+++ grass/trunk/vector/v.to.db/lines.c 2008-01-13 12:05:46 UTC (rev 29692)
@@ -47,7 +47,7 @@
/*
* Read: - points/centroids : cat,count,coor
- * - lines/boundaries : cat,count,length,slope
+ * - lines/boundaries : cat,count,length,slope,sinuous
*/
int
@@ -55,12 +55,13 @@
{
int i, idx, nlines, type, found;
register int line_num;
- struct line_pnts *Points;
+ struct line_pnts *Points,*EndPoints;
struct line_cats *Cats, *LCats, *RCats;
- double len,slope;
+ double len,slope,dist;
/* Initialize the Point struct */
Points = Vect_new_line_struct();
+ EndPoints = Vect_new_line_struct();
Cats = Vect_new_cats_struct ();
LCats = Vect_new_cats_struct ();
RCats = Vect_new_cats_struct ();
@@ -151,6 +152,21 @@
}
slope = (Points->z[Points->n_points-1] - Points->z[0])/len;
Values[idx].d1 += slope;
+ } else if ( options.option == O_SINUOUS && (type & GV_LINES) ) {
+ /* Calculate line length / distance between end points */
+ Vect_append_point(EndPoints, Points->x[0], Points->y[0], Points->z[0]);
+ Vect_append_point(EndPoints, Points->x[Points->n_points-1], Points->y[Points->n_points-1], Points->z[Points->n_points-1]);
+ if (!Vect_is_3d(Map)) {
+ len = length (Points->n_points, Points->x, Points->y);
+ dist = length (EndPoints->n_points, EndPoints->x, EndPoints->y);
+ }
+ else {
+ len = Vect_line_length(Points);
+ dist = Vect_line_length(EndPoints);
+ }
+ Vect_destroy_line_struct(EndPoints);
+ EndPoints = Vect_new_line_struct();
+ Values[idx].d1 = len / dist;
}
found = 1;
@@ -197,8 +213,22 @@
}
slope = (Points->z[Points->n_points-1] - Points->z[0])/len;
Values[idx].d1 += slope;
- }
-
+ } else if ( options.option == O_SINUOUS && (type & GV_LINES) ) {
+ /* Calculate line length / distance between end points */
+ Vect_append_point(EndPoints, Points->x[0], Points->y[0], Points->z[0]);
+ Vect_append_point(EndPoints, Points->x[Points->n_points-1], Points->y[Points->n_points-1], Points->z[Points->n_points-1]);
+ if (!Vect_is_3d(Map)) {
+ len = length (Points->n_points, Points->x, Points->y);
+ dist = length (EndPoints->n_points, EndPoints->x, EndPoints->y);
+ }
+ else {
+ len = Vect_line_length(Points);
+ dist = Vect_line_length(EndPoints);
+ }
+ Vect_destroy_line_struct(EndPoints);
+ EndPoints = Vect_new_line_struct();
+ Values[idx].d1 = len / dist;
+ }
}
}
Modified: grass/trunk/vector/v.to.db/parse.c
===================================================================
--- grass/trunk/vector/v.to.db/parse.c 2008-01-13 07:57:27 UTC (rev 29691)
+++ grass/trunk/vector/v.to.db/parse.c 2008-01-13 12:05:46 UTC (rev 29692)
@@ -47,12 +47,12 @@
parms.option->type = TYPE_STRING;
parms.option->required = YES;
parms.option->multiple = NO;
- parms.option->options = "cat,area,compact,fd,perimeter,length,count,coor,start,end,sides,query,slope";
+ parms.option->options = "cat,area,compact,fd,perimeter,length,count,coor,start,end,sides,query,slope,sinuous";
parms.option->description = _("Value to upload");
parms.option->descriptions =
"cat;insert new row for each category if doesn't exist yet;"
"area;area size;"
- "compact;compactness of an area, calculated as \n"
+ "compact;compactness of an area, calculated as \n"
" compactness = perimeter / (2 * sqrt(PI * area));"
"fd;fractal dimension of boundary defining a polygon, calculated as \n"
" fd = 2 * (log(perimeter) / log(area));"
@@ -66,7 +66,8 @@
"'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;"
- "slope;slope steepness of vector line or boundary";
+ "slope;slope steepness of vector line or boundary;"
+ "sinuous;Line Sinuousity. Calculated as line length / distance between end points;";
parms.units = G_define_option();
parms.units->key = "units";
@@ -138,7 +139,7 @@
if (!options.print) {
if ( options.option == O_AREA || options.option == O_LENGTH || options.option == O_COUNT
|| options.option == O_QUERY || options.option == O_COMPACT || options.option == O_FD
- || options.option == O_PERIMETER || options.option == O_SLOPE ) /* one column required */
+ || options.option == O_PERIMETER || options.option == O_SLOPE || options.option == O_SINUOUS ) /* one column required */
{
if ( ncols != 1) {
G_fatal_error ( _("This option requires one column") );
@@ -162,6 +163,10 @@
if ( options.option == O_SIDES && !(options.type | GV_BOUNDARY) )
G_fatal_error ( _("The 'sides' option makes sense only for boundaries"));
+ if ( options.option == O_SINUOUS && !(options.type | GV_LINES) )
+ G_fatal_error ( _("The 'sinuous' option makes sense only for lines"));
+
+
return 0;
}
@@ -196,6 +201,7 @@
else if (strcmp (s, "fd") == 0) x = O_FD;
else if (strcmp (s, "perimeter") == 0) x = O_PERIMETER;
else if (strcmp (s, "slope") == 0) x = O_SLOPE;
+ else if (strcmp (s, "sinuous") == 0) x = O_SINUOUS;
return x;
}
Modified: grass/trunk/vector/v.to.db/report.c
===================================================================
--- grass/trunk/vector/v.to.db/report.c 2008-01-13 07:57:27 UTC (rev 29691)
+++ grass/trunk/vector/v.to.db/report.c 2008-01-13 12:05:46 UTC (rev 29692)
@@ -82,7 +82,12 @@
break;
-
+ case O_SINUOUS:
+ if (G_verbose() > G_verbose_min())
+ fprintf (stdout,"cat|sinuous\n");
+ for ( i = 0; i < vstat.rcat; i++ )
+ fprintf (stdout, "%d|%.15g\n", Values[i].cat, Values[i].d1);
+ break;
case O_COOR:
case O_START:
case O_END:
Modified: grass/trunk/vector/v.to.db/update.c
===================================================================
--- grass/trunk/vector/v.to.db/update.c 2008-01-13 07:57:27 UTC (rev 29691)
+++ grass/trunk/vector/v.to.db/update.c 2008-01-13 12:05:46 UTC (rev 29692)
@@ -50,6 +50,7 @@
case O_FD:
case O_PERIMETER:
case O_SLOPE:
+ case O_SINUOUS:
sprintf (buf1, "update %s set %s =", Fi->table, options.col[0]);
break;
case O_COOR:
@@ -82,6 +83,7 @@
case O_FD:
case O_PERIMETER:
case O_SLOPE:
+ case O_SINUOUS:
sprintf (buf2, "%s %f where %s = %d", buf1, Values[i].d1, Fi->key, Values[i].cat);
break;
More information about the grass-commit
mailing list