1

I am looking to eliminate small slivers in a shapefile dataset using PostgreSQL. What would work to dissolve features < 0.1 hectares into the neighbour with the longest shared boundary (1) or the neighbour with the largest area (2)?

Basically I want to do what the Eliminate function can do in ArcGIS.

I am attempting to call an instance of a connection to the PostgreSQL database in Python then run the eliminate SQL in there.

I am very new to PostgreSQL.

  • 1
    Are you using PostGIS? If so can you mention that in your question and add a tag for it, please? – PolyGeo Sep 24 '15 at 19:28
2

I have the same problem. Unfortunately, I did not find any solution around. I tried to develop something on my own. It is not very elegant, but it works. With the following code you can extract the ID of the "small" polygon together with the ID of the largest neighbour so that you can then merge them:

SELECT id_small_poly, id_large_poly FROM (
     SELECT 
       a.id_poly AS id_small_poly, 
       b.id_poly AS id_large_poly,
       rank() OVER (partition by a.id_poly order by st_area(b.geom) desc) AS rankx
     FROM
       (SELECT * FROM TABLE WHERE ST_AREA(geom) < 10000) a,
       (SELECT * FROM TABLE WHERE ST_AREA(geom) >= 10000) b
     WHERE      
       ST_INTERSECTS(a.geom, b.geom)
     ) x
WHERE rankx = 1;

Once you know the polygons to be merged, it is trivial to update your table (e.g. you update the geometry of the large polygon as the ST_UNION of the small and the large polygon and then you remove the small one from the table). I used the largest area, but you can adapt and take the adjacent polygon with the longest common border.

  • A couple of comments/questions... ST_Intersects would not work in my case where I am dealing with a spatially unique dataset. I could probably get around this just adding a buffer though. Would this only merge slivers with slivers? How might you go about doing the longest shared boundary? That seems to be the toughest part. What would performance on this be like? I am going to test this soon, but just wanted to see if you knew these up-front. Thanks. – D_C Oct 16 '15 at 17:17

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.