[GRASS-SVN] r44479 - in grass/trunk/vector: . v.external.out
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Nov 29 06:15:31 EST 2010
Author: martinl
Date: 2010-11-29 03:15:31 -0800 (Mon, 29 Nov 2010)
New Revision: 44479
Added:
grass/trunk/vector/v.external.out/
grass/trunk/vector/v.external.out/Makefile
grass/trunk/vector/v.external.out/args.c
grass/trunk/vector/v.external.out/format.c
grass/trunk/vector/v.external.out/link.c
grass/trunk/vector/v.external.out/list.c
grass/trunk/vector/v.external.out/local_proto.h
grass/trunk/vector/v.external.out/main.c
grass/trunk/vector/v.external.out/status.c
grass/trunk/vector/v.external.out/v.external.out.html
Log:
new module v.external.out (based on r.external.out)
TODO: update vlib to use output settings
Property changes on: grass/trunk/vector/v.external.out
___________________________________________________________________
Added: svn:ignore
+ OBJ.*
Added: grass/trunk/vector/v.external.out/Makefile
===================================================================
--- grass/trunk/vector/v.external.out/Makefile (rev 0)
+++ grass/trunk/vector/v.external.out/Makefile 2010-11-29 11:15:31 UTC (rev 44479)
@@ -0,0 +1,15 @@
+MODULE_TOPDIR = ../..
+
+PGM=v.external.out
+
+LIBES = $(VECTORLIB) $(GISLIB) $(GDALLIBS)
+DEPENDENCIES = $(VECTORDEP) $(GISDEP)
+
+EXTRA_INC = $(VECT_INC)
+EXTRA_CFLAGS = $(VECT_CFLAGS)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+ifneq ($(USE_OGR),)
+default: cmd
+endif
Property changes on: grass/trunk/vector/v.external.out/Makefile
___________________________________________________________________
Added: svn:mime-type
+ text/x-makefile
Added: svn:eol-style
+ native
Added: grass/trunk/vector/v.external.out/args.c
===================================================================
--- grass/trunk/vector/v.external.out/args.c (rev 0)
+++ grass/trunk/vector/v.external.out/args.c 2010-11-29 11:15:31 UTC (rev 44479)
@@ -0,0 +1,58 @@
+#include <stdlib.h>
+
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
+#include "local_proto.h"
+
+void parse_args(int argc, char **argv,
+ struct _options *options, struct _flags *flags)
+{
+ options->dir = G_define_option();
+ options->dir->key = "directory";
+ options->dir->description = _("Name of output directory");
+ options->dir->required = YES;
+ options->dir->type = TYPE_STRING;
+ options->dir->key_desc = "path";
+
+ options->ext = G_define_option();
+ options->ext->key = "extension";
+ options->ext->description = _("Extension for output files");
+ options->ext->required = NO;
+ options->ext->type = TYPE_STRING;
+
+ options->format = G_define_option();
+ options->format->key = "format";
+ options->format->description = _("Format of output files");
+ options->format->required = YES;
+ options->format->type = TYPE_STRING;
+ options->format->options = format_list();
+ options->format->answer = "ESRI Shapefile";
+
+ options->opts = G_define_option();
+ options->opts->key = "options";
+ options->opts->description = _("Creation options");
+ options->opts->required = NO;
+ options->opts->multiple = YES;
+ options->opts->type = TYPE_STRING;
+
+ flags->f = G_define_flag();
+ flags->f->key = 'f';
+ flags->f->description = _("List supported formats and exit");
+ flags->f->guisection = _("Print");
+ flags->f->suppress_required = YES;
+
+ flags->r = G_define_flag();
+ flags->r->key = 'r';
+ flags->r->description = _("Cease using OGR and revert to native output");
+ flags->r->suppress_required = YES;
+
+ flags->p = G_define_flag();
+ flags->p->key = 'p';
+ flags->p->description = _("Print current status");
+ flags->p->guisection = _("Print");
+ flags->p->suppress_required = YES;
+
+ if (G_parser(argc, argv))
+ exit(EXIT_FAILURE);
+}
Property changes on: grass/trunk/vector/v.external.out/args.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Added: grass/trunk/vector/v.external.out/format.c
===================================================================
--- grass/trunk/vector/v.external.out/format.c (rev 0)
+++ grass/trunk/vector/v.external.out/format.c 2010-11-29 11:15:31 UTC (rev 44479)
@@ -0,0 +1,17 @@
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
+#include "ogr_api.h"
+
+void check_format(const char *format)
+{
+ OGRSFDriverH driver = OGRGetDriverByName(format);
+
+ if (!driver)
+ G_fatal_error(_("Format <%s> not supported"), format);
+
+ if (OGR_Dr_TestCapability(driver, ODrCCreateDataSource))
+ return;
+
+ G_fatal_error(_("Format <%s> does not support writing"), format);
+}
Property changes on: grass/trunk/vector/v.external.out/format.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Added: grass/trunk/vector/v.external.out/link.c
===================================================================
--- grass/trunk/vector/v.external.out/link.c (rev 0)
+++ grass/trunk/vector/v.external.out/link.c 2010-11-29 11:15:31 UTC (rev 44479)
@@ -0,0 +1,59 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
+void make_link(const char *dir, const char *ext,
+ const char *format, char **options)
+{
+ struct Key_Value *key_val = G_create_key_value();
+ char *opt_str = NULL;
+ FILE *fp;
+
+ if (options && *options) {
+ int n_opts = 0, opt_len = 0, i;
+ char *p;
+
+ for (i = 0; options[i]; i++) {
+ n_opts++;
+ opt_len += strlen(options[i]) + 1;
+ }
+
+ opt_str = G_malloc(opt_len);
+ p = opt_str;
+
+ for (i = 0; i < n_opts; i++) {
+ if (i > 0)
+ *p++ = ',';
+ strcpy(p, options[i]);
+ p += strlen(options[i]);
+ }
+ *p++ = '\0';
+ }
+
+ if (ext && ext[0] != '.') {
+ char *p;
+
+ G_asprintf(&p, ".%s", ext);
+ ext = p;
+ }
+
+ if (dir)
+ G_set_key_value("directory", dir, key_val);
+ if (ext)
+ G_set_key_value("extension", ext, key_val);
+ if (format)
+ G_set_key_value("format", format, key_val);
+ if (opt_str)
+ G_set_key_value("options", opt_str, key_val);
+
+ fp = G_fopen_new("", "OGR");
+ if (!fp)
+ G_fatal_error(_("Unable to create OGR file"));
+
+ if (G_fwrite_key_value(fp, key_val) < 0)
+ G_fatal_error(_("Error writing OGR file"));
+
+ fclose(fp);
+}
Property changes on: grass/trunk/vector/v.external.out/link.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Added: grass/trunk/vector/v.external.out/list.c
===================================================================
--- grass/trunk/vector/v.external.out/list.c (rev 0)
+++ grass/trunk/vector/v.external.out/list.c 2010-11-29 11:15:31 UTC (rev 44479)
@@ -0,0 +1,65 @@
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
+#include "ogr_api.h"
+
+char *format_list(void)
+{
+ char *buf, *p;
+ int len = 0;
+ char first = TRUE;
+ int i;
+
+ for (i = 0; i < OGRGetDriverCount(); i++) {
+ OGRSFDriverH driver = OGRGetDriver(i);
+
+ if (!OGR_Dr_TestCapability(driver, ODrCCreateDataSource))
+ continue;
+
+ len += strlen(OGR_Dr_GetName(driver)) + 1;
+ }
+
+ buf = G_malloc(len);
+ p = buf;
+
+ for (i = 0; i < OGRGetDriverCount(); i++) {
+ OGRSFDriverH driver = OGRGetDriver(i);
+ const char *name;
+
+ if (!OGR_Dr_TestCapability(driver, ODrCCreateDataSource))
+ continue;
+
+ if (first)
+ first = FALSE;
+ else
+ *p++ = ',';
+
+ name = OGR_Dr_GetName(driver);
+ strcpy(p, name);
+ p += strlen(name);
+ }
+ *p++ = '\0';
+
+ return buf;
+}
+
+void list_formats(void)
+{
+ /* -------------------------------------------------------------------- */
+ /* List supported formats and exit. */
+ /* code from GDAL 1.2.5 gcore/gdal_misc.cpp */
+ /* Copyright (c) 1999, Frank Warmerdam */
+ /* -------------------------------------------------------------------- */
+ int iDr;
+
+ G_message(_("Supported Formats:"));
+ for (iDr = 0; iDr < OGRGetDriverCount(); iDr++) {
+ OGRSFDriverH driver = OGRGetDriver(iDr);
+
+ if (!OGR_Dr_TestCapability(driver, ODrCCreateDataSource))
+ continue;
+
+ fprintf(stdout, " %s\n", OGR_Dr_GetName(driver));
+ }
+ fflush(stdout);
+}
Property changes on: grass/trunk/vector/v.external.out/list.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Added: grass/trunk/vector/v.external.out/local_proto.h
===================================================================
--- grass/trunk/vector/v.external.out/local_proto.h (rev 0)
+++ grass/trunk/vector/v.external.out/local_proto.h 2010-11-29 11:15:31 UTC (rev 44479)
@@ -0,0 +1,30 @@
+#ifndef V_EXTERNAL_OUT_LOCAL_PROTO_H
+#define V_EXTERNAL_OUT_LOCAL_PROTO_H
+
+struct _options {
+ struct Option *dir, *ext, *format, *opts;
+};
+
+struct _flags {
+ struct Flag *f, *p, *r;
+};
+
+/* args.c */
+void parse_args(int, char **,
+ struct _options *, struct _flags*);
+
+/* format.c */
+void check_format(const char *);
+
+/* link.c */
+void make_link(const char *, const char *,
+ const char *, char **);
+
+/* list.c */
+char *format_list(void);
+void list_formats(void);
+
+/* status.c */
+void print_status(void);
+
+#endif
Property changes on: grass/trunk/vector/v.external.out/local_proto.h
___________________________________________________________________
Added: svn:mime-type
+ text/x-chdr
Added: svn:eol-style
+ native
Added: grass/trunk/vector/v.external.out/main.c
===================================================================
--- grass/trunk/vector/v.external.out/main.c (rev 0)
+++ grass/trunk/vector/v.external.out/main.c 2010-11-29 11:15:31 UTC (rev 44479)
@@ -0,0 +1,68 @@
+
+/****************************************************************
+ *
+ * MODULE: v.external.out
+ *
+ * AUTHOR(S): Martin Landa <landa.martin gmail.com> (based on r.external.out code)
+ *
+ * PURPOSE: Make GRASS write vector maps utilizing the OGR library.
+ *
+ * COPYRIGHT: (C) 2010 by Martin Landa and 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 <grass/config.h>
+#include <grass/gis.h>
+#include <grass/vector.h>
+#include <grass/glocale.h>
+
+#include "ogr_api.h"
+#include "local_proto.h"
+
+int main(int argc, char *argv[])
+{
+ struct GModule *module;
+ struct _options options;
+ struct _flags flags;
+
+ G_gisinit(argv[0]);
+
+ module = G_define_module();
+ G_add_keyword(_("vector"));
+ G_add_keyword(_("output"));
+ G_add_keyword(_("external"));
+
+ module->description =
+ _("Defines vector output format utilizing OGR library.");
+
+ OGRRegisterAll();
+
+ parse_args(argc, argv, &options, &flags);
+
+ if (flags.p->answer) {
+ print_status();
+ exit(EXIT_SUCCESS);
+ }
+
+ if (flags.f->answer) {
+ list_formats();
+ exit(EXIT_SUCCESS);
+ }
+
+ if (flags.r->answer) {
+ G_remove("", "OGR");
+ exit(EXIT_SUCCESS);
+ }
+
+ if (options.format->answer)
+ check_format(options.format->answer);
+
+ make_link(options.dir->answer, options.ext->answer,
+ options.format->answer, options.opts->answers);
+
+ exit(EXIT_SUCCESS);
+}
Property changes on: grass/trunk/vector/v.external.out/main.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Added: grass/trunk/vector/v.external.out/status.c
===================================================================
--- grass/trunk/vector/v.external.out/status.c (rev 0)
+++ grass/trunk/vector/v.external.out/status.c 2010-11-29 11:15:31 UTC (rev 44479)
@@ -0,0 +1,38 @@
+#include <stdlib.h>
+
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
+void print_status(void)
+{
+ FILE *fp;
+ struct Key_Value *key_val;
+ const char *p;
+
+ if (!G_find_file2("", "OGR", G_mapset())) {
+ fprintf(stdout, _("Not using OGR\n"));
+ return;
+ }
+
+ fp = G_fopen_old("", "OGR", G_mapset());
+ if (!fp)
+ G_fatal_error(_("Unable to open OGR file"));
+ key_val = G_fread_key_value(fp);
+ fclose(fp);
+
+ p = G_find_key_value("directory", key_val);
+ fprintf(stdout, _("directory: %s\n"),
+ p ? p : _("not set (default 'ogr')"));
+
+ p = G_find_key_value("extension", key_val);
+ fprintf(stdout, _("extension: %s\n"), p ? p : _("<none>"));
+
+ p = G_find_key_value("format", key_val);
+ fprintf(stdout, _("format: %s\n"),
+ p ? p : _("not set (default ESRI_Shapefile)"));
+
+ p = G_find_key_value("options", key_val);
+ fprintf(stdout, _("options: %s\n"), p ? p : _("<none>"));
+
+ G_free_key_value(key_val);
+}
Property changes on: grass/trunk/vector/v.external.out/status.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Added: grass/trunk/vector/v.external.out/v.external.out.html
===================================================================
--- grass/trunk/vector/v.external.out/v.external.out.html (rev 0)
+++ grass/trunk/vector/v.external.out/v.external.out.html 2010-11-29 11:15:31 UTC (rev 44479)
@@ -0,0 +1,41 @@
+<h2>DESCRIPTION</h2>
+
+<em>v.external.out</em> instructs GRASS to write vector maps as data
+files (e.g. ESRI Shapefile) using OGR library.
+
+<h2>EXAMPLE</h2>
+
+The module <em>v.external.out</em> can be used along with
+<em><a href="v.external.html">v.external</a></em> to process external
+geodata in GRASS while writing out the results directly in ESRI
+Shapefile format:
+
+<div class="code"><pre>
+# register Shapefile in GRASS database:
+v.external dsn=cities.shp output=cities
+
+# define output directory for GRASS calculation results:
+v.external.out directory=$HOME/gisoutput/
+
+# do something (here: spatial query), write output directly as Shapefile
+v.select ainput=cities atype=point binput=forests btype=area operator=within output=fcities
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+ <a href="v.in.ogr.html">v.in.ogr</a>,
+ <a href="v.out.ogr.html">v.out.ogr</a>,
+ <a href="v.external.html">v.external</a>
+</em>
+
+<h2>REFERENCES</h2>
+
+OGR Pages: <a href="http://www.gdal.osgeo.org/ogr">http://www.gdal.osgeo.org/ogr</a>
+
+<h2>AUTHOR</h2>
+
+Martin Landa, CTU in Prague, Czech Republic (based on r.external.out code)
+
+<p>
+<i>Last changed: $Date$</i>
Property changes on: grass/trunk/vector/v.external.out/v.external.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