2

Two geometries can be clipped in various ways. I have expected the same result, but I got two different results. The following method I used.

I have selected the clip function and added two layers. The green feature is the correct result. The geometry has been clipped by the blue layer. Then I get the following result:

enter image description here

All processing commands are available from the QGIS built-in Python console. I used the function 'qgis: clip'.

processing.runandload('qgis:clip', layer1, layer2, None)

Then I get the following incorrect result:

enter image description here

It seems to me as if the blue layer is empty or is ignored.

What am I doing wrong?

Update:

The Feature (orange frame, layer1) should be cut at the blue layer (layer2).

enter image description here

What I do not understand is why the clip function of QGIS works. To find under: Vector -> Geoprocessing Tools -> Clip.

enter image description here

When I run the following code, I get an incorrect result:

processing.runandload('qgis:clip', layer1, layer2, None)

Even if I reverse the two layers, I get the same result:

enter image description here

Why I do not get the same result? Take the tools not the same clip function?

5
  • Where do layer1 and layer2 come from? Is there any output in the message log, processing tab? Or in the processing history? Commented Apr 4, 2016 at 14:27
  • Did you try switching layer1 and layer2 (e.g. processing.runandload('qgis:clip', layer2, layer1, None)?
    – Joseph
    Commented Apr 4, 2016 at 14:27
  • I've updated my question.
    – eftas
    Commented Apr 5, 2016 at 8:35
  • To me it simply looks like you switched layer 1 and 2 in the second approach. Would be helpful if you provide images of layer 1 and 2 alone. So it's easier to understand which layers you are using and want to clip. Commented Apr 5, 2016 at 9:18
  • Even if I reverse the two layers, I get the same incorrect result
    – eftas
    Commented Apr 8, 2016 at 14:12

1 Answer 1

1

I now use the function intersection. Returns a geometry representing the points shared by this geometry and other. This function gives me the desired result.

See: QgsGeometry::intersection

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.