23 #include "local_proto.h"
34 #define TOPO_POSTGIS 2
37 #include "pg_local_proto.h"
40 #define NOPG_UNUSED UNUSED
51 static int is_isle(
struct Map_info *,
int);
84 int ret, format, topo;
88 _(
"Unable to copy features. Input vector map <%s> is not open"),
109 G_warning(
_(
"Unable to create PostGIS layer <%s>"),
128 ret += copy_lines_2(In, field, topo, Out);
141 G_warning(
_(
"Vector map <%s> not open on topological level. "
142 "Areas will be skipped!"),
145 ret += copy_lines_1(In, field, Out);
148 return ret > 0 ? 1 : 0;
177 G_warning(
_(
"Unable to read vector map <%s>"),
182 else if (type == -2) {
185 else if (type == 0) {
216 int i, type, nlines, nskipped;
217 int ret, left, rite, centroid, with_z;
219 struct line_pnts *Points, *CPoints, *NPoints;
222 const char *ftype =
NULL;
236 G_debug(2,
"feature type: %s", ftype ? ftype :
"?");
240 G_message(
_(
"Copying features (%s)..."), ftype);
247 for (i = 1; i <= nlines; i++) {
254 G_warning(
_(
"Unable to read vector map <%s>"),
275 if (ftype && strcmp(ftype,
"linestring") != 0)
284 if (ftype && strcmp(ftype,
"point") != 0)
296 int skip_bndry =
TRUE;
373 _(
"%d features without category or from different layer skipped"),
397 int nnodes, node, with_z;
408 for (node = 1; node <= nnodes; node++) {
409 G_debug(3,
"Exporting GRASS node %d", node);
438 G_fatal_error(
_(
"GRASS is not compiled with PostgreSQL support"));
456 int is_isle(
struct Map_info *Map,
int area)
458 int i, line, left, right, isle, is_isle;
467 for (i = 0; i < List->
n_values && !is_isle; i++) {
468 line = List->
value[i];
472 isle = line > 0 ? left : right;
480 G_debug(3,
"is_isle(): area %d skip? -> %s", area, is_isle ?
"yes" :
"no");
498 int i, area, nareas, cat, isle, nisles, nparts_alloc, nskipped;
513 for (area = 1; area <= nareas; area++) {
543 G_debug(3,
"Area %d: is_isle() -> %d", area, is_isle(In, area));
552 if (nisles + 1 > nparts_alloc) {
555 Points, (nisles + 1) *
sizeof(
struct line_pnts *));
556 for (i = nparts_alloc; i < nisles + 1; i++)
558 nparts_alloc = nisles + 1;
560 G_debug(3,
"\tcat=%d, nisles=%d", cat, nisles);
561 for (i = 0; i < nisles; i++) {
586 _(
"%d areas without category or from different layer skipped"),
590 for (i = 0; i < nparts_alloc; i++)
621 G_debug(2,
"Vect_copy_tables(): copying %d tables", n);
624 if (field < 1 && n > 1)
627 for (i = 0; i < n; i++) {
630 G_warning(
_(
"Database connection not defined for layer %d"),
634 if (field > 0 && Fi->
number != field)
641 _(
"Unable to copy table <%s> for layer %d from <%s> to <%s>"),
665 int field_out,
const char *field_name,
int type)
689 int field_in,
int field_out,
690 const char *field_name,
int type,
729 int field_in,
int field_out,
const char *field_name,
730 int type,
int *cats,
int ncats)
737 G_debug(2,
"Vect_copy_table_by_cats(): field_in = %d field_out = %d",
738 field_in, field_out);
742 G_warning(
_(
"Database connection not defined for layer %d"), field_in);
746 if (field_name !=
NULL)
752 G_debug(3,
"Copy drv:db:table '%s:%s:%s' to '%s:%s:%s'", Fi->
driver,
758 G_warning(
_(
"Unable to add database link for vector map <%s>"),
780 G_warning(
_(
"Unable to open database <%s> with driver <%s>"),
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)
dbDriver * db_start_driver_open_database(const char *, const char *)
Open driver/database connection.
int db_close_database_shutdown_driver(dbDriver *)
Close driver/database connection.
int db_create_index2(dbDriver *, const char *, const char *)
Create unique index.
int db_grant_on_table(dbDriver *, const char *, int, int)
Grant privileges on table.
void G_percent(long, long, int)
Print percent complete messages.
void G_free(void *)
Free allocated memory.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
void void void G_important_message(const char *,...) __attribute__((format(printf
void G_message(const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf
void Vect_destroy_line_struct(struct line_pnts *)
Frees all memory associated with a line_pnts structure, including the structure itself.
int Vect_get_node_coor(struct Map_info *, int, double *, double *, double *)
Get node coordinates.
plus_t Vect_get_num_lines(struct Map_info *)
Fetch number of features (points, lines, boundaries, centroids) in vector map.
plus_t Vect_get_num_areas(struct Map_info *)
Get number of areas in vector map.
int Vect_reset_cats(struct line_cats *)
Reset category structure to make sure cats structure is clean to be re-used.
struct field_info * Vect_default_field_info(struct Map_info *, int, const char *, int)
Get default information about link to database for new dblink.
int Vect_cat_set(struct line_cats *, int, int)
Add new field/cat to category structure if doesn't exist yet.
int Vect_get_area_boundaries(struct Map_info *, int, struct ilist *)
Creates list of boundaries for given area.
const char * Vect_get_full_name(struct Map_info *)
Get fully qualified name of vector map.
int Vect_cat_get(const struct line_cats *, int, int *)
Get first found category of given field.
int Vect_get_isle_points(struct Map_info *, int, struct line_pnts *)
Returns polygon array of points for given isle.
int Vect_get_area_points(struct Map_info *, int, struct line_pnts *)
Returns polygon array of points (outer ring) of given area.
void Vect_destroy_list(struct ilist *)
Frees all memory associated with a struct ilist, including the struct itself.
int Vect_level(struct Map_info *)
Returns level that Map is opened at.
void Vect_destroy_cats_struct(struct line_cats *)
Frees all memory associated with line_cats structure, including the struct itself.
int Vect_get_area_isle(struct Map_info *, int, int)
Returns isle id for area.
int Vect_read_line(struct Map_info *, struct line_pnts *, struct line_cats *, int)
Read vector feature (topological level required)
struct ilist * Vect_new_list(void)
Creates and initializes a struct ilist.
int Vect_get_area_num_isles(struct Map_info *, int)
Returns number of isles for given area.
char * Vect_subst_var(const char *, struct Map_info *)
Substitute variable in string.
int Vect_cat_list_to_array(const struct cat_list *, int **, int *)
Convert cat_list struct to ordered array of unique integers.
int Vect_line_alive(struct Map_info *, int)
Check if feature is alive or dead (topological level required)
int Vect_get_num_dblinks(struct Map_info *)
Get number of defined dblinks.
int Vect_get_area_cat(struct Map_info *, int, int)
Find FIRST category of given field and area.
off_t Vect_write_line(struct Map_info *, int, const struct line_pnts *, const struct line_cats *)
Writes a new feature.
struct field_info * Vect_get_field(struct Map_info *, int)
Get information about link to database (by layer number)
struct line_pnts * Vect_new_line_struct(void)
Creates and initializes a line_pnts structure.
const char * Vect_get_finfo_geometry_type(struct Map_info *)
Get geometry type as string (relevant only for non-native formats)
struct field_info * Vect_get_dblink(struct Map_info *, int)
Get information about link to database.
plus_t Vect_get_num_nodes(struct Map_info *)
Get number of nodes in vector map.
int Vect_get_area_centroid(struct Map_info *, int)
Returns centroid id for given area.
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.
char * Vect_get_finfo_layer_name(struct Map_info *)
Get layer name (relevant only for non-native formats)
int Vect_rewind(struct Map_info *)
Rewind vector map to cause reads to start at beginning.
const char * Vect_get_name(struct Map_info *)
Get name of vector map.
int Vect_read_next_line(struct Map_info *, struct line_pnts *, struct line_cats *)
Read next vector feature.
int Vect_set_constraint_type(struct Map_info *, int)
Set constraint type.
struct line_cats * Vect_new_cats_struct(void)
Creates and initializes line_cats structure.
int Vect_get_line_areas(struct Map_info *, int, int *, int *)
Get area id on the left and right side of the boundary.
int Vect_is_3d(struct Map_info *)
Check if vector map is 3D.
int Vect_append_point(struct line_pnts *, double, double, double)
Appends one point to the end of a line.
int Vect_get_isle_area(struct Map_info *, int)
Returns area id for isle.
#define GV_FORMAT_POSTGIS
PostGIS format.
#define GV_1TABLE
One table linked to 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...
const struct driver * driver
char * name
Map name (for 4.0)
int type
Feature type constraint.
int type_flag
Non-zero value to enable feature type constraint.
int format
Map format (native, ogr, postgis)
struct Map_info::@11 constraint
Constraints for sequential feature access.
struct dblinks * dblnk
Array of DB links.
struct Format_info fInfo
Format info for non-native formats.
struct Plus_head plus
Plus info (topology, version, ...)
void * topo
Topology info.
struct P_line ** Line
Array of vector geometries.
struct field_info * field
Pointer to the first field_info structure.
Layer (old: field) information.
char * table
Name of DB table.
char * driver
Name of DB driver ('sqlite', 'dbf', ...)
char * name
Layer name (optional)
char * key
Name of key column (usually 'cat')
int n_values
Number of values in the list.
int * value
Array of values.
int * field
Array of layers (fields)
Feature geometry info - coordinates.
double * y
Array of Y coordinates.
double * x
Array of X coordinates.
double * z
Array of Z coordinates.
int Vect_copy_table(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.
int Vect_copy_tables(struct Map_info *In, struct Map_info *Out, int field)
Copy attribute tables linked to vector map.
#define TOPO_NONE
Copy topological elements.
int Vect_copy_table_by_cat_list(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 copy_line_nodes(struct Map_info *In, int node, int with_z, struct line_pnts *Points, struct Map_info *Out NOPG_UNUSED)
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_copy_table_by_cats(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.
int Vect__copy_areas(struct Map_info *In, int field, struct Map_info *Out)
Copy areas as polygons (OGR/PostGIS simple features access only)
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 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.
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)
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)