Skip to content

Commit

Permalink
Move information about strict provider geometry type check on point s…
Browse files Browse the repository at this point in the history
…hapefiles

to OGR provider and make use of it when pasting & merging features
(fixes #12488, refs #10672, refs #10747)

TODO: check if other OGR drivers have similar restrictions.
(cherry picked from commit 8289891)
  • Loading branch information
jef-n committed Jun 29, 2015
1 parent 3ed1ae4 commit ce99b8e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6208,12 +6208,13 @@ void QgisApp::editPaste( QgsMapLayer *destinationLayer )
// convert geometry to match destination layer
QGis::GeometryType destType = pasteVectorLayer->geometryType();
bool destIsMulti = QGis::isMultiType( pasteVectorLayer->wkbType() );
if ( pasteVectorLayer->storageType() == "ESRI Shapefile" && destType != QGis::Point )
if ( pasteVectorLayer->dataProvider() &&
!pasteVectorLayer->dataProvider()->doesStrictFeatureTypeCheck() )
{
// force destination to multi if shapefile if it's not a point file
// Should we really force anything here? Isn't it better to just transform?
// force destination to multi if provider doesn't do a feature strict check
destIsMulti = true;
}

if ( destType != QGis::UnknownGeometry )
{
QgsGeometry* newGeometry = featureIt->geometry()->convertToType( destType, destIsMulti );
Expand Down
6 changes: 6 additions & 0 deletions src/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2526,6 +2526,12 @@ void QgsOgrProvider::recalculateFeatureCount()
}
}

bool QgsOgrProvider::doesStrictFeatureTypeCheck() const
{
// FIXME probably other drivers too...
return ogrDriverName != "ESRI Shapefile" || geomType == wkbPoint;
}

OGRwkbGeometryType QgsOgrProvider::ogrWkbSingleFlatten( OGRwkbGeometryType type )
{
type = wkbFlatten( type );
Expand Down
6 changes: 3 additions & 3 deletions src/providers/ogr/qgsogrprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ class QgsOgrProvider : public QgsVectorDataProvider
QString description() const override;

/** Returns true if the provider is strict about the type of inserted features
(e.g. no multipolygon in a polygon layer)
*/
virtual bool doesStrictFeatureTypeCheck() const override { return false;}
(e.g. no multipolygon in a polygon layer)
*/
virtual bool doesStrictFeatureTypeCheck() const override;

/** return OGR geometry type */
static OGRwkbGeometryType getOgrGeomType( OGRLayerH ogrLayer );
Expand Down

0 comments on commit ce99b8e

Please sign in to comment.