Skip to content
Permalink
Browse files

negate write capabilities for shapefiles w/o attributes, fixes #803

git-svn-id: http://svn.osgeo.org/qgis/trunk@7612 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Nov 19, 2007
1 parent 6ba8b2a commit bf62b3969eb0dca937c0a8d8f934df361d508d58
Showing with 19 additions and 22 deletions.
  1. +19 −22 src/providers/ogr/qgsogrprovider.cpp
@@ -17,7 +17,7 @@ email : sherman at mrcc.com
/* $Id$ */

#include "qgsogrprovider.h"

#include "qgslogger.h"

#include <iostream>
#include <cassert>
@@ -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) {

@@ -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);
}
}
@@ -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
@@ -905,7 +904,6 @@ int QgsOgrProvider::capabilities() const
}
ability |= QgsVectorDataProvider::SelectGeometryAtId;


if (ogrLayer->TestCapability("SequentialWrite"))
// TRUE if the CreateFeature() method works for this layer.
{
@@ -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;
@@ -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)
{
@@ -1185,9 +1187,6 @@ QGISEXTERN QString fileVectorFilters()

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

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

} // fileVectorFilters() const
@@ -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)
{

0 comments on commit bf62b39

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