Skip to content

Commit

Permalink
negate write capabilities for shapefiles w/o attributes, fixes #803
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@7612 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Nov 19, 2007
1 parent 6ba8b2a commit bf62b39
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -17,7 +17,7 @@ email : sherman at mrcc.com
/* $Id$ */

#include "qgsogrprovider.h"

#include "qgslogger.h"

#include <iostream>
#include <cassert>
Expand Down Expand Up @@ -94,7 +94,7 @@ QgsOgrProvider::QgsOgrProvider(QString const & uri)

//TODO Need to set a flag or something to indicate that the layer
//TODO is in read-only mode, otherwise edit ops will fail
// TODO: capabilities() should now reflect this; need to test.
//TODO: capabilities() should now reflect this; need to test.
}
if (ogrDataSource != NULL) {

Expand Down Expand Up @@ -366,11 +366,11 @@ void QgsOgrProvider::select(QgsAttributeList fetchAttributes, QgsRect rect, bool
QgsDebugMsg("Setting spatial filter using " + wktExtent);
ogrLayer->SetSpatialFilter(filter);
//ogrLayer->SetSpatialFilterRect(rect->xMin(), rect->yMin(), rect->xMax(), rect->yMax());
}else{
#ifdef QGISDEBUG
QgsLogger::warning("Setting spatial filter failed!");
#endif
}
}
else
{
QgsDebugMsg("Setting spatial filter failed!");
}
OGRGeometryFactory::destroyGeometry(filter);
}
}
Expand Down Expand Up @@ -647,11 +647,10 @@ bool QgsOgrProvider::addFeature(QgsFeature& f)
}
else if(fdef->GetFieldDefn(targetAttributeId)->GetType()==OFTString)
{
#ifdef QGISDEBUG
std::cerr << "Writing string attribute " << targetAttributeId
<< " with " << it->toString().toLocal8Bit().data()
<< ", encoding " << mEncoding->name().data() << std::endl;
#endif
QgsDebugMsg( QString("Writing string attribute %1 with %2, encoding %3")
.arg( targetAttributeId )
.arg( it->toString() )
.arg( mEncoding->name().data() ) );
feature->SetField(targetAttributeId,mEncoding->fromUnicode(it->toString()).constData());
}
else
Expand Down Expand Up @@ -905,7 +904,6 @@ int QgsOgrProvider::capabilities() const
}
ability |= QgsVectorDataProvider::SelectGeometryAtId;


if (ogrLayer->TestCapability("SequentialWrite"))
// TRUE if the CreateFeature() method works for this layer.
{
Expand Down Expand Up @@ -971,6 +969,12 @@ int QgsOgrProvider::capabilities() const
ability |= QgsVectorDataProvider::CreateSpatialIndex;
}

// OGR doesn't handle shapefiles without attributes, ie. missing DBFs well, fixes #803
if( ogrDriverName.startsWith("ESRI") && mAttributeFields.size()==0 )
{
QgsDebugMsg("OGR doesn't handle shapefile without attributes well, ie. missing DBFs");
ability &= ~(AddFeatures|DeleteFeatures|ChangeAttributeValues|AddAttributes|DeleteAttributes);
}
}

return ability;
Expand Down Expand Up @@ -1065,9 +1069,7 @@ QGISEXTERN QString fileVectorFilters()
// theoreticaly we can open those files because there exists a
// driver for them, the user will have to use the "All Files" to
// open datasets with no explicitly defined file name extension.
#ifdef QGISDEBUG
QgsLogger::debug("Driver count: ", driverRegistrar->GetDriverCount(), 1, __FILE__, __FUNCTION__, __LINE__);
#endif
QgsDebugMsg( QString("Driver count: %1").arg( driverRegistrar->GetDriverCount() ) );

for (int i = 0; i < driverRegistrar->GetDriverCount(); ++i)
{
Expand Down Expand Up @@ -1185,9 +1187,6 @@ QGISEXTERN QString fileVectorFilters()

myFileFilters += "All files (*.*)";

#ifdef QGISDEBUG
//qDebug() << myFileFilters;
#endif
return myFileFilters;

} // fileVectorFilters() const
Expand Down Expand Up @@ -1353,9 +1352,7 @@ QGISEXTERN bool createEmptyDataSource(const QString& uri,

OGRDataSource::DestroyDataSource(dataSource);

#ifdef QGISDEBUG
QgsLogger::debug("GDAL Version number", GDAL_VERSION_NUM, 1, __FILE__, __FUNCTION__, __LINE__);
#endif
QgsDebugMsg( QString("GDAL Version number %1").arg( GDAL_VERSION_NUM ) );
#if GDAL_VERSION_NUM >= 1310
if(reference)
{
Expand Down

0 comments on commit bf62b39

Please sign in to comment.