Skip to content

Commit

Permalink
fix #1131
Browse files Browse the repository at this point in the history
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 1dd0f3e
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -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!");
Expand All @@ -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());
Expand Down

0 comments on commit 1dd0f3e

Please sign in to comment.