Browse Source

v.overlay: implement `atype=auto`

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@59154 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 11 years ago
parent
commit
8fae6aeb5c
2 changed files with 56 additions and 37 deletions
  1. 26 12
      vector/v.overlay/main.c
  2. 30 25
      vector/v.overlay/v.overlay.html

+ 26 - 12
vector/v.overlay/main.c

@@ -11,7 +11,7 @@
  *               OGR support by Martin Landa <landa.martin gmail.com>
  *               OGR support by Martin Landa <landa.martin gmail.com>
  *               Markus Metz
  *               Markus Metz
  * PURPOSE:      
  * PURPOSE:      
- * COPYRIGHT:    (C) 2003-2009, 2012-2013 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2003-2014 by the GRASS Development Team
  *
  *
  *               This program is free software under the GNU General
  *               This program is free software under the GNU General
  *               Public License (>=v2). Read the file COPYING that
  *               Public License (>=v2). Read the file COPYING that
@@ -75,8 +75,8 @@ int main(int argc, char *argv[])
     type_opt[0] = G_define_standard_option(G_OPT_V_TYPE);
     type_opt[0] = G_define_standard_option(G_OPT_V_TYPE);
     type_opt[0]->label = _("Feature type (vector map A)");
     type_opt[0]->label = _("Feature type (vector map A)");
     type_opt[0]->key = "atype";
     type_opt[0]->key = "atype";
-    type_opt[0]->options = "line,area";
-    type_opt[0]->answer = "area";
+    type_opt[0]->options = "line,area,auto";
+    type_opt[0]->answer = "auto";
 
 
     in_opt[1] = G_define_standard_option(G_OPT_V_INPUT);
     in_opt[1] = G_define_standard_option(G_OPT_V_INPUT);
     in_opt[1]->label = _("Name of input vector map (B)");
     in_opt[1]->label = _("Name of input vector map (B)");
@@ -144,8 +144,10 @@ int main(int argc, char *argv[])
     for (input = 0; input < 2; input++) {
     for (input = 0; input < 2; input++) {
 	type[input] = Vect_option_to_types(type_opt[input]);
 	type[input] = Vect_option_to_types(type_opt[input]);
     }
     }
+    /* not needed
     if (type[0] & GV_AREA)
     if (type[0] & GV_AREA)
 	type[0] = GV_AREA;
 	type[0] = GV_AREA;
+    */
 
 
     ofield[0] = ofield[1] = ofield[2] = 0;
     ofield[0] = ofield[1] = ofield[2] = 0;
     i = 0;
     i = 0;
@@ -165,17 +167,33 @@ int main(int argc, char *argv[])
     else
     else
 	G_fatal_error(_("Unknown operator '%s'"), operator_opt->answer);
 	G_fatal_error(_("Unknown operator '%s'"), operator_opt->answer);
 
 
+    Vect_check_input_output_name(in_opt[0]->answer, out_opt->answer,
+				 G_FATAL_EXIT);
+    Vect_check_input_output_name(in_opt[1]->answer, out_opt->answer,
+				 G_FATAL_EXIT);
+
+    for (input = 0; input < 2; input++) {
+        Vect_set_open_level(2);
+        Vect_open_old2(&(In[input]), in_opt[input]->answer, "", field_opt[input]->answer);
+	field[input] = Vect_get_field_number(&(In[input]), field_opt[input]->answer);
+    }
+    if (type[0] == 0) { /* atype=auto */
+        type[0] = Vect_read_next_line(&(In[0]), NULL, NULL);
+        if (type[0] == -1)
+            G_fatal_error(_("Unable to determine feature type for <%s>"),
+                          in_opt[0]->key);
+        if (!(type[0] & (GV_LINE | GV_AREA)))
+            G_fatal_error(_("Invalid fearure type for <%s>. Only '%s' or '%s' supported."),
+                          in_opt[0]->key, "line", "area");
+        G_debug(1, "auto -> atype=%d", type[0]);
+    }
+
     /* OP_OR, OP_XOR is not supported for lines,
     /* OP_OR, OP_XOR is not supported for lines,
        mostly because I'am not sure if they make enouhg sense */
        mostly because I'am not sure if they make enouhg sense */
     if (type[0] == GV_LINE && (operator == OP_OR || operator == OP_XOR))
     if (type[0] == GV_LINE && (operator == OP_OR || operator == OP_XOR))
 	G_fatal_error(_("Operator '%s' is not supported for type line"),
 	G_fatal_error(_("Operator '%s' is not supported for type line"),
 		      operator_opt->answer);
 		      operator_opt->answer);
 
 
