main.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /****************************************************************
  2. *
  3. * MODULE: v.external.out
  4. *
  5. * AUTHOR(S): Martin Landa <landa.martin gmail.com> (based on r.external.out code)
  6. *
  7. * PURPOSE: Make GRASS write vector maps utilizing the OGR library.
  8. *
  9. * COPYRIGHT: (C) 2010 by Martin Landa and the GRASS Development Team
  10. *
  11. * This program is free software under the GNU General
  12. * Public License (>=v2). Read the file COPYING that
  13. * comes with GRASS for details.
  14. *
  15. **************************************************************/
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <grass/gis.h>
  19. #include <grass/vector.h>
  20. #include <grass/glocale.h>
  21. #ifdef HAVE_OGR
  22. #include "ogr_api.h"
  23. #endif
  24. #include "local_proto.h"
  25. int main(int argc, char *argv[])
  26. {
  27. struct GModule *module;
  28. struct _options options;
  29. struct _flags flags;
  30. char * format;
  31. G_gisinit(argv[0]);
  32. module = G_define_module();
  33. G_add_keyword(_("vector"));
  34. G_add_keyword(_("export"));
  35. G_add_keyword(_("output"));
  36. G_add_keyword(_("external"));
  37. G_add_keyword("OGR");
  38. G_add_keyword("PostGIS");
  39. module->description = _("Defines vector output format.");
  40. #ifdef HAVE_OGR
  41. OGRRegisterAll();
  42. #endif
  43. parse_args(argc, argv, &options, &flags);
  44. if (flags.f->answer) {
  45. list_formats();
  46. exit(EXIT_SUCCESS);
  47. }
  48. if (flags.r->answer) {
  49. if (G_remove("", "OGR") == 0)
  50. G_remove("", "PG");
  51. exit(EXIT_SUCCESS);
  52. }
  53. format = NULL;
  54. if (options.format->answer) {
  55. format = G_store(options.format->answer);
  56. check_format(format);
  57. }
  58. if (options.dsn->answer) {
  59. make_link(options.dsn->answer, format,
  60. options.opts->answer, options.opts->answers);
  61. }
  62. if (flags.p->answer || flags.g->answer) {
  63. print_status(flags.g->answer ? 1 : 0);
  64. }
  65. exit(EXIT_SUCCESS);
  66. }