[GRASS-SVN] r47613 - in grass/trunk/vector: . v.colors.out

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Aug 14 04:38:30 EDT 2011


Author: martinl
Date: 2011-08-14 01:38:30 -0700 (Sun, 14 Aug 2011)
New Revision: 47613

Added:
   grass/trunk/vector/v.colors.out/
   grass/trunk/vector/v.colors.out/Makefile
   grass/trunk/vector/v.colors.out/local_proto.h
   grass/trunk/vector/v.colors.out/main.c
   grass/trunk/vector/v.colors.out/scan_cats.c
   grass/trunk/vector/v.colors.out/v.colors.out.html
Modified:
   grass/trunk/vector/Makefile
Log:
v.colors.out implemented


Modified: grass/trunk/vector/Makefile
===================================================================
--- grass/trunk/vector/Makefile	2011-08-14 08:33:11 UTC (rev 47612)
+++ grass/trunk/vector/Makefile	2011-08-14 08:38:30 UTC (rev 47613)
@@ -11,6 +11,7 @@
 	v.class \
 	v.clean \
 	v.colors \
+	v.colors.out \
 	v.convert \
 	v.db.connect \
 	v.db.select \


Property changes on: grass/trunk/vector/v.colors.out
___________________________________________________________________
Added: svn:ignore
   + OBJ.*


Added: grass/trunk/vector/v.colors.out/Makefile
===================================================================
--- grass/trunk/vector/v.colors.out/Makefile	                        (rev 0)
+++ grass/trunk/vector/v.colors.out/Makefile	2011-08-14 08:38:30 UTC (rev 47613)
@@ -0,0 +1,12 @@
+MODULE_TOPDIR = ../..
+
+PGM = v.colors.out
+
+LIBES = $(VECTORLIB) $(GISLIB) $(RASTERLIB)
+DEPENDENCIES = $(VECTORDEP) $(GISDEP) $(RASTERDEP)
+EXTRA_INC = $(VECT_INC)
+EXTRA_CFLAGS = $(VECT_CFLAGS)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd


Property changes on: grass/trunk/vector/v.colors.out/Makefile
___________________________________________________________________
Added: svn:mime-type
   + text/x-makefile
Added: svn:eol-style
   + native

Added: grass/trunk/vector/v.colors.out/local_proto.h
===================================================================
--- grass/trunk/vector/v.colors.out/local_proto.h	                        (rev 0)
+++ grass/trunk/vector/v.colors.out/local_proto.h	2011-08-14 08:38:30 UTC (rev 47613)
@@ -0,0 +1,2 @@
+/* scan_cats.c */
+void scan_cats(const char *, const char *, int *, int *);


Property changes on: grass/trunk/vector/v.colors.out/local_proto.h
___________________________________________________________________
Added: svn:mime-type
   + text/x-chdr
Added: svn:eol-style
   + native

