[GRASS-SVN] r50619 - in sandbox/martinl: . v.test v.topo.pg.out

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Feb 1 17:06:54 EST 2012


Author: martinl
Date: 2012-02-01 14:06:54 -0800 (Wed, 01 Feb 2012)
New Revision: 50619

Added:
   sandbox/martinl/v.test/
   sandbox/martinl/v.test/Makefile
   sandbox/martinl/v.test/main.c
   sandbox/martinl/v.test/v.test.html
Modified:
   sandbox/martinl/v.topo.pg.out/
Log:
sandbox martinl: add v.test module



Property changes on: sandbox/martinl/v.test
___________________________________________________________________
Added: svn:ignore
   + OBJ.*


Added: sandbox/martinl/v.test/Makefile
===================================================================
--- sandbox/martinl/v.test/Makefile	                        (rev 0)
+++ sandbox/martinl/v.test/Makefile	2012-02-01 22:06:54 UTC (rev 50619)
@@ -0,0 +1,13 @@
+
+MODULE_TOPDIR = ../..
+
+PGM = v.test
+
+LIBES = $(VECTORLIB) $(DIG2LIB) $(DBMILIB) $(GISLIB)
+DEPENDENCIES = $(VECTORDEP) $(DIG2DEP) $(DBMIDEP) $(GISDEP)
+EXTRA_INC = $(VECT_INC)
+EXTRA_CFLAGS = $(VECT_CFLAGS)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd


Property changes on: sandbox/martinl/v.test/Makefile
___________________________________________________________________
Added: svn:mime-type
   + text/x-makefile
Added: svn:eol-style
   + native

Added: sandbox/martinl/v.test/main.c
===================================================================
--- sandbox/martinl/v.test/main.c	                        (rev 0)
+++ sandbox/martinl/v.test/main.c	2012-02-01 22:06:54 UTC (rev 50619)
@@ -0,0 +1,182 @@
+/***************************************************************
+ *
+ * MODULE:       v.test
+ * 
+ * AUTHOR(S):    Martin Landa <landa.martin gmail.com>
+ *               
+ * PURPOSE:      Tests vector feature access
+ *               
+ * COPYRIGHT:    (C) 2012 by the GRASS Development Team
+ *
+ *               This program is free software under the GNU General
+ *               Public License (>=v2).  Read the file COPYING that
+ *               comes with GRASS for details.
+ *
+ **************************************************************/
+
+#include <stdlib.h>
+#include <sys/time.h>
+
+#include <grass/gis.h>
+#include <grass/vector.h>
+#include <grass/glocale.h>
+
+int main(int argc, char *argv[])
+{
+    struct GModule *module;
+    struct Map_info Map;
+    struct {
+	struct Option *input, *num, *type, *field;
+    } opt;
+    struct {
+	struct Flag *s, *r, *l;
+    } flag;
+    
+    int i, line, number, npoints, nlines, ltype;
+    double diff, sdiff;
+    
+    struct line_pnts *Points;
+    struct line_cats *Cats;
+    
+    G_gisinit(argv[0]);
+
+    module = G_define_module();
+    G_add_keyword(_("vector"));
+    G_add_keyword(_("testing"));
+    G_add_keyword(_("external data"));
+    
+    module->description =
+	_("Tests vector sequential/random feature access (native/OGR/PostGIS).");
+
+    opt.input = G_define_standard_option(G_OPT_V_MAP);
+
+    opt.field = G_define_standard_option(G_OPT_V_FIELD);
+    
+    opt.type = G_define_standard_option(G_OPT_V_TYPE);
+    opt.type->answer = "";
+    
+    opt.num = G_define_option();
+    opt.num->key = "n";
+    opt.num->description = _("Number of tests");
+    opt.num->type = TYPE_INTEGER;
+    opt.num->answer = "100";
+
+    flag.s = G_define_flag();
+    flag.s->key = 's';
+    flag.s->description = _("Sequential access");
+
+    flag.r = G_define_flag();
+    flag.r->key = 'r';
+    flag.r->description = _("Limit to current region");
+    
+    flag.l = G_define_flag();
+    flag.l->key = '1';
+    flag.l->description = _("Force level 1 (without topology)");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+    
+    Vect_set_open_level(flag.l->answer ? 1 : 2);
+    Vect_open_old2(&Map, opt.input->answer, "", "1");
+
+    Points = Vect_new_line_struct();
+    Cats   = Vect_new_cats_struct();
+
+    number = atoi(opt.num->answer);
+    
+    /* constraint by type */
+    if (strlen(opt.type->answer) > 0) {
+	int type;
+	
+	type = Vect_option_to_types(opt.type);
+	Vect_set_constraint_type(&Map, type);
+    }
+    
+    /* constraint by field */
+    Vect_set_constraint_field(&Map,
+			      Vect_get_field_number(&Map, opt.field->answer));
+
+    /* constraint by region */
+    if (flag.r->answer) {
+	struct Cell_head window;
+	G_get_window(&window);
+	
+	Vect_set_constraint_region(&Map, window.north, window.south,
+				   window.east, window.west,
+				   window.top, window.bottom);
+    }
+
+    npoints = nlines = sdiff = 0;
+    if (flag.s->answer) {
+	for (i = 0; i < number; i++) {
+	    struct timeval start_time, end_time;
+	    
+	    G_percent(i, number, 5);
+
+	    line = 0;
+	    Vect_rewind(&Map);
+	    
+	    gettimeofday(&start_time, NULL);
+	    while(TRUE) {
+		ltype = Vect_read_next_line(&Map, Points, Cats);
+		if (ltype < 0)
+		    break;
+		if (ltype == GV_POINT)
+		    npoints++;
+		else if (ltype == GV_LINE)
+		    nlines++;
+		line++;
+	    }
+	    gettimeofday(&end_time, NULL);
+	    
+	    diff = (double) end_time.tv_usec - start_time.tv_usec;
+	    if (diff > 0)
+		sdiff += end_time.tv_usec - start_time.tv_usec;
+	    else
+		G_debug(1, "%f", diff); /* ??? */
+	}
+    }
+    else {
+	int nlines;
+	nlines = Vect_get_num_lines(&Map);
+
+	for (i = 0; i < number; i++) {
+	    struct timeval start_time, end_time;
+	    
+	    G_percent(i, number, 5);
+
+	    gettimeofday(&start_time, NULL);
+	    for (line = 1; line < nlines; line++) {
+		ltype = Vect_read_line(&Map, Points, Cats, line);
+		if (ltype == GV_POINT)
+		    npoints++;
+		else if (ltype == GV_LINE)
+		    nlines++;
+
+	    }
+	    gettimeofday(&end_time, NULL);
+	    
+	    diff = (double) end_time.tv_usec - start_time.tv_usec;
+	    if (diff > 0)
+		sdiff += end_time.tv_usec - start_time.tv_usec;
+	    else
+		G_debug(1, "%f", diff); /* ??? */
+	}
+    }
+    
+    if (npoints > 0)
+	fprintf(stdout, "npoints=");
+    if (nlines > 0)
+	fprintf(stdout, "nlines=");
+    if (npoints > 0 || nlines > 0) { 
+	fprintf(stdout, "%d\t%.6f\t(%s)\n", line, (sdiff / number) / 1e6,
+		Vect_maptype_info(&Map));
+    }
+    else {
+	G_message(_("No feature read"));
+    }
+    
+    Vect_close(&Map);
+
+    return (EXIT_SUCCESS);
+}


