9

I got a dataset with polygon shapes, in which the geometry was updated by the QGIS plugin "Geometry Updater". Now I have the problem that in PostGIS I get invalid geometries with the error message "Hole lies outside shell". But when observing the geometry in QGIS, there are actually two shapes, where one is the main geometry and the other (probably) the hole.

enter image description here

I thought the reason for this was that the geometry type was set to ST_Polygon. But even after changing it to ST_MultiPolygon, the error still remains. Someone has an idea how to fix this? Also manually in QGIS would be fine.

EDIT:

This is the original WKT of the shape in the picture (before changing it to ST_MultiPolygon):

POLYGON((681328.211640639 5312556.84866055,681333.876018639 5312566.85338355,681344.126811639 5312584.17146655,681360.13777864 5312605.81168455,681368.571629639 5312620.16794654,681375.15817664 5312633.84801255,681380.74133464 5312647.74367554,681384.01769064 5312658.41482554,681392.01169764 5312694.63471254,681393.07199764 5312701.83700354,681389.16681464 5312705.85459254,681379.79126564 5312704.26135554,681393.93193764 5312715.39845154,681401.81727164 5312723.43382354,681398.09962564 5312710.95653254,681395.19739764 5312693.68448654,681387.20535464 5312657.40285554,681383.87846764 5312644.38168654,681378.69327164 5312632.35257854,681367.00831364 5312610.47778954,681346.401239639 5312581.83289054,681336.365640639 5312564.27437955,681340.423191639 5312560.69415655,681365.23709764 5312567.84133655,681374.16498264 5312570.47104354,681390.52225764 5312565.30077054,681395.29993964 5312563.90629854,681410.98915364 5312545.67508754,681413.79585564 5312536.98783954,681415.77221864 5312530.93185454,681416.991529641 5312523.86320254,681406.38747164 5312515.12414654,681403.96790864 5312507.57002154,681395.94924164 5312514.30082354,681394.08765664 5312516.71419154,681390.91027864 5312518.71529654,681387.07111564 5312520.63375054,681381.90838164 5312522.38690354,681376.13571264 5312525.04785255,681366.362498639 5312530.79640254,681349.071127639 5312540.57236955,681332.287335639 5312550.05537054,681321.992430639 5312555.23135255,681328.211640639 5312556.84866055),(681306.938491638 5312528.24474655,681318.811081639 5312521.75881455,681324.059996639 5312518.58690655,681330.950098639 5312514.72509155,681336.554227639 5312510.82277555,681341.802513639 5312506.35305054,681352.668573639 5312497.54885354,681356.654879639 5312493.59559054,681360.976303639 5312488.23147354,681363.302624639 5312486.88334655,681366.15656264 5312485.92264755,681369.80127664 5312486.22287554,681375.12800564 5312488.49191954,681382.62287464 5312493.11590554,681385.88903564 5312494.88743254,681387.74606564 5312495.25494754,681393.90959164 5312496.00535955,681389.15656464 5312487.38890554,681365.00476264 5312481.62211554,681327.726005639 5312490.52129555,681306.883836639 5312494.37629255,681298.999414638 5312496.84720955,681306.938491638 5312528.24474655))

  • 3
    Normally this is due to the direction of the vertices. If one of the polygons is clockwise and the other one is counter-clockwise then it thinks the second one is a hole. It is just an idea, unfortunately I don't know how to fix it – ylka Sep 6 '17 at 7:24
  • if you copy and paste the feature into a text editor you can probably change it to a multipolygon and reimport using QuickWKT – Ian Turton Sep 6 '17 at 7:44
  • Can you post the WKT of your feature? – thibautg Sep 6 '17 at 7:45
  • @thibautg I just add the WKT – JoeBe Sep 6 '17 at 7:56
10

indeed, in PostGIS ST_IsValidReason returns Hole lies outside shell[681306.938491638 5312528.24474655]

ST_MakeValid changes it to a MULTIPOLYGON:

