[GRASS-SVN] r53936 - grass/trunk/vector/v.overlay

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Nov 20 07:40:17 PST 2012


Author: mmetz
Date: 2012-11-20 07:40:16 -0800 (Tue, 20 Nov 2012)
New Revision: 53936

Modified:
   grass/trunk/vector/v.overlay/area_area.c
   grass/trunk/vector/v.overlay/local.h
   grass/trunk/vector/v.overlay/main.c
   grass/trunk/vector/v.overlay/v.overlay.html
Log:
v.overlay: fix areas x areas, update manual

Modified: grass/trunk/vector/v.overlay/area_area.c
===================================================================
--- grass/trunk/vector/v.overlay/area_area.c	2012-11-20 15:39:45 UTC (rev 53935)
+++ grass/trunk/vector/v.overlay/area_area.c	2012-11-20 15:40:16 UTC (rev 53936)
@@ -17,7 +17,7 @@
 
 int area_area(struct Map_info *In, int *field, struct Map_info *Out,
 	      struct field_info *Fi, dbDriver * driver, int operator,
-	      int *ofield, ATTRIBUTES * attr, struct ilist *BList)
+	      int *ofield, ATTRIBUTES * attr, struct ilist *BList, double snap)
 {
     int ret, input, line, nlines, area, nareas;
     int in_area, in_centr, out_cat;
@@ -28,11 +28,20 @@
     char buf[1000];
     dbString stmt;
     int nmodif;
+    int verbose;
 
+    verbose = G_verbose();
+
     Points = Vect_new_line_struct();
     Cats = Vect_new_cats_struct();
     
-    /* optional snap ? */
+    /* optional snap */
+    if (snap > 0) {
+	G_message(_("Snapping lines..."));
+	/* snap boundaries in B to boundaries in A
+	 * not modifying boundaries in A */
+	Vect_snap_lines_list2(Out, BList, GV_BOUNDARY, snap, NULL);
+    }
 
     /* same procedure like for v.in.ogr
      * Vect_clean_small_angles_at_nodes() can change the geometry so that new intersections
@@ -54,7 +63,9 @@
     /* ?: May be result of Vect_break_lines() + Vect_remove_duplicates() any dangle or bridge?
      * In that case, calls to Vect_remove_dangles() and Vect_remove_bridges() would be also necessary */
 
+    G_set_verbose(0);
     Vect_build_partial(Out, GV_BUILD_AREAS);
+    G_set_verbose(verbose);
     nlines = Vect_get_num_lines(Out);
     ret = 0;
     for (line = 1; line <= nlines; line++) {
@@ -76,8 +87,10 @@
 	Vect_remove_bridges(Out, NULL, NULL, NULL);
     }
 
+    G_set_verbose(0);
     Vect_build_partial(Out, GV_BUILD_NONE);
     Vect_build_partial(Out, GV_BUILD_BASE);
+    G_set_verbose(verbose);
     G_message(_("Merging lines..."));
     Vect_merge_lines(Out, GV_BOUNDARY, NULL, NULL);
 
@@ -186,7 +199,7 @@
 
 	Vect_append_point(Points, Centr[area].x, Centr[area].y, 0.0);
 
-	if (ofield[0]  > 0) {
+	if (ofield[0] > 0) {
 	    /* Add new cats for all combinations of input cats (-1 in cycle for null) */
 	    for (i = -1; i < Centr[area].cat[0]->n_cats; i++) {
 		int j;
@@ -342,6 +355,10 @@
     }
 
     /* Delete boundaries */
+    G_set_verbose(0);
+    Vect_build_partial(Out, GV_BUILD_NONE);
+    Vect_build_partial(Out, GV_BUILD_BASE);
+    G_set_verbose(verbose);
     for (line = 1; line <= nlines; line++) {
 	if (Del[line])
 	    Vect_delete_line(Out, line);

Modified: grass/trunk/vector/v.overlay/local.h
===================================================================
--- grass/trunk/vector/v.overlay/local.h	2012-11-20 15:39:45 UTC (rev 53935)
+++ grass/trunk/vector/v.overlay/local.h	2012-11-20 15:40:16 UTC (rev 53936)
@@ -32,7 +32,7 @@
 
 int area_area(struct Map_info *In, int *field, struct Map_info *Out,
 	      struct field_info *Fi, dbDriver * driver, int operator,
-	      int *ofield, ATTRIBUTES * attr, struct ilist *BList);
+	      int *ofield, ATTRIBUTES * attr, struct ilist *BList, double snap_thresh);
 int line_area(struct Map_info *In, int *field, struct Map_info *Out,
 	      struct field_info *Fi, dbDriver * driver, int operator,
 	      int *ofield, ATTRIBUTES * attr, struct ilist *BList);

Modified: grass/trunk/vector/v.overlay/main.c
===================================================================
--- grass/trunk/vector/v.overlay/main.c	2012-11-20 15:39:45 UTC (rev 53935)
+++ grass/trunk/vector/v.overlay/main.c	2012-11-20 15:40:16 UTC (rev 53936)
@@ -33,15 +33,17 @@
 {
     int i, input, line, nlines, operator;
     int type[2], field[2], ofield[3];
+    double snap_thresh;
     struct GModule *module;
     struct Option *in_opt[2], *out_opt, *type_opt[2], *field_opt[2],
-	*ofield_opt, *operator_opt;
+	*ofield_opt, *operator_opt, *snap_opt;
     struct Flag *table_flag;
     struct Map_info In[2], Out;
     struct line_pnts *Points, *Points2;
     struct line_cats *Cats;
     struct ilist *BList;
     char *desc;
+    int verbose;
 
     struct field_info *Fi = NULL;
     char buf[1000];
@@ -120,6 +122,13 @@
     ofield_opt->description = _("If 0 or not given, "
 				"the category is not written");
 
+    snap_opt = G_define_option();
+    snap_opt->key = "snap";
+    snap_opt->label = _("Snapping threshold for boundaries");
+    snap_opt->description = _("Disable snapping with snap <= 0");
+    snap_opt->type = TYPE_DOUBLE;
+    snap_opt->answer = "0";
+
     table_flag = G_define_standard_flag(G_FLG_V_TABLE);
 
     if (G_parser(argc, argv))
@@ -128,6 +137,8 @@
     for (input = 0; input < 2; input++) {
 	type[input] = Vect_option_to_types(type_opt[input]);
     }
+    if (type[0] & GV_AREA)
+	type[0] = GV_AREA;
 
     ofield[0] = ofield[1] = ofield[2] = 0;
     i = 0;
@@ -158,6 +169,8 @@
     Vect_check_input_output_name(in_opt[1]->answer, out_opt->answer,
 				 G_FATAL_EXIT);
 
+    snap_thresh = atof(snap_opt->answer);
+
     Points = Vect_new_line_struct();
     Points2 = Vect_new_line_struct();
     Cats = Vect_new_cats_struct();
@@ -196,7 +209,10 @@
 
     /* Copy lines to output */
     BList = Vect_new_list();
+    verbose = G_verbose();
+    G_set_verbose(0);
     Vect_build_partial(&Out, GV_BUILD_BASE);
+    G_set_verbose(verbose);
     for (input = 0; input < 2; input++) {
 	int ncats, index, nlines_out, newline;
 
@@ -519,7 +535,7 @@
 
     /* AREA x AREA */
     if (type[0] == GV_AREA) {
-	area_area(In, field, &Out, Fi, driver, operator, ofield, attr, BList);
+	area_area(In, field, &Out, Fi, driver, operator, ofield, attr, BList, snap_thresh);
     }
     else {			/* LINE x AREA */
 	line_area(In, field, &Out, Fi, driver, operator, ofield, attr, BList);

Modified: grass/trunk/vector/v.overlay/v.overlay.html
===================================================================
--- grass/trunk/vector/v.overlay/v.overlay.html	2012-11-20 15:39:45 UTC (rev 53935)
+++ grass/trunk/vector/v.overlay/v.overlay.html	2012-11-20 15:40:16 UTC (rev 53936)
@@ -1,6 +1,17 @@
 <h2>DESCRIPTION</h2>
 
-<em>v.overlay</em> allows the user to overlay two vector area maps.
+<em>v.overlay</em> allows the user to overlay two vector maps. Features 
+in <em>ainput</em> can be lines or areas and are cut with areas in 
+<em>binput</em>. Simple clipping can be performed with the <em>and</em> 
+oerator.
+<p>
+If areas in <em>ainput</em> are overlaid with areas in <em>binput</em>, 
+it is sometimes necessary to snap areas of <em>binput</em> to those of 
+<em>ainput</em>, otherwise areas can go missing or many sliver areas 
+can be created. Snapping can be enabled by setting the <em>snap</em> 
+option to a value larger zero. Recommended are values between 
+0.00000001 and 0.0001. Using larger values for snapping can have 
+undesired side-effects.
 <!-- This is outdated 
 There are 3 links attached to features in output map, 
 <ul>
@@ -14,17 +25,37 @@
 <li><b>field 3</b>: category of <i>bfield</i> from <i>binput</i>
 </ul>
 -->
-The resulting output map has a merged attribute-table. The origin column-names
-have a prefix (<em>a_</em> and <em>b_</em>) which results from the ainput- and binput-map.
+<p>
+If the first number of the <em>olayer</em> option is > 0, then the 
+resulting output map has a merged attribute table in the given layer 
+number. The original column names have a prefix (<em>a_</em> and 
+<em>b_</em>) corresponding to <em>ainput</em> and <em>binput</em> map.
+<p>
+If the second number of the <em>olayer</em> option is > 0, then the 
+categories of <em>ainput</em> in layer <em>alayer</em> are transfered to
+the output layer with the second number.
+<p>
+If the third number of the <em>olayer</em> option is > 0, then the 
+categories of <em>binput</em> in layer <em>blayer</em> are transfered to
+the output layer with the third number.
 
 <h2>NOTES</h2>
-Currently only areas are supported for the operators <em>or</em> and <em>xor</em>! See also <a href="v.select.html">v.select</a>.
+Currently only areas in <em>ainput</em> are supported for the operators 
+<em>or</em> and <em>xor</em>! See also <a href="v.select.html">v.select</a>.
 
-The operator defines what kind of operation will be done. Features are written to output,
-if the result of an operation 'ainput operator binput' is true.
+The operator defines what kind of operation will be done. Features are 
+written to output, if the result of an operation 'ainput operator binput' 
+is true.
 <p>
-Attributes of the tables from ainput and binput are joined into a new table
-linked to the output maps new cat-column. 
+If the first number of the <em>olayer</em> option is > 0, then attributes 
+of the tables from ainput and binput are joined into a new table linked 
+to the output map with a new cat column. 
+<p>
+If the second number of the <em>olayer</em> option is > 0, then the 
+attribute table of ainput is copied to the output map. 
+<p>
+If the third number of the <em>olayer</em> option is > 0, then the 
+attribute table of binput is copied to the output map. 
 
 <!-- This is outdated
 <p><div class="code"><pre>
@@ -94,17 +125,18 @@
 <h2>EXAMPLE LINE TO POLYGON CLIPPING</h2>
 
 Using the North Carolina sample dataset, we clip the roads map to the area
-of city of Raleigh:
+of city of Raleigh, preserving road attributes in layer 1:
 <div class="code"><pre>
 g.region vect=zipcodes_wake
 
-# extract Raleigh city
+# extract Raleigh city:
 v.extract in=zipcodes_wake out=raleigh \
             where="ZIPNAME = 'RALEIGH'"
 
 # clip road network to city polygon:
 v.overlay ainput=roadsmajor atype=line binput=raleigh \
-            out=roadsmajor_raleigh operator=and
+            out=roadsmajor_raleigh operator=and \
+	    olayer=0,1,0
 </pre></div>
 
 <center>
@@ -127,6 +159,7 @@
 
 <h2>AUTHORS</h2>
 
-Radim Blazek, ITC-Irst, Trento, Italy
+Radim Blazek, ITC-Irst, Trento, Italy<br>
+Markus Metz
 
 <p><i>Last changed: $Date$</i>



More information about the grass-commit mailing list