Skip to main content
deleted 6970 characters in body
Source Link
eftas
  • 545
  • 3
  • 15

There are various clip functionsThe Feature (orange frame, layer1) should be cut at the blue layer (layer2).

enter image description hereenter image description here

Which of these functions used QGIS?What I assume that it usesdo not understand is why the qgis:clip function. When I use thisclip function, then I get the mentioned problem of QGIS works. When I use the gdalogr:clipvectorsbypolygonfunction, then I get the following message on the console To find under: Vector -> Geoprocessing Tools -> Clip.

FAILURE: Invalid geometry. Must be a valid POLYGON or MULTIPOLYGON WKTenter image description here

Facts aboutWhen I run the datafollowing code, I get an incorrect result:

The data is returned and parsed in GeoJSON format from the server. From the data a QgsFeature is created. Two geometries in GeoJSON format:processing.runandload('qgis:clip', layer1, layer2, None)

{
  "type": "MultiPolygon",
  "crs": {
    "type": "name",
    "properties": {
      "name": "EPSG:25832"
    }
  },
  "coordinates": [
    [
      [
        [
          542706.2872924805,
          5912251.853271484
        ],
        [
          542660.6802978516,
          5912406.111877441
        ],
        [
          542657.5098876953,
          5912424.586303711
        ],
        [
          542660.5863037109,
          5912428.431884766
        ],
        [
          542781.7221069336,
          5912468.423706055
        ],
        [
          542779.7993164062,
          5912473.807922363
        ],
        [
          542754.1995239258,
          5912557.572875977
        ],
        [
          542937.4187011719,
          5912623.271118164
        ],
        [
          542807.6821289062,
          5912939.2958984375
        ],
        [
          542807.6586914062,
          5912939.402893066
        ],
        [
          542883.1987304688,
          5912963.785522461
        ],
        [
          542980.3286743164,
          5912995.460693359
        ],
        [
          543011.2399291992,
          5913003.633728027
        ],
        [
          543034.3947143555,
          5912941.547485352
        ],
        [
          543109.4404907227,
          5912974.619873047
        ],
        [
          543119.5639038086,
          5912910.467285156
        ],
        [
          543165.9216918945,
          5912924.134521484
        ],
        [
          543149.0244750977,
          5912985.780517578
        ],
        [
          543155.4230957031,
          5912991.063293457
        ],
        [
          543142.3414916992,
          5913045.31628418
        ],
        [
          543172.0249023438,
          5913052.859313965
        ],
        [
          543181.5848999023,
          5913024.989501953
        ],
        [
          543190.6074829102,
          5913009.733276367
        ],
        [
          543202.8676757812,
          5912971.409118652
        ],
        [
          543202.7836914062,
          5912971.390686035
        ],
        [
          543223.1716918945,
          5912907.660522461
        ],
        [
          543223.2565307617,
          5912907.665893555
        ],
        [
          543225.5717163086,
          5912898.450073242
        ],
        [
          543245.5651245117,
          5912901.910522461
        ],
        [
          543269.9141235352,
          5912822.526916504
        ],
        [
          543279.0458984375,
          5912791.772277832
        ],
        [
          543281.146484375,
          5912781.05847168
        ],
        [
          543283.3505249023,
          5912752.399719238
        ],
        [
          543283.6586914062,
          5912715.012878418
        ],
        [
          543290.9592895508,
          5912715.781494141
        ],
        [
          543314.8088989258,
          5912387.205688477
        ],
        [
          543236.6007080078,
          5912370.614318848
        ],
        [
          543102.8283081055,
          5912340.212280273
        ],
        [
          543096.9727172852,
          5912605.4122924805
        ],
        [
          543119.3286743164,
          5912604.2556762695
        ],
        [
          543140.4298706055,
          5912628.041870117
        ],
        [
          543140.0465087891,
          5912659.145324707
        ],
        [
          543135.8472900391,
          5912672.8876953125
        ],
        [
          543128.2797241211,
          5912669.860717773
        ],
        [
          543122.5164794922,
          5912653.724914551
        ],
        [
          543090.5717163086,
          5912626.014526367
        ],
        [
          543065.2230834961,
          5912614.109130859
        ],
        [
          543062.5369262695,
          5912591.083679199
        ],
        [
          543061.2634887695,
          5912579.625671387
        ],
        [
          543061.8616943359,
          5912560.014892578
        ],
        [
          542989.1051025391,
          5912534.125671387
        ],
        [
          543048.3267211914,
          5912327.992126465
        ],
        [
          542838.5480957031,
          5912281.3201293945
        ],
        [
          542706.3060913086,
          5912251.769104004
        ],
        [
          542706.2872924805,
          5912251.853271484
        ]
      ]
    ]
  ]
}