Added: grass/trunk/vector/v.colors.out/main.c
===================================================================
--- grass/trunk/vector/v.colors.out/main.c	                        (rev 0)
+++ grass/trunk/vector/v.colors.out/main.c	2011-08-14 08:38:30 UTC (rev 47613)
@@ -0,0 +1,95 @@
+
+/****************************************************************************
+ *
+ * MODULE:       v.colors.out
+ *
+ * AUTHOR(S):    Modified r.colors.out by Martin Landa <landa.martin gmail.com>
+ *
+ * PURPOSE:      Allows export of the color table for a vector map.
+ *
+ * COPYRIGHT:    (C) 2011 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 <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/vector.h>
+#include <grass/glocale.h>
+
+#include "local_proto.h"
+
+int main(int argc, char **argv)
+{    
+    struct GModule *module;
+    struct
+    {
+	struct Option *map, *field, *file;
+    } opt;
+    struct
+    {
+	struct Flag *p;
+    } flag;
+    struct Colors colors;
+    
+    int min, max;
+    const char *file, *name, *layer;
+    FILE *fp;
+    
+    G_gisinit(argv[0]);
+
+    module = G_define_module();
+    G_add_keyword(_("vector"));
+    G_add_keyword(_("color table"));
+    G_add_keyword(_("export"));
+    module->description =
+	_("Exports the color table associated with a vector map.");
+   
+    opt.map = G_define_standard_option(G_OPT_V_MAP);
+    
+    opt.field = G_define_standard_option(G_OPT_V_FIELD);
+    
+    opt.file = G_define_standard_option(G_OPT_F_OUTPUT);
+    opt.file->key = "rules";
+    opt.file->label = _("Path to output rules file");
+    opt.file->description = _("\"-\" to write to stdout");
+    opt.file->answer = "-";
+    
+    flag.p = G_define_flag();
+    flag.p->key = 'p';
+    flag.p->description = _("Output values as percentages");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    name = opt.map->answer;
+    layer = opt.field->answer;
+    file = opt.file->answer;
+    
+    if (Vect_read_colors(name, "", &colors) < 0)
+	G_fatal_error(_("Unable to read color table for vector map <%s>"),
+		      opt.map->answer);
+    
+    min = max = -1;
+    if (flag.p->answer) {
+	scan_cats(name, layer, &min, &max);
+    }
+    
+    if (!file || strcmp(file, "-") == 0)
+	fp = stdout;
+    else {
+	fp = fopen(file, "w");
+	if (!fp)
+	    G_fatal_error(_("Unable to open output file <%s>"), file);
+    }
+    
+    Rast_print_colors(&colors, (DCELL) min, (DCELL) max, fp,
+		      flag.p->answer ? 1 : 0);
+    
+    exit(EXIT_SUCCESS);
+}


Property changes on: grass/trunk/vector/v.colors.out/main.c
___________________________________________________________________
Added: svn:mime-type
   + text/x-csrc
Added: svn:eol-style
   + native

Added: grass/trunk/vector/v.colors.out/scan_cats.c
===================================================================
--- grass/trunk/vector/v.colors.out/scan_cats.c	                        (rev 0)
+++ grass/trunk/vector/v.colors.out/scan_cats.c	2011-08-14 08:38:30 UTC (rev 47613)
@@ -0,0 +1,58 @@
+#include <grass/vector.h>
+#include <grass/glocale.h>
+
+#include "local_proto.h"
+
+static void scan_layer(int, const struct line_cats *, int *, int *);
+
+void scan_cats(const char *name, const char *layer,
+	       int *cmin, int *cmax)
+{
+    int ltype, lmin, lmax, ilayer;
+
+    struct Map_info Map;
+    struct line_cats *Cats;
+
+    *cmin = *cmax = -1;
+
+    Vect_open_old2(&Map, name, "", layer);
+    ilayer = Vect_get_field_number(&Map, layer);
+    if (ilayer < 1)
+	G_fatal_error(_("Layer <%s> not found"), layer);
+
+    Cats = Vect_new_cats_struct();
+
+    G_message(_("Reading features..."));
+    while(TRUE) {
+	ltype = Vect_read_next_line(&Map, NULL, Cats);
+	if (ltype == -1)
+	    G_fatal_error(_("Unable to read vector map"));
+	if (ltype == -2)
+	    break; /* EOF */
+
+	scan_layer(ilayer, Cats, &lmin, &lmax);
+
+	if (*cmin == -1 || lmin <= *cmin)
+	    *cmin = lmin;
+	if (*cmax == -1 || lmax >= *cmax)
+	    *cmax = lmax;
+    }
+
+    Vect_destroy_cats_struct(Cats);
+}
+
+void scan_layer(int field, const struct line_cats *Cats, int *cmin, int *cmax)
+{
+    int n, cat;
+
+    *cmin = *cmax = -1;
+    for (n = 0; n < Cats->n_cats; n++) {
+        if (Cats->field[n] == field) {
+	    cat = Cats->cat[n];
+	    if (*cmin == -1 || cat <= *cmin)
+		*cmin = cat;
+	    if (*cmax == -1 || cat >= *cmax)
+		*cmax = cat;
+        }
+    }
+}


Property changes on: grass/trunk/vector/v.colors.out/scan_cats.c
___________________________________________________________________
Added: svn:mime-type
   + text/x-csrc
Added: svn:eol-style
   + native

Added: grass/trunk/vector/v.colors.out/v.colors.out.html
===================================================================
--- grass/trunk/vector/v.colors.out/v.colors.out.html	                        (rev 0)
+++ grass/trunk/vector/v.colors.out/v.colors.out.html	2011-08-14 08:38:30 UTC (rev 47613)
@@ -0,0 +1,29 @@
+<h2>DESCRIPTION</h2>
+
+<em>v.colors.out</em> allows the user to export the color table for a
+vector map to a file which is suitable as input
+to <em><a href="v.colors.html">v.colors</a></em>.
+
+<h2>EXAMPLES</h2>
+
+<div class="code"><pre>
+v.colors.out map=soils_general rules=rules.txt
+v.colors map=soils_wake rules=rules.txt
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+  <a href="v.colors.html">v.colors</a>,
+  <a href="r.colors.html">r.colors</a>,
+  <a href="r3.colors.html">r3.colors</a>,
+  <a href="r.colors.out.html">r.colors.out</a>,
+  <a href="r3.colors.out.html">r3.colors.out</a>,
+</em>
+
+<h2>AUTHOR</h2>
+
+Martin Landa, Czech Technical University in Prague, Czech Republic
+
+<p>
+<i>Last changed: $Date$</i>


Property changes on: grass/trunk/vector/v.colors.out/v.colors.out.html
___________________________________________________________________
Added: svn:mime-type
   + text/html
Added: svn:keywords
   + Author Date Id
Added: svn:eol-style
   + native



More information about the grass-commit mailing list