+}
+
+bool HYDROData_ShapeFile::DBF_WriteFieldAndValues(const QString& theFileName, const QString& theFieldName, DBF_FieldType theType, const std::vector<DBF_AttrValue>& theAttrV, bool bUseRawValue)
+{
+ // Check that given field type is equal to field types of attributes values
+ for (size_t i = 0; i < theAttrV.size(); i++)
+ {
+ if (theAttrV[i].myFieldType != theType)
+ return false;
+ }
+
+ DBFHandle hDBF;
+ hDBF = DBFCreate( theFileName.toStdString().c_str() );
+ if( hDBF == NULL )
+ return false;
+
+ if (theType != DBF_FieldType_String && theType != DBF_FieldType_Integer && theType != DBF_FieldType_Double)
+ {
+ DBFClose( hDBF );
+ return false; //cant handle any other cases
+ }
+
+ int nWidth = 20;
+ switch( theType )
+ {
+ case DBF_FieldType_String:
+ {
+ DBFAddField (hDBF, theFieldName.toStdString().c_str(), FTString, nWidth, 0);
+ break;
+ }
+
+ case DBF_FieldType_Integer:
+ {
+ DBFAddField (hDBF, theFieldName.toStdString().c_str(), FTInteger, nWidth, 0);
+ break;
+ }
+
+ case DBF_FieldType_Double:
+ {
+ DBFAddField (hDBF, theFieldName.toStdString().c_str(), FTDouble, nWidth, 0);
+ break;
+ }
+ default:
+ break;
+ }
+
+ if (DBFGetFieldCount( hDBF ) != 1)
+ {
+ DBFClose( hDBF );
+ return false;
+ }
+ if (DBFGetRecordCount( hDBF ) != 0)
+ {
+ DBFClose( hDBF );
+ return false;
+ }
+ int stat = -1;
+
+ if (bUseRawValue)
+ {
+ for (size_t i = 0; i < theAttrV.size(); i++)
+ {
+ if (!theAttrV[i].myIsNull)
+ stat = DBFWriteStringAttribute(hDBF, (int)i, 0, theAttrV[i].myRawValue.c_str());
+ else
+ stat = DBFWriteNULLAttribute(hDBF, (int)i, 0 );
+
+ if (stat != 1)
+ {
+ DBFClose( hDBF );
+ return false;
+ }
+ }
+ }
+ else
+ {
+ for (size_t i = 0; i < theAttrV.size(); i++)
+ {
+ if (!theAttrV[i].myIsNull)
+ switch( theType )
+ {
+ case DBF_FieldType_String:
+ {
+ stat = DBFWriteStringAttribute(hDBF, (int)i, 0, theAttrV[i].myStrVal.toStdString().c_str());
+ break;
+ }
+
+ case DBF_FieldType_Integer:
+ {
+ stat = DBFWriteIntegerAttribute(hDBF, (int)i, 0, theAttrV[i].myIntVal);
+ break;
+ }
+
+ case DBF_FieldType_Double:
+ {
+ stat = DBFWriteDoubleAttribute(hDBF, (int)i, 0, theAttrV[i].myDoubleVal);
+ break;
+ }
+ default:
+ break;
+ }
+ else
+ stat = DBFWriteNULLAttribute(hDBF, (int)i, 0 );
+
+ if (stat != 1)
+ {
+ DBFClose( hDBF );
+ return false;
+ }
+ }
+ }
+
+ DBFClose( hDBF );
+ return true;
+