[GRASS-SVN] r39882 - grass/trunk/vector/v.out.dxf

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Dec 3 14:11:51 EST 2009


Author: martinl
Date: 2009-12-03 14:11:50 -0500 (Thu, 03 Dec 2009)
New Revision: 39882

Modified:
   grass/trunk/vector/v.out.dxf/main.c
Log:
v.out.dxf: OGR support (read access)


Modified: grass/trunk/vector/v.out.dxf/main.c
===================================================================
--- grass/trunk/vector/v.out.dxf/main.c	2009-12-03 18:50:41 UTC (rev 39881)
+++ grass/trunk/vector/v.out.dxf/main.c	2009-12-03 19:11:50 UTC (rev 39882)
@@ -1,26 +1,32 @@
 /*
+ ****************************************************************************
+ *
  * MODULE:      v.out.dxf
  *
  * AUTHOR(S):   Chuck Ehlschlaeger
  *              Update to GRASS 5.7 by Radim Blazek
+ *              OGR support by Martin Landa <landa.martin gmail.com>
  *
- * PURPOSE:     Convert vector maps into DXF files.  This program is a
- *              small demo and not to be taken seriously.
+ * PURPOSE:     Convert vector maps into DXF files.
  *
  * COPYRIGHT:   (C) 1989-2006 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.
+ *
+ ****************************************************************************
+*/
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+
 #include <grass/gis.h>
 #include <grass/dbmi.h>
 #include <grass/vector.h>
 #include <grass/glocale.h>
+
 #include "global.h"
 
 FILE *dxf_fp;
@@ -32,7 +38,7 @@
 
 static double do_limits(struct Map_info *);
 static int make_layername(void);
-static int add_plines(struct Map_info *, double);
+static int add_plines(struct Map_info *, int, double);
 
 int main(int argc, char *argv[])
 {
@@ -41,7 +47,7 @@
     char *dxf_file;
     struct Map_info In;
     struct GModule *module;
-    struct Option *input, *output;
+    struct Option *input, *output, *field;
 
     G_gisinit(argv[0]);
 
@@ -50,17 +56,15 @@
     G_add_keyword(_("vector"));
     G_add_keyword(_("export"));
     module->description =
-	_("Exports GRASS vector map layers to DXF file format.");
+	_("Exports vector map to DXF file format.");
 
     input = G_define_standard_option(G_OPT_V_INPUT);
 
-    output = G_define_option();
-    output->key = "output";
-    output->type = TYPE_STRING;
+    field = G_define_standard_option(G_OPT_V_FIELD);
+    
+    output = G_define_standard_option(G_OPT_F_OUTPUT);
     output->required = YES;
-    output->multiple = NO;
-    output->gisprompt = "new_file,file,output";
-    output->description = _("DXF output file");
+    output->description = _("Name for DXF output file");
 
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
@@ -71,14 +75,15 @@
     dxf_file = G_store(output->answer);
 
     Vect_set_open_level(2);
-    Vect_open_old(&In, input->answer, "");
+    Vect_open_old2(&In, input->answer, "", field->answer);
 
     dxf_open(dxf_file);		/* open output */
 
     textsize = do_limits(&In);	/* does header in dxf_fp */
     make_layername();
     dxf_entities();
-    nlines = add_plines(&In, textsize);	/* puts plines in dxf_fp */
+    nlines = add_plines(&In, Vect_get_field_number(&In, field->answer),
+			textsize);	/* puts plines in dxf_fp */
 
     dxf_endsec();
     dxf_eof();			/* puts final stuff in dxf_fp, closes file */
@@ -131,9 +136,9 @@
     return 0;
 }
 
-int add_plines(struct Map_info *Map, double textsize)
+int add_plines(struct Map_info *Map, int field, double textsize)
 {
-    int nlines, line;
+    int nlines, line, nlines_dxf;
     struct line_pnts *Points;
     struct line_cats *Cats;
     char *layer, *llayer;
@@ -144,14 +149,17 @@
     Cats = Vect_new_cats_struct();
 
     nlines = Vect_get_num_lines(Map);
-
+    nlines_dxf = 0;
     for (line = 1; line <= nlines; line++) {
 	int i, ltype;
 
 	G_percent(line, nlines, 2);
 
 	ltype = Vect_read_line(Map, Points, Cats, line);
-	Vect_cat_get(Cats, 1, &cat);
+	Vect_cat_get(Cats, field, &cat);
+	if (cat < 0)
+	    continue;
+	
 	sprintf(cat_num, "%d", cat);
 
 	if (ltype == GV_POINT) {
@@ -185,7 +193,8 @@
 
 	    dxf_poly_end(layer);
 	}
+	nlines_dxf++;
     }
 
-    return nlines;
+    return nlines_dxf;
 }



More information about the grass-commit mailing list