[GRASS-SVN] r71552 - grass/trunk/vector/v.out.ogr
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Oct 12 13:18:46 PDT 2017
Author: mmetz
Date: 2017-10-12 13:18:46 -0700 (Thu, 12 Oct 2017)
New Revision: 71552
Modified:
grass/trunk/vector/v.out.ogr/args.c
grass/trunk/vector/v.out.ogr/list.c
grass/trunk/vector/v.out.ogr/local_proto.h
grass/trunk/vector/v.out.ogr/main.c
grass/trunk/vector/v.out.ogr/v.out.ogr.html
Log:
v.out.ogr: +-l flag to list supported formats (sync to r.out.gdal)
Modified: grass/trunk/vector/v.out.ogr/args.c
===================================================================
--- grass/trunk/vector/v.out.ogr/args.c 2017-10-12 18:47:34 UTC (rev 71551)
+++ grass/trunk/vector/v.out.ogr/args.c 2017-10-12 20:18:46 UTC (rev 71552)
@@ -116,7 +116,7 @@
flags->multi = G_define_flag();
flags->multi->key = 'm';
- flags->multi->description =
+ flags->multi->description =
_("Export vector data as multi-features");
flags->multi->guisection = _("Creation");
@@ -127,6 +127,12 @@
"and exit. Nothing is read from input.");
flags->new->guisection = _("Creation");
+ flags->list = G_define_flag();
+ flags->list->key = 'l';
+ flags->list->description =
+ _("List supported output formats and exit");
+ flags->list->suppress_required = YES;
+
G_option_requires(flags->append, options->layer, NULL);
if (G_parser(argc, argv))
Modified: grass/trunk/vector/v.out.ogr/list.c
===================================================================
--- grass/trunk/vector/v.out.ogr/list.c 2017-10-12 18:47:34 UTC (rev 71551)
+++ grass/trunk/vector/v.out.ogr/list.c 2017-10-12 20:18:46 UTC (rev 71552)
@@ -1,3 +1,5 @@
+#include "gdal.h"
+#include <grass/glocale.h>
#include "local_proto.h"
static int cmp(const void *, const void *);
@@ -62,3 +64,46 @@
{
return (strcmp(*(char **)a, *(char **)b));
}
+
+void list_formats(void)
+{
+ int iDriver;
+
+ G_message(_("Supported formats:"));
+
+#if GDAL_VERSION_NUM >= 2000000
+ for (iDriver = 0; iDriver < GDALGetDriverCount(); iDriver++) {
+ GDALDriverH hDriver = GDALGetDriver(iDriver);
+ const char *pszRWFlag;
+
+ if (!GDALGetMetadataItem(hDriver, GDAL_DCAP_VECTOR, NULL))
+ continue;
+
+ if (GDALGetMetadataItem(hDriver, GDAL_DCAP_CREATE, NULL))
+ pszRWFlag = "rw+";
+ else if (GDALGetMetadataItem(hDriver, GDAL_DCAP_CREATECOPY, NULL))
+ pszRWFlag = "rw";
+ else
+ continue;
+
+ fprintf(stdout, " %s (%s): %s\n",
+ GDALGetDriverShortName(hDriver),
+ pszRWFlag, GDALGetDriverLongName(hDriver));
+ }
+
+#else
+ for (iDriver = 0; iDriver < OGRGetDriverCount(); iDriver++) {
+ OGRSFDriverH poDriver = OGRGetDriver(iDriver);
+ const char *pszRWFlag;
+
+ if (OGR_Dr_TestCapability(poDriver, ODrCCreateDataSource))
+ pszRWFlag = "rw";
+ else
+ continue;
+
+ fprintf(stdout, " %s (%s): %s\n",
+ OGR_Dr_GetName(poDriver),
+ pszRWFlag, OGR_Dr_GetName(poDriver));
+ }
+#endif
+}
Modified: grass/trunk/vector/v.out.ogr/local_proto.h
===================================================================
--- grass/trunk/vector/v.out.ogr/local_proto.h 2017-10-12 18:47:34 UTC (rev 71551)
+++ grass/trunk/vector/v.out.ogr/local_proto.h 2017-10-12 20:18:46 UTC (rev 71552)
@@ -16,7 +16,8 @@
};
struct Flags {
- struct Flag *cat, *esristyle, *update, *nocat, *new, *append, *force2d, *multi;
+ struct Flag *cat, *esristyle, *update, *nocat, *new, *append,
+ *force2d, *multi, *list;
};
/* args.c */
@@ -33,6 +34,7 @@
/* list.c */
char *OGR_list_write_drivers();
+void list_formats(void);
/* create.c */
void create_ogr_layer(const char *, const char *, const char *,
Modified: grass/trunk/vector/v.out.ogr/main.c
===================================================================
--- grass/trunk/vector/v.out.ogr/main.c 2017-10-12 18:47:34 UTC (rev 71551)
+++ grass/trunk/vector/v.out.ogr/main.c 2017-10-12 20:18:46 UTC (rev 71552)
@@ -90,7 +90,12 @@
/* parse & read options */
parse_args(argc, argv, &options, &flags);
-
+
+ if (flags.list->answer) {
+ list_formats();
+ exit(EXIT_SUCCESS);
+ }
+
/* check for weird options */
if (G_strncasecmp(options.dsn->answer, "PG:", 3) == 0 &&
strcmp(options.format->answer, "PostgreSQL") != 0)
Modified: grass/trunk/vector/v.out.ogr/v.out.ogr.html
===================================================================
--- grass/trunk/vector/v.out.ogr/v.out.ogr.html 2017-10-12 18:47:34 UTC (rev 71551)
+++ grass/trunk/vector/v.out.ogr/v.out.ogr.html 2017-10-12 20:18:46 UTC (rev 71552)
@@ -24,6 +24,8 @@
<li>... and many others</li>
</ul>
+The list of supported formats is printed with the <em>-l</em> flag.
+
<p>
For further available other supported formats go
<a href="http://www.gdal.org/ogr_formats.html">here</a>.
More information about the grass-commit
mailing list