21 #include "local_proto.h" 32 #define TOPO_POSTGIS 2 35 #include "pg_local_proto.h" 45 static int is_isle(
const struct Map_info *,
int);
78 int ret, format, topo;
81 G_fatal_error(
_(
"Unable to copy features. Input vector map <%s> is not open"),
102 G_warning(
_(
"Unable to create PostGIS layer <%s>"),
121 ret += copy_lines_2(In, field, topo, Out);
134 G_warning(
_(
"Vector map <%s> not open on topological level. " 137 ret += copy_lines_1(In, field, Out);
140 return ret > 0 ? 1 : 0;
169 G_warning(
_(
"Unable to read vector map <%s>"),
174 else if (type == -2) {
177 else if (type == 0) {
208 int i, type, nlines, nskipped;
209 int ret, left, rite, centroid, with_z;
211 struct line_pnts *Points, *CPoints, *NPoints;
214 const char *ftype =
NULL;
228 G_debug(2,
"feature type: %s", ftype ? ftype :
"?");
232 G_message(
_(
"Copying features (%s)..."), ftype);
239 for (i = 1; i <= nlines; i++) {
246 G_warning(
_(
"Unable to read vector map <%s>"),
267 if (ftype && strcmp(ftype,
"linestring") != 0)
276 if (ftype && strcmp(ftype,
"point") != 0)
288 int skip_bndry =
TRUE;
351 if (n1 > 0 && (n1 > offset->
array_num || offset->
array[n1-1] == 0))
352 copy_line_nodes(In, n1, with_z, NPoints, Out);
353 if (n2 > 0 && (n2 > offset->
array_num || offset->
array[n2-1] == 0))
354 copy_line_nodes(In, n2, with_z, NPoints, Out);
364 G_important_message(
_(
"%d features without category or from different layer skipped"), nskipped);
387 int nnodes, node, with_z;
398 for (node = 1; node <= nnodes; node++) {
399 G_debug(3,
"Exporting GRASS node %d", node);
402 copy_line_nodes(In, node, with_z, Points, Out);
411 int copy_line_nodes(
const struct Map_info *In,
int node,
int with_z,
428 G_fatal_error(
_(
"GRASS is not compiled with PostgreSQL support"));
446 int is_isle(
const struct Map_info *Map,
int area)
448 int i, line, left, right, isle, is_isle;
457 for (i = 0; i < List->
n_values && !is_isle; i++) {
458 line = List->
value[i];
462 isle = line > 0 ? left : right;
470 G_debug(3,
"is_isle(): area %d skip? -> %s", area, is_isle ?
"yes" :
"no");
488 int i, area, nareas, cat, isle, nisles, nparts_alloc, nskipped;
503 for (area = 1; area <= nareas; area++) {
533 G_debug(3,
"Area %d: is_isle() -> %d", area, is_isle(In, area));
542 if (nisles + 1 > nparts_alloc) {
547 for (i = nparts_alloc; i < nisles + 1; i++)
549 nparts_alloc = nisles + 1;
551 G_debug(3,
"\tcat=%d, nisles=%d", cat, nisles);
552 for (i = 0; i < nisles; i++) {
579 for (i = 0; i < nparts_alloc; i++)
611 G_debug(2,
"Vect_copy_tables(): copying %d tables", n);
614 if (field < 1 && n > 1)
617 for (i = 0; i < n; i++) {
620 G_warning(
_(
"Database connection not defined for layer %d"),
624 if (field > 0 && Fi->
number != field)
630 G_warning(
_(
"Unable to copy table <%s> for layer %d from <%s> to <%s>"),
653 int field_out,
const char *field_name,
int type)
677 int field_in,
int field_out,
const char *field_name,
717 int field_in,
int field_out,
const char *field_name,
718 int type,
int *cats,
int ncats)
725 G_debug(2,
"Vect_copy_table_by_cats(): field_in = %d field_out = %d", field_in,
730 G_warning(
_(
"Database connection not defined for layer %d"),
735 if (field_name !=
NULL)
741 G_debug(3,
"Copy drv:db:table '%s:%s:%s' to '%s:%s:%s'",
749 G_warning(
_(
"Unable to add database link for vector map <%s>"),
773 G_warning(
_(
"Unable to open database <%s> with driver <%s>"),
786 G_warning(
_(
"Unable to grant privileges on table <%s>"),
int Vect_copy_table_by_cats(const struct Map_info *In, struct Map_info *Out, int field_in, int field_out, const char *field_name, int type, int *cats, int ncats)
Copy attribute table linked to vector map based on category numbers.
char * name
Map name (for 4.0)
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void void void G_important_message(const char *,...) __attribute__((format(printf
int Vect_get_area_isle(const struct Map_info *, int, int)
Returns isle id for area.
plus_t Vect_get_num_nodes(const struct Map_info *)
Get number of nodes in vector map.
#define GV_MTABLE
More tables linked to vector map.
#define GV_FORMAT_NATIVE
Geometry data formats supported by lib Don't change GV_FORMAT_* values, this order is hardcoded in li...
struct P_line ** Line
Array of vector geometries.
int Vect_map_add_dblink(struct Map_info *, int, const char *, const char *, const char *, const char *, const char *)
Add new db connection to Map_info structure.
plus_t Vect_get_num_lines(const struct Map_info *)
Fetch number of features (points, lines, boundaries, centroids) in vector map.
int Vect_get_area_centroid(const struct Map_info *, int)
Returns centroid id for given area.
#define TOPO_NONE
Copy topological elements.
struct field_info * field
Pointer to the first field_info structure.
int Vect_set_constraint_type(struct Map_info *, int)
Set constraint type.
char * table
Name of DB table.
int n_values
Number of values in the list.
void G_free(void *)
Free allocated memory.
int Vect_get_area_num_isles(const struct Map_info *, int)
Returns number of isles for given area.
struct Format_info fInfo
Format info for non-native formats.
dbDriver * db_start_driver_open_database(const char *, const char *)
Open driver/database connection.
int Vect_copy_map_lines_field(struct Map_info *In, int field, struct Map_info *Out)
Copy all alive vector features from given layer from input vector map to output vector map...
int type
Feature type constraint.
int db_close_database_shutdown_driver(dbDriver *)
Close driver/database connection.
struct field_info * Vect_get_field(const struct Map_info *, int)
Get information about link to database (by layer number)
int Vect_get_num_dblinks(const struct Map_info *)
Get number of defined dblinks.
int Vect_get_node_coor(const struct Map_info *, int, double *, double *, double *)
Get node coordinates.
int Vect_copy_table(const struct Map_info *In, struct Map_info *Out, int field_in, int field_out, const char *field_name, int type)
Copy attribute table linked to vector map based on type.
Layer (old: field) information.
void G_message(const char *,...) __attribute__((format(printf
double * x
Array of X coordinates.
int db_grant_on_table(dbDriver *, const char *, int, int)
Grant privileges on table.
Feature geometry info - coordinates.
char * name
Layer name (optional)
char * Vect_subst_var(const char *, const struct Map_info *)
Substitute variable in string.
char * Vect_get_finfo_layer_name(const struct Map_info *)
Get layer name (relevant only for non-native formats)
struct Map_info::@11 constraint
Constraints for sequential feature access.
void Vect_destroy_list(struct ilist *)
Frees all memory associated with a struct ilist, including the struct itself.
struct line_pnts * Vect_new_line_struct(void)
Creates and initializes a line_pnts structure.
void Vect_destroy_cats_struct(struct line_cats *)
Frees all memory associated with line_cats structure, including the struct itself.
void * topo
Topology info.
struct field_info * Vect_get_dblink(const struct Map_info *, int)
Get information about link to database.
off_t Vect_write_line(struct Map_info *, int, const struct line_pnts *, const struct line_cats *)
Writes a new feature.
int Vect_get_isle_points(const struct Map_info *, int, struct line_pnts *)
Returns polygon array of points for given isle.
int Vect_append_point(struct line_pnts *, double, double, double)
Appends one point to the end of a line.
const struct driver * driver
struct Plus_head plus
Plus info (topology, version, ...)
int Vect_get_area_boundaries(const struct Map_info *, int, struct ilist *)
Creates list of boundaries for given area.
off_t V2__write_node_pg(struct Map_info *Map, const struct line_pnts *points)
Writes node on topological level (PostGIS Topology interface, internal use only)
plus_t Vect_get_num_areas(const struct Map_info *)
Get number of areas in vector map.
#define GV_1TABLE
One table linked to vector map.
int Vect_reset_cats(struct line_cats *)
Reset category structure to make sure cats structure is clean to be re-used.
int Vect_rewind(struct Map_info *)
Rewind vector map to cause reads to start at beginning.
int type_flag
Non-zero value to enable feature type constraint.
int Vect_get_isle_area(const struct Map_info *, int)
Returns area id for isle.
off_t V2__write_area_sfa(struct Map_info *Map, const struct line_pnts **points, int nparts, const struct line_cats *cats)
Writes area on topological level (Simple Features interface, internal use only)
void G_percent(long, long, int)
Print percent complete messages.
#define GV_FORMAT_POSTGIS
PostGIS format.
int db_create_index2(dbDriver *, const char *, const char *)
Create unique index.
double * y
Array of Y coordinates.
struct dblinks * dblnk
Array of DB links.
char * driver
Name of DB driver ('sqlite', 'dbf', ...)
struct field_info * Vect_default_field_info(struct Map_info *, int, const char *, int)
Get default information about link to database for new dblink.
struct ilist * Vect_new_list(void)
Creates and initializes a struct ilist.
int Vect_is_3d(const struct Map_info *)
Check if vector map is 3D.
struct line_cats * Vect_new_cats_struct(void)
Creates and initializes line_cats structure.
const char * Vect_get_full_name(const struct Map_info *)
Get fully qualified name of vector map.
void G_warning(const char *,...) __attribute__((format(printf
const char * Vect_get_finfo_geometry_type(const struct Map_info *)
Get geometry type as string (relevant only for non-native formats)
int Vect_line_alive(const struct Map_info *, int)
Check if feature is alive or dead (topological level required)
double * z
Array of Z coordinates.
int Vect_copy_map_lines(struct Map_info *In, struct Map_info *Out)
Copy all alive vector features from input vector map to output vector map.
int Vect_cat_list_to_array(const struct cat_list *, int **, int *)
Convert cat_list struct to ordered array of unique integers.
int format
Map format (native, ogr, postgis)
int Vect_copy_tables(const struct Map_info *In, struct Map_info *Out, int field)
Copy attribute tables linked to vector map.
int * field
Array of layers (fields)
int Vect_copy_table_by_cat_list(const struct Map_info *In, struct Map_info *Out, int field_in, int field_out, const char *field_name, int type, const struct cat_list *cat_list)
Copy attribute table linked to vector map based on category list.
int * value
Array of values.
int Vect_read_next_line(const struct Map_info *, struct line_pnts *, struct line_cats *)
Read next vector feature.
void Vect_destroy_line_struct(struct line_pnts *)
Frees all memory associated with a line_pnts structure, including the structure itself.
int Vect_get_area_points(const struct Map_info *, int, struct line_pnts *)
Returns polygon array of points (outer ring) of given area.
int Vect_read_line(const struct Map_info *, struct line_pnts *, struct line_cats *, int)
Read vector feature (topological level required)
int db_copy_table_by_ints(const char *, const char *, const char *, const char *, const char *, const char *, const char *, int *, int)
Copy a table (by keys)
const char * Vect_get_name(const struct Map_info *)
Get name of vector map.
int Vect_level(const struct Map_info *)
Returns level that Map is opened at.
int G_debug(int, const char *,...) __attribute__((format(printf
int Vect__copy_areas(const struct Map_info *In, int field, struct Map_info *Out)
Copy areas as polygons (OGR/PostGIS simple features access only)
int Vect_get_line_areas(const struct Map_info *, int, int *, int *)
Get area id on the left and right side of the boundary.
int Vect_get_area_cat(const struct Map_info *, int, int)
Find FIRST category of given field and area.
int Vect_cat_get(const struct line_cats *, int, int *)
Get first found category of given field.
int Vect_cat_set(struct line_cats *, int, int)
Add new field/cat to category structure if doesn't exist yet.
int V2__update_area_pg(struct Map_info *Map, const struct line_pnts **points, int nparts, int cat)
Updates simple features geometry from GRASS-like topo.
char * key
Name of key column (usually 'cat')