1

I am trying to use the ST_Difference tool within PostGIS. The intention is to take two multipolyogn layers that have some overlap and eliminate the overlap by taking the difference. The problem is that I am using two multipolygon tables as input but the output table is a polygon type.

Information seems to be lost (the individual division of the polygon). The output is indeed differenced, but it is one polygon without the original divisions included. What is making this query change geometry types?

SELECT ST_GeometryType(divided1.geom)
FROM divided1;
--st_geometrytype
--ST_MultiPolygon

The geometry of the 2nd table is the same type.

CREATE TABLE box_diff AS
SELECT divided_1.cat, ROW_NUMBER () OVER(), ST_Difference(divided1.geom, divided2.geom) AS geom
FROM divided1, divided2;

Then the geometry type of the created table is

SELECT ST_GeometryType(box_diff.geom)
FROM box_diff;
--st_geometrytype
--ST_Polygon

This shows the north south buffered network line as divided1.geom and the east west buffered network line as divided2.geom

This image shows two screen shots of two spatial tables in PostGIS. They were created by taking a buffer of a file similar to a road network, and then in QGIS I used the polygon divide tool to make evenly sized boxes. The north-south lines have overlap with the east-west lines and I wish to remove the overlap by using the difference function. If you can suggest a better tool please let me know

JGH
  • 41,794
  • 3
  • 43
  • 89
nerdsconsider
  • 379
  • 1
  • 8
  • 1
    the result of st_difference can be any type of geometry even a point or a line. Can you add an image of your problem so we can see what's going on – Ian Turton Apr 19 '22 at 08:54
  • @IanTurton I added a picture and a short explanation, thank you for the suggestion – nerdsconsider Apr 19 '22 at 11:30

1 Answers1

2

Most geometric operations will return a geometry of the smallest kind needed to represent the result regardless of the input. Eg. if the result can be represented as a polygon it will return a polygon, not a multi polygon with only one outer ring. Also if the result can be represented as line it will be returned as a line etc.

As for the lost dividers, I would guess that the multipolygons are not in fact valid multipolygons. If the segments in the multipolygon have overlapping edges it is not a valid multipolygon and ST_Difference might perform something similar to ST_MakeValid on them, which would dissolve each multipolygon to a polygon.

Stefan
  • 1,667
  • 9
  • 11