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