{
        "type": "Polygon",
        "crs": {
          "type": "name",
          "properties": {
            "name": "EPSG:25832"
          }
        },
        "coordinates": [
          [
            [
              543213.9880981445,
              5912697.975708008
            ],
            [
              543217.0557250977,
              5912698.373901367
            ],
            [
              543290.9578857422,
              5912707.9705200195
            ],
            [
              543312.944519043,
              5912387.097900391
            ],
            [
              543236.9743041992,
              5912371.105529785
            ],
            [
              543236.9490966797,
              5912371.401672363
            ],
            [
              543235.0921020508,
              5912393.182312012
            ],
            [
              543213.9880981445,
              5912697.975708008
            ]
          ]
        ]
      }

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

Whenenter image description here

Why I loaddo not get the GeoJSON to QGIS, then both clip variants are correct. I'm assuming that I make a mistake when creatingsame result? Take the QgsFeature. I will check that. Nevertheless, I have to ask whytools not the same clip function in the first case works?!

There are various clip functions.

enter image description here

Which of these functions used QGIS? I assume that it uses the qgis:clip function. When I use this function, then I get the mentioned problem. When I use the gdalogr:clipvectorsbypolygonfunction, then I get the following message on the console:

FAILURE: Invalid geometry. Must be a valid POLYGON or MULTIPOLYGON WKT

Facts about the data:

The data is returned and parsed in GeoJSON format from the server. From the data a QgsFeature is created. Two geometries in GeoJSON format:

{
  "type": "MultiPolygon",
  "crs": {
    "type": "name",
    "properties": {
      "name": "EPSG:25832"
    }
  },
  "coordinates": [
    [
      [
        [
          542706.2872924805,
          5912251.853271484
        ],
        [
          542660.6802978516,
          5912406.111877441
        ],
        [
          542657.5098876953,
          5912424.586303711
        ],
        [
          542660.5863037109,
          5912428.431884766
        ],
        [
          542781.7221069336,
          5912468.423706055
        ],
        [
          542779.7993164062,
          5912473.807922363
        ],
        [
          542754.1995239258,
          5912557.572875977
        ],
        [
          542937.4187011719,
          5912623.271118164
        ],
        [
          542807.6821289062,
          5912939.2958984375
        ],
        [
          542807.6586914062,
          5912939.402893066
        ],
        [
          542883.1987304688,
          5912963.785522461
        ],
        [
          542980.3286743164,
          5912995.460693359
        ],
        [
          543011.2399291992,
          5913003.633728027
        ],
        [
          543034.3947143555,
          5912941.547485352
        ],
        [
          543109.4404907227,
          5912974.619873047
        ],
        [
          543119.5639038086,
          5912910.467285156
        ],
        [
          543165.9216918945,
          5912924.134521484
        ],
        [
          543149.0244750977,
          5912985.780517578
        ],
        [
          543155.4230957031,
          5912991.063293457
        ],
        [
          543142.3414916992,
          5913045.31628418
        ],
        [
          543172.0249023438,
          5913052.859313965
        ],
        [
          543181.5848999023,
          5913024.989501953
        ],
        [
          543190.6074829102,
          5913009.733276367
        ],
        [
          543202.8676757812,
          5912971.409118652
        ],
        [
          543202.7836914062,
          5912971.390686035
        ],
        [
          543223.1716918945,
          5912907.660522461
        ],
        [
          543223.2565307617,
          5912907.665893555
        ],
        [
          543225.5717163086,
          5912898.450073242
        ],
        [
          543245.5651245117,
          5912901.910522461
        ],
        [
          543269.9141235352,
          5912822.526916504
        ],
        [
          543279.0458984375,
          5912791.772277832
        ],
        [
          543281.146484375,
          5912781.05847168
        ],
        [
          543283.3505249023,
          5912752.399719238
        ],
        [
          543283.6586914062,
          5912715.012878418
        ],
        [
          543290.9592895508,
          5912715.781494141
        ],
        [
          543314.8088989258,
          5912387.205688477
        ],
        [
          543236.6007080078,
          5912370.614318848
        ],
        [
          543102.8283081055,
          5912340.212280273
        ],
        [
          543096.9727172852,
          5912605.4122924805
        ],
        [
          543119.3286743164,
          5912604.2556762695
        ],
        [
          543140.4298706055,
          5912628.041870117
        ],
        [
          543140.0465087891,
          5912659.145324707
        ],
        [
          543135.8472900391,
          5912672.8876953125
        ],
        [
          543128.2797241211,
          5912669.860717773
        ],
        [
          543122.5164794922,
          5912653.724914551
        ],
        [
          543090.5717163086,
          5912626.014526367
        ],
        [
          543065.2230834961,
          5912614.109130859
        ],
        [
          543062.5369262695,
          5912591.083679199
        ],
        [
          543061.2634887695,
          5912579.625671387
        ],
        [
          543061.8616943359,
          5912560.014892578
        ],
        [
          542989.1051025391,
          5912534.125671387
        ],
        [
          543048.3267211914,
          5912327.992126465
        ],
        [
          542838.5480957031,
          5912281.3201293945
        ],
        [
          542706.3060913086,
          5912251.769104004
        ],
        [
          542706.2872924805,
          5912251.853271484
        ]
      ]
    ]
  ]
}

