[GRASS-SVN] r39897 - grass/trunk/vector/v.perturb
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Dec 4 14:14:07 EST 2009
Author: martinl
Date: 2009-12-04 14:14:06 -0500 (Fri, 04 Dec 2009)
New Revision: 39897
Modified:
grass/trunk/vector/v.perturb/main.c
Log:
v.pertrub: OGR support (read access)
Modified: grass/trunk/vector/v.perturb/main.c
===================================================================
--- grass/trunk/vector/v.perturb/main.c 2009-12-04 16:35:28 UTC (rev 39896)
+++ grass/trunk/vector/v.perturb/main.c 2009-12-04 19:14:06 UTC (rev 39897)
@@ -1,25 +1,12 @@
-/*-
- * s.perturb
- * Copyright (C) 1994. James Darrell McCauley.
+/****************************************************************************
*
- * Author: James Darrell McCauley darrell at mccauley-usa.com
- * http://mccauley-usa.com/
+ * MODULE: v.pertrub
+ * AUTHOR(S): James Darrell McCauley darrell at mccauley-usa.com
+ * http://mccauley-usa.com/
+ * PURPOSE:
+ * COPYRIGHT: (C) 1994-2009 by James Darrell McCauley and the GRASS Development Team
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
* Modification History:
* 3/2006 added min and seed MN/SM ITC-irst
* 2005 updated to GRASS 6 RB ITC-irst
@@ -28,15 +15,20 @@
* 0.3B <25 Feb 1995> cleaned up 'gcc -Wall' warnings (jdm)
* <13 Sept 2000> released under GPL
*
- * TODO: see code below
- */
+ * This program is free software under the GNU General
+ * Public License (>=v2). Read the file COPYING that
+ * comes with GRASS for details.
+ *
+ *****************************************************************************/
#include <stdlib.h>
#include <math.h>
+
#include <grass/gis.h>
#include <grass/dbmi.h>
#include <grass/vector.h>
#include <grass/glocale.h>
+
#include "perturb.h"
#include "zufall.h"
@@ -44,8 +36,8 @@
{
double p1, p2, numbers[1000], numbers2[1000];
int (*rng) ();
- int i, verbose;
- int line, nlines, ttype, n, ret, seed;
+ int i;
+ int line, nlines, ttype, n, ret, seed, field;
struct field_info *Fi, *Fin;
double min = 0.;
int debuglevel = 3;
@@ -59,23 +51,22 @@
struct GModule *module;
struct
{
- struct Option *in, *out, *dist, *pars, *min, *seed;
+ struct Option *in, *out, *dist, *pars, *min, *seed, *field;
} parm;
- struct
- {
- struct Flag *q;
- } flag;
G_gisinit(argv[0]);
module = G_define_module();
G_add_keyword(_("vector"));
+ G_add_keyword(_("statistics"));
+
module->description =
- _("Random location perturbations of GRASS vector points");
+ _("Random location perturbations of vector points.");
parm.in = G_define_standard_option(G_OPT_V_INPUT);
- parm.in->description = _("Vector points to be spatially perturbed");
+ parm.field = G_define_standard_option(G_OPT_V_FIELD_ALL);
+
parm.out = G_define_standard_option(G_OPT_V_OUTPUT);
parm.dist = G_define_option();
@@ -91,11 +82,11 @@
parm.pars->type = TYPE_DOUBLE;
parm.pars->required = YES;
parm.pars->multiple = YES;
- parm.pars->description =
- _("Parameter(s) of distribution. If the distribution "
- "is uniform, only one parameter, the maximum, is needed. "
- "For a normal distribution, two parameters, the mean and "
- "standard deviation, are required.");
+ parm.pars->label = _("Parameter(s) of distribution");
+ parm.pars->description = _("If the distribution "
+ "is uniform, only one parameter, the maximum, is needed. "
+ "For a normal distribution, two parameters, the mean and "
+ "standard deviation, are required.");
parm.min = G_define_option();
parm.min->key = "minimum";
@@ -110,15 +101,10 @@
parm.seed->required = NO;
parm.seed->answer = "0";
parm.seed->description = _("Seed for random number generation");
-
- flag.q = G_define_flag();
- flag.q->key = 'q';
- flag.q->description = _("Quiet");
-
+
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
- verbose = (!flag.q->answer);
min = atof(parm.min->answer);
seed = atoi(parm.seed->answer);
@@ -150,10 +136,12 @@
/* Open input */
Vect_set_open_level(2);
- Vect_open_old(&In, parm.in->answer, "");
-
+ Vect_open_old2(&In, parm.in->answer, "", parm.field->answer);
+
+ field = Vect_get_field_number(&In, parm.field->answer);
+
/* Open output */
- Vect_open_new(&Out, parm.out->answer, 0); /* TODO add z support ? */
+ Vect_open_new(&Out, parm.out->answer, WITHOUT_Z); /* TODO add z support ? */
Vect_hist_copy(&In, &Out);
Vect_hist_command(&Out);
@@ -174,6 +162,9 @@
type = Vect_read_line(&In, Points, Cats, line);
+ if (field != -1 && !Vect_cat_get(Cats, field, NULL))
+ continue;
+
if (type & GV_POINT) {
if (i >= 800) {
/* Generate some more random numbers */
More information about the grass-commit
mailing list