3

I'm experimenting a result issue using the ST_Difference spatial function in PostGIS.

Input :

Feature 1 and 2 overlaps each other. Both contains 5 vertices, like a rectangle (4 plus an additional one to close the polygon).

I want to get the geometry difference between feature 2 and feature 1. (st_difference(geom(feature2),geom(feature1))

input

Result :

After executing the function, the result of geom(feature2)-geom(feature1), in green, contains unexpected residual vertices (highlighted), inside feature 1 :

difference

Result only :

result

Anyone knows how to avoid this issue, or how to get a "cleaned" difference of 2 input polygons?


The input data is Polygon, the result (after st_difference) is multipolygon. I get the same result with Polygon geometry for the result.

Input : enter image description here

Result :

enter image description here

Edit 2 :

Input polygon geometry :

Feature 1 :

"POLYGON((363011.683640322 5784798.67947383,363061.369728361 5784794.01684973,363060.058365334 5784774.34640432,363009.64374228 5784780.75751245,363011.683640322 5784798.67947383))"

Feature 2 :

"POLYGON((363079.583103742 5784786.58579258,363079.583103742 5784777.55195839,363053.501550197 5784780.32039144,363054.230085212 5784789.06281163,363079.583103742 5784786.58579258))"

Result of st_difference(feature2(geom),feature1(geom)) :

MULTIPOLYGON(((363079.583103742 5784786.58579258,363079.583103742 5784777.55195839,363053.501550197 5784780.32039144,363060.407760381 5784779.58733003,363060.995393925 5784788.40183319,363054.230085212 5784789.06281163,363079.583103742 5784786.58579258)))

As shown on the screenshot, the result contains 7 vertices (instead of 5 as expected).

CRS : 28355

  • Can you share the data needed to reproduce this? – bugmenot123 Jul 4 '18 at 9:19
  • It seems to me like your geometries are not actually polygons, but just their boundaries. Can you confirm this ? If it's true, you can run a ST_MakePolygon, or ST_Polygonize before you do the differences. – GHRF Jul 4 '18 at 9:23
  • I just add an edit with data screenshots. I'm happy to share the data too. Should I upload the shp file and add a hyperlink on the post? – Olivier Jul 4 '18 at 10:11
  • 3
    Easiest is to just post the result of st_astext(geom). If it is only 2 polygons with 5 vertex points that is the best. – Nicklas Avén Jul 4 '18 at 10:56
  • I have just added a post update containing the wkt geometry. thanks for your help – Olivier Jul 4 '18 at 15:28

Your Answer

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

Browse other questions tagged or ask your own question.