Bug report #16524

Processing/geoprocessing operations failing in 2.18 with memory layers

Added by Calvin Hamilton about 3 years ago. Updated about 2 years ago.

Status:Closed
Priority:High
Assignee:-
Category:Processing/QGIS
Affected QGIS version:2.18.13 Regression?:Yes
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:fixed/implemented
Crashes QGIS or corrupts data:No Copied to github as #:24430

Description

This issue is applicable to some of the other Geoprocessing tools, but I have only really investigated Difference.

This is a bug report where Difference fails. Create two memory layer polygons in QGIS 2.18.7. In my case I created a large triangle and then an inner triangle for a second layer. If I run "Geooprocessing Tools->Difference" with the small triangle as the difference layer, I get an empty difference layer. I tried this specifying a temporary layer and a shapefile as the output layer and both fail. If I first save the two input memory layers as shapefiles and then do the same thing, it works correctly and I get a proper difference layer of a triangle with a hole in it. I also tested QGIS 2.14.7 and it works correctly so this is only failing in 2.18.

To create the shapes I used the "New Memory Layer" plugin to create polygon memory layers and then hand drew the shapes. I have also tried it with the "Shape Tools" plugin to create the shapes. It doesn't matter how the memory layers are created. I get the same results.

This is also true when creating layers with (example)

QgsVectorLayer("Polygon?crs=epsg:4326", "Layer Name", "memory")

example1.jpg - Polygons created by the script (93.3 KB) Calvin Hamilton, 2018-02-02 07:46 PM

example2.jpg - Correct results showing clip function (94.6 KB) Calvin Hamilton, 2018-02-02 07:46 PM

two-polygons.py Magnifier - Script to illustrate problem (912 Bytes) Calvin Hamilton, 2018-02-02 07:46 PM

qgis2.18example.jpg - Error results of clip function (106 KB) Calvin Hamilton, 2018-02-02 07:46 PM


Related issues

Related to QGIS Application - Bug report #18006: Geoprocessing Tools Fail with Memory Layers in QGIS 2.18 Rejected 2018-01-30

History

#1 Updated by Giovanni Manghi about 3 years ago

  • Status changed from Open to Feedback
  • Subject changed from Geoprocessing Tools->Difference Failing with 2.18.7 and memory layer to Vector difference Failing in 2.18.7 with memory layers (created with the "memory layers" plugin)
  • Category changed from Vectors to Processing/QGIS
  • Priority changed from Normal to High
  • Operating System deleted (Windows 7)

In 2.18.7 you don't need such plugin, you have the (core) "new temporary scratch layer" functionality, and with that there are no issues.

#2 Updated by Calvin Hamilton about 3 years ago

It doesn't matter how the memory layer is created it still fails and should be fixed. The memory layers plugin was just an example. Are memory layers going away in 3.0?

#3 Updated by Giovanni Manghi about 3 years ago

Calvin Hamilton wrote:

It doesn't matter how the memory layer is created it still fails and should be fixed. The memory layers plugin was just an example. Are memory layers going away in 3.0?

the "New Memory Layer" plugin functionality has been replaced by the core "new temporary scratch layer". So if the problem is only about layers created with the plugin then I shouls say we should mark it as obsolete.

If there are other ways to create "memory/scratch" layers that turns to not play well with processing then is another matter. Is this the case? cheers!

#4 Updated by Calvin Hamilton about 3 years ago

Somehow I don't get notified when this is updated. The New Memory Layer plugin was just one example. My own Shape Tools plugin is another example. This is a problem no matter how the memory layer is created. Any layer created by calling

QgsVectorLayer("Polygon?crs=epsg:4326", "Layer Name", "memory")

will fail.

#5 Updated by Calvin Hamilton about 3 years ago

Not to be picky but "(created with the "memory layers" plugin)" really should not be in the title. I first found this problem not using the "memory layers" plugin and then to test to see if it failed using another way I tried the "memory layers" plugin. That was apparently a mistake because the focus has been on that plugin and not on the fact that it fails with any memory layer.

This problem is not about the "memory layers" plugin.

#6 Updated by Giovanni Manghi about 3 years ago

  • Status changed from Feedback to Open
  • Description updated (diff)
  • Subject changed from Vector difference Failing in 2.18.7 with memory layers (created with the "memory layers" plugin) to Processing/geoprocessing operations failing in 2.18 with memory layers

This problem is not about the "memory layers" plugin.

ok, now we have w new piece of information that makes the issue clear.

#7 Updated by Giovanni Manghi almost 3 years ago

  • Affected QGIS version changed from 2.18.7 to 2.18.13

#8 Updated by Victor Olaya over 2 years ago

Cannot reproduce here

I tried you suggestion of creating two polygons in two memory layers, and difference work fine. Also, i tried creating 2 buffers of different size from a point memory layer, and then computing the difference between them, and it also works fine.

Tried in latest version of Processing, and also in the one corresponding to 2.8.7. Both worked fine.

Any more detail you can provide so we can reproduce?

#9 Updated by Alexander Bruy over 2 years ago

  • Status changed from Open to Feedback

I have tested almost all geoprocessing tools and their combinations and also was not able to reproduce this bug.

#10 Updated by Calvin Hamilton over 2 years ago

I have found that it is caused by 3rd party plugins that create memory layers. Something must have changed recently in QGIS with how polygons are created and the 3rd party plugin shapes do not work. Two examples are the old "New Memory Layer" plugin and the "Shape Tools" plugin which I wrote. The geoprocessing operations used to work so the question is what has changed? Do these plugins need to make some change or do the geoprocessing algorithms need to be more robust? I would think that if you have a polygon the algorithms should be able to work with them or at least be able to report that there is a problem.

#11 Updated by Alexander Bruy over 2 years ago

  • Related to Bug report #18006: Geoprocessing Tools Fail with Memory Layers in QGIS 2.18 added

#12 Updated by Calvin Hamilton over 2 years ago

Since my new ticket #18006 related to this was rejected. Here is the additional information that I wrote in that ticket to diagnose this issue.

I have attached a python script to illustrate this bug. I posted this problem on the qgis-developer group and Richard Duivenvoorde confirmed the problem. This problem appears to only affect QGIS 2.18.x. Richard tested it on QGIS 3.0 and it works fine. example1.jpg and exmple2.jpg were run using 2.14 to show the correct results.

Run two-polygons.py and it will create two polygons (see example1.jpg). Note that I have given Polygon 2 some transparency so you can see how they overlap. Now run "Vector->Geoprocessing Tools->Clip". I used 'Polygon 1' for the 'Input vector layer' and 'Polygon 2' for the 'Clip layer'. QGIS 2.14 produces the correct results as shown by example2.jpg. QGIS 2.18.16 does not clip. It returns 'Polygon 1' as shown by qgis2.18example.jpg.

This example just shows the Clip function but I think all of the Geoprocessing Tools have issues. 'Intersection' gives the same results. 'Symmetrical difference' and 'Difference' don't return any polygon result, but they should both return a result. I have not checked the rest.

#13 Updated by Nyall Dawson about 2 years ago

  • Resolution set to fixed/implemented
  • Status changed from Open to Closed

Fixed in 3.0

Also available in: Atom PDF