Skip to content
Permalink
Browse files

QgsVectorFileWriter:

- added missing deleteShapeFile() PyQGIS wrapper
- added some error handling when adding features
- improved deleteShapeFile method


git-svn-id: http://svn.osgeo.org/qgis/trunk@8621 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Jun 8, 2008
1 parent e674fca commit e32b9bf1e3361dcce0d728f98b122217d16adfbf
Showing with 21 additions and 34 deletions.
  1. +5 −0 python/core/qgsvectorfilewriter.sip
  2. +16 −34 src/core/qgsvectorfilewriter.cpp
@@ -47,5 +47,10 @@ public:
/** close opened shapefile for writing */
~QgsVectorFileWriter();

/** Delete a shapefile (and its accompanying shx / dbf / prf)
* @param QString theFileName - /path/to/file.shp
* @return bool true if the file was deleted successfully
*/
static bool deleteShapeFile(QString theFileName);
};

@@ -200,7 +200,7 @@ bool QgsVectorFileWriter::addFeature(QgsFeature& feature)
OGR_F_SetFieldString(poFeature, ogrField, mCodec->fromUnicode(attrValue.toString()).data());
break;
default:
//assert(0 && "invalid variant type");
QgsDebugMsg("Invalid variant type for field "+QString::number(ogrField)+": "+QString::number(attrValue.type()));
return false;
}
}
@@ -321,43 +321,25 @@ bool QgsVectorFileWriter::deleteShapeFile(QString theFileName)
{
//
// Remove old copies that may be lying around
// TODO: should be case-insensitive
//
QFileInfo myInfo(theFileName);
QString myFileBase = theFileName.replace(".shp","");
if (myInfo.exists())
{
if(!QFile::remove(myFileBase + ".shp"))
{
qDebug("Removing file failed : " + myFileBase.toLocal8Bit() + ".shp");
return false;
}
}
myInfo.setFile(myFileBase + ".shx");
if (myInfo.exists())
{
if(!QFile::remove(myFileBase + ".shx"))
{
qDebug("Removing file failed : " + myFileBase.toLocal8Bit() + ".shx");
return false;
}
}
myInfo.setFile(myFileBase + ".dbf");
if (myInfo.exists())
{
if(!QFile::remove(myFileBase + ".dbf"))
{
qDebug("Removing file failed : " + myFileBase.toLocal8Bit() + ".dbf");
return false;
}
}
myInfo.setFile(myFileBase + ".prj");
if (myInfo.exists())
bool ok = TRUE;

const char* suffixes[] = { ".shp", ".shx", ".dbf", ".prj", ".qix" };
for (int i = 0; i < sizeof(suffixes) / sizeof(char*); i++)
{
if(!QFile::remove(myFileBase + ".prj"))
QString file = myFileBase + suffixes[i];
QFileInfo myInfo(file);
if (myInfo.exists())
{
qDebug("Removing file failed : " + myFileBase.toLocal8Bit() + ".prj");
return false;
if(!QFile::remove(file))
{
QgsDebugMsg("Removing file failed : " + file);
ok = FALSE;
}
}
}
return true;

return ok;
}

0 comments on commit e32b9bf

Please sign in to comment.
You can’t perform that action at this time.