{
        "type": "Polygon",
        "crs": {
          "type": "name",
          "properties": {
            "name": "EPSG:25832"
          }
        },
        "coordinates": [
          [
            [
              543213.9880981445,
              5912697.975708008
            ],
            [
              543217.0557250977,
              5912698.373901367
            ],
            [
              543290.9578857422,
              5912707.9705200195
            ],
            [
              543312.944519043,
              5912387.097900391
            ],
            [
              543236.9743041992,
              5912371.105529785
            ],
            [
              543236.9490966797,
              5912371.401672363
            ],
            [
              543235.0921020508,
              5912393.182312012
            ],
            [
              543213.9880981445,
              5912697.975708008
            ]
          ]
        ]
      }

When I load the GeoJSON to QGIS, then both clip variants are correct. I'm assuming that I make a mistake when creating the QgsFeature. I will check that. Nevertheless, I have to ask why the clip function in the first case works?!

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?

Update for problem solving
Source Link
eftas
  • 545
  • 3
  • 15

Update:

There are various clip functions.

enter image description here

Which of these functions used QGIS? I assume that it uses the qgis:clip function. When I use this function, then I get the mentioned problem. When I use the gdalogr:clipvectorsbypolygonfunction, then I get the following message on the console:

FAILURE: Invalid geometry. Must be a valid POLYGON or MULTIPOLYGON WKT

Facts about the data:

The data is returned and parsed in GeoJSON format from the server. From the data a QgsFeature is created. Two geometries in GeoJSON format:

