Skip to content
Permalink
Browse files

Only convert geometries to provider type when provider does strict ty…

…pe checking (ie. not for shapes; fixes #16593, #16784, #16792, #16770, followup 53d90b5)
  • Loading branch information
jef-n committed Jul 5, 2017
1 parent 8731840 commit d19ed1c627ac43c7a00221f5cb637b8b049f6681
Showing with 14 additions and 11 deletions.
  1. +14 −11 src/core/qgsvectorlayereditbuffer.cpp
@@ -310,19 +310,22 @@ bool QgsVectorLayerEditBuffer::commitChanges( QStringList& commitErrors )
{
if ( cap & QgsVectorDataProvider::AddFeatures )
{
QgsFeatureMap::iterator featureIt = mAddedFeatures.begin();
for ( ; featureIt != mAddedFeatures.end(); ++featureIt )
if ( provider->doesStrictFeatureTypeCheck() )
{
if ( !featureIt->geometry() ||
featureIt->geometry()->isEmpty() ||
featureIt->geometry()->wkbType() == provider->geometryType() )
continue;

if ( !provider->convertToProviderType( featureIt->geometry() ) )
QgsFeatureMap::iterator featureIt = mAddedFeatures.begin();
for ( ; featureIt != mAddedFeatures.end(); ++featureIt )
{
commitErrors << tr( "ERROR: %n feature(s) not added - geometry type is not compatible with the current layer.", "not added features count", mAddedFeatures.size() );
success = false;
break;
if ( !featureIt->geometry() ||
featureIt->geometry()->isEmpty() ||
featureIt->geometry()->wkbType() == provider->geometryType() )
continue;

if ( !provider->convertToProviderType( featureIt->geometry() ) )
{
commitErrors << tr( "ERROR: %n feature(s) not added - geometry type is not compatible with the current layer.", "not added features count", mAddedFeatures.size() );
success = false;
break;
}
}
}
}

9 comments on commit d19ed1c

@gioman

This comment has been minimized.

Copy link
Contributor

@gioman gioman replied Jul 13, 2017

@jef-n Hi Jurgen, I tested the fix on 2.18.10 nightly and it seems to work fine in general. I was anyway (by pure chance) "able" to still get a case where the copy/paste operation fails with the

Errors: ERROR: 1087 feature(s) not added - geometry type is not compatible with the current layer.

message.

This happens when you copy/paste feature between layers in different projects, and does not happen if the operation is done within the same project.

I found that while triaging

https://issues.qgis.org/issues/16822

that also shows another problem: copy/pasting between table in different projects does not retains the attributes, while is ok if the operation is done within the same project.

@jef-n

This comment has been minimized.

Copy link
Member Author

@jef-n jef-n replied Jul 13, 2017

Pasting to shape files?

@gioman

This comment has been minimized.

Copy link
Contributor

@gioman gioman replied Jul 13, 2017

Pasting to shape files?

yes. The tables are identical copies, and there is no issue if the operation is done within the same project (both regarding the error message on save and the lost attributes).

@jef-n

This comment has been minimized.

Copy link
Member Author

@jef-n jef-n replied Jul 13, 2017

yes. The tables are identical copies, and there is no issue if the operation is done within the same project (both regarding the error message on save and the lost attributes).

Point features?

@gioman

This comment has been minimized.

Copy link
Contributor

@gioman gioman replied Jul 13, 2017

Point features?

yes. Didn't tried with other type of geometries. I did tried anyway with 2.14.16 and the operation works fine regarding the geometries (but still does not retain the attributes).

@gioman

This comment has been minimized.

Copy link
Contributor

@gioman gioman replied Jul 14, 2017

Point features?
@jef-n

Hi Jurgen, better open/re-open a ticket as a reminder or there is something "in the work"?

@jef-n

This comment has been minimized.

Copy link
Member Author

@jef-n jef-n replied Jul 14, 2017

This commit doesn't touch point features - it just cures the regression introduced with the referenced commit. doesStrictFeatureTypeCheck returns false only for non-point shapefiles; because OGR is - or was at the point of it's introduction - as picky about single vs. multi geomety features in the point case as other data sinks; just with line strings and polygon it copes(/d?) with both.
So convertToProviderType still kicks in with points and convertToProviderType doesn't convert multi to single geometries. I guess you are trying to paste multi points to a shapefile.

@gioman

This comment has been minimized.

Copy link
Contributor

@gioman gioman replied Jul 14, 2017

I guess you are trying to paste multi points to a shapefile.

@jef-n

sorry, upon further tests the issue appears description appears to be different from what I wrote yesterday.

With 2.18.10 nightly and a specific point dataset (attached, just make a clone of it to test) the copy/paste/save operation fails even within the same qgis project/instance (don't know why yesterday it seemed to fail only when done between separate instances of QGIS).

With the same dataset the operation works in 2.14, works in 2.18.10 and then it broke in 2.18.10-nigthly and master.

I cannot replicate with other datasets, so it can be an edge case, but is indeed a regression. Will file a ticket to not forget about it.

points.zip

@gioman

This comment has been minimized.

Copy link
Contributor

@gioman gioman replied Jul 14, 2017

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