-    Vect_check_input_output_name(in_opt[0]->answer, out_opt->answer,
-				 G_FATAL_EXIT);
-    Vect_check_input_output_name(in_opt[1]->answer, out_opt->answer,
-				 G_FATAL_EXIT);
-
     snap_thresh = atof(snap_opt->answer);
     snap_thresh = atof(snap_opt->answer);
 
 
     Points = Vect_new_line_struct();
     Points = Vect_new_line_struct();
@@ -225,10 +243,6 @@ int main(int argc, char *argv[])
     for (input = 0; input < 2; input++) {
     for (input = 0; input < 2; input++) {
 	int ncats, index, nlines_out, newline;
 	int ncats, index, nlines_out, newline;
 
 
-	Vect_set_open_level(2);
-	Vect_open_old2(&(In[input]), in_opt[input]->answer, "", field_opt[input]->answer);
-	field[input] = Vect_get_field_number(&(In[input]), field_opt[input]->answer);
-
 	G_message(_("Copying vector features from <%s>..."),
 	G_message(_("Copying vector features from <%s>..."),
 		  Vect_get_full_name(&(In[input])));
 		  Vect_get_full_name(&(In[input])));
 
 

+ 30 - 25
vector/v.overlay/v.overlay.html

@@ -1,21 +1,21 @@
 <h2>DESCRIPTION</h2>
 <h2>DESCRIPTION</h2>
 
 
 <em>v.overlay</em> allows the user to overlay two vector maps. Features 
 <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> 
+in <b>ainput</b> can be lines or areas and are cut with areas in 
+<b>binput</b>. Simple <i>clipping</i> can be performed with the <b>and</b> 
 oerator.
 oerator.
 <p>
 <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 
+If areas in <b>ainput</b> are overlaid with areas in <b>binput</b>, 
+it is sometimes necessary to snap areas of <b>binput</b> to those of 
+<b>ainput</b>, otherwise areas can go missing or many sliver areas 
 can be created. Snapping is enabled by default and can be disabled by 
 can be created. Snapping is enabled by default and can be disabled by 
-setting the <em>snap</em> option to a negative value. Recommended values 
+setting the <b>snap</b> option to a negative value. Recommended values 
 are between 0.00000001 and 0.0001. Using larger values for snapping can 
 are between 0.00000001 and 0.0001. Using larger values for snapping can 
 have undesired side-effects, but may sometimes be necessary to get a 
 have undesired side-effects, but may sometimes be necessary to get a 
 clean output (see example below). In general, it is recommended to start 
 clean output (see example below). In general, it is recommended to start 
 with a small snapping threshold, gradually increasing the threshold until 
 with a small snapping threshold, gradually increasing the threshold until 
 the result is reasonably clean. Snapping modifies only boundaries in 
 the result is reasonably clean. Snapping modifies only boundaries in 
-binput, which are snapped to boundaries in ainput. Boundaries in ainput 
+binput, which are snapped to boundaries in ainput. Boundaries in <b>ainput</b> 
 are not modified.
 are not modified.
 <!-- This is outdated 
 <!-- This is outdated 
 There are 3 links attached to features in output map, 
 There are 3 links attached to features in output map, 
@@ -31,36 +31,40 @@ There are 3 links attached to features in output map,
 </ul>
 </ul>
 -->
 -->
 <p>
 <p>
-If the first number of the <em>olayer</em> option is > 0, then the 
+If the <i>first</i> number of the <b>olayer</b> option is greater than 0, then the 
 resulting output map has a merged attribute table in the given layer 
 resulting output map has a merged attribute table in the given layer 
 number. The original column names have a prefix (<em>a_</em> and 
 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.
+<em>b_</em>) corresponding to <b>ainput</b> and <b>binput</b> map.
 <p>
 <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 transferred to
+If the <i>second</i> number of the <b>olayer</b> option is greater than 0, then the 
+categories of <b>ainput</b> in layer <b>alayer</b> are transferred to
 the output layer with the second number.
 the output layer with the second number.
 <p>
 <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 transferred to
+If the <i>third</i> number of the <b>olayer</b> option is greater than 0, then the 
+categories of <b>binput</b> in layer <em>blayer</em> are transferred to
 the output layer with the third number.
 the output layer with the third number.
 
 
 <h2>NOTES</h2>
 <h2>NOTES</h2>
-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>.
+Currently only areas in <b>ainput</b> are supported for the operators 
+<em>or</em> and <em>xor</em>! See also <em><a href="v.select.html">v.select</a></em>.
 
 
 The operator defines what kind of operation will be done. Features are 
 The operator defines what kind of operation will be done. Features are 
-written to output, if the result of an operation 'ainput operator binput' 
+written to output, if the result of an operation <b>ainput</b> operator <b>binput</b> 
 is true.
 is true.
 <p>
 <p>
-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 
+If the <i>first</i> number of the <b>olayer</b> option is greater than 0, then attributes 
+of the tables from <b>ainput</b> and <b>binput</b> are joined into a new table linked 
 to the output map with a new cat column. 
 to the output map with a new cat column. 
 <p>
 <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. 
+If the <i>second</i> number of the <b>olayer</b> option is greater than 0, then the 
+attribute table of <b>ainput</b> is copied to the output map. 
 <p>
 <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. 
+If the <i>third</i> number of the <b>olayer</b> option is greater than 0, then the 
+attribute table of <b>binput</b> is copied to the output map. 
+
+<p>
+If <b>atype</b>=auto is given than <em>v.overlay</em> determines
+feature type for <b>ainput</b> from the first found feature.
 
 
 <!-- This is outdated
 <!-- This is outdated
 <p><div class="code"><pre>
 <p><div class="code"><pre>
@@ -75,7 +79,7 @@ connect the copied tables to the output map.-->
 
 
 <h2>EXAMPLES</h2>
 <h2>EXAMPLES</h2>
 
 
-<h4>Polygons overlaid with ploygons</h4>
+<h3>Polygons overlaid with ploygons</h3>
 <div class="code"><pre>
 <div class="code"><pre>
 v.overlay ainput=lake binput=province output=lakeXprovince operator=or
 v.overlay ainput=lake binput=province output=lakeXprovince operator=or
 </pre></div>
 </pre></div>
@@ -131,7 +135,7 @@ As can be seen by the resulting large number of centroids on boundaries,
 the urban areas do not match exactly the Census 2000 areas. In this case 
 the urban areas do not match exactly the Census 2000 areas. In this case 
 a clean result can be obtained by snapping with a threshold of 0.1 m.
 a clean result can be obtained by snapping with a threshold of 0.1 m.
 
 
-<h4>Lines overlaid with polygons</h4>
+<h3>Lines overlaid with polygons</h3>
 
 
 Using the North Carolina sample dataset, we clip the roads map to the area
 Using the North Carolina sample dataset, we clip the roads map to the area
 of city of Raleigh, preserving road attributes in layer 1:
 of city of Raleigh, preserving road attributes in layer 1:
@@ -171,4 +175,5 @@ v.overlay ainput=roadsmajor atype=line binput=raleigh \
 Radim Blazek, ITC-Irst, Trento, Italy<br>
 Radim Blazek, ITC-Irst, Trento, Italy<br>
 Markus Metz
 Markus Metz
 
 
-<p><i>Last changed: $Date$</i>
+<p>
+<i>Last changed: $Date$</i>