Skip to content
Permalink
Browse files
fix #1131
git-svn-id: http://svn.osgeo.org/qgis/trunk@8677 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Jun 24, 2008
1 parent 978fb0a commit 1dd0f3e8544d0086e50a58e57df640ab0c2c99ee
Showing with 16 additions and 3 deletions.
  1. +16 −3 src/core/qgsvectorfilewriter.cpp
@@ -111,16 +111,21 @@ QgsVectorFileWriter::QgsVectorFileWriter(const QString& shapefileName,
const QgsField& attrField = fldIt.value();

OGRFieldType ogrType = OFTString; //default to string
int ogrWidth = -1;
int ogrPrecision = -1;
switch (attrField.type())
{
case QVariant::String:
ogrType = OFTString;
break;
case QVariant::Int:
ogrType = OFTInteger;
ogrWidth = 10;
break;
case QVariant::Double:
ogrType = OFTReal;
ogrWidth = 32;
ogrPrecision = 3;
break;
default:
//assert(0 && "invalid variant type!");
@@ -130,13 +135,21 @@ QgsVectorFileWriter::QgsVectorFileWriter(const QString& shapefileName,

// create field definition
OGRFieldDefnH fld = OGR_Fld_Create(mCodec->fromUnicode(attrField.name()), ogrType);
OGR_Fld_SetWidth(fld,attrField.length());
OGR_Fld_SetPrecision(fld,attrField.precision());
if(ogrWidth>0)
{
OGR_Fld_SetWidth(fld, ogrWidth);
}

if(ogrPrecision>=0)
{
OGR_Fld_SetPrecision(fld, ogrPrecision);
}

// create the field
QgsDebugMsg("creating field " + attrField.name() +
" type " + QString(QVariant::typeToName(attrField.type())) +
" width length " + QString::number(attrField.length()));
" width " + QString::number(ogrWidth) +
" precision " + QString::number(ogrPrecision));
if (OGR_L_CreateField(mLayer,fld,TRUE) != OGRERR_NONE)
{
QgsDebugMsg("error creating field " + attrField.name());

0 comments on commit 1dd0f3e

Please sign in to comment.