6

I have a rectangle polygon which divides my country into small grids (like tiling). I have a system in which by selecting single/multiple features users can send applications to get license to those single/multiple selected polygons. But there is one requirement. All selected features must be in neighborhood (must intersect with wall, edge intersection is not considered). For example, if user selected these like this

enter image description here

the system should say ok (true), because all polygons have connections.

If user selections like this:

enter image description here

then, it checking algorithm should say that it is not ok (false), because the upper-left polygon does not intersect with its walls, which means edge intersection is not counted. Same conclusion applies to the last image, I should get False.

enter image description here

Are there any ready functions/algorithms to check such conditions? I am looking for PostGIS solutions/recommendations. Users will select polygons from the drop-down list and press the check button to see the results.

4
  • 1
    One question per Question, please. Choose PostGIS or Python, and make an attempt, though dissolving and counting parts would suffice either way.
    – Vince
    Commented Aug 22, 2022 at 11:31
  • @Vince, thanks for your comment. okay i will change Commented Aug 22, 2022 at 11:33
  • SQL questions should contain SQL code.
    – Vince
    Commented Aug 22, 2022 at 11:46
  • Is the selection an UI frontend application? If so, save yourself a roundtrip to the server and DB (and comparably more costly spatial relationship operations) and simply lookup tile indices (col, row) as keys in a map (with altering (col+-1, row+-1)) of previously selected.
    – geozelot
    Commented Aug 22, 2022 at 18:52

1 Answer 1

8

If the rectangles are all edge-adjacent, then their union will be a single polygon. If not, it will be a MultiPolygon with more than one element. So, union the rectangles, and then test if ST_NumGeometries(union) equals 1.

ST_NumGeometries( ST_Union( geom )) = 1 AS isEdgeAdjacent
0

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.