27#include <cpl_string.h>
30static int create_ogr_layer(
struct Map_info *,
int);
35static int sqltype_to_ogrtype(
int);
65 return write_feature(
Map, type, &points, 1, cats);
86 G_debug(3,
"V1_rewrite_line_ogr(): type=%d offset=%" PRId64, type, offset);
88 G_warning(
_(
"Unable to rewrite feature (incompatible feature types)"));
111 G_debug(3,
"V1_delete_line_ogr(), offset = %lu", (
unsigned long)
offset);
174 G_warning(
_(
"Unable to start driver <%s>"),
Fi->driver);
179 G_warning(
_(
"Unable to open database <%s> by driver <%s>"),
180 Fi->database,
Fi->driver);
245int create_ogr_layer(
struct Map_info *
Map,
int type)
252 struct Key_Value *projinfo, *projunits, *projepsg;
283 G_warning(
_(
"Unsupported geometry type (%d)"), type);
306 G_warning(
_(
"Unable to create OGR layer <%s> in '%s'"),
318 G_warning(
_(
"More layers defined, using driver <%s> and "
320 Fi->driver,
Fi->database);
325 G_warning(
_(
"Database connection not defined. "
326 "Unable to write attributes."));
331 G_warning(
_(
"OGR transaction with layer <%s> failed to start"),
380 if (create_ogr_layer(
Map, type) < 0)
393 G_warning(
_(
"No category defined for layer %d"),
Fi->number);
395 G_warning(
_(
"Feature has more categories, using "
396 "category %d (from layer %d)"),
397 cat, cats->
field[0]);
408 G_warning(
_(
"Feature is not a point. Skipping."));
416 G_warning(
_(
"Feature is not a line. Skipping."));
423 G_warning(
_(
"Feature is not a polygon. Skipping."));
430 G_warning(
_(
"Feature is not a face. Skipping."));
436 G_warning(
_(
"Unsupported feature type (%d)"), type);
440 G_debug(3,
"V1_write_line_ogr(): type = %d", type);
452 if (points->
x[0] != points->
x[npoints] ||
453 points->
y[0] != points->
y[npoints] ||
454 points->
z[0] != points->
z[npoints]) {
455 G_warning(
_(
"Boundary is not closed. Feature skipped."));
460 for (i = 0; i < npoints; i++) {
469 for (i = 0; i < points->
n_points; i++) {
481 if (cat > -1 &&
ogr_info->dbdriver) {
484 G_warning(
_(
"Unable to writes feature attributes"));
513 G_debug(3,
"write_feature(): -> offset = %lu offset_num = %d cat = %d",
514 (
unsigned long)offset,
offset_info->array_num, cat);
546 G_debug(3,
"write_attributes(): cat = %d", cat);
549 G_warning(
_(
"Feature without category of layer %d"),
Fi->number);
556 snprintf(buf,
sizeof(buf),
"SELECT * FROM %s WHERE %s = %d",
Fi->table,
564 G_warning(
_(
"Unable to select attributes for category %d"), cat);
569 G_warning(
_(
"Unable to fetch data from table <%s>"),
Fi->table);
574 G_warning(
_(
"No database record for category %d, "
575 "no attributes will be written"),
599 G_debug(3,
" colctype = %d", ctype);
634 G_warning(
_(
"Unsupported column type %d"), ctype);
647int sqltype_to_ogrtype(
int sqltype)
Main header of GRASS DataBase Management Interface.
#define DB_C_TYPE_DATETIME
int db_test_value_isnull(dbValue *)
Check of value is null.
int db_get_column_length(dbColumn *)
Get column's length.
dbColumn * db_get_table_column(dbTable *, int)
Returns column structure for given table and column number.
double db_get_value_double(dbValue *)
Get double precision value.
int db_sqltype_to_Ctype(int)
Get C data type based on given SQL data type.
dbValue * db_get_column_value(dbColumn *)
Returns column value for given column structure.
int db_get_column_sqltype(dbColumn *)
Returns column sqltype for column.
int db_open_database(dbDriver *, dbHandle *)
Open database connection.
int db_close_database_shutdown_driver(dbDriver *)
Close driver/database connection.
void db_free_string(dbString *)
Free allocated space for dbString.
char * db_get_string(const dbString *)
Get string.
dbTable * db_get_cursor_table(dbCursor *)
Get table allocated by cursor.
int db_set_string(dbString *, const char *)
Inserts string to dbString (enlarge string)
const char * db_get_column_name(dbColumn *)
Returns column name for given column.
int db_set_handle(dbHandle *, const char *, const char *)
Set handle (database and schema name)
int db_get_value_int(dbValue *)
Get integer value.
dbDriver * db_start_driver(const char *)
Initialize a new dbDriver for db transaction.
void db_init_handle(dbHandle *)
Initialize handle (i.e database/schema)
void db_init_string(dbString *)
Initialize dbString.
int db_close_cursor(dbCursor *)
Close cursor.
int db_open_select_cursor(dbDriver *, dbString *, dbCursor *, int)
Open select cursor.
int db_append_string(dbString *, const char *)
Append string to dbString.
int db_convert_column_value_to_string(dbColumn *, dbString *)
?
const char * db_get_value_string(dbValue *)
Get string value.
int db_fetch(dbCursor *, int, int *)
Fetch data from open cursor.
int db_get_table_number_of_columns(dbTable *)
Return the number of columns of the table.
void G_free(void *)
Free allocated memory.
struct Key_Value * G_get_projinfo(void)
Gets projection information for location.
void G_warning(const char *,...) __attribute__((format(printf
struct Key_Value * G_get_projepsg(void)
Gets EPSG information for the current location.
void G_free_key_value(struct Key_Value *)
Free allocated Key_Value structure.
struct Key_Value * G_get_projunits(void)
Gets units information for location.
int G_debug(int, const char *,...) __attribute__((format(printf
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...
int Vect_cat_get(const struct line_cats *, int, int *)
Get first found category of given field.
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)
struct field_info * Vect_get_dblink(struct Map_info *, int)
Get information about link to database.
int Vect_get_num_dblinks(struct Map_info *)
Get number of defined dblinks.
int Vect_is_3d(struct Map_info *)
Check if vector map is 3D.
#define GV_POINT
Feature types used in memory on run time (may change)
Layer (old: field) information.
int * field
Array of layers (fields)
int n_cats
Number of categories attached to element.
Feature geometry info - coordinates.
double * y
Array of Y coordinates.
double * x
Array of X coordinates.
int n_points
Number of points.
double * z
Array of Z coordinates.
int V1_delete_line_ogr(struct Map_info *Map, off_t offset)
Deletes feature at the given offset on level 1 (OGR interface)
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)
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)
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)