{
  "type": "MultiPolygon",
  "crs": {
    "type": "name",
    "properties": {
      "name": "EPSG:25832"
    }
  },
  "coordinates": [
    [
      [
        [
          542706.2872924805,
          5912251.853271484
        ],
        [
          542660.6802978516,
          5912406.111877441
        ],
        [
          542657.5098876953,
          5912424.586303711
        ],
        [
          542660.5863037109,
          5912428.431884766
        ],
        [
          542781.7221069336,
          5912468.423706055
        ],
        [
          542779.7993164062,
          5912473.807922363
        ],
        [
          542754.1995239258,
          5912557.572875977
        ],
        [
          542937.4187011719,
          5912623.271118164
        ],
        [
          542807.6821289062,
          5912939.2958984375
        ],
        [
          542807.6586914062,
          5912939.402893066
        ],
        [
          542883.1987304688,
          5912963.785522461
        ],
        [
          542980.3286743164,
          5912995.460693359
        ],
        [
          543011.2399291992,
          5913003.633728027
        ],
        [
          543034.3947143555,
          5912941.547485352
        ],
        [
          543109.4404907227,
          5912974.619873047
        ],
        [
          543119.5639038086,
          5912910.467285156
        ],
        [
          543165.9216918945,
          5912924.134521484
        ],
        [
          543149.0244750977,
          5912985.780517578
        ],
        [
          543155.4230957031,
          5912991.063293457
        ],
        [
          543142.3414916992,
          5913045.31628418
        ],
        [
          543172.0249023438,
          5913052.859313965
        ],
        [
          543181.5848999023,
          5913024.989501953
        ],
        [
          543190.6074829102,
          5913009.733276367
        ],
        [
          543202.8676757812,
          5912971.409118652
        ],
        [
          543202.7836914062,
          5912971.390686035
        ],
        [
          543223.1716918945,
          5912907.660522461
        ],
        [
          543223.2565307617,
          5912907.665893555
        ],
        [
          543225.5717163086,
          5912898.450073242
        ],
        [
          543245.5651245117,
          5912901.910522461
        ],
        [
          543269.9141235352,
          5912822.526916504
        ],
        [
          543279.0458984375,
          5912791.772277832
        ],
        [
          543281.146484375,
          5912781.05847168
        ],
        [
          543283.3505249023,
          5912752.399719238
        ],
        [
          543283.6586914062,
          5912715.012878418
        ],
        [
          543290.9592895508,
          5912715.781494141
        ],
        [
          543314.8088989258,
          5912387.205688477
        ],
        [
          543236.6007080078,
          5912370.614318848
        ],
        [
          543102.8283081055,
          5912340.212280273
        ],
        [
          543096.9727172852,
          5912605.4122924805
        ],
        [
          543119.3286743164,
          5912604.2556762695
        ],
        [
          543140.4298706055,
          5912628.041870117
        ],
        [
          543140.0465087891,
          5912659.145324707
        ],
        [
          543135.8472900391,
          5912672.8876953125
        ],
        [
          543128.2797241211,
          5912669.860717773
        ],
        [
          543122.5164794922,
          5912653.724914551
        ],
        [
          543090.5717163086,
          5912626.014526367
        ],
        [
          543065.2230834961,
          5912614.109130859
        ],
        [
          543062.5369262695,
          5912591.083679199
        ],
        [
          543061.2634887695,
          5912579.625671387
        ],
        [
          543061.8616943359,
          5912560.014892578
        ],
        [
          542989.1051025391,
          5912534.125671387
        ],
        [
          543048.3267211914,
          5912327.992126465
        ],
        [
          542838.5480957031,
          5912281.3201293945
        ],
        [
          542706.3060913086,
          5912251.769104004
        ],
        [
          542706.2872924805,
          5912251.853271484
        ]
      ]
    ]
  ]
}

{
        "type": "Polygon",
        "crs": {
          "type": "name",
          "properties": {
            "name": "EPSG:25832"
          }
        },
        "coordinates": [
          [
            [
              543213.9880981445,
              5912697.975708008
            ],
            [
              543217.0557250977,
              5912698.373901367
            ],
            [
              543290.9578857422,
              5912707.9705200195
            ],
            [
              543312.944519043,
              5912387.097900391
            ],
            [
              543236.9743041992,
              5912371.105529785
            ],
            [
              543236.9490966797,
              5912371.401672363
            ],
            [
              543235.0921020508,
              5912393.182312012
            ],
            [
              543213.9880981445,
              5912697.975708008
            ]
          ]
        ]
      }

When I load the GeoJSON to QGIS, then both clip variants are correct. I'm assuming that I make a mistake when creating the QgsFeature. I will check that. Nevertheless, I have to ask why the clip function in the first case works?!

Update:

There are various clip functions.

enter image description here

Which of these functions used QGIS? I assume that it uses the qgis:clip function. When I use this function, then I get the mentioned problem. When I use the gdalogr:clipvectorsbypolygonfunction, then I get the following message on the console:

FAILURE: Invalid geometry. Must be a valid POLYGON or MULTIPOLYGON WKT

Facts about the data:

The data is returned and parsed in GeoJSON format from the server. From the data a QgsFeature is created. Two geometries in GeoJSON format:

