[GRASS-SVN] r39823 - grass/trunk/vector/v.distance

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Nov 27 08:14:13 EST 2009


Author: martinl
Date: 2009-11-27 08:14:12 -0500 (Fri, 27 Nov 2009)
New Revision: 39823

Modified:
   grass/trunk/vector/v.distance/main.c
Log:
v.distance: OGR support (read access) - 'to'


Modified: grass/trunk/vector/v.distance/main.c
===================================================================
--- grass/trunk/vector/v.distance/main.c	2009-11-27 12:59:01 UTC (rev 39822)
+++ grass/trunk/vector/v.distance/main.c	2009-11-27 13:14:12 UTC (rev 39823)
@@ -7,10 +7,11 @@
  *                 Faculty of Forestry, Finland
  *               - some additions 2002 Markus Neteler
  *               - updated to 5.7 by Radim Blazek 2003
+ *               - OGR support by Martin Landa <landa.martin gmail.com> (2009)
  *               
  * PURPOSE:      Calculates distance from a point to nearest line or point in vector layer. 
  *               
- * COPYRIGHT:    (C) 2002-2007 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2002-2009 by the GRASS Development Team
  *
  *               This program is free software under the 
  *               GNU General Public License (>=v2). 
@@ -23,12 +24,12 @@
 #include <string.h>
 #include <unistd.h>
 #include <math.h>
+
 #include <grass/gis.h>
 #include <grass/glocale.h>
 #include <grass/dbmi.h>
 #include <grass/vector.h>
 
-
 /* TODO: support all types (lines, boundaries, areas for 'from' (from_type) */
 
 /* define codes for characteristics of relation between two nearest features */
@@ -122,10 +123,10 @@
     from_opt->description = _("Name of existing vector map (from)");
     from_opt->guisection = _("From");
 
-    to_opt = G_define_standard_option(G_OPT_V_INPUT);
-    to_opt->key = "to";
-    to_opt->description = _("Name of existing vector map (to)");
-    to_opt->guisection = _("To");
+    from_field_opt = G_define_standard_option(G_OPT_V_FIELD);
+    from_field_opt->key = "from_layer";
+    from_field_opt->label = _("Layer number or name (from)");
+    from_field_opt->guisection = _("From");
 
     from_type_opt = G_define_standard_option(G_OPT_V_TYPE);
     from_type_opt->key = "from_type";
@@ -134,6 +135,16 @@
     from_type_opt->label = _("Feature type (from)");
     from_type_opt->guisection = _("From");
 
+    to_opt = G_define_standard_option(G_OPT_V_INPUT);
+    to_opt->key = "to";
+    to_opt->description = _("Name of existing vector map (to)");
+    to_opt->guisection = _("To");
+
+    to_field_opt = G_define_standard_option(G_OPT_V_FIELD);
+    to_field_opt->key = "to_layer";
+    to_field_opt->label = _("Layer number or name (to)");
+    to_field_opt->guisection = _("To");
+
     to_type_opt = G_define_standard_option(G_OPT_V_TYPE);
     to_type_opt->key = "to_type";
     to_type_opt->options = "point,line,boundary,centroid,area";
@@ -141,16 +152,6 @@
     to_type_opt->label = _("Feature type (to)");
     to_type_opt->guisection = _("To");
 
-    from_field_opt = G_define_standard_option(G_OPT_V_FIELD);
-    from_field_opt->key = "from_layer";
-    from_field_opt->label = _("Layer number (from)");
-    from_field_opt->guisection = _("From");
-    
-    to_field_opt = G_define_standard_option(G_OPT_V_FIELD);
-    to_field_opt->key = "to_layer";
-    to_field_opt->label = _("Layer number (to)");
-    to_field_opt->guisection = _("To");
-    
     out_opt = G_define_standard_option(G_OPT_V_OUTPUT);
     out_opt->key = "output";
     out_opt->required = NO;
@@ -238,7 +239,6 @@
     to_type = Vect_option_to_types(to_type_opt);
 
     from_field = atoi(from_field_opt->answer);
-    to_field = atoi(to_field_opt->answer);
 
     max = atof(max_opt->answer);
     min = atof(min_opt->answer);
@@ -307,8 +307,10 @@
 
     /* Open 'to' vector */
     Vect_set_open_level(2);
-    Vect_open_old(&To, to_opt->answer, "");
+    Vect_open_old2(&To, to_opt->answer, "", to_field_opt->answer);
 
+    to_field = Vect_get_field_number(&To, to_field_opt->answer);
+
     /* Open output vector */
     if (out_opt->answer) {
 	Vect_open_new(&Out, out_opt->answer, WITHOUT_Z);
@@ -508,7 +510,7 @@
 	else {
 	    LLPoints = NULL;
 	}
-	G_verbose_message(_("Finding nearest lines..."));
+	G_message(_("Finding nearest feature..."));
 	for (fline = 1; fline <= nfrom; fline++) {
 	    int tmp_tcat;
 	    double tmp_tangle, tangle;
@@ -638,7 +640,7 @@
 
     /* Find nearest areas */
     if (to_type & GV_AREA) {
-	G_verbose_message(_("Finding nearest areas..."));
+	G_message(_("Finding nearest areas..."));
 	for (fline = 1; fline <= nfrom; fline++) {
 	    G_debug(3, "fline = %d", fline);
 	    G_percent(fline, nfrom, 2);



More information about the grass-commit mailing list