[GRASS-SVN] r34357 - grass/trunk/vector/v.out.ogr
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Nov 18 06:03:31 EST 2008
Author: hamish
Date: 2008-11-18 06:03:31 -0500 (Tue, 18 Nov 2008)
New Revision: 34357
Modified:
grass/trunk/vector/v.out.ogr/main.c
Log:
Don't assume that the GRASS db column ID is the same as the OGRFieldID,
they can be different (eg OGR GPX driver has standard fields 1-9)
- removed keycol from mk_att() as unused
- OGR_F_UnsetField() moved into set loop as table needs to be open to
query the OGR field ID by column name.
(bug #354, allows v.out.gpsbabel to work; merge from devbr6)
Modified: grass/trunk/vector/v.out.ogr/main.c
===================================================================
--- grass/trunk/vector/v.out.ogr/main.c 2008-11-18 11:02:03 UTC (rev 34356)
+++ grass/trunk/vector/v.out.ogr/main.c 2008-11-18 11:03:31 UTC (rev 34357)
@@ -30,8 +30,8 @@
int fout, fskip; /* features written/ skip */
int nocat, noatt, nocatskip; /* number of features without cats/atts written/skip */
-int mk_att(int cat, struct field_info *Fi, dbDriver * Driver,
- int ncol, int keycol, int doatt, OGRFeatureH Ogr_feature);
+int mk_att(int cat, struct field_info *Fi, dbDriver *Driver,
+ int ncol, int doatt, OGRFeatureH Ogr_feature);
char *OGR_list_write_drivers();
char OGRdrivers[2000];
@@ -482,7 +482,7 @@
continue;
}
- mk_att(cat, Fi, Driver, ncol, keycol, doatt, Ogr_feature);
+ mk_att(cat, Fi, Driver, ncol, doatt, Ogr_feature);
OGR_L_CreateFeature(Ogr_layer, Ogr_feature);
}
OGR_G_DestroyGeometry(Ogr_geometry);
@@ -554,7 +554,7 @@
continue;
}
- mk_att(cat, Fi, Driver, ncol, keycol, doatt, Ogr_feature);
+ mk_att(cat, Fi, Driver, ncol, doatt, Ogr_feature);
OGR_L_CreateFeature(Ogr_layer, Ogr_feature);
}
OGR_G_DestroyGeometry(Ogr_geometry);
@@ -609,7 +609,7 @@
continue;
}
- mk_att(cat, Fi, Driver, ncol, keycol, doatt, Ogr_feature);
+ mk_att(cat, Fi, Driver, ncol, doatt, Ogr_feature);
OGR_L_CreateFeature(Ogr_layer, Ogr_feature);
}
@@ -653,11 +653,11 @@
exit(EXIT_SUCCESS);
}
-int
-mk_att(int cat, struct field_info *Fi, dbDriver * Driver, int ncol,
- int keycol, int doatt, OGRFeatureH Ogr_feature)
+
+int mk_att(int cat, struct field_info *Fi, dbDriver *Driver, int ncol,
+ int doatt, OGRFeatureH Ogr_feature)
{
- int j;
+ int j, ogrfieldnum;
char buf[2000];
int colsqltype, colctype, more;
dbTable *Table;
@@ -671,13 +671,12 @@
/* Attributes */
/* Reset */
- if (doatt) {
- for (j = 0; j < ncol; j++)
- OGR_F_UnsetField(Ogr_feature, j);
+ if (!doatt) {
+ ogrfieldnum = OGR_F_GetFieldIndex(Ogr_feature, "cat");
+ OGR_F_UnsetField(Ogr_feature, ogrfieldnum);
+ /* doatt reset moved into have cat loop as the table needs to be
+ open to know the OGR field ID. Hopefully this has no ill consequences */
}
- else {
- OGR_F_UnsetField(Ogr_feature, 0);
- }
/* Read & set attributes */
if (cat >= 0) { /* Line with category */
@@ -697,7 +696,8 @@
if (!more) {
/* G_warning ("No database record for cat = %d", cat); */
/* Set at least key column to category */
- OGR_F_SetFieldInteger(Ogr_feature, keycol, cat);
+ ogrfieldnum = OGR_F_GetFieldIndex(Ogr_feature, Fi->key);
+ OGR_F_SetFieldInteger(Ogr_feature, ogrfieldnum, cat);
noatt++;
}
else {
@@ -712,26 +712,32 @@
colsqltype = db_get_column_sqltype(Column);
colctype = db_sqltype_to_Ctype(colsqltype);
G_debug(2, " colctype = %d", colctype);
-
+
+ ogrfieldnum = OGR_F_GetFieldIndex(Ogr_feature,
+ db_get_column_name(Column));
+
+ /* Reset */
+ OGR_F_UnsetField(Ogr_feature, ogrfieldnum);
+
/* prevent writing NULL values */
if (!db_test_value_isnull(Value)) {
switch (colctype) {
case DB_C_TYPE_INT:
- OGR_F_SetFieldInteger(Ogr_feature, j,
+ OGR_F_SetFieldInteger(Ogr_feature, ogrfieldnum,
db_get_value_int(Value));
break;
case DB_C_TYPE_DOUBLE:
- OGR_F_SetFieldDouble(Ogr_feature, j,
+ OGR_F_SetFieldDouble(Ogr_feature, ogrfieldnum,
db_get_value_double(Value));
break;
case DB_C_TYPE_STRING:
- OGR_F_SetFieldString(Ogr_feature, j,
+ OGR_F_SetFieldString(Ogr_feature, ogrfieldnum,
db_get_value_string(Value));
break;
case DB_C_TYPE_DATETIME:
db_convert_column_value_to_string(Column,
&dbstring);
- OGR_F_SetFieldString(Ogr_feature, j,
+ OGR_F_SetFieldString(Ogr_feature, ogrfieldnum,
db_get_string(&dbstring));
break;
}
@@ -742,7 +748,8 @@
}
else { /* Use cat only */
- OGR_F_SetFieldInteger(Ogr_feature, 0, cat);
+ ogrfieldnum = OGR_F_GetFieldIndex(Ogr_feature, "cat");
+ OGR_F_SetFieldInteger(Ogr_feature, ogrfieldnum, cat);
}
}
else {
@@ -754,6 +761,7 @@
return 1;
}
+
/* to print available drivers in help text */
char *OGR_list_write_drivers(void)
{
More information about the grass-commit
mailing list