153 | | CREATE OR REPLACE FUNCTION ST_SplitPolygon(poly geometry, blade geometry) |
154 | | RETURNS geometry AS |
155 | | 'SELECT ST_Polygonize(ST_Union(ST_Boundary($1), $2))' LANGUAGE sql IMMUTABLE STRICT COST 100; |
| 153 | CREATE OR REPLACE FUNCTION ST_SplitPolygon(poly geometry, blade geometry) RETURNS geometry AS |
| 154 | 'SELECT ST_Collect((d).geom) |
| 155 | FROM (SELECT ST_Dump(ST_Polygonize(ST_Union(ST_Boundary($1), $2))) AS d) f |
| 156 | WHERE ST_Area(ST_Intersection($1, (d).geom)) / ST_Area((d).geom) >= 1 - 1e-10;' LANGUAGE sql IMMUTABLE STRICT COST 100; |
159 | | SELECT ST_AsText(ST_SplitPolygon(circle, line)) result |
160 | | FROM (SELECT |
161 | | ST_MakeLine(ST_MakePoint(10, 10),ST_MakePoint(190, 190)) line, |
162 | | ST_Buffer(ST_GeomFromText('POINT(100 90)'), 50) circle) f; |
| 160 | SELECT ST_AsText(ST_SplitPolygon(poly, blade)) AS result |
| 161 | FROM ( |
| 162 | SELECT 'POLYGON ((20 30, 100 180, 160 20, 20 30), (70 70, 92 105, 110 50, 70 70))'::geometry AS poly, |
| 163 | 'MULTILINESTRING ((150 90, 90 70, 60 20), (50 140, 90 70))'::geometry AS blade |
| 164 | ) f; |
166 | | GEOMETRYCOLLECTION( |
167 | | POLYGON((150 90,...,150 90)), |
168 | | POLYGON((60.1371179574584 60.1371179574584,...,60.1371179574584 60.1371179574584))) |
| 168 | MULTIPOLYGON(((20 30,64.8275862068966 114.051724137931,80.4761904761905 86.6666666666667, |
| 169 | 70 70,85.3846153846154 62.3076923076923,64.1095890410959 26.8493150684932,20 30)), |
| 170 | ((64.8275862068966 114.051724137931,100 180,135.555555555556 85.1851851851852, |
| 171 | 102.131147540984 74.0437158469945,92 105,80.4761904761905 86.6666666666667, |
| 172 | 64.8275862068966 114.051724137931)), |
| 173 | ((135.555555555556 85.1851851851852,160 20,64.1095890410959 26.8493150684932, |
| 174 | 85.3846153846154 62.3076923076923,110 50,102.131147540984 74.0437158469945, |
| 175 | 135.555555555556 85.1851851851852))) |