GRASS 8 Programmer's Manual 8.6.0dev(2026)-1878fdfec5
Loading...
Searching...
No Matches
close_ogr.c
Go to the documentation of this file.
1/*!
2 \file lib/vector/Vlib/close_ogr.c
3
4 \brief Vector library - Close map (OGR)
5
6 Higher level functions for reading/writing/manipulating vectors.
7
8 SPDX-FileCopyrightText: 2001-2009, 2012 GRASS Development Team
9 SPDX-License-Identifier: GPL-2.0-or-later
10
11 \author Original author CERL, probably Dave Gerdes or Mike Higgins.
12 \author Update to GRASS 5.7 Radim Blazek and Piero Cavalieri.
13 */
14
15#include <stdlib.h>
16#include <grass/vector.h>
17#include <grass/glocale.h>
18
19#include <ogr_api.h>
20
21#include "local_proto.h"
22
23/*!
24 \brief Close vector map (OGR dsn & layer) on level 1
25
26 \param Map pointer to Map_info structure
27
28 \return 0 on success
29 \return non-zero on error
30 */
32{
34
35 G_debug(3, "V1_close_ogr() name = %s mapset = %s", Map->name, Map->mapset);
36
37 if (!VECT_OPEN(Map))
38 return -1;
39
40 ogr_info = &(Map->fInfo.ogr);
41 if (Map->format != GV_FORMAT_OGR_DIRECT &&
42 (Map->mode == GV_MODE_WRITE || Map->mode == GV_MODE_RW)) {
43 /* write header */
45 if (G_find_file2("", "OGR", G_mapset())) {
46 /* write frmt file for created PG-link */
48 }
49 }
50
51 if (ogr_info->feature_cache)
52 OGR_F_Destroy(ogr_info->feature_cache);
53
54 /* destroy OGR datasource */
56
57 Vect__free_cache(&(ogr_info->cache));
58
59 /* close DB connection (for atgtributes) */
60 if (ogr_info->dbdriver) {
62 }
63
64 G_free(ogr_info->driver_name);
65 G_free(ogr_info->dsn);
66 G_free(ogr_info->layer_name);
67 if (ogr_info->layer_options)
68 G_free_tokens(ogr_info->layer_options);
69
70 return 0;
71}
72
73/*!
74 \brief Close vector map on topological level (write out fidx file)
75
76 \param Map pointer to Map_info structure
77
78 \return 0 on success
79 \return non-zero on error
80 */
82{
84
85 G_debug(3, "V2_close_ogr() name = %s mapset = %s", Map->name, Map->mapset);
86
87 if (!VECT_OPEN(Map))
88 return -1;
89
90 ogr_info = &(Map->fInfo.ogr);
91
92 /* write fidx for maps in the current mapset */
93 if (Vect_save_fidx(Map, &(ogr_info->offset)) != 1)
94 G_warning(_("Unable to save feature index file for vector map <%s>"),
95 Map->name);
96
97 Vect__free_offset(&(ogr_info->offset));
98
99 return 0;
100}
AMI_err name(char **stream_name)
Definition ami_stream.h:426
int V1_close_ogr(struct Map_info *Map)
Close vector map (OGR dsn & layer) on level 1.
Definition close_ogr.c:31
int V2_close_ogr(struct Map_info *Map)
Close vector map on topological level (write out fidx file)
Definition close_ogr.c:81
int db_close_database_shutdown_driver(dbDriver *)
Close driver/database connection.
Definition db.c:58
void G_free(void *)
Free allocated memory.
Definition gis/alloc.c:145
void G_warning(const char *,...) __attribute__((format(printf
const char * G_find_file2(const char *, const char *, const char *)
Searches for a file from the mapset search list or in a specified mapset. (look but don't touch)
Definition find_file.c:230
void G_free_tokens(char **)
Free memory allocated to tokens.
Definition gis/token.c:195
int G_debug(int, const char *,...) __attribute__((format(printf
const char * G_mapset(void)
Get current mapset name.
Definition gis/mapset.c:31
int Vect_save_frmt(struct Map_info *)
Save format definition file for vector map.
int Vect_save_fidx(struct Map_info *, struct Format_info_offset *)
Save feature index file for vector map.
Definition build_ogr.c:107
int Vect__write_head(struct Map_info *)
Writes head information to text file (GV_HEAD_ELEMENT)
#define VECT_OPEN(Map)
Check if vector map is open.
#define GV_MODE_WRITE
Write vector map open mode.
#define GV_FORMAT_OGR_DIRECT
OGR format (direct access)
Definition dig_defines.h:87
#define GV_MODE_RW
Read-write vector map open mode.
#define _(str)
Definition glocale.h:10
Non-native format info (OGR)
Vector map info.
void Vect__free_offset(struct Format_info_offset *offset)
void Vect__free_cache(struct Format_info_cache *cache)