Property changes on: sandbox/martinl/v.test/main.c
___________________________________________________________________
Added: svn:mime-type
   + text/x-csrc
Added: svn:eol-style
   + native

Added: sandbox/martinl/v.test/v.test.html
===================================================================
--- sandbox/martinl/v.test/v.test.html	                        (rev 0)
+++ sandbox/martinl/v.test/v.test.html	2012-02-01 22:06:54 UTC (rev 50619)
@@ -0,0 +1,69 @@
+<h2>DESCRIPTION</h2>
+
+<em>v.test</em> is dedicated for testing feature access for vector
+maps in native or non-native external formats like PostGIS or other
+data formats linked using OGR library.
+
+<h2>EXAMPLES</h2>
+
+Testing sequential access:
+
+<div class="code"><pre>
+# sequential access on non-topological level
+v.test -s1 map
+
+# sequential access on non-topological level with type constraint
+v.test -s1 map type=line
+
+# sequential access on non-topological level with layer constraint
+v.test -s1 map layer=2
+
+# sequential access on non-topological level with region constraint
+v.test -s1r map
+
+# sequential access on topological level
+v.test -s map
+
+# sequential access on topological level with type constraint
+v.test -s map type=line
+
+# sequential access on topological level with layer constraint
+v.test -s map layer=2
+
+# sequential access on topological level with region constraint
+v.test -sr map
+</pre></div>
+
+Testing random access:
+
+<div class="code"><pre>
+# random access on non-topological level
+v.test -1 map
+
+# random access on non-topological level with type constraint
+v.test -1 map type=line
+
+# random access on non-topological level with layer constraint
+v.test -1 map layer=2
+
+# random access on non-topological level with region constraint
+v.test -1r map
+
+# random access on topological level
+v.test map
+
+# random access on topological level with type constraint
+v.test map type=line
+
+# random access on topological level with layer constraint
+v.test map layer=2
+
+# random access on topological level with region constraint
+v.test -r map
+</pre></div>
+
+<h2>AUTHOR</h2>
+
+Martin Landa, CTU in Prague, Czech Republic
+
+<p><i>Last changed: $Date$</i>


Property changes on: sandbox/martinl/v.test/v.test.html
___________________________________________________________________
Added: svn:mime-type
   + text/html
Added: svn:keywords
   + Author Date Id
Added: svn:eol-style
   + native


Property changes on: sandbox/martinl/v.topo.pg.out
___________________________________________________________________
Added: svn:ignore
   + OBJ.*




More information about the grass-commit mailing list