MULTIPOLYGON(((681306.938491638 5312528.24474655,681318.811081639 5312521.75881455,681324.059996639 5312518.58690655,681330.950098639 5312514.72509155,681336.554227639 5312510.82277555,681341.802513639 5312506.35305054,681352.668573639 5312497.54885354,681356.654879639 5312493.59559054,681360.976303639 5312488.23147354,681363.302624639 5312486.88334655,681366.15656264 5312485.92264755,681369.80127664 5312486.22287554,681375.12800564 5312488.49191954,681382.62287464 5312493.11590554,681385.88903564 5312494.88743254,681387.74606564 5312495.25494754,681393.90959164 5312496.00535955,681389.15656464 5312487.38890554,681365.00476264 5312481.62211554,681327.726005639 5312490.52129555,681306.883836639 5312494.37629255,681298.999414638 5312496.84720955,681306.938491638 5312528.24474655)),((681328.211640639 5312556.84866055,681333.876018639 5312566.85338355,681344.126811639 5312584.17146655,681360.13777864 5312605.81168455,681368.571629639 5312620.16794654,681375.15817664 5312633.84801255,681380.74133464 5312647.74367554,681384.01769064 5312658.41482554,681392.01169764 5312694.63471254,681393.07199764 5312701.83700354,681389.16681464 5312705.85459254,681379.79126564 5312704.26135554,681393.93193764 5312715.39845154,681401.81727164 5312723.43382354,681398.09962564 5312710.95653254,681395.19739764 5312693.68448654,681387.20535464 5312657.40285554,681383.87846764 5312644.38168654,681378.69327164 5312632.35257854,681367.00831364 5312610.47778954,681346.401239639 5312581.83289054,681336.365640639 5312564.27437955,681340.423191639 5312560.69415655,681365.23709764 5312567.84133655,681374.16498264 5312570.47104354,681390.52225764 5312565.30077054,681395.29993964 5312563.90629854,681410.98915364 5312545.67508754,681413.79585564 5312536.98783954,681415.77221864 5312530.93185454,681416.991529641 5312523.86320254,681406.38747164 5312515.12414654,681403.96790864 5312507.57002154,681395.94924164 5312514.30082354,681394.08765664 5312516.71419154,681390.91027864 5312518.71529654,681387.07111564 5312520.63375054,681381.90838164 5312522.38690354,681376.13571264 5312525.04785255,681366.362498639 5312530.79640254,681349.071127639 5312540.57236955,681332.287335639 5312550.05537054,681321.992430639 5312555.23135255,681328.211640639 5312556.84866055)))
3

I had a try with the "Make Geometries Valid" tool of OpenJUMP and it returns corrected geometry as a multipolygon. OpenJUMP is using it's own makeValid function. I do not know if QGIS has an equivalent function but because you have the feature already in PostGIS you can simply use ST_MakeValid http://postgis.net/docs/ST_MakeValid.html.

MULTIPOLYGON ((( 681328.211640639 5312556.84866055, 681333.876018639 5312566.85338355, 681344.126811639 5312584.17146655, 681360.13777864 5312605.81168455, 681368.571629639 5312620.16794654, 681375.15817664 5312633.84801255, 681380.74133464 5312647.74367554, 681384.01769064 5312658.41482554, 681392.01169764 5312694.63471254, 681393.07199764 5312701.83700354, 681389.16681464 5312705.85459254, 681379.79126564 5312704.26135554, 681393.93193764 5312715.39845154, 681401.81727164 5312723.43382354, 681398.09962564 5312710.95653254, 681395.19739764 5312693.68448654, 681387.20535464 5312657.40285554, 681383.87846764 5312644.38168654, 681378.69327164 5312632.35257854, 681367.00831364 5312610.47778954, 681346.401239639 5312581.83289054, 681336.365640639 5312564.27437955, 681340.423191639 5312560.69415655, 681365.23709764 5312567.84133655, 681374.16498264 5312570.47104354, 681390.52225764 5312565.30077054, 681395.29993964 5312563.90629854, 681410.98915364 5312545.67508754, 681413.79585564 5312536.98783954, 681415.77221864 5312530.93185454, 681416.991529641 5312523.86320254, 681406.38747164 5312515.12414654, 681403.96790864 5312507.57002154, 681395.94924164 5312514.30082354, 681394.08765664 5312516.71419154, 681390.91027864 5312518.71529654, 681387.07111564 5312520.63375054, 681381.90838164 5312522.38690354, 681376.13571264 5312525.04785255, 681366.362498639 5312530.79640254, 681349.071127639 5312540.57236955, 681332.287335639 5312550.05537054, 681321.992430639 5312555.23135255, 681328.211640639 5312556.84866055 )), (( 681306.938491638 5312528.24474655, 681318.811081639 5312521.75881455, 681324.059996639 5312518.58690655, 681330.950098639 5312514.72509155, 681336.554227639 5312510.82277555, 681341.802513639 5312506.35305054, 681352.668573639 5312497.54885354, 681356.654879639 5312493.59559054, 681360.976303639 5312488.23147354, 681363.302624639 5312486.88334655, 681366.15656264 5312485.92264755, 681369.80127664 5312486.22287554, 681375.12800564 5312488.49191954, 681382.62287464 5312493.11590554, 681385.88903564 5312494.88743254, 681387.74606564 5312495.25494754, 681393.90959164 5312496.00535955, 681389.15656464 5312487.38890554, 681365.00476264 5312481.62211554, 681327.726005639 5312490.52129555, 681306.883836639 5312494.37629255, 681298.999414638 5312496.84720955, 681306.938491638 5312528.24474655 )))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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