[GRASS-SVN] r50392 - grass-addons/grass7/vector/v.out.ply
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Jan 23 10:28:53 EST 2012
Author: mmetz
Date: 2012-01-23 07:28:53 -0800 (Mon, 23 Jan 2012)
New Revision: 50392
Modified:
grass-addons/grass7/vector/v.out.ply/body.c
grass-addons/grass7/vector/v.out.ply/header.c
grass-addons/grass7/vector/v.out.ply/main.c
Log:
reduce database overhead
Modified: grass-addons/grass7/vector/v.out.ply/body.c
===================================================================
--- grass-addons/grass7/vector/v.out.ply/body.c 2012-01-23 13:06:34 UTC (rev 50391)
+++ grass-addons/grass7/vector/v.out.ply/body.c 2012-01-23 15:28:53 UTC (rev 50392)
@@ -13,7 +13,7 @@
{
int type, i, cat, n_lines, line;
static struct line_pnts *Points;
- struct line_cats *Cats, *ACats;
+ struct line_cats *Cats;
char *fs = G_store(" ");
struct ilist *fcats;
@@ -30,6 +30,7 @@
char buf[2000];
dbCursor cursor;
int *coltypes = NULL;
+ char *all_columns = NULL;
n_lines = ncats = 0;
@@ -37,6 +38,8 @@
db_init_string(&dbstring);
if (columns) {
+ int len_all = 0;
+
Fi = Vect_get_field(Map, field);
if (!Fi) {
G_fatal_error(_("Database connection not defined for layer %d"),
@@ -53,24 +56,30 @@
if (db_open_database(driver, &handle) != DB_OK)
G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
Fi->database, Fi->driver);
-
+
i = 0;
- while (columns[i++]);
+ while (columns[i])
+ len_all += strlen(columns[i++]);
coltypes = G_malloc(i * sizeof(int));
+
+ all_columns = G_malloc(len_all + i + 2);
i = 0;
+ strcpy(all_columns, columns[0]);
while (columns[i]) {
coltypes[i] = db_column_Ctype(driver, Fi->table, columns[i]);
+ if (i > 0) {
+ strcat(all_columns, ",");
+ strcat(all_columns, columns[i]);
+ }
i++;
}
-
-
+ G_debug(0, "all column string: %s", all_columns);
}
Points = Vect_new_line_struct();
Cats = Vect_new_cats_struct();
- ACats = Vect_new_cats_struct();
fcats = Vect_new_list();
/* by default, read_next_line will NOT read Dead lines */
@@ -137,13 +146,28 @@
/* print attributes */
if (columns) {
+ sprintf(buf, "SELECT %s FROM %s WHERE %s = %d",
+ all_columns, Fi->table, Fi->key, fcats->value[0]);
+ G_debug(2, "SQL: %s", buf);
+ db_set_string(&dbstring, buf);
+
+ if (db_open_select_cursor
+ (driver, &dbstring, &cursor, DB_SEQUENTIAL) != DB_OK) {
+ db_close_database(driver);
+ db_shutdown_driver(driver);
+ G_fatal_error(_("Cannot select attributes for cat = %d"),
+ fcats->value[0]);
+ }
+ if (db_fetch(&cursor, DB_NEXT, &more) != DB_OK) {
+ db_close_database(driver);
+ db_shutdown_driver(driver);
+ G_fatal_error(_("Unable to fetch data from table"));
+ }
+
+ Table = db_get_cursor_table(&cursor);
+
for(i = 0; columns[i]; i++) {
- sprintf(buf, "SELECT %s FROM %s WHERE %s = %d",
- columns[i], Fi->table, Fi->key, fcats->value[0]);
- G_debug(2, "SQL: %s", buf);
- db_set_string(&dbstring, buf);
-
/* original
if (db_select_value(driver, Fi->table, Fi->key, fcats->value[0],
columns[i], &value) < 0)
@@ -151,16 +175,7 @@
Fi->table, Fi->key, columns[i]);
*/
- if (db_open_select_cursor
- (driver, &dbstring, &cursor, DB_SEQUENTIAL) != DB_OK) {
- G_fatal_error(_("Cannot select attributes for cat = %d"),
- fcats->value[0]);
- }
- if (db_fetch(&cursor, DB_NEXT, &more) != DB_OK)
- G_fatal_error(_("Unable to fetch data from table"));
-
- Table = db_get_cursor_table(&cursor);
- Column = db_get_table_column(Table, 0);
+ Column = db_get_table_column(Table, i);
Value = db_get_column_value(Column);
if (db_test_value_isnull(Value)) {
@@ -190,15 +205,22 @@
case DB_C_TYPE_DATETIME: {
break;
}
- case -1:
+ case -1: {
+ db_close_database(driver);
+ db_shutdown_driver(driver);
G_fatal_error(_("Column <%s> not found in table <%s>"),
columns[i], Fi->table);
- default: G_fatal_error(_("Column <%s>: unsupported data type"),
+ }
+ default: {
+ db_close_database(driver);
+ db_shutdown_driver(driver);
+ G_fatal_error(_("Column <%s>: unsupported data type"),
columns[i]);
}
+ }
}
- db_close_cursor(&cursor);
}
+ db_close_cursor(&cursor);
}
fprintf(fp, "\n");
@@ -208,7 +230,6 @@
db_free_string(&dbstring);
Vect_destroy_line_struct(Points);
Vect_destroy_cats_struct(Cats);
- Vect_destroy_cats_struct(ACats);
return n_lines;
}
Modified: grass-addons/grass7/vector/v.out.ply/header.c
===================================================================
--- grass-addons/grass7/vector/v.out.ply/header.c 2012-01-23 13:06:34 UTC (rev 50391)
+++ grass-addons/grass7/vector/v.out.ply/header.c 2012-01-23 15:28:53 UTC (rev 50392)
@@ -59,9 +59,12 @@
fi->database, fi->driver);
db_init_string(&table_name);
db_set_string(&table_name, fi->table);
- if (db_describe_table(driver, &table_name, &table) != DB_OK)
+ if (db_describe_table(driver, &table_name, &table) != DB_OK) {
+ db_close_database(driver);
+ db_shutdown_driver(driver);
G_fatal_error(_("Unable to describe table <%s>"),
fi->table);
+ }
for (i = 0; columns[i]; i++) {
@@ -82,18 +85,21 @@
fprintf(fp, "property %s %s\n", dbltype, columns[i]);
break;
}
- case DB_C_TYPE_STRING: {
- break;
- }
- case DB_C_TYPE_DATETIME: {
- break;
- }
- case -1:
+ case -1: {
+ db_close_database(driver);
+ db_shutdown_driver(driver);
G_fatal_error(_("Column <%s> not found in table <%s>"),
columns[i], fi->table);
- default: G_fatal_error(_("Column <%s>: unsupported data type"),
- columns[i]);
}
+ default: {
+ db_close_database(driver);
+ db_shutdown_driver(driver);
+ G_fatal_error(_("Column <%s>: unsupported data type <%s>"),
+ columns[i],
+ db_sqltype_name(db_column_sqltype(driver,
+ fi->table, columns[i])));
+ }
+ }
}
Modified: grass-addons/grass7/vector/v.out.ply/main.c
===================================================================
--- grass-addons/grass7/vector/v.out.ply/main.c 2012-01-23 13:06:34 UTC (rev 50391)
+++ grass-addons/grass7/vector/v.out.ply/main.c 2012-01-23 15:28:53 UTC (rev 50392)
@@ -69,6 +69,10 @@
/* get the region */
G_get_window(&window);
Vect_region_box(&window, &box);
+ if (!Vect_is_3d(&Map)) {
+ box.T = PORT_DOUBLE_MAX;
+ box.B = -PORT_DOUBLE_MAX;
+ }
/* count points */
Points = Vect_new_line_struct();
@@ -98,7 +102,6 @@
write_ply_body_ascii(fp, &Map, dp, region, field,
(const char **)columns, &box);
-
if (fp != NULL)
fclose(fp);
More information about the grass-commit
mailing list