[GRASS-SVN] r39888 - in grass/trunk: include lib/gis
lib/vector/Vlib vector/v.buffer vector/v.clean
vector/v.delaunay vector/v.drape vector/v.extract
vector/v.extrude vector/v.generalize vector/v.hull
vector/v.kcv vector/v.neighbors vector/v.out.dxf
vector/v.out.pov vector/v.out.svg
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Dec 4 02:21:43 EST 2009
Author: martinl
Date: 2009-12-04 02:21:40 -0500 (Fri, 04 Dec 2009)
New Revision: 39888
Modified:
grass/trunk/include/gis.h
grass/trunk/lib/gis/parser_standard_options.c
grass/trunk/lib/vector/Vlib/field.c
grass/trunk/vector/v.buffer/main.c
grass/trunk/vector/v.clean/main.c
grass/trunk/vector/v.delaunay/in_out.c
grass/trunk/vector/v.delaunay/main.c
grass/trunk/vector/v.drape/main.c
grass/trunk/vector/v.extract/main.c
grass/trunk/vector/v.extrude/main.c
grass/trunk/vector/v.generalize/main.c
grass/trunk/vector/v.hull/main.c
grass/trunk/vector/v.hull/read.c
grass/trunk/vector/v.kcv/main.c
grass/trunk/vector/v.neighbors/main.c
grass/trunk/vector/v.out.dxf/main.c
grass/trunk/vector/v.out.pov/main.c
grass/trunk/vector/v.out.svg/main.c
Log:
synchronize vector modules (G_OPT_V_FIELD_ALL)
Modified: grass/trunk/include/gis.h
===================================================================
--- grass/trunk/include/gis.h 2009-12-04 02:59:43 UTC (rev 39887)
+++ grass/trunk/include/gis.h 2009-12-04 07:21:40 UTC (rev 39888)
@@ -188,6 +188,7 @@
G_OPT_V_TYPE, /* primitive type */
G_OPT_V3_TYPE, /* primitive type, 2D and 3D */
G_OPT_V_FIELD, /* layer number (layers used to be called fields) */
+ G_OPT_V_FIELD_ALL, /* layer number (layers used to be called fields) */
G_OPT_V_CAT, /* one category */
G_OPT_V_CATS, /* more categories */
G_OPT_V_ID, /* one feature id */
Modified: grass/trunk/lib/gis/parser_standard_options.c
===================================================================
--- grass/trunk/lib/gis/parser_standard_options.c 2009-12-04 02:59:43 UTC (rev 39887)
+++ grass/trunk/lib/gis/parser_standard_options.c 2009-12-04 07:21:40 UTC (rev 39888)
@@ -354,10 +354,22 @@
Opt->label = _("Layer number or name");
Opt->description =
_("A single vector map can be connected to multiple database "
- "tables. This number determines which table to use. If reasonable '-1' selects all vector map layers. "
+ "tables. This number determines which table to use. "
"Layer name for OGR access.");
Opt->gisprompt = "old_layer,layer,layer";
break;
+ case G_OPT_V_FIELD_ALL:
+ Opt->key = "layer";
+ Opt->type = TYPE_STRING;
+ Opt->required = NO;
+ Opt->answer = "1";
+ Opt->label = _("Layer number or name ('-1' for all layers)");
+ Opt->description =
+ _("A single vector map can be connected to multiple database "
+ "tables. This number determines which table to use. "
+ "Layer name for OGR access.");
+ Opt->gisprompt = "old_layer,layer,layer_all";
+ break;
case G_OPT_V_CAT:
Opt->key = "cat";
Opt->type = TYPE_INTEGER;
Modified: grass/trunk/lib/vector/Vlib/field.c
===================================================================
--- grass/trunk/lib/vector/Vlib/field.c 2009-12-04 02:59:43 UTC (rev 39887)
+++ grass/trunk/lib/vector/Vlib/field.c 2009-12-04 07:21:40 UTC (rev 39888)
@@ -485,6 +485,7 @@
\param field layer name
\return layer number
+ \return -1 for all layers
\return 0 if layer not found
*/
int Vect_get_field_number(const struct Map_info *Map, const char *field)
@@ -493,6 +494,9 @@
G_debug(1, "Vect_get_field_number(): field = %s", field);
+ if (strcmp(field, "-1") == 0)
+ return -1;
+
fi = Vect_get_field2(Map, field);
if (fi)
Modified: grass/trunk/vector/v.buffer/main.c
===================================================================
--- grass/trunk/vector/v.buffer/main.c 2009-12-04 02:59:43 UTC (rev 39887)
+++ grass/trunk/vector/v.buffer/main.c 2009-12-04 07:21:40 UTC (rev 39888)
@@ -157,7 +157,7 @@
type_opt->answer = "point,line,area";
type_opt->guisection = _("Selection");
- field_opt = G_define_standard_option(G_OPT_V_FIELD);
+ field_opt = G_define_standard_option(G_OPT_V_FIELD_ALL);
field_opt->guisection = _("Selection");
dista_opt = G_define_option();
@@ -350,7 +350,7 @@
if (!(ltype & type))
continue;
- if (!Vect_cat_get(Cats, field, &cat))
+ if (field != -1 && !Vect_cat_get(Cats, field, &cat))
continue;
if (bufcol_opt->answer) {
@@ -416,7 +416,7 @@
continue;
Vect_read_line(&In, NULL, Cats, centroid);
- if (!Vect_cat_get(Cats, field, &cat))
+ if (field > 0 && !Vect_cat_get(Cats, field, &cat))
continue;
if (bufcol_opt->answer) {
Modified: grass/trunk/vector/v.clean/main.c
===================================================================
--- grass/trunk/vector/v.clean/main.c 2009-12-04 02:59:43 UTC (rev 39887)
+++ grass/trunk/vector/v.clean/main.c 2009-12-04 07:21:40 UTC (rev 39888)
@@ -47,7 +47,7 @@
module->description = _("Toolset for cleaning topology of vector map.");
in_opt = G_define_standard_option(G_OPT_V_INPUT);
- field_opt = G_define_standard_option(G_OPT_V_FIELD);
+ field_opt = G_define_standard_option(G_OPT_V_FIELD_ALL);
field_opt->guisection = _("Selection");
type_opt = G_define_standard_option(G_OPT_V3_TYPE);
type_opt->guisection = _("Selection");
Modified: grass/trunk/vector/v.delaunay/in_out.c
===================================================================
--- grass/trunk/vector/v.delaunay/in_out.c 2009-12-04 02:59:43 UTC (rev 39887)
+++ grass/trunk/vector/v.delaunay/in_out.c 2009-12-04 07:21:40 UTC (rev 39888)
@@ -187,7 +187,7 @@
if (!(type & GV_POINTS))
continue;
- if (Vect_cat_get(Cats, field, NULL) == 0)
+ if (field != -1 && Vect_cat_get(Cats, field, NULL) == 0)
continue;
if (!complete_map) {
Modified: grass/trunk/vector/v.delaunay/main.c
===================================================================
--- grass/trunk/vector/v.delaunay/main.c 2009-12-04 02:59:43 UTC (rev 39887)
+++ grass/trunk/vector/v.delaunay/main.c 2009-12-04 07:21:40 UTC (rev 39888)
@@ -64,7 +64,7 @@
"vector map containing points or centroids.");
in_opt = G_define_standard_option(G_OPT_V_INPUT);
- field_opt = G_define_standard_option(G_OPT_V_FIELD);
+ field_opt = G_define_standard_option(G_OPT_V_FIELD_ALL);
out_opt = G_define_standard_option(G_OPT_V_OUTPUT);
reg_flag = G_define_flag();
Modified: grass/trunk/vector/v.drape/main.c
===================================================================
--- grass/trunk/vector/v.drape/main.c 2009-12-04 02:59:43 UTC (rev 39887)
+++ grass/trunk/vector/v.drape/main.c 2009-12-04 07:21:40 UTC (rev 39888)
@@ -147,7 +147,7 @@
in_opt = G_define_standard_option(G_OPT_V_INPUT);
- layer_opt = G_define_standard_option(G_OPT_V_FIELD);
+ layer_opt = G_define_standard_option(G_OPT_V_FIELD_ALL);
type_opt = G_define_standard_option(G_OPT_V3_TYPE);
@@ -323,7 +323,9 @@
/* get the line type */
ltype = Vect_read_line(&In, Points, Cats, line);
-
+ if (layer != -1 && !Vect_cat_get(Cats, layer, NULL))
+ continue;
+
/* write the new line file, with the updated Points struct */
if (sample_raster
(ltype, fdrast, window, Points, method, scale, null_opt,
@@ -381,8 +383,8 @@
else {
/* close input vector */
Vect_close(&In);
- G_warning(_("No features drapped. Check Your computational region and input raster map."));
- exit(EXIT_FAILURE);
+ G_warning(_("No features drapped. Check your computational region and input vector map."));
+ exit(EXIT_SUCCESS);
}
/* close input vector */
Modified: grass/trunk/vector/v.extract/main.c
===================================================================
--- grass/trunk/vector/v.extract/main.c 2009-12-04 02:59:43 UTC (rev 39887)
+++ grass/trunk/vector/v.extract/main.c 2009-12-04 07:21:40 UTC (rev 39888)
@@ -68,6 +68,7 @@
{
int i, new_cat, type, ncats, *cats, c;
int **ocats, *nocats, nfields, *fields;
+ int field;
int dissolve = 0, x, y, type_only;
char buffr[1024], text[80];
char *input, *output;
@@ -116,10 +117,7 @@
typopt->label = _("Types to be extracted");
typopt->guisection = _("Selection");
- fieldopt = G_define_standard_option(G_OPT_V_FIELD);
- fieldopt->gisprompt = "old_layer,layer,layer_all";
- fieldopt->label =
- _("Layer number (if -1, all features in all layers of given type " "are extracted)");
+ fieldopt = G_define_standard_option(G_OPT_V_FIELD_ALL);
fieldopt->guisection = _("Selection");
listopt = G_define_standard_option(G_OPT_V_CATS);
@@ -202,7 +200,9 @@
/* Do initial read of input file */
Vect_set_open_level(2); /* topology required */
Vect_open_old2(&In, input, "", fieldopt->answer);
-
+
+ field = Vect_get_field_number(&In, fieldopt->answer);
+
type = Vect_option_to_types(typopt);
if (type & GV_AREA) {
type |= GV_CENTROID;
@@ -261,7 +261,7 @@
}
else if (whereopt->answer != NULL) {
- Fi = Vect_get_field2(&In, fieldopt->answer);
+ Fi = Vect_get_field(&In, field);
if (!Fi) {
G_fatal_error(_("Database connection not defined for layer <%s>"),
fieldopt->answer);
@@ -292,7 +292,7 @@
else if (nrandopt->answer != NULL) { /* Generate random category list */
/* We operate on layer's CAT's and thus valid layer is required */
- if (Vect_cidx_get_field_index(&In, atoi(fieldopt->answer)) < 0)
+ if (Vect_cidx_get_field_index(&In, field) < 0)
G_fatal_error(_("This map has no categories attached. "
"Use v.category to attach categories to this vector map."));
@@ -301,7 +301,7 @@
if (nrandom < 1)
G_fatal_error(_("Please specify random number larger than 0"));
- nfeatures = Vect_cidx_get_type_count(&In, atoi(fieldopt->answer), type);
+ nfeatures = Vect_cidx_get_type_count(&In, field, type);
if (nrandom >= nfeatures)
G_fatal_error(_("Random category count must be smaller than feature count. "
"There are only %d features of type(s): %s"),
@@ -309,7 +309,7 @@
/* Let's create an array of uniq CAT values
According to Vlib/build.c, cidx should be allready sorted by dig_cidx_sort() */
- ci = &(In.plus.cidx[Vect_cidx_get_field_index(&In, atoi(fieldopt->answer))]);
+ ci = &(In.plus.cidx[Vect_cidx_get_field_index(&In, field)]);
ucat_count = 0;
for (c = 0; c < ci->n_cats; c++) {
/* Bitwise AND compares ci feature type with user's requested types */
@@ -364,8 +364,7 @@
Vect_copy_head_data(&In, &Out);
G_message(_("Extracting features..."));
- xtract_line(cat_count, cat_array, &In, &Out, new_cat, type, dissolve,
- Vect_get_field_number(&In, fieldopt->answer),
+ xtract_line(cat_count, cat_array, &In, &Out, new_cat, type, dissolve, field,
type_only, r_flag->answer ? 1 : 0);
Vect_build(&Out);
Modified: grass/trunk/vector/v.extrude/main.c
===================================================================
--- grass/trunk/vector/v.extrude/main.c 2009-12-04 02:59:43 UTC (rev 39887)
+++ grass/trunk/vector/v.extrude/main.c 2009-12-04 07:21:40 UTC (rev 39888)
@@ -46,6 +46,7 @@
struct Cell_head window;
struct cat_list *Clist;
+ int field;
int i, only_type, cat, ctype, fdrast = 0, areanum = 0;
int nelements;
int line, type;
@@ -77,7 +78,7 @@
old = G_define_standard_option(G_OPT_V_INPUT);
- field_opt = G_define_standard_option(G_OPT_V_FIELD);
+ field_opt = G_define_standard_option(G_OPT_V_FIELD_ALL);
type_opt = G_define_standard_option(G_OPT_V_TYPE);
type_opt->answer = "point,line,boundary,area";
@@ -149,6 +150,8 @@
/* opening old vector */
Vect_open_old2(&In, old->answer, "", field_opt->answer);
+ field = Vect_get_field_number(&In, field_opt->answer);
+
Vect_hist_copy(&In, &Out);
Vect_hist_command(&Out);
@@ -261,7 +264,7 @@
continue;
/* fetch categories */
- if (Vect_cat_get(Cats, 1, &cat) == 0) {
+ if (field != -1 && !Vect_cat_get(Cats, field, &cat)) {
Vect_cat_set(Cats, 1, i);
i++;
}
Modified: grass/trunk/vector/v.generalize/main.c
===================================================================
--- grass/trunk/vector/v.generalize/main.c 2009-12-04 02:59:43 UTC (rev 39887)
+++ grass/trunk/vector/v.generalize/main.c 2009-12-04 07:21:40 UTC (rev 39888)
@@ -86,7 +86,7 @@
/* Define the different options as defined in gis.h */
map_in = G_define_standard_option(G_OPT_V_INPUT);
- field_opt = G_define_standard_option(G_OPT_V_FIELD);
+ field_opt = G_define_standard_option(G_OPT_V_FIELD_ALL);
type_opt = G_define_standard_option(G_OPT_V_TYPE);
type_opt->options = "line,boundary,area";
@@ -317,7 +317,7 @@
/* parse filter option and select appropriate lines */
- layer = atoi(field_opt->answer);
+ layer = Vect_get_field_number(&In, field_opt->answer);
if (where_opt->answer) {
if (layer < 1)
G_fatal_error(_("'%s' must be > 0 for '%s'"), "layer", "where");
@@ -372,6 +372,10 @@
(type = Vect_read_next_line(&In, Points, Cats)) > 0) {
i++;
G_percent(i, n_lines, 1);
+
+ if (layer != -1 && !Vect_cat_get(Cats, layer, NULL))
+ continue;
+
if (type == GV_CENTROID && (mask_type & GV_BOUNDARY))
continue; /* skip old centroids,
* we calculate new if we generalize boundarie */
@@ -443,6 +447,10 @@
n_lines = Vect_get_num_lines(&Out);
for (i = 1; i <= n_lines; i++) {
type = Vect_read_line(&Out, Points, Cats, i);
+
+ if (layer > 0 && !Vect_cat_get(Cats, layer, NULL))
+ continue;
+
if (type != GV_BOUNDARY)
continue;
Vect_get_line_areas(&Out, i, &left, &right);
Modified: grass/trunk/vector/v.hull/main.c
===================================================================
--- grass/trunk/vector/v.hull/main.c 2009-12-04 02:59:43 UTC (rev 39887)
+++ grass/trunk/vector/v.hull/main.c 2009-12-04 07:21:40 UTC (rev 39888)
@@ -54,7 +54,7 @@
input = G_define_standard_option(G_OPT_V_INPUT);
- field = G_define_standard_option(G_OPT_V_FIELD);
+ field = G_define_standard_option(G_OPT_V_FIELD_ALL);
output = G_define_standard_option(G_OPT_V_OUTPUT);
@@ -88,7 +88,7 @@
G_fatal_error(_("Error loading vector points map <%s>"), sitefile);
if (numSitePoints < 3)
- G_fatal_error(_("Convex hull calculation requires at least three points"));
+ G_fatal_error(_("Convex hull calculation requires at least three points (%d found)"), numSitePoints);
/* create a 2D or a 3D hull? */
Modified: grass/trunk/vector/v.hull/read.c
===================================================================
--- grass/trunk/vector/v.hull/read.c 2009-12-04 02:59:43 UTC (rev 39887)
+++ grass/trunk/vector/v.hull/read.c 2009-12-04 07:21:40 UTC (rev 39888)
@@ -24,7 +24,7 @@
if (type != GV_POINT)
continue;
- if (Vect_cat_get(cats, field, &cat) == 0)
+ if (field != -1 && Vect_cat_get(cats, field, &cat) == 0)
continue;
G_debug(4, "Point: %f|%f|%f|#%d", sites->x[0], sites->y[0],
Modified: grass/trunk/vector/v.kcv/main.c
===================================================================
--- grass/trunk/vector/v.kcv/main.c 2009-12-04 02:59:43 UTC (rev 39887)
+++ grass/trunk/vector/v.kcv/main.c 2009-12-04 07:21:40 UTC (rev 39888)
@@ -72,7 +72,7 @@
in_opt = G_define_standard_option(G_OPT_V_INPUT);
- field_opt = G_define_standard_option(G_OPT_V_FIELD);
+ field_opt = G_define_standard_option(G_OPT_V_FIELD_ALL);
out_opt = G_define_standard_option(G_OPT_V_OUTPUT);
Modified: grass/trunk/vector/v.neighbors/main.c
===================================================================
--- grass/trunk/vector/v.neighbors/main.c 2009-12-04 02:59:43 UTC (rev 39887)
+++ grass/trunk/vector/v.neighbors/main.c 2009-12-04 07:21:40 UTC (rev 39888)
@@ -30,7 +30,7 @@
int out_fd;
CELL *result, *rp;
int nrows, ncols;
- int row, col;
+ int row, col, count_sum;
int field;
struct GModule *module;
struct Option *in_opt, *out_opt, *field_opt;
@@ -56,7 +56,7 @@
in_opt = G_define_standard_option(G_OPT_V_INPUT);
- field_opt = G_define_standard_option(G_OPT_V_FIELD);
+ field_opt = G_define_standard_option(G_OPT_V_FIELD_ALL);
out_opt = G_define_standard_option(G_OPT_R_OUTPUT);
@@ -101,6 +101,7 @@
box.T = PORT_DOUBLE_MAX;
box.B = -PORT_DOUBLE_MAX;
+ count_sum = 0;
for (row = 0; row < nrows; row++) {
double x, y;
@@ -130,7 +131,7 @@
for (i = 0; i < List->n_values; i++) {
Vect_read_line(&In, Points, Cats, List->value[i]);
- if (Vect_cat_get(Cats, field, NULL) == 0)
+ if (field != -1 && Vect_cat_get(Cats, field, NULL) == 0)
continue;
if (Vect_points_distance(x, y, 0.0, Points->x[0],
@@ -143,6 +144,7 @@
Rast_set_d_value(rp, value, CELL_TYPE);
}
rp = G_incr_void_ptr(rp, Rast_cell_size(CELL_TYPE));
+ count_sum += count;
}
Rast_put_row(out_fd, result, CELL_TYPE);
@@ -152,5 +154,8 @@
Vect_close(&In);
Rast_close(out_fd);
+ if (count_sum < 1)
+ G_warning(_("No points found"));
+
exit(EXIT_SUCCESS);
}
Modified: grass/trunk/vector/v.out.dxf/main.c
===================================================================
--- grass/trunk/vector/v.out.dxf/main.c 2009-12-04 02:59:43 UTC (rev 39887)
+++ grass/trunk/vector/v.out.dxf/main.c 2009-12-04 07:21:40 UTC (rev 39888)
@@ -60,7 +60,7 @@
input = G_define_standard_option(G_OPT_V_INPUT);
- field = G_define_standard_option(G_OPT_V_FIELD);
+ field = G_define_standard_option(G_OPT_V_FIELD_ALL);
output = G_define_standard_option(G_OPT_F_OUTPUT);
output->required = YES;
@@ -157,7 +157,7 @@
ltype = Vect_read_line(Map, Points, Cats, line);
Vect_cat_get(Cats, field, &cat);
- if (cat < 0)
+ if (field != -1 && cat < 0)
continue;
sprintf(cat_num, "%d", cat);
Modified: grass/trunk/vector/v.out.pov/main.c
===================================================================
--- grass/trunk/vector/v.out.pov/main.c 2009-12-04 02:59:43 UTC (rev 39887)
+++ grass/trunk/vector/v.out.pov/main.c 2009-12-04 07:21:40 UTC (rev 39888)
@@ -50,7 +50,7 @@
in_opt = G_define_standard_option(G_OPT_V_INPUT);
- field_opt = G_define_standard_option(G_OPT_V_FIELD);
+ field_opt = G_define_standard_option(G_OPT_V_FIELD_ALL);
type_opt = G_define_standard_option(G_OPT_V3_TYPE);
type_opt->answer = "point,line,area,face";
@@ -117,7 +117,7 @@
type = Vect_read_line(&In, Points, Cats, i);
G_debug(2, "line = %d type = %d", i, type);
- if (Vect_cat_get(Cats, field, NULL) == 0)
+ if (field != -1 && Vect_cat_get(Cats, field, NULL) == 0)
continue;
if (!(otype & type)) {
@@ -175,7 +175,7 @@
centroid = Vect_get_area_centroid(&In, i);
if (centroid > 0) {
Vect_read_line(&In, NULL, Cats, centroid);
- if (Vect_cat_get(Cats, field, NULL) < 0)
+ if (field != -1 && Vect_cat_get(Cats, field, NULL) < 0)
continue;
}
G_debug(2, "area = %d centroid = %d", i, centroid);
Modified: grass/trunk/vector/v.out.svg/main.c
===================================================================
--- grass/trunk/vector/v.out.svg/main.c 2009-12-04 02:59:43 UTC (rev 39887)
+++ grass/trunk/vector/v.out.svg/main.c 2009-12-04 07:21:40 UTC (rev 39888)
@@ -75,7 +75,7 @@
in_opt = G_define_standard_option(G_OPT_V_INPUT);
- field_opt = G_define_standard_option(G_OPT_V_FIELD);
+ field_opt = G_define_standard_option(G_OPT_V_FIELD_ALL);
out_opt = G_define_standard_option(G_OPT_F_OUTPUT);
out_opt->description = _("Name for SVG output file");
@@ -250,7 +250,7 @@
for (i = 1; i <= Vect_get_num_primitives(&In, GV_POINTS); i++) {
G_percent(i, Vect_get_num_primitives(&In, GV_POINTS), 10);
Vect_read_line(&In, Points, Cats, i);
- if (field > 0 && !Vect_cat_get(Cats, field, NULL))
+ if (field != -1 && !Vect_cat_get(Cats, field, NULL))
continue;
for (j = 0; j < Points->n_points; j++) {
fprintf(fpsvg, " <circle ");
More information about the grass-commit
mailing list