File: close_ogr.c

package info (click to toggle)
grass 6.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 104,028 kB
  • ctags: 40,409
  • sloc: ansic: 419,980; python: 63,559; tcl: 46,692; cpp: 29,791; sh: 18,564; makefile: 7,000; xml: 3,505; yacc: 561; perl: 559; lex: 480; sed: 70; objc: 7
file content (121 lines) | stat: -rw-r--r-- 2,714 bytes parent folder | download | duplicates (3)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121

/*****************************************************************************
*
* MODULE:       Vector library 
*   	    	
* AUTHOR(S):    Radim Blazek, Piero Cavalieri 
*
* PURPOSE:      Higher 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 <grass/Vect.h>
#include <stdlib.h>

#ifdef HAVE_OGR
#include <ogr_api.h>

/* 
 ** return 0 on success
 **         non-zero on error
 */
int V1_close_ogr(struct Map_info *Map)
{
    int i;

    if (!VECT_OPEN(Map))
	return -1;

    if (Map->mode == GV_MODE_WRITE || Map->mode == GV_MODE_RW)
	Vect__write_head(Map);

    if (Map->fInfo.ogr.feature_cache)
	OGR_F_Destroy(Map->fInfo.ogr.feature_cache);

    OGR_DS_Destroy(Map->fInfo.ogr.ds);

    for (i = 0; i < Map->fInfo.ogr.lines_alloc; i++) {
	Vect_destroy_line_struct(Map->fInfo.ogr.lines[i]);
    }

    free(Map->fInfo.ogr.lines);
    free(Map->fInfo.ogr.lines_types);

    free(Map->fInfo.ogr.dsn);
    free(Map->fInfo.ogr.layer_name);

    return 0;
}

/* 
 *  Write OGR specific files (fidx)
 * 
 *  return 0 on success
 *         non-zero on error
 */
int V2_close_ogr(struct Map_info *Map)
{
    char fname[1000], elem[1000];
    char buf[5];
    long length = 9;
    GVFILE fp;
    struct Port_info port;

    G_debug(3, "V2_close_ogr()");

    if (!VECT_OPEN(Map))
	return -1;

    if (strcmp(Map->mapset, G_mapset()) == 0 && Map->support_updated &&
	Map->plus.built == GV_BUILD_ALL) {
	sprintf(elem, "%s/%s", GRASS_VECT_DIRECTORY, Map->name);
	G__file_name(fname, elem, "fidx", Map->mapset);
	G_debug(4, "Open fidx: %s", fname);
	dig_file_init(&fp);
	fp.file = fopen(fname, "w");
	if (fp.file == NULL) {
	    G_warning("Can't open fidx file for write: %s\n", fname);
	    return 1;
	}

	dig_init_portable(&port, dig__byte_order_out());
	dig_set_cur_port(&port);

	/* Header */
	/* bytes 1 - 5 */
	buf[0] = 5;
	buf[1] = 0;
	buf[2] = 5;
	buf[3] = 0;
	buf[4] = (char)dig__byte_order_out();
	if (0 >= dig__fwrite_port_C(buf, 5, &fp))
	    return (1);

	/* bytes 6 - 9 : header size */
	if (0 >= dig__fwrite_port_L(&length, 1, &fp))
	    return (1);

	/* Body */
	/* number of records  */
	if (0 >= dig__fwrite_port_I(&(Map->fInfo.ogr.offset_num), 1, &fp))
	    return (1);

	/* offsets */
	if (0 >= dig__fwrite_port_I(Map->fInfo.ogr.offset,
				    Map->fInfo.ogr.offset_num, &fp))
	    return (1);

	fclose(fp.file);

    }

    free(Map->fInfo.ogr.offset);

    return 0;
}
#endif