Skip to content

Commit 558c693

Browse files
committed
fixes logical->int conversion; #1409
1 parent 692e43b commit 558c693

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/gdal_write.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,22 @@ void SetFields(OGRFeature *poFeature, std::vector<OGRFieldType> tp, Rcpp::List o
8181
SetNull(poFeature, j);
8282
} break;
8383
case OFTInteger: {
84-
Rcpp::IntegerVector iv;
85-
iv = obj[j];
86-
if (! Rcpp::IntegerVector::is_na(iv[i])) {
87-
if (shape)
84+
const OGRFieldDefn *def = poFeature->GetFieldDefnRef(j);
85+
if (def->GetSubType() == OFSTBoolean) {
86+
Rcpp::LogicalVector lv;
87+
lv = obj[j];
88+
if (! Rcpp::LogicalVector::is_na(lv[i]))
89+
poFeature->SetField(j, (int) lv[i]);
90+
else
91+
SetNull(poFeature, j); // #nocov
92+
} else { // integer:
93+
Rcpp::IntegerVector iv;
94+
iv = obj[j];
95+
if (! Rcpp::IntegerVector::is_na(iv[i]))
8896
poFeature->SetField(j, (int) iv[i]);
8997
else
90-
poFeature->SetField(nm[j], (int) iv[i]);
91-
} else
92-
SetNull(poFeature, j); // #nocov
98+
SetNull(poFeature, j); // #nocov
99+
}
93100
} break;
94101
case OFTReal: {
95102
Rcpp::NumericVector nv;

0 commit comments

Comments
 (0)