[GRASS-SVN] r58842 - grass-addons/grass7/vector/v.centerpoint
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Feb 3 00:22:16 PST 2014
Author: mmetz
Date: 2014-02-03 00:22:15 -0800 (Mon, 03 Feb 2014)
New Revision: 58842
Modified:
grass-addons/grass7/vector/v.centerpoint/areas.c
grass-addons/grass7/vector/v.centerpoint/lines.c
grass-addons/grass7/vector/v.centerpoint/points.c
grass-addons/grass7/vector/v.centerpoint/v.centerpoint.html
Log:
v.centerpoint: write cats to stdout
Modified: grass-addons/grass7/vector/v.centerpoint/areas.c
===================================================================
--- grass-addons/grass7/vector/v.centerpoint/areas.c 2014-02-03 06:39:57 UTC (rev 58841)
+++ grass-addons/grass7/vector/v.centerpoint/areas.c 2014-02-03 08:22:15 UTC (rev 58842)
@@ -16,7 +16,7 @@
double x, y, z, meanx, meany, meanz;
double *xp, *yp;
double w, tot_w;
- int i;
+ int cat, i;
Points = Vect_new_line_struct();
OPoints = Vect_new_line_struct();
@@ -45,12 +45,18 @@
Vect_reset_cats(Cats);
if (Vect_get_area_cats(In, area, ICats) != 0)
continue;
- if (!Vect_cats_in_constraint(ICats, layer, cat_list))
- continue;
+
+ cat = -1;
+ if (layer > 0) {
+ if (!Vect_cats_in_constraint(ICats, layer, cat_list))
+ continue;
- for (i = 0; i < ICats->n_cats; i++) {
- if (ICats->field[i] == layer)
- Vect_cat_set(Cats, 1, ICats->cat[i]);
+ for (i = 0; i < ICats->n_cats; i++) {
+ if (ICats->field[i] == layer) {
+ Vect_cat_set(Cats, 1, ICats->cat[i]);
+ cat = ICats->cat[i];
+ }
+ }
}
Vect_get_area_points(In, area, Points);
@@ -113,8 +119,12 @@
Vect_cat_set(Cats, 2, 7);
Vect_write_line(Out, GV_POINT, OPoints, Cats);
}
- else
- fprintf(stdout, "7|%.15g|%.15g|%.15g\n", x, y, z);
+ else {
+ if (layer > 0)
+ fprintf(stdout, "%.15g|%.15g|%.15g|7|%d\n", x, y, z, cat);
+ else
+ fprintf(stdout, "%.15g|%.15g|%.15g|7\n", x, y, z);
+ }
G_percent(area, nareas, 4);
}
@@ -145,12 +155,17 @@
Vect_reset_cats(Cats);
if (Vect_get_area_cats(In, area, ICats) != 0)
continue;
- if (!Vect_cats_in_constraint(ICats, layer, cat_list))
- continue;
- for (i = 0; i < ICats->n_cats; i++) {
- if (ICats->field[i] == layer)
- Vect_cat_set(Cats, 1, ICats->cat[i]);
+ cat = -1;
+ if (layer > 0) {
+ if (!Vect_cats_in_constraint(ICats, layer, cat_list))
+ continue;
+
+ for (i = 0; i < ICats->n_cats; i++) {
+ if (ICats->field[i] == layer)
+ Vect_cat_set(Cats, 1, ICats->cat[i]);
+ cat = ICats->cat[i];
+ }
}
Vect_get_area_points(In, area, Points);
@@ -393,8 +408,12 @@
Vect_cat_set(Cats, 2, 8);
Vect_write_line(Out, GV_POINT, OPoints, Cats);
}
- else
- fprintf(stdout, "8|%.15g|%.15g|%.15g\n", x, y, 0.);
+ else {
+ if (layer > 0)
+ fprintf(stdout, "%.15g|%.15g|%.15g|8|%d\n", x, y, 0., cat);
+ else
+ fprintf(stdout, "%.15g|%.15g|%.15g|8\n", x, y, 0.);
+ }
G_percent(area, nareas, 4);
}
@@ -425,12 +444,18 @@
Vect_reset_cats(Cats);
if (Vect_get_area_cats(In, area, ICats) != 0)
continue;
- if (!Vect_cats_in_constraint(ICats, layer, cat_list))
- continue;
- for (i = 0; i < ICats->n_cats; i++) {
- if (ICats->field[i] == layer)
- Vect_cat_set(Cats, 1, ICats->cat[i]);
+ cat = -1;
+ if (layer > 0) {
+ if (!Vect_cats_in_constraint(ICats, layer, cat_list))
+ continue;
+
+ for (i = 0; i < ICats->n_cats; i++) {
+ if (ICats->field[i] == layer) {
+ Vect_cat_set(Cats, 1, ICats->cat[i]);
+ cat = ICats->cat[i];
+ }
+ }
}
Vect_get_area_points(In, area, Points);
@@ -568,8 +593,12 @@
Vect_cat_set(Cats, 2, 9);
Vect_write_line(Out, GV_POINT, OPoints, Cats);
}
- else
- fprintf(stdout, "9|%.15g|%.15g|%.15g\n", x, y, 0.);
+ else {
+ if (layer > 0)
+ fprintf(stdout, "%.15g|%.15g|%.15g|9|%d\n", x, y, 0., cat);
+ else
+ fprintf(stdout, "%.15g|%.15g|%.15g|9\n", x, y, 0.);
+ }
G_percent(area, nareas, 4);
}
Modified: grass-addons/grass7/vector/v.centerpoint/lines.c
===================================================================
--- grass-addons/grass7/vector/v.centerpoint/lines.c 2014-02-03 06:39:57 UTC (rev 58841)
+++ grass-addons/grass7/vector/v.centerpoint/lines.c 2014-02-03 08:22:15 UTC (rev 58842)
@@ -12,7 +12,7 @@
struct line_pnts *Points, *OPoints;
struct line_cats *Cats, *ICats;
double x, y, z;
- int type;
+ int type, cat;
int i, counter;
Points = Vect_new_line_struct();
@@ -28,18 +28,24 @@
counter = 0;
Vect_rewind(In);
- while ((type = Vect_read_next_line(In, Points, Cats)) > 0) {
+ while ((type = Vect_read_next_line(In, Points, ICats)) > 0) {
G_percent(counter, n_primitives, 4);
counter++;
if (!(type & GV_LINE))
continue;
- if (!Vect_cats_in_constraint(ICats, layer, cat_list))
- continue;
+
+ cat = -1;
+ if (layer > 0) {
+ if (!Vect_cats_in_constraint(ICats, layer, cat_list))
+ continue;
- for (i = 0; i < ICats->n_cats; i++) {
- if (ICats->field[i] == layer)
- Vect_cat_set(Cats, 1, ICats->cat[i]);
+ for (i = 0; i < ICats->n_cats; i++) {
+ if (ICats->field[i] == layer) {
+ Vect_cat_set(Cats, 1, ICats->cat[i]);
+ cat = ICats->cat[i];
+ }
+ }
}
Vect_line_prune(Points);
@@ -54,8 +60,12 @@
Vect_cat_set(Cats, 2, 4);
Vect_write_line(Out, GV_POINT, OPoints, Cats);
}
- else
- fprintf(stdout, "4|%.15g|%.15g|%.15g\n", x, y, z);
+ else {
+ if (layer > 0)
+ fprintf(stdout, "%.15g|%.15g|%.15g|4|%d\n", x, y, z, cat);
+ else
+ fprintf(stdout, "%.15g|%.15g|%.15g|4\n", x, y, z);
+ }
}
G_percent(1, 1, 1);
}
@@ -69,17 +79,23 @@
counter = 0;
Vect_rewind(In);
- while ((type = Vect_read_next_line(In, Points, Cats)) > 0) {
+ while ((type = Vect_read_next_line(In, Points, ICats)) > 0) {
G_percent(counter, n_primitives, 4);
counter++;
if (!(type & GV_LINE))
continue;
- if (!Vect_cats_in_constraint(ICats, layer, cat_list))
- continue;
- for (i = 0; i < ICats->n_cats; i++) {
- if (ICats->field[i] == layer)
- Vect_cat_set(Cats, 1, ICats->cat[i]);
+ cat = -1;
+ if (layer > 0) {
+ if (!Vect_cats_in_constraint(ICats, layer, cat_list))
+ continue;
+
+ for (i = 0; i < ICats->n_cats; i++) {
+ if (ICats->field[i] == layer) {
+ Vect_cat_set(Cats, 1, ICats->cat[i]);
+ cat = ICats->cat[i];
+ }
+ }
}
Vect_line_prune(Points);
@@ -112,8 +128,12 @@
Vect_cat_set(Cats, 2, 5);
Vect_write_line(Out, GV_POINT, OPoints, Cats);
}
- else
- fprintf(stdout, "5|%.15g|%.15g|%.15g\n", x, y, z);
+ else {
+ if (layer > 0)
+ fprintf(stdout, "%.15g|%.15g|%.15g|5|%d\n", x, y, z, cat);
+ else
+ fprintf(stdout, "%.15g|%.15g|%.15g|5\n", x, y, z);
+ }
}
G_percent(1, 1, 1);
}
@@ -135,17 +155,23 @@
counter = 0;
Vect_rewind(In);
- while ((type = Vect_read_next_line(In, Points, Cats)) > 0) {
+ while ((type = Vect_read_next_line(In, Points, ICats)) > 0) {
G_percent(counter, n_primitives, 4);
counter++;
if (!(type & GV_LINE))
continue;
- if (!Vect_cats_in_constraint(ICats, layer, cat_list))
- continue;
- for (i = 0; i < ICats->n_cats; i++) {
- if (ICats->field[i] == layer)
- Vect_cat_set(Cats, 1, ICats->cat[i]);
+ cat = -1;
+ if (layer > 0) {
+ if (!Vect_cats_in_constraint(ICats, layer, cat_list))
+ continue;
+
+ for (i = 0; i < ICats->n_cats; i++) {
+ if (ICats->field[i] == layer) {
+ Vect_cat_set(Cats, 1, ICats->cat[i]);
+ cat = ICats->cat[i];
+ }
+ }
}
Vect_line_prune(Points);
@@ -252,8 +278,12 @@
Vect_cat_set(Cats, 2, 6);
Vect_write_line(Out, GV_POINT, OPoints, Cats);
}
- else
- fprintf(stdout, "6|%.15g|%.15g|%.15g\n", x, y, z);
+ else {
+ if (layer > 0)
+ fprintf(stdout, "%.15g|%.15g|%.15g|6|%d\n", x, y, z, cat);
+ else
+ fprintf(stdout, "%.15g|%.15g|%.15g|6\n", x, y, z);
+ }
}
G_percent(1, 1, 1);
}
Modified: grass-addons/grass7/vector/v.centerpoint/points.c
===================================================================
--- grass-addons/grass7/vector/v.centerpoint/points.c 2014-02-03 06:39:57 UTC (rev 58841)
+++ grass-addons/grass7/vector/v.centerpoint/points.c 2014-02-03 08:22:15 UTC (rev 58842)
@@ -76,7 +76,7 @@
Vect_write_line(Out, GV_POINT, OPoints, Cats);
}
else
- fprintf(stdout, "1|%.15g|%.15g|%.15g\n", x, y, z);
+ fprintf(stdout, "%.15g|%.15g|%.15g|1\n", x, y, z);
}
medx = xmean;
@@ -166,7 +166,7 @@
Vect_write_line(Out, GV_POINT, OPoints, Cats);
}
else
- fprintf(stdout, "2|%.15g|%.15g|%.15g\n", x, y, z);
+ fprintf(stdout, "%.15g|%.15g|%.15g|2\n", x, y, z);
}
}
@@ -221,7 +221,7 @@
Vect_write_line(Out, GV_POINT, OPoints, Cats);
}
else
- fprintf(stdout, "3|%.15g|%.15g|%.15g\n", x, y, z);
+ fprintf(stdout, "%.15g|%.15g|%.15g|3\n", x, y, z);
}
return 1;
Modified: grass-addons/grass7/vector/v.centerpoint/v.centerpoint.html
===================================================================
--- grass-addons/grass7/vector/v.centerpoint/v.centerpoint.html 2014-02-03 06:39:57 UTC (rev 58841)
+++ grass-addons/grass7/vector/v.centerpoint/v.centerpoint.html 2014-02-03 08:22:15 UTC (rev 58842)
@@ -2,7 +2,8 @@
<em>v.centerpoint</em> calculates center points for point clouds, lines
and areas. Center points can be centers of gravity (coordinates' mean) or
-geometric medians, which is more robust in case of outliers.
+geometric medians (points of minimum distance, which is more robust
+in case of outliers.
<p>
For points, center points are calculated considering all points. For
lines and areas, center points are calculated for each line or area
@@ -11,7 +12,7 @@
If no output vector is given, center points are printed to stdout in
ASCII point format:
<div class="code"><pre>
-<cat>|<easting>|<northing>
+<easting>|<northing>|<height>|<cat>
</pre></div>
The category values are
<ul>
More information about the grass-commit
mailing list