|
@@ -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 @@ int main(int argc, char *argv[])
|
|
|
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 @@ int main(int argc, char *argv[])
|
|
|
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 @@ int main(int argc, char *argv[])
|
|
|
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 @@ int main(int argc, char *argv[])
|
|
|
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,12 +671,11 @@ mk_att(int cat, struct field_info *Fi, dbDriver * Driver, int ncol,
|
|
|
|
|
|
/* Attributes */
|
|
|
/* Reset */
|
|
|
- if (doatt) {
|
|
|
- for (j = 0; j < ncol; j++)
|
|
|
- OGR_F_UnsetField(Ogr_feature, j);
|
|
|
- }
|
|
|
- else {
|
|
|
- OGR_F_UnsetField(Ogr_feature, 0);
|
|
|
+ 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 */
|
|
|
}
|
|
|
|
|
|
/* Read & set attributes */
|
|
@@ -697,7 +696,8 @@ mk_att(int cat, struct field_info *Fi, dbDriver * Driver, int ncol,
|
|
|
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 @@ mk_att(int cat, struct field_info *Fi, dbDriver * Driver, int ncol,
|
|
|
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 @@ mk_att(int cat, struct field_info *Fi, dbDriver * Driver, int ncol,
|
|
|
|
|
|
}
|
|
|
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 @@ mk_att(int cat, struct field_info *Fi, dbDriver * Driver, int ncol,
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/* to print available drivers in help text */
|
|
|
char *OGR_list_write_drivers(void)
|
|
|
{
|