frmt.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. ****************************************************************************
  3. *
  4. * MODULE: Vector library
  5. *
  6. * AUTHOR(S): Radim Blazek
  7. *
  8. * PURPOSE: Lower level functions for reading/writing/manipulating vectors.
  9. *
  10. * COPYRIGHT: (C) 2001 by the GRASS Development Team
  11. *
  12. * This program is free software under the GNU General Public
  13. * License (>=v2). Read the file COPYING that comes with GRASS
  14. * for details.
  15. *
  16. *****************************************************************************/
  17. #include <grass/config.h>
  18. #include <string.h>
  19. #include <stdio.h>
  20. #include <grass/vector.h>
  21. #include <grass/gis.h>
  22. /*!
  23. \brief Read external vector format file
  24. \param dascii format file (frmt)
  25. \param[out] finfo pointer to Format_info structure
  26. \return format code
  27. \return -1 on error
  28. */
  29. int dig_read_frmt_ascii(FILE * dascii, struct Format_info *finfo)
  30. {
  31. char buff[20001], buf1[1024];
  32. char *ptr;
  33. int frmt = -1;
  34. G_debug(3, "dig_read_frmt_ascii()");
  35. /* read first line which must be FORMAT: */
  36. if (G_getl2(buff, 2000, dascii)) {
  37. G_chop(buff);
  38. if (!(ptr = strchr(buff, ':'))) {
  39. G_warning("Vector format not recognized: %s", buff);
  40. return (-1);
  41. }
  42. strcpy(buf1, buff);
  43. buf1[ptr - buff] = '\0';
  44. ptr++; /* Search for the start of text */
  45. while (*ptr == ' ')
  46. ptr++;
  47. if (strcmp(buf1, "FORMAT") == 0) {
  48. if (G_strcasecmp(ptr, "ogr") == 0) {
  49. frmt = GV_FORMAT_OGR;
  50. }
  51. }
  52. }
  53. if (frmt == -1) {
  54. G_warning("Vector format not recognized: %s", buff);
  55. return (-1);
  56. }
  57. /* init format info values */
  58. #ifdef HAVE_OGR
  59. finfo->ogr.dsn = NULL;
  60. finfo->ogr.layer_name = NULL;
  61. #endif
  62. while (G_getl2(buff, 2000, dascii)) {
  63. G_chop(buff);
  64. if (!(ptr = strchr(buff, ':'))) {
  65. G_warning("Format definition is not correct: %s", buff);
  66. continue;
  67. }
  68. strcpy(buf1, buff);
  69. buf1[ptr - buff] = '\0';
  70. ptr++; /* Search for the start of text */
  71. while (*ptr == ' ')
  72. ptr++;
  73. #ifdef HAVE_OGR
  74. if (strcmp(buf1, "DSN") == 0)
  75. finfo->ogr.dsn = G_store(ptr);
  76. if (strcmp(buf1, "LAYER") == 0)
  77. finfo->ogr.layer_name = G_store(ptr);
  78. #endif
  79. }
  80. return frmt;
  81. }
  82. /* Write vector format, currently does not work
  83. * Parse also connection string.
  84. *
  85. * Returns: 0 OK
  86. * -1 on error
  87. */
  88. int dig_write_frmt_ascii(FILE * dascii, struct Format_info *finfo, int format)
  89. {
  90. G_debug(3, "dig_write_frmt_ascii()");
  91. G_fatal_error("Format not supported by dig_write_frmt_ascii()");
  92. return 0;
  93. }