{
  "type": "MultiPolygon",
  "crs": {
    "type": "name",
    "properties": {
      "name": "EPSG:25832"
    }
  },
  "coordinates": [
    [
      [
        [
          542706.2872924805,
          5912251.853271484
        ],
        [
          542660.6802978516,
          5912406.111877441
        ],
        [
          542657.5098876953,
          5912424.586303711
        ],
        [
          542660.5863037109,
          5912428.431884766
        ],
        [
          542781.7221069336,
          5912468.423706055
        ],
        [
          542779.7993164062,
          5912473.807922363
        ],
        [
          542754.1995239258,
          5912557.572875977
        ],
        [
          542937.4187011719,
          5912623.271118164
        ],
        [
          542807.6821289062,
          5912939.2958984375
        ],
        [
          542807.6586914062,
          5912939.402893066
        ],
        [
          542883.1987304688,
          5912963.785522461
        ],
        [
          542980.3286743164,
          5912995.460693359
        ],
        [
          543011.2399291992,
          5913003.633728027
        ],
        [
          543034.3947143555,
          5912941.547485352
        ],
        [
          543109.4404907227,
          5912974.619873047
        ],
        [
          543119.5639038086,
          5912910.467285156
        ],
        [
          543165.9216918945,
          5912924.134521484
        ],
        [
          543149.0244750977,
          5912985.780517578
        ],
        [
          543155.4230957031,
          5912991.063293457
        ],
        [
          543142.3414916992,
          5913045.31628418
        ],
        [
          543172.0249023438,
          5913052.859313965
        ],
        [
          543181.5848999023,
          5913024.989501953
        ],
        [
          543190.6074829102,
          5913009.733276367
        ],
        [
          543202.8676757812,
          5912971.409118652
        ],
        [
          543202.7836914062,
          5912971.390686035
        ],
        [
          543223.1716918945,
          5912907.660522461
        ],
        [
          543223.2565307617,
          5912907.665893555
        ],
        [
          543225.5717163086,
          5912898.450073242
        ],
        [
          543245.5651245117,
          5912901.910522461
        ],
        [
          543269.9141235352,
          5912822.526916504
        ],
        [
          543279.0458984375,
          5912791.772277832
        ],
        [
          543281.146484375,
          5912781.05847168
        ],
        [
          543283.3505249023,
          5912752.399719238
        ],
        [
          543283.6586914062,
          5912715.012878418
        ],
        [
          543290.9592895508,
          5912715.781494141
        ],
        [
          543314.8088989258,
          5912387.205688477
        ],
        [
          543236.6007080078,
          5912370.614318848
        ],
        [
          543102.8283081055,
          5912340.212280273
        ],
        [
          543096.9727172852,
          5912605.4122924805
        ],
        [
          543119.3286743164,
          5912604.2556762695
        ],
        [
          543140.4298706055,
          5912628.041870117
        ],
        [
          543140.0465087891,
          5912659.145324707
        ],
        [
          543135.8472900391,
          5912672.8876953125
        ],
        [
          543128.2797241211,
          5912669.860717773
        ],
        [
          543122.5164794922,
          5912653.724914551
        ],
        [
          543090.5717163086,
          5912626.014526367
        ],
        [
          543065.2230834961,
          5912614.109130859
        ],
        [
          543062.5369262695,
          5912591.083679199
        ],
        [
          543061.2634887695,
          5912579.625671387
        ],
        [
          543061.8616943359,
          5912560.014892578
        ],
        [
          542989.1051025391,
          5912534.125671387
        ],
        [
          543048.3267211914,
          5912327.992126465
        ],
        [
          542838.5480957031,
          5912281.3201293945
        ],
        [
          542706.3060913086,
          5912251.769104004
        ],
        [
          542706.2872924805,
          5912251.853271484
        ]
      ]
    ]
  ]
}

{
        "type": "Polygon",
        "crs": {
          "type": "name",
          "properties": {
            "name": "EPSG:25832"
          }
        },
        "coordinates": [
          [
            [
              543213.9880981445,
              5912697.975708008
            ],
            [
              543217.0557250977,
              5912698.373901367
            ],
            [
              543290.9578857422,
              5912707.9705200195
            ],
            [
              543312.944519043,
              5912387.097900391
            ],
            [
              543236.9743041992,
              5912371.105529785
            ],
            [
              543236.9490966797,
              5912371.401672363
            ],
            [
              543235.0921020508,
              5912393.182312012
            ],
            [
              543213.9880981445,
              5912697.975708008
            ]
          ]
        ]
      }

When I load the GeoJSON to QGIS, then both clip variants are correct. I'm assuming that I make a mistake when creating the QgsFeature. I will check that. Nevertheless, I have to ask why the clip function in the first case works?!

Source Link
eftas
  • 545
  • 3
  • 15

QGIS - Clip: Differences between processing commands and built-in Python console

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?