Prechádzať zdrojové kódy

v.out.svg: OGR support (read access)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@39885 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 15 rokov pred
rodič
commit
b1d4b3b811
1 zmenil súbory, kde vykonal 19 pridanie a 15 odobranie
  1. 19 15
      vector/v.out.svg/main.c

+ 19 - 15
vector/v.out.svg/main.c

@@ -4,13 +4,14 @@
  * MODULE:       v.out.svg
  * AUTHOR(S):    Original author Klaus Foerster
  *               Klaus Foerster - klaus.foerster@uibk.ac.at
+ *               OGR support by Martin Landa <landa.martin gmail.com> (2009)
  * PURPOSE:      Export GRASS vector map to SVG with custom
  *               coordinate-precision and optional attributes
- * COPYRIGHT:    (C) 2006 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2006-2009 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.
+ *               This program is free software under the GNU General
+ *               Public License (>=v2). Read the file COPYING that
+ *               comes with GRASS for details.
  *
  *****************************************************************************/
 
@@ -68,12 +69,14 @@ int main(int argc, char *argv[])
 
     /* parse command-line */
     module = G_define_module();
-    module->description = _("Exports a GRASS vector map to SVG.");
+    module->description = _("Exports a vector map to SVG file.");
     G_add_keyword(_("vector"));
     G_add_keyword(_("export"));
 
     in_opt = G_define_standard_option(G_OPT_V_INPUT);
 
+    field_opt = G_define_standard_option(G_OPT_V_FIELD);
+
     out_opt = G_define_standard_option(G_OPT_F_OUTPUT);
     out_opt->description = _("Name for SVG output file");
 
@@ -95,15 +98,12 @@ int main(int argc, char *argv[])
     prec_opt->multiple = NO;
     prec_opt->description = _("Coordinate precision");
 
-    attr_opt = G_define_option();
+    attr_opt = G_define_standard_option(G_OPT_DB_COLUMNS);
     attr_opt->key = "attribute";
-    attr_opt->type = TYPE_STRING;
     attr_opt->required = NO;
     attr_opt->multiple = YES;
     attr_opt->description = _("Attribute(s) to include in output SVG");
-
-    field_opt = G_define_standard_option(G_OPT_V_FIELD);
-
+    
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
@@ -119,12 +119,12 @@ int main(int argc, char *argv[])
 	G_fatal_error(_("Precision must not be higher than 15"));
     }
 
-    /* parse field number */
-    field = atoi(field_opt->answer);
-
     /* open input vector */
     Vect_set_open_level(2);
-    Vect_open_old(&In, in_opt->answer, "");
+    Vect_open_old2(&In, in_opt->answer, "", field_opt->answer);
+
+    /* parse field number */
+    field = Vect_get_field_number(&In, field_opt->answer);
 
     /* open db-driver to attribs */
     db_init_string(&dbstring);
@@ -183,7 +183,7 @@ int main(int argc, char *argv[])
 
     /* open output SVG-file and print SVG-header with viewBox and Namenspaces */
     if ((fpsvg = fopen(out_opt->answer, "w")) == NULL) {
-	G_fatal_error(_("Unable to open SVG file <%s>"), out_opt->answer);
+	G_fatal_error(_("Unable to create SVG file <%s>"), out_opt->answer);
     }
 
     fprintf(fpsvg, "<svg xmlns=\"%s\" xmlns:xlink=\"%s\" xmlns:gg=\"%s\" ",
@@ -250,6 +250,8 @@ int main(int argc, char *argv[])
 	    for (i = 1; i <= Vect_get_num_primitives(&In, GV_POINTS); i++) {
 		G_percent(i, Vect_get_num_primitives(&In, GV_POINTS), 10);
 		Vect_read_line(&In, Points, Cats, i);
+		if (field > 0 && !Vect_cat_get(Cats, field, NULL))
+		    continue;
 		for (j = 0; j < Points->n_points; j++) {
 		    fprintf(fpsvg, "  <circle ");
 		    if (Cats->n_cats > 0) {
@@ -306,6 +308,8 @@ int main(int argc, char *argv[])
     /* close SVG-file */
     fclose(fpsvg);
 
+    G_done_msg(" ");
+    
     exit(EXIT_SUCCESS);
 }