File: read.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 (198 lines) | stat: -rw-r--r-- 4,040 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*!
   \file read.c

   \brief Vector library - read vector features

   Higher level functions for reading/writing/manipulating vectors.

   (C) 2001-2008 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.

   \author Original author CERL, probably Dave Gerdes or Mike Higgins.
   \author Update to GRASS 5.7 Radim Blazek and David D. Gray.

   \date 2001-2008
 */

#include <grass/Vect.h>
#include <grass/glocale.h>

static int read_next_dummy()
{
    return -1;
}

#ifndef HAVE_OGR
static int format()
{
    G_fatal_error(_("Requested format is not compiled in this version"));
    return 0;
}
#endif

static int (*Read_next_line_array[][3]) () = {
    {
    read_next_dummy, V1_read_next_line_nat, V2_read_next_line_nat}
#ifdef HAVE_OGR
    , {
    read_next_dummy, V1_read_next_line_ogr, V2_read_next_line_ogr}
#else
    , {
    read_next_dummy, format, format}
#endif
};

static int (*V2_read_line_array[]) () = {
    V2_read_line_nat
#ifdef HAVE_OGR
	, V2_read_line_ogr
#else
	, format
#endif
};

/*!
   \brief Read next vector feature (level 1 and 2)

   \param Map pointer vector map
   \param[out] line_p feature geometry
   \param[out] line_c feature categories

   \return feature type,
   \return -1 out of memory
   \return -2 EOF   
 */
int Vect_read_next_line(struct Map_info *Map,
			struct line_pnts *line_p, struct line_cats *line_c)
{

    G_debug(3, "Vect_read_next_line()");

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

    return (*Read_next_line_array[Map->format][Map->level]) (Map, line_p,
							     line_c);
}

/*!
   \brief Read vector feature

   \param Map pointer to vector map
   \param[out] line_p feature geometry
   \param[out] line_c feature categories
   \param line feature id 
   
   \return feature type
   \return -1 out of memory,
   \return -2 EOF   
 */
int Vect_read_line(struct Map_info *Map,
		   struct line_pnts *line_p, struct line_cats *line_c, int line)
{

    G_debug(3, "Vect_read_line()");

    if (!VECT_OPEN(Map))
	G_fatal_error("Vect_read_line(): %s", _("vector map is not opened"));

    if (line < 1 || line > Map->plus.n_lines)
	G_fatal_error(_("Vect_read_line(): feature id %d is not reasonable "
			"(max features in vector map <%s>: %d)"),
		      line, Vect_get_full_name(Map), Map->plus.n_lines);

    return (*V2_read_line_array[Map->format]) (Map, line_p, line_c, line);
}

/*!
   \brief Check if feature is alive or dead

   \param Map pointer to vector map
   \param line feature id

   \return 1 if feature alive
   \return 0 if feature is dead
 */
int Vect_line_alive(struct Map_info *Map, int line)
{
    if (Map->plus.Line[line] != NULL)
	return 1;
    
    return 0;
}

/*!
   \brief Check if node is alive or dead

   \param Map pointer to vector map
   \param node node id

   \return 1 if node alive
   \return 0 if node is dead
 */
int Vect_node_alive(struct Map_info *Map, int node)
{
    if (Map->plus.Node[node] != NULL)
	return 1;

    return 0;
}

/*!
   \brief Check if area is alive or dead

   \param Map pointer to vector map
   \param area area id

   \return 1 if area alive
   \return 0 if area is dead
 */
int Vect_area_alive(struct Map_info *Map, int area)
{
    if (Map->plus.Area[area] != NULL)
	return 1;

    return 0;
}

/*!
   \brief Check if isle is alive or dead

   \param Map pointer to vector map
   \param isle isle id

   \return 1 if isle alive
   \return 0 if isle is dead
 */
int Vect_isle_alive(struct Map_info *Map, int isle)
{
    if (Map->plus.Isle[isle] != NULL)
	return 1;

    return 0;
}

/*!
  \brief Get feature offset

  Can be used for Vect_restore_line().

  \param Map pointer to vector map
  \param line feature id

  \return feature offset
  \return -1 on error
*/
long Vect_get_line_offset(const struct Map_info *Map, int line)
{
    if (line < 1 || line > Map->plus.n_lines)
	return -1;
    
    if (Map->plus.Line[line] != NULL) {
	return Map->plus.Line[line]->offset;
    }
    
    return -1;
}