Skip to content

Commit

Permalink
This commit contains some small bugfixes, code clean-ups, performance…
Browse files Browse the repository at this point in the history
… improvement, and a new feature for v.out.ogr.

1. Fixed a but that would spawn ugly error messages in conjunction with the "-s" flag
2. Reduced the SQL SELECT statements to just one instead of one per feature, increasing output speed by several magnitudes.
3. Added a new "-z" flag, which provides a simple and robust means of producing 3D ESRI Shapefiles
--> Please test intensively!

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@45044 15284696-431f-4ddb-bdfa-cd5b030d7da7
  • Loading branch information
benducke committed Jan 14, 2011
1 parent 980064d commit ffaa430
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 147 deletions.
5 changes: 5 additions & 0 deletions vector/v.out.ogr/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ void parse_args(int argc, char **argv,
flags->esristyle->description = _("Use ESRI-style .prj file format "
"(applies to Shapefile output only)");
flags->esristyle->guisection = _("Creation");

flags->shapez = G_define_flag();
flags->shapez->key = 'z';
flags->shapez->description = _("Create 3D output if input is 3D "
"(applies to Shapefile output only)");

flags->poly = G_define_flag();
flags->poly->key = 'p';
Expand Down
24 changes: 8 additions & 16 deletions vector/v.out.ogr/attrb.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

int mk_att(int cat, struct field_info *Fi, dbDriver *Driver, int ncol,
int doatt, int nocat, OGRFeatureH Ogr_feature, int *noatt,
int *fout)
int *fout, dbCursor cursor)
{
int j, ogrfieldnum;
char buf[2000];
int colsqltype, colctype, more;
dbTable *Table;
dbString dbstring;
dbColumn *Column;
dbCursor cursor;
dbValue *Value;

G_debug(2, "mk_att() cat = %d, doatt = %d", cat, doatt);
Expand All @@ -30,16 +28,6 @@ int mk_att(int cat, struct field_info *Fi, dbDriver *Driver, int ncol,
/* Read & set attributes */
if (cat >= 0) { /* Line with category */
if (doatt) {
sprintf(buf, "SELECT * FROM %s WHERE %s = %d", Fi->table, Fi->key,
cat);
G_debug(2, "SQL: %s", buf);
db_set_string(&dbstring, buf);
if (db_open_select_cursor
(Driver, &dbstring, &cursor, DB_SEQUENTIAL) != DB_OK) {
G_fatal_error(_("Cannot select attributes for cat = %d"),
cat);
}
else {
if (db_fetch(&cursor, DB_NEXT, &more) != DB_OK)
G_fatal_error(_("Unable to fetch data from table"));
if (!more) {
Expand Down Expand Up @@ -76,10 +64,15 @@ int mk_att(int cat, struct field_info *Fi, dbDriver *Driver, int ncol,
db_get_column_name(Column), ogrfieldnum);

/* Reset */
OGR_F_UnsetField(Ogr_feature, ogrfieldnum);
if ( ( ( nocat ) && (strcmp(Fi->key, db_get_column_name(Column)) == 0) ) == 0 ) {
/* if this is 'cat', then execute the following only if the '-s' flag was NOT given*/
OGR_F_UnsetField(Ogr_feature, ogrfieldnum);
}

/* prevent writing NULL values */
if (!db_test_value_isnull(Value)) {
if ( ( (nocat) && (strcmp(Fi->key, db_get_column_name(Column)) == 0) ) == 0 ) {
/* if this is 'cat', then execute the following only if the '-s' flag was NOT given*/
switch (colctype) {
case DB_C_TYPE_INT:
OGR_F_SetFieldInteger(Ogr_feature,
Expand Down Expand Up @@ -107,9 +100,8 @@ int mk_att(int cat, struct field_info *Fi, dbDriver *Driver, int ncol,
}
}
}
}
}
db_close_cursor(&cursor);
}
}
else { /* Use cat only */
ogrfieldnum = OGR_F_GetFieldIndex(Ogr_feature, "cat");
Expand Down
9 changes: 7 additions & 2 deletions vector/v.out.ogr/local_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
#include "ogr_api.h"
#include "cpl_string.h"


/* some hard limits */
#define SQL_BUFFER_SIZE 2000


struct Options {
struct Option *input, *dsn, *layer, *type, *format,
*field, *dsco, *lco;
};

struct Flags {
struct Flag *cat, *esristyle, *poly, *update, *nocat, *new, *append;
struct Flag *cat, *esristyle, *poly, *update, *nocat, *new, *append, *shapez;
};

/* args.c */
Expand All @@ -20,7 +25,7 @@ void parse_args(int, char **,

/* attributes.c */
int mk_att(int cat, struct field_info *Fi, dbDriver *Driver,
int ncol, int doatt, int nocat, OGRFeatureH Ogr_feature, int *, int *);
int ncol, int doatt, int nocat, OGRFeatureH Ogr_feature, int *, int *, dbCursor cursor);

/* list.c */
char *OGR_list_write_drivers();
Expand Down
Loading

0 comments on commit ffaa430

Please sign in to comment.