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