23 #include "local_proto.h" 26 #include "pg_local_proto.h" 43 static int parse_bbox(
const char *,
struct bound_box *);
45 const char *,
const char *,
const char *,
48 const struct line_data *,
int,
51 const char *,
int,
const char *);
54 static void notice_processor(
void *,
const char *);
55 static char **scan_array(
const char *);
57 static int remap_line(
const struct Plus_head*, off_t,
int);
81 G_debug(2,
"V1_open_old_pg(): update = %d", update);
90 G_warning(
_(
"PostGIS feature table not defined"));
94 G_debug(1,
"V1_open_old_pg(): conninfo='%s' table='%s'",
102 sprintf(stmt,
"SELECT f_geometry_column, coord_dimension, srid, type " 103 "FROM geometry_columns WHERE f_table_schema = '%s' AND " 107 res = PQexec(pg_info->
conn, stmt);
108 if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
109 G_fatal_error(
"%s\n%s",
_(
"No feature tables found in database."),
110 PQresultErrorMessage(res));
112 found = PQntuples(res) > 0 ?
TRUE :
FALSE;
119 pg_info->
fid_column = get_key_column(pg_info);
121 pg_info->
coor_dim = atoi(PQgetvalue(res, 0, 1));
123 pg_info->
srid = atoi(PQgetvalue(res, 0, 2));
125 pg_info->
feature_type = ftype_from_string(PQgetvalue(res, 0, 3));
133 G_warning(
_(
"Feature table <%s> not found in 'geometry_columns'"),
139 check_topo(pg_info, &(Map->
plus));
143 G_fatal_error(
_(
"GRASS is not compiled with PostgreSQL support"));
168 G_debug(3,
"V2_open_old_pg(): name = %s mapset = %s", Map->
name,
177 sprintf(stmt,
"SELECT id FROM topology.topology WHERE name = '%s'",
179 res = PQexec(pg_info->
conn, stmt);
180 if (!res || PQresultStatus(res) != PGRES_TUPLES_OK) {
181 G_warning(
"%s\n%s",
_(
"Topology schema not found."),
182 PQresultErrorMessage(res));
193 G_warning(
_(
"Unable to open feature index file for vector map <%s>"),
200 G_fatal_error(
_(
"GRASS is not compiled with PostgreSQL support"));
228 G_debug(2,
"V1_open_new_pg(): name = %s with_z = %d", name, with_z);
232 G_warning(
_(
"Connection string not defined"));
237 G_warning(
_(
"PostGIS feature table not defined"));
241 G_debug(1,
"V1_open_new_pg(): conninfo='%s' table='%s'",
260 sprintf(stmt,
"SELECT * FROM pg_tables " 261 "WHERE schemaname = '%s' AND tablename = '%s'",
265 res = PQexec(pg_info->
conn, stmt);
266 if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
267 G_fatal_error(
"%s\n%s",
_(
"No feature tables found in database."),
268 PQresultErrorMessage(res));
270 if (PQntuples(res) > 0) {
273 G_warning(
_(
"PostGIS layer <%s.%s> already exists and will be overwritten"),
275 if (drop_table(pg_info) == -1) {
276 G_warning(
_(
"Unable to delete PostGIS layer <%s>"),
282 G_warning(
_(
"PostGIS layer <%s.%s> already exists in database '%s'"),
299 G_fatal_error(
_(
"GRASS is not compiled with PostgreSQL support"));
330 if (check_topo(pg_info, plus) != 0)
349 G_fatal_error(
_(
"GRASS is not compiled with PostgreSQL support"));
371 "SELECT kcu.column_name " 372 "FROM INFORMATION_SCHEMA.TABLES t " 373 "LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc " 374 "ON tc.table_catalog = t.table_catalog " 375 "AND tc.table_schema = t.table_schema " 376 "AND tc.table_name = t.table_name " 377 "AND tc.constraint_type = 'PRIMARY KEY' " 378 "LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu " 379 "ON kcu.table_catalog = tc.table_catalog " 380 "AND kcu.table_schema = tc.table_schema " 381 "AND kcu.table_name = tc.table_name " 382 "AND kcu.constraint_name = tc.constraint_name " 383 "WHERE t.table_schema = '%s' AND t.table_name = '%s'",
387 res = PQexec(pg_info->
conn, stmt);
388 if (!res || PQresultStatus(res) != PGRES_TUPLES_OK ||
389 PQntuples(res) != 1 || strlen(PQgetvalue(res, 0, 0)) < 1) {
395 key_column =
G_store(PQgetvalue(res, 0, 0));
430 G_debug(3,
"ftype_from_string(): type='%s' -> %d", type, sf_type);
449 PGresult *result, *result_drop;
452 sprintf(stmt,
"SELECT COUNT(*) FROM pg_tables WHERE schemaname = 'topology'");
455 sprintf(stmt,
"SELECT t.name FROM topology.layer AS l JOIN " 456 "topology.topology AS t ON l.topology_id = t.id " 457 "WHERE l.table_name = '%s'", pg_info->
table_name);
460 result = PQexec(pg_info->
conn, stmt);
461 if (!result || PQresultStatus(result) != PGRES_TUPLES_OK) {
462 G_warning(
_(
"Execution failed: %s"), PQerrorMessage(pg_info->
conn));
466 for (i = 0; i < PQntuples(result); i++) {
467 topo_schema = PQgetvalue(result, i, 0);
468 sprintf(stmt,
"SELECT topology.DropTopology('%s')",
472 result_drop = PQexec(pg_info->
conn, stmt);
473 if (!result_drop || PQresultStatus(result_drop) != PGRES_TUPLES_OK)
474 G_warning(
_(
"Execution failed: %s"), PQerrorMessage(pg_info->
conn));
478 PQclear(result_drop);
484 sprintf(stmt,
"DROP TABLE \"%s\".\"%s\"",
507 if (!strstr(pg_info->
conninfo,
"user")) {
510 const char *user, *passwd, *host, *port;
513 p = strstr(pg_info->
conninfo,
"dbname");
516 p += strlen(
"dbname") + 1;
518 for (i = 0; *p && *p !=
' '; i++, p++)
530 if (user || passwd || host || port) {
533 sprintf(conninfo,
"%s", pg_info->
conninfo);
535 strcat(conninfo,
" user=");
536 strcat(conninfo, user);
539 strcat(conninfo,
" password=");
540 strcat(conninfo, passwd);
543 strcat(conninfo,
" host=");
544 strcat(conninfo, host);
547 strcat(conninfo,
" port=");
548 strcat(conninfo, port);
557 if (PQstatus(pg_info->
conn) == CONNECTION_BAD)
559 _(
"Connection to PostgreSQL database failed. " 560 "Try to set up username/password by db.login."),
561 PQerrorMessage(pg_info->
conn));
568 sprintf(stmt,
"SELECT COUNT(*) FROM pg_tables WHERE tablename = 'spatial_ref_sys'");
570 PQfinish(pg_info->
conn);
571 G_fatal_error(
_(
"<%s> is not PostGIS database. DB table 'spatial_ref_sys' not found."),
577 sprintf(stmt,
"SELECT COUNT(*) FROM pg_tables WHERE schemaname = 'topology'");
579 PQfinish(pg_info->
conn);
580 G_fatal_error(
_(
"PostGIS Topology extension not found in the database <%s>"),
586 PQsetNoticeProcessor(pg_info->
conn, notice_processor,
NULL);
613 "SELECT t.id,t.name,t.hasz,l.feature_column FROM topology.layer " 614 "AS l JOIN topology.topology AS t ON l.topology_id = t.id " 615 "WHERE schema_name = '%s' AND table_name = '%s'",
619 res = PQexec(pg_info->
conn, stmt);
620 if (!res || PQresultStatus(res) != PGRES_TUPLES_OK ||
621 PQntuples(res) != 1) {
622 G_debug(1,
"Topology layers for '%s.%s' not found (%s)",
624 PQerrorMessage(pg_info->
conn));
635 sprintf(stmt,
"SELECT COUNT(*) FROM pg_tables WHERE schemaname = '%s' " 640 G_debug(1,
"PostGIS topology detected: schema = %s column = %s topo_geo_only = %d",
644 if (strcmp(PQgetvalue(res, 0, 2),
"t") == 0)
660 int parse_bbox(
const char *value,
struct bound_box *bbox)
663 size_t length, prefix_length;
664 char **tokens, **tokens_coord, *coord;
666 if (strlen(value) < 1) {
671 prefix_length = strlen(
"box3d(");
676 length = strlen(value);
677 coord =
G_malloc(length - prefix_length);
678 for (i = prefix_length; i < length; i++)
679 coord[i-prefix_length] = value[i];
680 coord[length-prefix_length-1] =
'\0';
696 bbox->
W = atof(tokens_coord[0]);
697 bbox->
S = atof(tokens_coord[1]);
698 bbox->
B = atof(tokens_coord[2]);
708 bbox->
E = atof(tokens_coord[0]);
709 bbox->
N = atof(tokens_coord[1]);
710 bbox->
T = atof(tokens_coord[2]);
736 int id,
const char *wkb_data,
const char *lines_data,
750 lines = angles =
NULL;
752 if (!lines_data && !angles_data) {
756 "SELECT edge_id,'s' as node," 757 "ST_Azimuth(ST_StartPoint(geom), ST_PointN(geom, 2)) AS angle" 758 " FROM \"%s\".edge WHERE start_node = %d UNION ALL " 759 "SELECT edge_id,'e' as node," 760 "ST_Azimuth(ST_EndPoint(geom), ST_PointN(geom, ST_NumPoints(geom) - 1)) AS angle" 761 " FROM \"%s\".edge WHERE end_node = %d" 762 " ORDER BY angle DESC",
766 res = PQexec(pg_info->
conn, stmt);
767 if (!res || PQresultStatus(res) != PGRES_TUPLES_OK) {
768 G_warning(
_(
"Inconsistency in topology: unable to read node %d"),
id);
773 cnt = PQntuples(res);
776 lines = scan_array(lines_data);
777 angles = scan_array(angles_data);
792 G_debug(4,
"read_p_node(): id = %d, n_lines = %d",
id, cnt);
800 for (i = 0; i < node->
n_lines; i++) {
801 node->
lines[i] = atoi(lines[i]);
802 node->
angles[i] = atof(angles[i]);
812 for (i = 0; i < node->
n_lines; i++) {
813 node->
lines[i] = atoi(PQgetvalue(res, i, 0));
814 if (strcmp(PQgetvalue(res, i, 1),
"s") != 0) {
816 node->
lines[i] *= -1;
818 node->
angles[i] =
M_PI / 2 - atof(PQgetvalue(res, i, 2));
834 G_warning(
_(
"Inconsistency in topology: node %d - unexpected feature type %d"),
838 node->
x = points->
x[0];
839 node->
y = points->
y[0];
841 node->
z = points->
z[0];
853 plus->
Node[n] = node;
878 const struct line_data *data,
int topo_geo_only,
884 if (data->start_node == 0 && data->end_node == 0) {
885 if (data->left_face == 0)
890 else if (data->left_face == 0 && data->right_face == 0) {
907 G_debug(4,
"read_p_line(): id/offset = %d type = %d", data->id, line->
type);
916 if ((line->
type &
GV_LINES) & (data->start_node < 0 || data->end_node < 0))
923 topo->
N1 = data->start_node;
924 topo->
N2 = data->end_node;
930 topo->
N1 = data->start_node;
931 topo->
N2 = data->end_node;
937 topo->
left = data->left_face;
938 topo->
right = data->right_face;
945 topo->
area = data->left_face;
971 plus->
Line[n] = line;
989 const char *lines_data,
int centroid,
const char *isles_data)
997 lines = scan_array(lines_data);
999 isles = scan_array(isles_data);
1003 G_warning(
_(
"Area %d without boundary detected"), n);
1007 G_debug(3,
"read_p_area(): n = %d nlines = %d nisles = %d", n, nlines, nisles);
1016 for (i = 0; i < nlines; i++) {
1017 area->
lines[i] = atoi(lines[i]);
1022 for (i = 0; i < nisles; i++) {
1023 area->
isles[i] = atoi(isles[i]);
1032 plus->
Area[n] = area;
1049 const char *lines_data,
int area)
1057 lines = scan_array(lines_data);
1061 G_warning(
_(
"Isle %d without boundary detected"), n);
1065 G_debug(3,
"read_p_isle(): n = %d nlines = %d", n, nlines);
1073 for (i = 0; i < nlines; i++) {
1074 isle->
lines[i] = atoi(lines[i]);
1082 plus->
Isle[n] = isle;
1104 plus = &(Map->
plus);
1112 "SELECT %s FROM \"%s\".\"%s\" WHERE %s = %d",
1113 TOPO_BBOX, TOPO_SCHEMA, TOPO_TABLE, TOPO_ID, pg_info->
toposchema_id);
1115 res = PQexec(pg_info->
conn, stmt);
1116 if (!res || PQresultStatus(res) != PGRES_TUPLES_OK ||
1117 PQntuples(res) != 1) {
1122 "SELECT ST_3DExtent(%s) FROM \"%s\".\"%s\"",
1125 res = PQexec(pg_info->
conn, stmt);
1126 if (!res || PQresultStatus(res) != PGRES_TUPLES_OK ||
1127 PQntuples(res) != 1 || strlen(PQgetvalue(res, 0, 0)) < 1) {
1128 G_warning(
_(
"Unable to get map bounding box from topology"));
1134 if (parse_bbox(PQgetvalue(res, 0, 0), &(plus->
box)) != 0) {
1135 G_warning(
_(
"Unable to parse map bounding box:\n%s"),
1136 PQgetvalue(res, 0, 0));
1146 "SELECT COUNT(DISTINCT node) FROM (SELECT start_node AS node " 1147 "FROM \"%s\".edge GROUP BY start_node UNION ALL SELECT end_node " 1148 "AS node FROM \"%s\".edge GROUP BY end_node) AS foo",
1155 sprintf(stmt,
"SELECT COUNT(*) FROM \"%s\".%s",
1158 if (n_nodes != plus->
n_nodes) {
1159 G_warning(
_(
"Different number of nodes detected (%d, %d)"),
1168 "SELECT COUNT(*) FROM \"%s\".edge",
1176 "SELECT COUNT(*) FROM \"%s\".face WHERE face_id > 0",
1183 sprintf(stmt,
"SELECT COUNT(*) FROM \"%s\".%s",
1186 if (n_areas != plus->
n_areas) {
1187 G_warning(
_(
"Different number of areas detected (%d, %d)"),
1198 "SELECT COUNT(*) FROM \"%s\".face WHERE face_id < 0",
1205 sprintf(stmt,
"SELECT COUNT(*) FROM \"%s\".%s",
1208 if (n_isles != plus->
n_isles) {
1209 G_warning(
_(
"Different number of areas detected (%d, %d)"),
1220 "SELECT COUNT(*) FROM \"%s\".node WHERE containing_face " 1221 "IS NULL AND node_id NOT IN " 1222 "(SELECT node FROM (SELECT start_node AS node FROM \"%s\".edge " 1223 "GROUP BY start_node UNION ALL SELECT end_node AS node FROM " 1224 "\"%s\".edge GROUP BY end_node) AS foo)",
1232 "SELECT COUNT(*) FROM \"%s\".edge WHERE " 1233 "left_face = 0 AND right_face = 0",
1240 "SELECT COUNT(*) FROM \"%s\".edge WHERE " 1241 "left_face != 0 OR right_face != 0",
1248 "SELECT COUNT(*) FROM \"%s\".node WHERE containing_face " 1249 "IS NOT NULL AND node_id NOT IN " 1250 "(SELECT node FROM (SELECT start_node AS node FROM \"%s\".edge " 1251 "GROUP BY start_node UNION ALL SELECT end_node AS node FROM " 1252 "\"%s\".edge GROUP BY end_node) AS foo)",
1290 plus = &(Map->
plus);
1320 for (line = 1; line <= plus->
n_lines; line++) {
1321 Line = plus->
Line[line];
1325 for (i = 0; i < 2; i++) {
1328 G_debug(3,
"Build area for line = %d, side = %d",
1339 "SELECT area_id,lines,centroid,isles FROM \"%s\".%s ORDER BY area_id",
1343 res = PQexec(pg_info->
conn, stmt);
1344 if (!res || PQresultStatus(res) != PGRES_TUPLES_OK ||
1345 plus->
n_areas != PQntuples(res)) {
1356 for (i = 0; i < plus->
n_areas; i++) {
1357 read_p_area(plus, i + 1, (
char *)PQgetvalue(res, i, 1),
1358 atoi(PQgetvalue(res, i, 2)), (
char *)PQgetvalue(res, i, 3));
1380 G_warning(
_(
"To be implemented: isles not attached in Topo-Geo-only mode"));
1385 "SELECT isle_id,lines,area FROM \"%s\".%s ORDER BY isle_id",
1389 res = PQexec(pg_info->
conn, stmt);
1390 if (!res || PQresultStatus(res) != PGRES_TUPLES_OK ||
1391 plus->
n_isles != PQntuples(res)) {
1401 for (i = 0; i < plus->
n_isles; i++) {
1402 read_p_isle(plus, i + 1, (
char *)PQgetvalue(res, i, 1),
1403 atoi(PQgetvalue(res, i, 2)));
1422 for (line = 1; line <= plus->
n_lines; line++) {
1423 Line = plus->
Line[line];
1464 plus = &(Map->
plus);
1466 offset = &(pg_info->
offset);
1470 "SELECT node_id,geom FROM \"%s\".node WHERE node_id IN " 1471 "(SELECT node FROM (SELECT start_node AS node FROM \"%s\".edge " 1472 "GROUP BY start_node UNION ALL SELECT end_node AS node FROM " 1473 "\"%s\".edge GROUP BY end_node) AS foo) ORDER BY node_id",
1477 sprintf(stmt,
"SELECT node.node_id,geom,lines,angles FROM \"%s\".node AS node " 1478 "JOIN \"%s\".%s AS node_grass ON node.node_id = node_grass.node_id " 1482 res = PQexec(pg_info->
conn, stmt);
1483 if (!res || PQresultStatus(res) != PGRES_TUPLES_OK ||
1484 (!geom_only && PQntuples(res) != plus->
n_nodes)) {
1485 G_warning(
_(
"Inconsistency in topology: number of " 1486 "nodes %d (should be %d)"),
1487 PQntuples(res), plus->
n_nodes);
1493 n_nodes = PQntuples(res);
1494 G_debug(3,
"load_plus(): n_nodes = %d", n_nodes);
1498 for (i = 0; i < n_nodes; i++) {
1500 id = atoi(PQgetvalue(res, i, 0));
1501 read_p_node(plus, i + 1,
1502 id, (
const char *) PQgetvalue(res, i, 1),
1505 pg_info, geom_only);
1507 offset->
array[i] = id;
1529 struct line_data line_data;
1534 plus = &(Map->
plus);
1536 offset = &(pg_info->
offset);
1546 "SELECT tt.node_id,tt.geom,ft.%s FROM \"%s\".node AS tt " 1547 "LEFT JOIN \"%s\".\"%s\" AS ft ON " 1548 "(%s).type = 1 AND (%s).id = node_id WHERE containing_face " 1549 "IS NULL AND node_id NOT IN " 1550 "(SELECT node FROM (SELECT start_node AS node FROM \"%s\".edge " 1551 "GROUP BY start_node UNION ALL SELECT end_node AS node FROM " 1552 "\"%s\".edge GROUP BY end_node) AS foo) ORDER BY node_id",
1558 "SELECT tt.node_id,tt.geom,ft.%s " 1559 "FROM \"%s\".node AS tt LEFT JOIN \"%s\".\"%s\" AS ft ON " 1560 "(%s).type = 1 AND (%s).id = node_id WHERE node_id NOT IN " 1561 "(SELECT node_id FROM \"%s\".%s) AND containing_face IS NULL ORDER BY node_id",
1566 res = PQexec(pg_info->
conn, stmt);
1567 if (!res || PQresultStatus(res) != PGRES_TUPLES_OK ||
1569 G_warning(
_(
"Inconsistency in topology: number of " 1570 "points %d (should be %d)"),
1577 ntuples = PQntuples(res);
1578 G_zero(&line_data,
sizeof(
struct line_data));
1579 for (i = 0; i < ntuples; i++) {
1581 line_data.id = atoi(PQgetvalue(res, i, 0));
1582 line_data.wkb_geom = (
char *) PQgetvalue(res, i, 1);
1583 line_data.fid = atoi(PQgetvalue(res, i, 2));
1595 "SELECT edge_id,start_node,end_node,left_face,right_face AS right_area,tt.geom,ft.%s " 1596 "FROM \"%s\".edge AS tt LEFT JOIN \"%s\".\"%s\" AS ft ON (%s).type = 2 AND " 1597 "(%s).id = edge_id ORDER BY edge_id",
1602 "SELECT edge_id,start_node,end_node,left_area,right_area,tt.geom,ft.%s " 1603 "FROM \"%s\".edge AS tt LEFT JOIN \"%s\".\"%s\" ON " 1604 "edge_id = line_id LEFT JOIN \"%s\".\"%s\" AS ft ON (%s).type = 2 AND " 1605 "(%s).id = edge_id ORDER BY edge_id",
1611 res = PQexec(pg_info->
conn, stmt);
1612 if (!res || PQresultStatus(res) != PGRES_TUPLES_OK ||
1613 PQntuples(res) > plus->
n_lines) {
1614 G_warning(
_(
"Inconsistency in topology: number of " 1615 "lines %d (should be %d)"),
1616 PQntuples(res), plus->
n_lines);
1623 ntuples = PQntuples(res);
1624 for (i = 0; i < ntuples; i++) {
1625 line_data.id = atoi(PQgetvalue(res, i, 0));
1626 line_data.start_node = remap_node(offset, atoi(PQgetvalue(res, i, 1)));
1627 line_data.end_node = remap_node(offset, atoi(PQgetvalue(res, i, 2)));
1628 line_data.left_face = atoi(PQgetvalue(res, i, 3));
1629 line_data.right_face = atoi(PQgetvalue(res, i, 4));
1630 line_data.wkb_geom = (
char *) PQgetvalue(res, i, 5);
1631 line_data.fid = atoi(PQgetvalue(res, i, 6));
1643 "SELECT node_id,tt.geom,containing_face,ft.%s FROM " 1644 "\"%s\".node AS tt LEFT JOIN \"%s\".\"%s\" AS ft ON " 1645 "(%s).type = 3 AND (%s).id = containing_face WHERE containing_face " 1646 "IS NOT NULL AND node_id NOT IN " 1647 "(SELECT node FROM (SELECT start_node AS node FROM \"%s\".edge " 1648 "GROUP BY start_node UNION ALL SELECT end_node AS node FROM " 1649 "\"%s\".edge GROUP BY end_node) AS foo) ORDER BY node_id",
1656 "SELECT tt.node_id,tt.geom,containing_face,ft.%s FROM " 1657 "\"%s\".node AS tt LEFT JOIN \"%s\".\"%s\" AS ft ON " 1658 "(%s).type = 3 AND (%s).id = containing_face WHERE " 1659 "node_id NOT IN (SELECT node_id FROM \"%s\".%s) AND containing_face " 1660 "IS NOT NULL ORDER BY node_id",
1665 res = PQexec(pg_info->
conn, stmt);
1666 if (!res || PQresultStatus(res) != PGRES_TUPLES_OK ||
1667 PQntuples(res) != plus->
n_clines) {
1668 G_warning(
_(
"Inconsistency in topology: number of " 1669 "centroids %d (should be %d)"),
1676 G_zero(&line_data,
sizeof(
struct line_data));
1678 for (i = 0; i < plus->
n_clines; i++) {
1679 line_data.id = atoi(PQgetvalue(res, i, 0));
1680 line_data.wkb_geom = (
char *)PQgetvalue(res, i, 1);
1681 line_data.left_face = atoi(PQgetvalue(res, i, 2));
1682 line_data.fid = atoi(PQgetvalue(res, i, 3));
1699 void notice_processor(
void *arg,
const char *message)
1702 fprintf(stderr,
"%s", message);
1718 char **scan_array(
const char *sarray)
1720 char *buf, **tokens;
1724 len = strlen(sarray) - 1;
1727 for (i = 1; i < len; i++)
1728 buf[i-1] = sarray[i];
1758 return offset->
array[node-1];
1771 int remap_line(
const struct Plus_head* plus, off_t offset,
int type)
1777 for (i = (
int) offset; i <= plus->
n_lines; i++) {
1778 Line = plus->
Line[i];
1780 if (!Line || Line->
type != type)
1783 if ((
int) Line->
offset == offset)
int G_strncasecmp(const char *, const char *, int)
String compare ignoring case (upper or lower) - limited number of characters.
int Spidx_new
Build new spatial index.
plus_t n_areas
Current number of areas.
char * name
Map name (for 4.0)
int Vect_build_line_area(struct Map_info *, int, int)
Build area on given side of line (GV_LEFT or GV_RIGHT)
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
int built
Highest level of topology currently available.
int G_verbose(void)
Get current verbosity level.
plus_t area
Area number, negative for duplicate centroid.
int V1_open_new_pg(struct Map_info *Map, const char *name, int with_z)
Prepare PostGIS database for creating new feature table (level 1)
#define GV_LEFT
Boundary side indicator left/right.
int V2_open_old_pg(struct Map_info *Map)
Open vector map - PostGIS feature table on topological level.
#define GV_PG_FID_COLUMN
GRASS-PostGIS data provider - default fid column.
off_t offset
Offset in coor file for line.
struct P_isle * dig_alloc_isle()
Allocate new isle structure.
int Vect__clean_grass_db_topo(struct Format_info_pg *pg_info)
Clean-up GRASS Topology tables.
struct P_line ** Line
Array of vector geometries.
struct P_area * dig_alloc_area()
Allocate new area structure.
int Vect__load_map_lines_pg(struct Map_info *Map)
Read features from DB.
int with_z
2D/3D vector data
plus_t n_plines
Current number of points.
plus_t right
Area number to the right, negative for isle.
#define GV_BUILD_BASE
Topology levels - basic level (without areas and isles)
struct P_area ** Area
Array of areas.
struct P_node ** Node
Array of nodes.
int dig_line_box(const struct line_pnts *, struct bound_box *)
int Vect__load_plus_pg(struct Map_info *Map, int head_only)
Read topo info from PostGIS topology schema.
void * dig_alloc_topo(char)
Allocate new topo struct.
void Vect__free_cache(struct Format_info_cache *cache)
#define GV_PG_GEOMETRY_COLUMN
GRASS-PostGIS data provider - default geometry column.
plus_t n_lines
Number of attached lines (size of lines, angle)
void G_free(void *)
Free allocated memory.
plus_t left
Area number to the left, negative for isle.
struct Format_info fInfo
Format info for non-native formats.
struct P_isle ** Isle
Array of isles.
plus_t * lines
List of connected lines.
plus_t * isles
1st generation interior islands
plus_t n_isles
Current number of isles.
plus_t centroid
Number of first centroid within area.
char ** G_tokenize(const char *, const char *)
Tokenize string.
int do_uplist
Indicates if the list of updated features is maintained.
plus_t n_lines
Number of boundary lines.
#define GV_POINT
Feature types used in memory on run time (may change)
plus_t n_lines
Current number of lines.
int dig_cidx_add_cat(struct Plus_head *, int, int, int, int)
int dig_spidx_add_area(struct Plus_head *, int, const struct bound_box *)
Add new area to spatial index.
int G_get_overwrite()
Get overwrite value.
int dig_alloc_lines(struct Plus_head *, int)
Reallocate array of pointers to lines.
double * x
Array of X coordinates.
double z
Z coordinate (used only for 3D data)
int cidx_up_to_date
Category index to be updated.
int Vect__execute_get_value_pg(PGconn *conn, const char *stmt)
Execute SQL statement and get value.
Feature geometry info - coordinates.
int off_t_size
Offset size.
plus_t * lines
List of boundary lines.
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)
Basic topology-related info.
int dig_alloc_areas(struct Plus_head *, int)
Reallocate array of pointers to areas.
#define GV_BUILD_AREAS
Topology levels - build areas.
void dig_node_add_updated(struct Plus_head *, int)
Add node to updated.
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 * topo
Topology info.
float * angles
List of angles of connected lines.
int Vect__load_map_nodes_pg(struct Map_info *Map, int geom_only)
Read nodes from DB.
int V1_open_old_pg(struct Map_info *Map, int update)
Open vector map - PostGIS feature table on non-topological level.
int Vect_get_isle_points(const struct Map_info *, int, struct line_pnts *)
Returns polygon array of points for given isle.
int G_number_of_tokens(char **)
Return number of tokens.
struct P_line * dig_alloc_line()
Allocate new line structure.
plus_t * lines
List of boundary lines.
struct Plus_head plus
Plus info (topology, version, ...)
int dig_node_alloc_line(struct P_node *, int)
Allocate space in P_node struct.
struct P_node * dig_alloc_node()
Allocate new node structure.
Topological feature - node.
int dig_spidx_add_isle(struct Plus_head *, int, const struct bound_box *)
Add new island to spatial index.
int dig_spidx_add_node(struct Plus_head *, int, double, double, double)
Add new node to spatial index.
struct bound_box box
Bounding box of features.
char * mapset
Mapset name.
void dig_line_add_updated(struct Plus_head *, int, off_t)
Add new line to updated.
plus_t n_isles
Number of islands inside.
#define GV_BUILD_ATTACH_ISLES
Topology levels - attach islands to areas.
int Vect_find_area(struct Map_info *, double, double)
Find the nearest area.
int support_updated
Support files were updated.
int dig_area_alloc_isle(struct P_area *, int)
Allocate space in P_area for add new isles.
double * y
Array of Y coordinates.
plus_t n_llines
Current number of lines.
int Vect__load_plus_head(struct Map_info *Map)
Read topo from PostGIS topology schema – header info only.
int dig_area_alloc_line(struct P_area *, int)
allocate space in P_area for add new lines
int Vect__execute_pg(PGconn *conn, const char *stmt)
Execute SQL statement.
struct ilist * Vect_new_list(void)
Creates and initializes a struct ilist.
const char * Vect_get_full_name(const struct Map_info *)
Get fully qualified name of vector map.
SF_FeatureType Vect__cache_feature_pg(const char *data, int skip_polygon, int force_type, struct Format_info_cache *cache, struct feat_parts *fparts)
Read geometry from HEX data.
void G_zero(void *, int)
Zero out a buffer, buf, of length i.
void G_free_tokens(char **)
Free memory allocated to tokens.
void G_warning(const char *,...) __attribute__((format(printf
int Vect_open_fidx(struct Map_info *, struct Format_info_offset *)
Open feature index file.
double * z
Array of Z coordinates.
plus_t n_clines
Current number of centroids.
int G_verbose_std(void)
Get standard verbosity level.
int dig_alloc_isles(struct Plus_head *, int)
Reallocate array of pointers to isles.
#define GV_BUILD_CENTROIDS
Topology levels - assign centroids to areas.
char * G_store(const char *)
Copy string to allocated memory.
int dig_isle_alloc_line(struct P_isle *, int)
Allocate space in P_isle for add new lines.
int dig_spidx_add_line(struct Plus_head *, int, const struct bound_box *)
Add new line to spatial index.
#define GV_BUILD_ALL
Topology levels - build everything (currently same as GV_BUILD_CENTROIDS)
int db_get_login2(const char *, const char *, const char **, const char **, const char **, const char **)
Get login parameters for driver/database.
struct Plus_head::@10 uplist
List of updated lines/nodes.
plus_t n_blines
Current number of boundaries.
void Vect_destroy_line_struct(struct line_pnts *)
Frees all memory associated with a line_pnts structure, including the structure itself.
int update_cidx
Update category index if vector is modified.
int Vect_get_area_points(const struct Map_info *, int, struct line_pnts *)
Returns polygon array of points (outer ring) of given area.
void void G_verbose_message(const char *,...) __attribute__((format(printf
plus_t n_lines
Number of boundary lines.
int Vect_read_line(const struct Map_info *, struct line_pnts *, struct line_cats *, int)
Read vector feature (topological level required)
plus_t area
Area it exists w/in, if any.
int G_debug(int, const char *,...) __attribute__((format(printf
#define VECT_OPEN_CODE
Vector map open code.
int dig_alloc_nodes(struct Plus_head *, int)
Reallocate array of pointers to nodes.
int dig_init_plus(struct Plus_head *)
Initialize Plus_head structure.
int Vect__open_topo_pg(struct Map_info *Map, int head_only, int update)
Read full-topology for PostGIS links.
plus_t n_nodes
Current number of topological features derived from vector geometries.
SF_FeatureType
Simple feature types.