GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
write_ogr.c
Go to the documentation of this file.
1 /*!
2  \file lib/vector/Vlib/write_ogr.c
3 
4  \brief Vector library - write vector feature (OGR format)
5 
6  Higher level functions for reading/writing/manipulating vectors.
7 
8  Partly inspired by v.out.ogr's code.
9 
10  \todo How to deal with OGRNullFID
11 
12  (C) 2009-2013 by Martin Landa, and the GRASS Development Team
13 
14  This program is free software under the GNU General Public License
15  (>=v2). Read the file COPYING that comes with GRASS for details.
16 
17  \author Martin Landa <landa.martin gmail.com>
18  */
19 
20 #include <grass/vector.h>
21 #include <grass/dbmi.h>
22 #include <grass/gprojects.h>
23 #include <grass/glocale.h>
24 
25 #ifdef HAVE_OGR
26 #include <ogr_api.h>
27 #include <cpl_string.h>
28 
29 static dbDriver *create_table(OGRLayerH, const struct field_info *);
30 static int create_ogr_layer(struct Map_info *, int);
31 static off_t write_feature(struct Map_info *, int, const struct line_pnts **, int,
32  const struct line_cats *);
33 static int write_attributes(dbDriver *, int, const struct field_info *,
34  OGRLayerH, OGRFeatureH);
35 static int sqltype_to_ogrtype(int);
36 #endif
37 
38 /*!
39  \brief Writes feature on level 1 (OGR interface)
40 
41  Note:
42  - centroids are not supported in OGR, pseudotopo holds virtual
43  centroids (it's coordinates determined from spatial index)
44  - unclosed boundaries are not supported in OGR, pseudotopo treats
45  polygons as boundaries
46 
47  Supported feature types:
48  - GV_POINT (written as wkbPoint)
49  - GV_LINE (wkbLineString)
50  - GV_BOUNDARY (wkbPolygon)
51  - GV_FACE (wkbPolygon25D)
52  - GV_KERNEL (wkbPoint25D)
53 
54  \param Map pointer to Map_info structure
55  \param type feature type
56  \param points pointer to line_pnts structure (feature geometry)
57  \param cats pointer to line_cats structure (feature categories)
58 
59  \return feature index in offset array (related to pseudo-topology)
60  \return -1 on error
61 */
62 off_t V1_write_line_ogr(struct Map_info *Map, int type,
63  const struct line_pnts *points,
64  const struct line_cats *cats)
65 {
66 #ifdef HAVE_OGR
67  return write_feature(Map, type, &points, 1, cats);
68 #else
69  G_fatal_error(_("GRASS is not compiled with OGR support"));
70  return -1;
71 #endif
72 }
73 
74 /*!
75  \brief Rewrites feature at the given offset on level 1 (OGR interface)
76 
77  This function simply calls V1_delete_line_ogr() and V1_write_line_ogr().
78 
79  \param Map pointer to Map_info structure
80  \param offset feature offset
81  \param type feature type (see V1_write_line_ogr() for supported types)
82  \param points pointer to line_pnts structure (feature geometry)
83  \param cats pointer to line_cats structure (feature categories)
84 
85  \return feature offset (rewritten feature)
86  \return -1 on error
87 */
88 off_t V1_rewrite_line_ogr(struct Map_info *Map,
89  off_t offset, int type,
90  const struct line_pnts *points, const struct line_cats *cats)
91 {
92  G_debug(3, "V1_rewrite_line_ogr(): type=%d offset=%" PRI_OFF_T,
93  type, offset);
94 #ifdef HAVE_OGR
95  if (type != V1_read_line_ogr(Map, NULL, NULL, offset)) {
96  G_warning(_("Unable to rewrite feature (incompatible feature types)"));
97  return -1;
98  }
99 
100  /* delete old */
101  V1_delete_line_ogr(Map, offset);
102 
103  return V1_write_line_ogr(Map, type, points, cats);
104 #else
105  G_fatal_error(_("GRASS is not compiled with OGR support"));
106  return -1;
107 #endif
108 }
109 
110 /*!
111  \brief Deletes feature at the given offset on level 1 (OGR interface)
112 
113  \param Map pointer Map_info structure
114  \param offset offset of feature to be deleted
115 
116  \return 0 on success
117  \return -1 on error
118 */
119 int V1_delete_line_ogr(struct Map_info *Map, off_t offset)
120 {
121 #ifdef HAVE_OGR
122  struct Format_info_ogr *ogr_info;
123 
124  G_debug(3, "V1_delete_line_ogr(), offset = %lu", (unsigned long) offset);
125 
126  ogr_info = &(Map->fInfo.ogr);
127 
128  if (!ogr_info->layer) {
129  G_warning(_("OGR layer not defined"));
130  return -1;
131  }
132 
133  if (offset >= ogr_info->offset.array_num) {
134  G_warning(_("Invalid offset (%" PRI_OFF_T ")"), offset);
135  return -1;
136  }
137 
138  if (OGR_L_DeleteFeature(ogr_info->layer,
139  ogr_info->offset.array[offset]) != OGRERR_NONE) {
140  G_warning(_("Unable to delete feature"));
141  return -1;
142  }
143 
144  return 0;
145 #else
146  G_fatal_error(_("GRASS is not compiled with OGR support"));
147  return -1;
148 #endif
149 }
150 
151 #ifdef HAVE_OGR
152 /*!
153  \brief Writes area on topological level (OGR Simple Features
154  interface, internal use only)
155 
156  \param Map pointer to Map_info structure
157  \param points feature geometry (exterior + interior rings)
158  \param nparts number of parts including exterior ring
159  \param cats feature categories
160 
161  \return feature offset
162  \return -1 on error
163 */
164 off_t V2__write_area_ogr(struct Map_info *Map,
165  const struct line_pnts **points, int nparts,
166  const struct line_cats *cats)
167 {
168  return write_feature(Map, GV_BOUNDARY, points, nparts, cats);
169 }
170 
171 dbDriver *create_table(OGRLayerH hLayer, const struct field_info *Fi)
172 {
173  int col, ncols;
174  int sqltype, ogrtype, length;
175 
176  const char *colname;
177 
178  dbDriver *driver;
179  dbHandle handle;
180  dbCursor cursor;
181  dbTable *table;
182  dbColumn *column;
183  dbString sql;
184 
185  OGRFieldDefnH hFieldDefn;
186  OGRFeatureDefnH hFeatureDefn;
187 
188  db_init_string(&sql);
189  db_init_handle(&handle);
190 
191  driver = db_start_driver(Fi->driver);
192  if (!driver) {
193  G_warning(_("Unable to start driver <%s>"), Fi->driver);
194  return NULL;
195  }
196  db_set_handle(&handle, Fi->database, NULL);
197  if (db_open_database(driver, &handle) != DB_OK) {
198  G_warning(_("Unable to open database <%s> by driver <%s>"),
199  Fi->database, Fi->driver);
201  return NULL;
202  }
203 
204  /* to get no data */
205  db_set_string(&sql, "select * from ");
206  db_append_string(&sql, Fi->table);
207  db_append_string(&sql, " where 0 = 1");
208 
209  if (db_open_select_cursor(driver, &sql, &cursor, DB_SEQUENTIAL) !=
210  DB_OK) {
211  G_warning(_("Unable to open select cursor: '%s'"),
212  db_get_string(&sql));
214  return NULL;
215  }
216 
217  table = db_get_cursor_table(&cursor);
218  ncols = db_get_table_number_of_columns(table);
219 
220  hFeatureDefn = OGR_L_GetLayerDefn(hLayer);
221 
222  for (col = 0; col < ncols; col++) {
223  column = db_get_table_column(table, col);
224  colname = db_get_column_name(column);
225  sqltype = db_get_column_sqltype(column);
226  ogrtype = sqltype_to_ogrtype(sqltype);
227  length = db_get_column_length(column);
228 
229  if (strcmp(OGR_L_GetFIDColumn(hLayer), colname) == 0 ||
230  OGR_FD_GetFieldIndex(hFeatureDefn, colname) > -1) {
231  /* field already exists */
232  continue;
233  }
234 
235  hFieldDefn = OGR_Fld_Create(colname, ogrtype);
236  /* GDAL 1.9.0 (r22968) uses VARCHAR instead of CHAR */
237  if (ogrtype == OFTString && length > 0)
238  OGR_Fld_SetWidth(hFieldDefn, length);
239  if (OGR_L_CreateField(hLayer, hFieldDefn, TRUE) != OGRERR_NONE) {
240  G_warning(_("Creating field <%s> failed"), colname);
242  return NULL;
243  }
244 
245  OGR_Fld_Destroy(hFieldDefn);
246  }
247 
248  return driver;
249 }
250 
251 /*!
252  \brief Create new OGR layer in given OGR datasource (internal use only)
253 
254  V1_open_new_ogr() is required to be called before this function.
255 
256  List of currently supported types:
257  - GV_POINT (wkbPoint)
258  - GV_LINE (wkbLineString)
259  - GV_BOUNDARY (wkb_Polygon)
260  \param[in,out] Map pointer to Map_info structure
261  \param type feature type (GV_POINT, GV_LINE, ...)
262 
263  \return 0 success
264  \return -1 error
265 */
266 int create_ogr_layer(struct Map_info *Map, int type)
267 {
268  int ndblinks;
269  OGRLayerH Ogr_layer;
270  OGRSpatialReferenceH Ogr_spatial_ref;
271 
272  struct field_info *Fi;
273  struct Key_Value *projinfo, *projunits, *projepsg;
274  struct Format_info_ogr *ogr_info;
275 
276  OGRwkbGeometryType Ogr_geom_type;
277  char **Ogr_layer_options;
278 
279  ogr_info = &(Map->fInfo.ogr);
280 
281  if (!ogr_info->driver_name ||
282  !ogr_info->layer_name ||
283  !ogr_info->ds)
284  return -1;
285 
286  /* get spatial reference */
287  projinfo = G_get_projinfo();
288  projunits = G_get_projunits();
289  projepsg = G_get_projepsg();
290  Ogr_spatial_ref = GPJ_grass_to_osr2(projinfo, projunits, projepsg);
291  G_free_key_value(projinfo);
292  G_free_key_value(projunits);
293 
294  /* determine geometry type */
295  switch(type) {
296  case GV_POINT:
297  Ogr_geom_type = wkbPoint;
298  break;
299  case GV_LINE:
300  Ogr_geom_type = wkbLineString;
301  break;
302  case GV_BOUNDARY:
303  Ogr_geom_type = wkbPolygon;
304  break;
305  default:
306  G_warning(_("Unsupported geometry type (%d)"), type);
307  return -1;
308  }
309 
310  /* check creation options */
311  Ogr_layer_options = ogr_info->layer_options;
312  if (Vect_is_3d(Map)) {
313  if (strcmp(ogr_info->driver_name, "PostgreSQL") == 0) {
314  Ogr_layer_options = CSLSetNameValue(Ogr_layer_options, "DIM", "3");
315  }
316  }
317  else {
318  if (strcmp(ogr_info->driver_name, "PostgreSQL") == 0) {
319  Ogr_layer_options = CSLSetNameValue(Ogr_layer_options, "DIM", "2");
320  }
321  }
322 
323  /* create new OGR layer */
324  Ogr_layer = OGR_DS_CreateLayer(ogr_info->ds, ogr_info->layer_name,
325  Ogr_spatial_ref, Ogr_geom_type, Ogr_layer_options);
326  CSLDestroy(Ogr_layer_options);
327  if (!Ogr_layer) {
328  G_warning(_("Unable to create OGR layer <%s> in '%s'"),
329  ogr_info->layer_name, ogr_info->dsn);
330  return -1;
331  }
332  ogr_info->layer = Ogr_layer;
333 
334  ndblinks = Vect_get_num_dblinks(Map);
335  if (ndblinks > 0) {
336  /* write also attributes */
337  Fi = Vect_get_dblink(Map, 0);
338  if (Fi) {
339  if (ndblinks > 1)
340  G_warning(_("More layers defined, using driver <%s> and "
341  "database <%s>"), Fi->driver, Fi->database);
342  ogr_info->dbdriver = create_table(ogr_info->layer, Fi);
343  G_free(Fi);
344  }
345  else
346  G_warning(_("Database connection not defined. "
347  "Unable to write attributes."));
348  }
349 
350  if (OGR_L_TestCapability(ogr_info->layer, OLCTransactions) &&
351  (OGR_L_StartTransaction(ogr_info->layer) != OGRERR_NONE)) {
352  G_warning(_("OGR transaction with layer <%s> failed to start"),
353  ogr_info->layer_name);
354  return -1;
355  }
356 
357  return 0;
358 }
359 
360 /*!
361  \brief Write OGR feature
362 
363  \param Map pointer to Map_info structure
364  \param type feature type (GV_POINT, GV_LINE, ...)
365  \param bpoints feature geometry
366  \param cats feature categories
367  \param ipoints isle geometry for polygons on NULL
368  \param nisles number of isles
369 
370  \return feature offset into file
371  \return -1 on error
372 */
373 off_t write_feature(struct Map_info *Map, int type,
374  const struct line_pnts **p_points, int nparts,
375  const struct line_cats *cats)
376 {
377  int i, cat, ret;
378 
379  struct field_info *Fi;
380  const struct line_pnts *points;
381  struct Format_info_ogr *ogr_info;
382  struct Format_info_offset *offset_info;
383 
384  off_t offset;
385 
386  OGRGeometryH Ogr_geometry;
387  OGRFeatureH Ogr_feature;
388  OGRFeatureDefnH Ogr_featuredefn;
389  OGRwkbGeometryType Ogr_geom_type;
390 
391  ogr_info = &(Map->fInfo.ogr);
392  offset_info = &(ogr_info->offset);
393 
394  if (nparts < 1)
395  return -1;
396 
397  points = p_points[0]; /* feature geometry */
398 
399  if (!ogr_info->layer) {
400  /* create OGR layer if doesn't exist */
401  if (create_ogr_layer(Map, type) < 0)
402  return -1;
403  }
404 
405  if (!points)
406  return 0;
407 
408  cat = -1; /* no attributes to be written */
409  if (cats->n_cats > 0 && Vect_get_num_dblinks(Map) > 0) {
410  /* check for attributes */
411  Fi = Vect_get_dblink(Map, 0);
412  if (Fi) {
413  if (!Vect_cat_get(cats, Fi->number, &cat))
414  G_warning(_("No category defined for layer %d"), Fi->number);
415  if (cats->n_cats > 1) {
416  G_warning(_("Feature has more categories, using "
417  "category %d (from layer %d)"),
418  cat, cats->field[0]);
419  }
420  }
421  }
422 
423  Ogr_featuredefn = OGR_L_GetLayerDefn(ogr_info->layer);
424  Ogr_geom_type = OGR_FD_GetGeomType(Ogr_featuredefn);
425 
426  /* determine matching OGR feature geometry type */
427  if (type & (GV_POINT | GV_KERNEL)) {
428  if (Ogr_geom_type != wkbPoint &&
429  Ogr_geom_type != wkbPoint25D) {
430  G_warning(_("Feature is not a point. Skipping."));
431  return -1;
432  }
433  Ogr_geometry = OGR_G_CreateGeometry(wkbPoint);
434  }
435  else if (type & GV_LINE) {
436  if (Ogr_geom_type != wkbLineString &&
437  Ogr_geom_type != wkbLineString25D) {
438  G_warning(_("Feature is not a line. Skipping."));
439  return -1;
440  }
441  Ogr_geometry = OGR_G_CreateGeometry(wkbLineString);
442  }
443  else if (type & GV_BOUNDARY) {
444  if (Ogr_geom_type != wkbPolygon) {
445  G_warning(_("Feature is not a polygon. Skipping."));
446  return -1;
447  }
448  Ogr_geometry = OGR_G_CreateGeometry(wkbPolygon);
449  }
450  else if (type & GV_FACE) {
451  if (Ogr_geom_type != wkbPolygon25D) {
452  G_warning(_("Feature is not a face. Skipping."));
453  return -1;
454  }
455  Ogr_geometry = OGR_G_CreateGeometry(wkbPolygon25D);
456  }
457  else {
458  G_warning(_("Unsupported feature type (%d)"), type);
459  return -1;
460  }
461 
462  G_debug(3, "V1_write_line_ogr(): type = %d", type);
463 
464  if (Ogr_geom_type == wkbPolygon || Ogr_geom_type == wkbPolygon25D) {
465  int iring, npoints;
466 
467  /* add rings (first is exterior ring) */
468  for (iring = 0; iring < nparts; iring++) {
469  OGRGeometryH Ogr_ring;
470 
471  points = p_points[iring];
472  npoints = points->n_points - 1;
473  Ogr_ring = OGR_G_CreateGeometry(wkbLinearRing);
474  if (points->x[0] != points->x[npoints] ||
475  points->y[0] != points->y[npoints] ||
476  points->z[0] != points->z[npoints]) {
477  G_warning(_("Boundary is not closed. Feature skipped."));
478  return -1;
479  }
480 
481  /* add points */
482  for (i = 0; i < npoints; i++) {
483  OGR_G_AddPoint(Ogr_ring, points->x[i], points->y[i],
484  points->z[i]);
485  }
486  G_debug(4, " ring(%d): n_points = %d", iring, npoints);
487  OGR_G_AddGeometry(Ogr_geometry, Ogr_ring);
488  }
489  }
490  else {
491  for (i = 0; i < points->n_points; i++) {
492  OGR_G_AddPoint(Ogr_geometry, points->x[i], points->y[i],
493  points->z[i]);
494  }
495  G_debug(4, " n_points = %d", points->n_points);
496  }
497 
498  /* create feature & set geometry */
499  Ogr_feature = OGR_F_Create(Ogr_featuredefn);
500  OGR_F_SetGeometry(Ogr_feature, Ogr_geometry);
501 
502  /* write attributes */
503  if (cat > -1 && ogr_info->dbdriver) {
504  if (0 > write_attributes(ogr_info->dbdriver,
505  cat, Fi, ogr_info->layer, Ogr_feature))
506  G_warning(_("Unable to writes feature attributes"));
507  G_free(Fi);
508  }
509  /* write feature into layer */
510  ret = OGR_L_CreateFeature(ogr_info->layer, Ogr_feature);
511 
512  /* update offset array */
513  if (offset_info->array_num >= offset_info->array_alloc) {
514  offset_info->array_alloc += 1000;
515  offset_info->array = (int *) G_realloc(offset_info->array,
516  offset_info->array_alloc *
517  sizeof(int));
518  }
519 
520  offset = offset_info->array_num;
521 
522  offset_info->array[offset_info->array_num++] = (int) OGR_F_GetFID(Ogr_feature);
523  if (Ogr_geom_type == wkbPolygon || Ogr_geom_type == wkbPolygon25D) {
524  /* register exterior ring in offset array */
525  offset_info->array[offset_info->array_num++] = 0;
526  }
527 
528  /* destroy */
529  OGR_G_DestroyGeometry(Ogr_geometry);
530  OGR_F_Destroy(Ogr_feature);
531 
532  if (ret != OGRERR_NONE)
533  return -1;
534 
535  G_debug(3, "write_feature(): -> offset = %lu offset_num = %d cat = %d",
536  (unsigned long) offset, offset_info->array_num, cat);
537 
538  return offset;
539 }
540 
541 /*!
542  \brief Writes attributes
543 
544  \param driver pointer to dbDriver
545  \param Fi pointer to field_info struct
546  \param[in,out] Ogr_layer OGR layer
547  \param[in,out] Ogr_feature OGR feature to modify
548 
549  \return 1 on success
550  \return 0 no attributes
551  \return -1 on error
552 */
553 int write_attributes(dbDriver *driver, int cat, const struct field_info *Fi,
554  OGRLayerH Ogr_layer, OGRFeatureH Ogr_feature)
555 {
556  int j, ogrfieldnum;
557  char buf[2000];
558  int ncol, sqltype, ctype, ogrtype, more;
559  const char *fidcol, *colname;
560  dbTable *table;
561  dbString dbstring;
562  dbColumn *column;
563  dbCursor cursor;
564  dbValue *value;
565 
566  OGRFieldDefnH hFieldDefn;
567 
568  G_debug(3, "write_attributes(): cat = %d", cat);
569 
570  if (cat < 0) {
571  G_warning(_("Feature without category of layer %d"), Fi->number);
572  return 0;
573  }
574 
575  db_init_string(&dbstring);
576 
577  /* read & set attributes */
578  sprintf(buf, "SELECT * FROM %s WHERE %s = %d", Fi->table, Fi->key,
579  cat);
580  G_debug(4, "SQL: %s", buf);
581  db_set_string(&dbstring, buf);
582 
583  /* select data */
584  if (db_open_select_cursor(driver, &dbstring, &cursor, DB_SEQUENTIAL) != DB_OK) {
585  G_warning(_("Unable to select attributes for category %d"),
586  cat);
587  return -1;
588  }
589 
590  if (db_fetch(&cursor, DB_NEXT, &more) != DB_OK) {
591  G_warning(_("Unable to fetch data from table <%s>"),
592  Fi->table);
593  return -1;
594  }
595 
596  if (!more) {
597  G_warning(_("No database record for category %d, "
598  "no attributes will be written"),
599  cat);
600  return -1;
601  }
602 
603  fidcol = OGR_L_GetFIDColumn(Ogr_layer);
604 
605  table = db_get_cursor_table(&cursor);
606  ncol = db_get_table_number_of_columns(table);
607  for (j = 0; j < ncol; j++) {
608  column = db_get_table_column(table, j);
609  colname = db_get_column_name(column);
610  if (fidcol && *fidcol && strcmp(colname, fidcol) == 0) {
611  /* skip fid column */
612  continue;
613  }
614  value = db_get_column_value(column);
615  /* for debug only */
616  db_convert_column_value_to_string(column, &dbstring);
617  G_debug(3, "col %d : val = %s", j,
618  db_get_string(&dbstring));
619 
620  sqltype = db_get_column_sqltype(column);
621  ctype = db_sqltype_to_Ctype(sqltype);
622  ogrtype = sqltype_to_ogrtype(sqltype);
623  G_debug(3, " colctype = %d", ctype);
624 
625  ogrfieldnum = OGR_F_GetFieldIndex(Ogr_feature, colname);
626  if (ogrfieldnum < 0) {
627  /* create field if not exists */
628  hFieldDefn = OGR_Fld_Create(colname, ogrtype);
629  if (OGR_L_CreateField(Ogr_layer, hFieldDefn, TRUE) != OGRERR_NONE)
630  G_warning(_("Unable to create field <%s>"), colname);
631  ogrfieldnum = OGR_F_GetFieldIndex(Ogr_feature, colname);
632  }
633 
634  /* Reset */
635  OGR_F_UnsetField(Ogr_feature, ogrfieldnum);
636 
637  /* prevent writing NULL values */
638  if (!db_test_value_isnull(value)) {
639  switch (ctype) {
640  case DB_C_TYPE_INT:
641  OGR_F_SetFieldInteger(Ogr_feature, ogrfieldnum,
642  db_get_value_int(value));
643  break;
644  case DB_C_TYPE_DOUBLE:
645  OGR_F_SetFieldDouble(Ogr_feature, ogrfieldnum,
646  db_get_value_double(value));
647  break;
648  case DB_C_TYPE_STRING:
649  OGR_F_SetFieldString(Ogr_feature, ogrfieldnum,
650  db_get_value_string(value));
651  break;
652  case DB_C_TYPE_DATETIME:
654  &dbstring);
655  OGR_F_SetFieldString(Ogr_feature, ogrfieldnum,
656  db_get_string(&dbstring));
657  break;
658  default:
659  G_warning(_("Unsupported column type %d"), ctype);
660  break;
661  }
662  }
663  }
664 
665  db_close_cursor (&cursor);
666 
667  db_free_string(&dbstring);
668 
669  return 1;
670 }
671 
672 int sqltype_to_ogrtype(int sqltype)
673 {
674  int ctype, ogrtype;
675 
676  ctype = db_sqltype_to_Ctype(sqltype);
677 
678  switch(ctype) {
679  case DB_C_TYPE_INT:
680  ogrtype = OFTInteger;
681  break;
682  case DB_C_TYPE_DOUBLE:
683  ogrtype = OFTReal;
684  break;
685  case DB_C_TYPE_STRING:
686  ogrtype = OFTString;
687  break;
688  case DB_C_TYPE_DATETIME:
689  ogrtype = OFTString;
690  break;
691  default:
692  ogrtype = OFTString;
693  break;
694  }
695 
696  return ogrtype;
697 }
698 
699 #endif /* HAVE_OGR */
int * array
Offset list.
Definition: dig_structs.h:446
#define TRUE
Definition: gis.h:59
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
dbValue * db_get_column_value(dbColumn *)
Returns column value for given column structure.
off_t V2__write_area_ogr(struct Map_info *Map, const struct line_pnts **points, int nparts, const struct line_cats *cats)
Writes area on topological level (OGR Simple Features interface, internal use only) ...
Definition: write_ogr.c:164
dbDriver * db_start_driver(const char *)
Initialize a new dbDriver for db transaction.
Definition: start.c:50
struct Key_Value * G_get_projinfo(void)
Gets projection information for location.
Definition: get_projinfo.c:61
OGRDataSourceH ds
Pointer to OGRDataSource.
Definition: dig_structs.h:542
int db_get_column_length(dbColumn *)
Get column&#39;s length.
const char * db_get_column_name(dbColumn *)
Returns column name for given column.
void db_init_string(dbString *)
Initialize dbString.
Definition: string.c:25
struct Format_info_offset offset
Offset list used for building pseudo-topology.
Definition: dig_structs.h:589
int db_fetch(dbCursor *, int, int *)
Fetch data from open cursor.
Definition: c_fetch.c:28
off_t V1_rewrite_line_ogr(struct Map_info *Map, off_t offset, int type, const struct line_pnts *points, const struct line_cats *cats)
Rewrites feature at the given offset on level 1 (OGR interface)
Definition: write_ogr.c:88
int db_open_select_cursor(dbDriver *, dbString *, dbCursor *, int)
Open select cursor.
Definition: c_openselect.c:37
int n_points
Number of points.
Definition: dig_structs.h:1692
char * db_get_string(const dbString *)
Get string.
Definition: string.c:140
char * table
Name of DB table.
Definition: dig_structs.h:155
#define DB_C_TYPE_DATETIME
Definition: dbmi.h:110
void G_free(void *)
Free allocated memory.
Definition: gis/alloc.c:149
int db_get_value_int(dbValue *)
Get integer value.
Definition: value.c:38
int V1_delete_line_ogr(struct Map_info *Map, off_t offset)
Deletes feature at the given offset on level 1 (OGR interface)
Definition: write_ogr.c:119
char * dsn
OGR datasource name.
Definition: dig_structs.h:525
struct Format_info fInfo
Format info for non-native formats.
Definition: dig_structs.h:1415
#define PRI_OFF_T
Definition: gis.h:69
int db_set_handle(dbHandle *, const char *, const char *)
Set handle (database and schema name)
Definition: handle.c:39
char ** layer_options
Array of OGR layer options.
Definition: dig_structs.h:568
#define NULL
Definition: ccmath.h:32
int V1_read_line_ogr(struct Map_info *, struct line_pnts *, struct line_cats *, off_t)
Read feature from OGR layer at given offset (level 1 without topology)
Definition: read_ogr.c:179
int db_set_string(dbString *, const char *)
Inserts string to dbString (enlarge string)
Definition: string.c:41
#define GV_POINT
Feature types used in memory on run time (may change)
Definition: dig_defines.h:182
int db_close_database_shutdown_driver(dbDriver *)
Close driver/database connection.
Definition: db.c:62
int Vect_get_num_dblinks(const struct Map_info *)
Get number of defined dblinks.
Definition: level_two.c:163
char * database
Definition: dig_structs.h:151
int db_convert_column_value_to_string(dbColumn *, dbString *)
?
Definition: columnfmt.c:61
Feature category info.
Definition: dig_structs.h:1702
struct Key_Value * G_get_projunits(void)
Gets units information for location.
Definition: get_projinfo.c:32
#define GV_LINE
Definition: dig_defines.h:183
Layer (old: field) information.
Definition: dig_structs.h:134
double * x
Array of X coordinates.
Definition: dig_structs.h:1680
Feature geometry info - coordinates.
Definition: dig_structs.h:1675
int db_get_column_sqltype(dbColumn *)
Returns column sqltype for column.
off_t V1_write_line_ogr(struct Map_info *Map, int type, const struct line_pnts *points, const struct line_cats *cats)
Writes feature on level 1 (OGR interface)
Definition: write_ogr.c:62
int db_test_value_isnull(dbValue *)
Check of value is null.
Definition: value.c:26
int db_append_string(dbString *, const char *)
Append string to dbString.
Definition: string.c:205
#define GV_FACE
Definition: dig_defines.h:186
OGRSpatialReferenceH GPJ_grass_to_osr2(const struct Key_Value *, const struct Key_Value *, const struct Key_Value *)
Converts a GRASS co-ordinate system to an OGRSpatialReferenceH object. EPSG code is preferred if avai...
Definition: convert.c:361
Data structure used for building pseudo-topology.
Definition: dig_structs.h:397
struct field_info * Vect_get_dblink(const struct Map_info *, int)
Get information about link to database.
Definition: field.c:467
#define DB_NEXT
Definition: dbmi.h:114
#define DB_C_TYPE_STRING
Definition: dbmi.h:107
int n_cats
Number of categories attached to element.
Definition: dig_structs.h:1715
#define GV_BOUNDARY
Definition: dig_defines.h:184
const struct driver * driver
Definition: driver/init.c:25
Non-native format info (OGR)
Definition: dig_structs.h:516
int db_sqltype_to_Ctype(int)
Get C data type based on given SQL data type.
Definition: sqlCtype.c:24
struct Format_info_ogr ogr
OGR info.
Definition: dig_structs.h:722
#define DB_C_TYPE_INT
Definition: dbmi.h:108
void db_init_handle(dbHandle *)
Initialize handle (i.e database/schema)
Definition: handle.c:23
int array_num
Number of items in offset list.
Definition: dig_structs.h:450
Definition: gis.h:512
int array_alloc
Space allocated for offset list.
Definition: dig_structs.h:454
Vector map info.
Definition: dig_structs.h:1259
const char * db_get_value_string(dbValue *)
Get string value.
Definition: value.c:92
double * y
Array of Y coordinates.
Definition: dig_structs.h:1684
char * driver
Name of DB driver (&#39;sqlite&#39;, &#39;dbf&#39;, ...)
Definition: dig_structs.h:147
int db_open_database(dbDriver *, dbHandle *)
Open database connection.
Definition: c_opendb.c:27
char * layer_name
OGR layer name.
Definition: dig_structs.h:529
Definition: driver.h:22
double db_get_value_double(dbValue *)
Get double precision value.
Definition: value.c:50
int Vect_is_3d(const struct Map_info *)
Check if vector map is 3D.
#define DB_SEQUENTIAL
Definition: dbmi.h:123
#define DB_C_TYPE_DOUBLE
Definition: dbmi.h:109
void G_warning(const char *,...) __attribute__((format(printf
int number
Layer number.
Definition: dig_structs.h:139
dbColumn * db_get_table_column(dbTable *, int)
Returns column structure for given table and column number.
char * driver_name
OGR driver name.
Definition: dig_structs.h:521
dbDriver * dbdriver
Open DB driver when writing attributes.
Definition: dig_structs.h:559
#define G_realloc(p, n)
Definition: defs/gis.h:114
double * z
Array of Z coordinates.
Definition: dig_structs.h:1688
#define _(str)
Definition: glocale.h:10
int * field
Array of layers (fields)
Definition: dig_structs.h:1707
OGRLayerH layer
Pointer to OGRLayer.
Definition: dig_structs.h:546
dbTable * db_get_cursor_table(dbCursor *)
Get table allocated by cursor.
Definition: cursor.c:67
int db_get_table_number_of_columns(dbTable *)
Return the number of columns of the table.
int G_debug(int, const char *,...) __attribute__((format(printf
void db_free_string(dbString *)
Free allocated space for dbString.
Definition: string.c:150
void G_free_key_value(struct Key_Value *)
Free allocated Key_Value structure.
Definition: key_value1.c:103
int db_close_cursor(dbCursor *)
Close cursor.
Definition: c_close_cur.c:27
int Vect_cat_get(const struct line_cats *, int, int *)
Get first found category of given field.
#define GV_KERNEL
Definition: dig_defines.h:187
struct Key_Value * G_get_projepsg(void)
Gets EPSG information for the current location.
Definition: get_projinfo.c:102
#define DB_OK
Definition: dbmi.h:71
char * key
Name of key column (usually &#39;cat&#39;)
Definition: dig_structs.h:159