GRASS Programmer's Manual 6.4.1(2011)
|
00001 /* 00002 **************************************************************************** 00003 * 00004 * MODULE: Vector library 00005 * 00006 * AUTHOR(S): Radim Blazek 00007 * 00008 * PURPOSE: Lower level functions for reading/writing/manipulating vectors. 00009 * 00010 * COPYRIGHT: (C) 2001 by the GRASS Development Team 00011 * 00012 * This program is free software under the GNU General Public 00013 * License (>=v2). Read the file COPYING that comes with GRASS 00014 * for details. 00015 * 00016 *****************************************************************************/ 00017 #include <string.h> 00018 #include <stdio.h> 00019 #include <grass/Vect.h> 00020 #include <grass/gis.h> 00021 00022 /* Read vector format. 00023 * 00024 * Returns: format number 00025 * -1 on error 00026 */ 00027 int dig_read_frmt_ascii(FILE * dascii, struct Format_info *finfo) 00028 { 00029 char buff[20001], buf1[1024]; 00030 char *ptr; 00031 int frmt = -1; 00032 00033 G_debug(3, "dig_read_frmt_ascii()"); 00034 00035 /* read first line which must be FORMAT: */ 00036 if (G_getl2(buff, 2000, dascii)) { 00037 G_chop(buff); 00038 00039 if (!(ptr = G_index(buff, ':'))) { 00040 G_warning("Vector format not recognized: %s", buff); 00041 return (-1); 00042 } 00043 00044 strcpy(buf1, buff); 00045 buf1[ptr - buff] = '\0'; 00046 00047 ptr++; /* Search for the start of text */ 00048 while (*ptr == ' ') 00049 ptr++; 00050 00051 if (strcmp(buf1, "FORMAT") == 0) { 00052 if (G_strcasecmp(ptr, "ogr") == 0) { 00053 frmt = GV_FORMAT_OGR; 00054 } 00055 } 00056 } 00057 if (frmt == -1) { 00058 G_warning("Vector format not recognized: %s", buff); 00059 return (-1); 00060 } 00061 00062 /* init format info values */ 00063 #ifdef HAVE_OGR 00064 finfo->ogr.dsn = NULL; 00065 finfo->ogr.layer_name = NULL; 00066 #endif 00067 00068 while (G_getl2(buff, 2000, dascii)) { 00069 G_chop(buff); 00070 00071 if (!(ptr = G_index(buff, ':'))) { 00072 G_warning("Format definition is not correct: %s", buff); 00073 continue; 00074 } 00075 00076 strcpy(buf1, buff); 00077 buf1[ptr - buff] = '\0'; 00078 00079 ptr++; /* Search for the start of text */ 00080 while (*ptr == ' ') 00081 ptr++; 00082 00083 #ifdef HAVE_OGR 00084 if (strcmp(buf1, "DSN") == 0) 00085 finfo->ogr.dsn = G_store(ptr); 00086 if (strcmp(buf1, "LAYER") == 0) 00087 finfo->ogr.layer_name = G_store(ptr); 00088 #endif 00089 } 00090 00091 return frmt; 00092 } 00093 00094 /* Write vector format, currently does not work 00095 * Parse also connection string. 00096 * 00097 * Returns: 0 OK 00098 * -1 on error 00099 */ 00100 int dig_write_frmt_ascii(FILE * dascii, struct Format_info *finfo, int format) 00101 { 00102 G_debug(3, "dig_write_frmt_ascii()"); 00103 00104 G_fatal_error("Format not supported by dig_write_frmt_ascii()"); 00105 00106 return 0; 00107 }