[GRASS-SVN] r31651 - grass-addons/vector/v.parallel2
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Jun 7 08:56:26 EDT 2008
Author: rmatev
Date: 2008-06-07 08:56:26 -0400 (Sat, 07 Jun 2008)
New Revision: 31651
Modified:
grass-addons/vector/v.parallel2/main.c
grass-addons/vector/v.parallel2/vlib_buffer.c
Log:
Added cmdline options in v.parallel2
Modified: grass-addons/vector/v.parallel2/main.c
===================================================================
--- grass-addons/vector/v.parallel2/main.c 2008-06-06 16:17:02 UTC (rev 31650)
+++ grass-addons/vector/v.parallel2/main.c 2008-06-07 12:56:26 UTC (rev 31651)
@@ -2,7 +2,7 @@
*
* MODULE: v.parallel
*
- * AUTHOR(S): Radim Blazek
+ * AUTHOR(S): Radim Blazek, Rosen Matev
*
* PURPOSE: Create parallel lines
*
@@ -22,16 +22,18 @@
#include <grass/Vect.h>
#include <grass/glocale.h>
-int
-main (int argc, char *argv[])
+int main (int argc, char *argv[])
{
struct GModule *module;
- struct Option *in_opt, *out_opt, *distance_opt;
+ struct Option *in_opt, *out_opt, *dista_opt;
+ struct Option *distb_opt, *angle_opt, *side_opt;
+ struct Flag *round_flag, *loops_flag;
struct Map_info In, Out;
struct line_pnts *Points, *Points2;
struct line_cats *Cats;
int line, nlines;
- double distance, tolerance;
+ double da, db, dalpha, tolerance;
+ int side;
G_gisinit(argv[0]);
@@ -43,19 +45,57 @@
out_opt = G_define_standard_option(G_OPT_V_OUTPUT);
/* layer_opt = G_define_standard_option(G_OPT_V_FIELD); */
- distance_opt = G_define_option();
- distance_opt->key = "distance";
- distance_opt->type = TYPE_DOUBLE;
- distance_opt->required = YES;
- distance_opt->multiple = NO;
- distance_opt->description = _("Offset in map units, positive for right side, "
- "negative for left side.");
+ dista_opt = G_define_option();
+ dista_opt->key = "dista";
+ dista_opt->type = TYPE_DOUBLE;
+ dista_opt->required = YES;
+ dista_opt->multiple = NO;
+ dista_opt->description = _("Offset along major axis in map units");
- if (G_parser (argc, argv)) exit(EXIT_FAILURE);
+ distb_opt = G_define_option();
+ distb_opt->key = "distb";
+ distb_opt->type = TYPE_DOUBLE;
+ distb_opt->required = YES;
+ distb_opt->multiple = NO;
+ distb_opt->description = _("Offset along minor axis in map units");
+ angle_opt = G_define_option();
+ angle_opt->key = "angle";
+ angle_opt->type = TYPE_DOUBLE;
+ angle_opt->required = YES;
+ angle_opt->answer = "0";
+ angle_opt->multiple = NO;
+ angle_opt->description = _("Angle of major axis in degrees");
+
+ side_opt = G_define_option();
+ side_opt->key = "side";
+ side_opt->type = TYPE_STRING;
+ side_opt->required = YES;
+ side_opt->answer = "right";
+ side_opt->multiple = NO;
+ side_opt->options = "left,right";
+ side_opt->description = _("left;Parallel line is on the left;right;Parallel line is on the right;");
+
+ round_flag = G_define_flag();
+ round_flag->key = 'r';
+ round_flag->description = _("Make outside corners round");
+
+ loops_flag = G_define_flag();
+ loops_flag->key = 'l';
+ loops_flag->description = _("Don't remove loops");
+
+ if (G_parser (argc, argv))
+ exit(EXIT_FAILURE);
+
/* layer = atoi ( layer_opt->answer ); */
- distance = atof ( distance_opt->answer );
- tolerance = distance/10.;
+ da = atof(dista_opt->answer);
+ db = atof(distb_opt->answer);
+ dalpha = atof(angle_opt->answer);
+ tolerance = ((da>db)?da:db)/10.;
+ if (strcmp(side_opt->answer, "right"))
+ side = 1;
+ else if (strcmp(side_opt->answer, "left"))
+ side = -1;
Vect_set_open_level (2);
Vect_open_old (&In, in_opt->answer, "");
@@ -71,18 +111,18 @@
nlines = Vect_get_num_lines ( &In );
for ( line = 1; line <= nlines; line++ ) {
- int ltype;
-
- G_percent ( line, nlines, 1 );
-
- ltype = Vect_read_line ( &In, Points, Cats, line);
-
- if ( ltype & GV_LINES ) {
- Vect_line_parallel ( Points, distance, tolerance, 1, Points2 );
- Vect_write_line ( &Out, ltype, Points2, Cats );
- } else {
- Vect_write_line ( &Out, ltype, Points, Cats );
- }
+ int ltype;
+
+ G_percent ( line, nlines, 1 );
+
+ ltype = Vect_read_line ( &In, Points, Cats, line);
+
+ if ( ltype & GV_LINES ) {
+ Vect_line_parallel2(Points, da, db, dalpha, side, round_flag->answer, loops_flag->answer, tolerance, Points2);
+ Vect_write_line(&Out, ltype, Points2, Cats);
+ } else {
+ Vect_write_line(&Out, ltype, Points, Cats);
+ }
}
Vect_close (&In);
Modified: grass-addons/vector/v.parallel2/vlib_buffer.c
===================================================================
--- grass-addons/vector/v.parallel2/vlib_buffer.c 2008-06-06 16:17:02 UTC (rev 31650)
+++ grass-addons/vector/v.parallel2/vlib_buffer.c 2008-06-07 12:56:26 UTC (rev 31651)
@@ -369,25 +369,26 @@
* It is not to be used directly for creating buffers.
* + added elliptical buffers/par.lines support
*
-* dalpha - direction of elliptical buffer major axis
+* dalpha - direction of elliptical buffer major axis in degrees
* da - distance along major axis
* db: distance along minor (perp.) axis
* side: side >= 0 - right side, side < 0 - left side
* when (da == db) we have plain distances (old case)
-* round_corners - 1 for round, 0 for sharp. (tol is used only if round_corners == 1)
-* round_corners == 1 will be implemented soon
+* round - 1 for round corners, 0 for sharp corners. (tol is used only if round == 1)
+* round == 1 will be implemented soon
*/
-void parallel_line(struct line_pnts *Points, double da, double db, double dalpha, double tol, int round_corners, struct line_pnts *nPoints)
+void parallel_line(struct line_pnts *Points, double da, double db, double dalpha, int side, int round, double tol, struct line_pnts *nPoints)
{
int i, j, res, np, na;
double *x, *y;
- double tx, ty, vx, vy, nx, ny, mx, my, rx, ry, side;
+ double tx, ty, vx, vy, nx, ny, mx, my, rx, ry;
double a0, b0, c0, a1, b1, c1;
double ux, uy, wx, wy;
double atol, atol2, a, av, aw;
G_debug(4, "parallel_line2()");
+ dalpha *= 180/PI;
Vect_reset_line ( nPoints );
Vect_line_prune ( Points );
@@ -414,7 +415,7 @@
for (i = 0; i < np-1; i++)
{
norm_vector(x[i], y[i], x[i+1], y[i+1], &tx, &ty);
- elliptic_transform(ty*side, -tx*side, da, db, dalpha, &vx, &vy);
+ elliptic_transform(-ty*side, tx*side, da, db, dalpha, &vx, &vy);
nx = x[i] + vx;
ny = y[i] + vy;
@@ -476,8 +477,8 @@
Vect_line_prune ( nPoints );
}
-/*!
- \fn void Vect_line_parallel ( struct line_pnts *InPoints, double distance, double tolerance, int rm_end,
+/*
+ \fn void Vect_line_parallel2 ( struct line_pnts *InPoints, double distance, double tolerance, int rm_end,
struct line_pnts *OutPoints )
\brief Create parrallel line
\param InPoints input line
@@ -486,17 +487,16 @@
\param rm_end remove end points falling into distance
\param OutPoints output line
*/
-void
-Vect_line_parallel ( struct line_pnts *InPoints, double distance, double tolerance, int rm_end,
- struct line_pnts *OutPoints )
+void Vect_line_parallel2(struct line_pnts *InPoints, double da, double db, double dalpha, int side, int round, int loops, double tol, struct line_pnts *OutPoints )
{
- G_debug (4, "Vect_line_parallel(): npoints = %d, distance = %f, tolerance = %f",
- InPoints->n_points, distance, tolerance);
+ G_debug(4, "Vect_line_parallel(): npoints = %d, da = %f, db = %f, dalpha = %f, side = %d, round_corners = %d, loops = %d, tol = %f",
+ InPoints->n_points, da, db, dalpha, side, round, loops, tol);
-/* parallel_line ( InPoints, distance, tolerance, OutPoints); */
- parallel_line (InPoints, distance, distance, 0, tolerance, 0, OutPoints);
-
- /*clean_parallel ( OutPoints, InPoints, distance, rm_end );*/
+ parallel_line (InPoints, da, db, dalpha, side, round, tol, OutPoints);
+
+/* if (!loops)
+ clean_parallel(OutPoints, InPoints, distance, rm_end);
+ */
}
/*!
More information about the grass-commit
mailing list