close_ogr.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <grass/Vect.h>
00018 #include <stdlib.h>
00019
00020 #ifdef HAVE_OGR
00021 #include <ogr_api.h>
00022
00023
00024
00025
00026
00027 int V1_close_ogr(struct Map_info *Map)
00028 {
00029 int i;
00030
00031 if (!VECT_OPEN(Map))
00032 return -1;
00033
00034 if (Map->mode == GV_MODE_WRITE || Map->mode == GV_MODE_RW)
00035 Vect__write_head(Map);
00036
00037 if (Map->fInfo.ogr.feature_cache)
00038 OGR_F_Destroy(Map->fInfo.ogr.feature_cache);
00039
00040 OGR_DS_Destroy(Map->fInfo.ogr.ds);
00041
00042 for (i = 0; i < Map->fInfo.ogr.lines_alloc; i++) {
00043 Vect_destroy_line_struct(Map->fInfo.ogr.lines[i]);
00044 }
00045
00046 free(Map->fInfo.ogr.lines);
00047 free(Map->fInfo.ogr.lines_types);
00048
00049 free(Map->fInfo.ogr.dsn);
00050 free(Map->fInfo.ogr.layer_name);
00051
00052 return 0;
00053 }
00054
00055
00056
00057
00058
00059
00060
00061 int V2_close_ogr(struct Map_info *Map)
00062 {
00063 char fname[1000], elem[1000];
00064 char buf[5];
00065 long length = 9;
00066 GVFILE fp;
00067 struct Port_info port;
00068
00069 G_debug(3, "V2_close_ogr()");
00070
00071 if (!VECT_OPEN(Map))
00072 return -1;
00073
00074 if (strcmp(Map->mapset, G_mapset()) == 0 && Map->support_updated &&
00075 Map->plus.built == GV_BUILD_ALL) {
00076 sprintf(elem, "%s/%s", GRASS_VECT_DIRECTORY, Map->name);
00077 G__file_name(fname, elem, "fidx", Map->mapset);
00078 G_debug(4, "Open fidx: %s", fname);
00079 dig_file_init(&fp);
00080 fp.file = fopen(fname, "w");
00081 if (fp.file == NULL) {
00082 G_warning("Can't open fidx file for write: %s\n", fname);
00083 return 1;
00084 }
00085
00086 dig_init_portable(&port, dig__byte_order_out());
00087 dig_set_cur_port(&port);
00088
00089
00090
00091 buf[0] = 5;
00092 buf[1] = 0;
00093 buf[2] = 5;
00094 buf[3] = 0;
00095 buf[4] = (char)dig__byte_order_out();
00096 if (0 >= dig__fwrite_port_C(buf, 5, &fp))
00097 return (1);
00098
00099
00100 if (0 >= dig__fwrite_port_L(&length, 1, &fp))
00101 return (1);
00102
00103
00104
00105 if (0 >= dig__fwrite_port_I(&(Map->fInfo.ogr.offset_num), 1, &fp))
00106 return (1);
00107
00108
00109 if (0 >= dig__fwrite_port_I(Map->fInfo.ogr.offset,
00110 Map->fInfo.ogr.offset_num, &fp))
00111 return (1);
00112
00113 fclose(fp.file);
00114
00115 }
00116
00117 free(Map->fInfo.ogr.offset);
00118
00119 return 0;
00120 }
00121 #endif