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;
85 const char *geometry_type =
NULL;
86 const char *map_name =
NULL;
90 _(
"Unable to copy features. Input vector map <%s> is not open"),
111 G_warning(
_(
"Unable to create PostGIS layer <%s>"),
130 ret += copy_lines_2(In, field, topo, Out);
136 if (geometry_type && strcmp(geometry_type,
"polygon") == 0) {
141 G_free((
void *)geometry_type);
148 G_warning(
_(
"Vector map <%s> not open on topological level. "
149 "Areas will be skipped!"),
154 ret += copy_lines_1(In, field, Out);
156 return ret > 0 ? 1 : 0;
172 const char *map_name =
NULL;
187 G_warning(
_(
"Unable to read vector map <%s>"), map_name);
192 else if (type == -2) {
195 else if (type == 0) {
225 int i, type, nlines, nskipped;
226 int ret, left, rite, centroid, with_z;
228 struct line_pnts *Points, *CPoints, *NPoints;
231 const char *ftype =
NULL;
232 const char *map_name =
NULL;
246 G_debug(2,
"feature type: %s", ftype ? ftype :
"?");
250 G_message(
_(
"Copying features (%s)..."), ftype);
257 for (i = 1; i <= nlines; i++) {
265 G_warning(
_(
"Unable to read vector map <%s>"), map_name);
286 if (ftype && strcmp(ftype,
"linestring") != 0)
295 if (ftype && strcmp(ftype,
"point") != 0)
307 int skip_bndry =
TRUE;
385 _(
"%d features without category or from different layer skipped"),
410 int nnodes, node, with_z;
421 for (node = 1; node <= nnodes; node++) {
422 G_debug(3,
"Exporting GRASS node %d", node);
451 G_fatal_error(
_(
"GRASS is not compiled with PostgreSQL support"));
469 int is_isle(
struct Map_info *Map,
int area)
471 int i, line, left, right, isle, is_isle;
480 for (i = 0; i < List->
n_values && !is_isle; i++) {
481 line = List->
value[i];
485 isle = line > 0 ? left : right;
493 G_debug(3,
"is_isle(): area %d skip? -> %s", area, is_isle ?
"yes" :
"no");
511 int i, area, nareas, cat, isle, nisles, nparts_alloc, nskipped;
527 for (area = 1; area <= nareas; area++) {
557 G_debug(3,
"Area %d: is_isle() -> %d", area, is_isle(In, area));
566 if (nisles + 1 > nparts_alloc) {
569 Points, (nisles + 1) *
sizeof(
struct line_pnts *));
570 for (i = nparts_alloc; i < nisles + 1; i++)
572 nparts_alloc = nisles + 1;
574 G_debug(3,
"\tcat=%d, nisles=%d", cat, nisles);
575 for (i = 0; i < nisles; i++) {
602 _(
"%d areas without category or from different layer skipped"),
607 for (i = 0; i < nparts_alloc; i++)
636 const char *map_name =
NULL;
640 G_debug(2,
"Vect_copy_tables(): copying %d tables", n);
643 if (field < 1 && n > 1)
646 for (i = 0; i < n; i++) {
649 G_warning(
_(
"Database connection not defined for layer %d"),
653 if (field > 0 && Fi->
number != field) {
662 _(
"Unable to copy table <%s> for layer %d from <%s> to <%s>"),
687 int field_out,
const char *field_name,
int type)
711 int field_in,
int field_out,
712 const char *field_name,
int type,
751 int field_in,
int field_out,
const char *field_name,
752 int type,
int *cats,
int ncats)
759 G_debug(2,
"Vect_copy_table_by_cats(): field_in = %d field_out = %d",
760 field_in, field_out);
764 G_warning(
_(
"Database connection not defined for layer %d"), field_in);
768 if (field_name !=
NULL)
774 G_debug(3,
"Copy drv:db:table '%s:%s:%s' to '%s:%s:%s'", Fi->
driver,
780 G_warning(
_(
"Unable to add database link for vector map <%s>"),
803 G_warning(
_(
"Unable to open database <%s> with driver <%s>"),
813 goto close_db_free_exit;
820 goto close_db_free_exit;
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)
void Vect_destroy_field_info(struct field_info *)
Free a struct field_info and all memory associated with it.
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...
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)