GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
vector/Vlib/write.c
Go to the documentation of this file.
1 
20 #include <grass/gis.h>
21 #include <grass/glocale.h>
22 #include <grass/Vect.h>
23 
24 static long write_dummy()
25 {
26  G_warning("Vect_write_line() %s",
27  _("for this format/level not supported"));
28  return -1;
29 }
30 static int rewrite_dummy()
31 {
32  G_warning("Vect_rewrite_line() %s",
33  _("for this format/level not supported"));
34  return -1;
35 }
36 static int delete_dummy()
37 {
38  G_warning("Vect_delete_line() %s",
39  _("for this format/level not supported"));
40  return -1;
41 }
42 
43 static int restore_dummy()
44 {
45  G_warning("Vect_restore_line() %s",
46  _("for this format/level not supported"));
47  return -1;
48 }
49 
50 #ifndef HAVE_OGR
51 static int format()
52 {
53  G_fatal_error(_("Requested format is not compiled in this version"));
54  return 0;
55 }
56 
57 static long format_l()
58 {
59  G_fatal_error(_("Requested format is not compiled in this version"));
60  return 0;
61 }
62 
63 #endif
64 
65 static long (*Write_line_array[][3]) () = {
66  {
68 #ifdef HAVE_OGR
69  , {
70  write_dummy, write_dummy, write_dummy}
71 #else
72  , {
73  write_dummy, format_l, format_l}
74 #endif
75 };
76 
77 static int (*Vect_rewrite_line_array[][3]) () = {
78  {
79  rewrite_dummy, rewrite_dummy, V2_rewrite_line_nat}
80 #ifdef HAVE_OGR
81  , {
82  rewrite_dummy, rewrite_dummy, rewrite_dummy}
83 #else
84  , {
85  rewrite_dummy, format, format}
86 #endif
87 };
88 
89 static int (*Vect_delete_line_array[][3]) () = {
90  {
91  delete_dummy, delete_dummy, V2_delete_line_nat}
92 #ifdef HAVE_OGR
93  , {
94  delete_dummy, delete_dummy, delete_dummy}
95 #else
96  , {
97  delete_dummy, format, format}
98 #endif
99 };
100 
101 static int (*Vect_restore_line_array[][3]) () = {
102  {
103  restore_dummy, restore_dummy, V2_restore_line_nat}
104 #ifdef HAVE_OGR
105  , {
106  restore_dummy, restore_dummy, restore_dummy}
107 #else
108  , {
109  restore_dummy, format, format}
110 #endif
111 };
112 
125 long
126 Vect_write_line(struct Map_info *Map,
127  int type, struct line_pnts *points, struct line_cats *cats)
128 {
129  long offset;
130 
131  G_debug(3, "Vect_write_line(): name = %s, format = %d, level = %d",
132  Map->name, Map->format, Map->level);
133 
134  if (!VECT_OPEN(Map))
135  G_fatal_error(_("Unable to write feature, vector map is not opened"));
136 
137  dig_line_reset_updated(&(Map->plus));
138  dig_node_reset_updated(&(Map->plus));
139  if (!(Map->plus.update_cidx)) {
140  Map->plus.cidx_up_to_date = 0;
141  }
142 
143  offset =
144  (*Write_line_array[Map->format][Map->level]) (Map, type, points,
145  cats);
146 
147  if (offset == -1)
148  G_fatal_error(_("Unable to write feature (negative offset)"));
149 
150  return offset;
151 }
152 
153 
171 int
172 Vect_rewrite_line(struct Map_info *Map,
173  int line,
174  int type, struct line_pnts *points, struct line_cats *cats)
175 {
176  long ret;
177 
178  G_debug(3, "Vect_rewrite_line(): name = %s, line = %d", Map->name, line);
179 
180  if (!VECT_OPEN(Map))
181  G_fatal_error(_("Unable to rewrite feature, vector map is not opened"));
182 
183  dig_line_reset_updated(&(Map->plus));
184  dig_node_reset_updated(&(Map->plus));
185  if (!(Map->plus.update_cidx)) {
186  Map->plus.cidx_up_to_date = 0;
187  }
188 
189  ret =
190  (*Vect_rewrite_line_array[Map->format][Map->level]) (Map, line, type,
191  points, cats);
192 
193  if (ret == -1)
194  G_fatal_error(_("Unable to rewrite feature %d"), line);
195 
196  return ret;
197 }
198 
212 int Vect_delete_line(struct Map_info *Map, int line)
213 {
214  int ret;
215 
216  G_debug(3, "Vect_delete_line(): name = %s, line = %d", Map->name, line);
217 
218  if (Map->level < 2) {
219  G_fatal_error(_("Unable to delete feature %d, "
220  "vector map <%s> is not opened on topology level"),
221  line, Map->name);
222  }
223 
224  if (Map->mode != GV_MODE_RW && Map->mode != GV_MODE_WRITE) {
225  G_fatal_error(_("Unable to delete feature %d, "
226  "vector map <%s> is not opened in 'write' mode"),
227  line, Map->name);
228  }
229 
230  dig_line_reset_updated(&(Map->plus));
231  dig_node_reset_updated(&(Map->plus));
232  if (!(Map->plus.update_cidx)) {
233  Map->plus.cidx_up_to_date = 0;
234  }
235 
236  ret = (*Vect_delete_line_array[Map->format][Map->level]) (Map, line);
237 
238  if (ret == -1)
239  G_fatal_error(_("Unable to delete feature %d from vector map <%s>"),
240  line, Map->name);
241 
242  return ret;
243 }
244 
258 int Vect_restore_line(struct Map_info *Map, int line, long offset)
259 {
260  int ret;
261 
262  G_debug(3, "Vect_restore_line(): name = %s, line = %d", Map->name, line);
263 
264  if (Map->level < 2) {
265  G_fatal_error(_("Unable to restore feature %d, "
266  "vector map <%s> is not opened on topology level"),
267  line, Map->name);
268  }
269 
270  if (Map->mode != GV_MODE_RW && Map->mode != GV_MODE_WRITE) {
271  G_fatal_error(_("Unable to restore feature %d, "
272  "vector map <%s> is not opened in 'write' mode"),
273  line, Map->name);
274  }
275 
276  dig_line_reset_updated(&(Map->plus));
277  dig_node_reset_updated(&(Map->plus));
278  if (!(Map->plus.update_cidx)) {
279  Map->plus.cidx_up_to_date = 0;
280  }
281 
282  ret = (*Vect_restore_line_array[Map->format][Map->level]) (Map, line, offset);
283 
284  if (ret == -1)
285  G_fatal_error(_("Unable to restore feature %d from vector map <%s>"),
286  line, Map->name);
287 
288  return ret;
289 }
int V2_restore_line_nat(struct Map_info *Map, int line, long offset)
Restores feature (topology level)
Definition: write_nat.c:866
void dig_node_reset_updated(struct Plus_head *Plus)
Reset number of updated nodes.
int Vect_restore_line(struct Map_info *Map, int line, long offset)
Restore previously deleted feature.
long V2_write_line_nat(struct Map_info *Map, int type, struct line_pnts *points, struct line_cats *cats)
Writes feature to &#39;coor&#39; file (topology level)
Definition: write_nat.c:340
int Vect_rewrite_line(struct Map_info *Map, int line, int type, struct line_pnts *points, struct line_cats *cats)
Rewrites feature info at the given offset.
long V1_write_line_nat(struct Map_info *Map, int type, struct line_pnts *points, struct line_cats *cats)
Writes feature to &#39;coor&#39; file.
Definition: write_nat.c:314
int
Definition: g3dcolor.c:48
int V2_rewrite_line_nat(struct Map_info *Map, int line, int type, struct line_pnts *points, struct line_cats *cats)
Rewrites feature (topology level)
Definition: write_nat.c:459
void dig_line_reset_updated(struct Plus_head *Plus)
Reset number of updated lines.
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
tuple Map
Definition: render.py:1310
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51
int Vect_delete_line(struct Map_info *Map, int line)
Delete feature.
long Vect_write_line(struct Map_info *Map, int type, struct line_pnts *points, struct line_cats *cats)
Writes new feature to the end of file (table)
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int V2_delete_line_nat(struct Map_info *Map, int line)
Deletes feature (topology level).
Definition: write_nat.c:624