[postgis-users] Splitting a polygon.

Paul moen pmoen at offroadsoftware.com
Sun Jan 24 17:19:04 PST 2010


I made a much more simplified version of what I am trying to do.  I am  
using PostgreSQL 8.4.2 and POSTGIS="1.4.1" GEOS="3.2.0-CAPI-1.6.0"  
PROJ="Rel. 4.7.1, 23 September 2009"

I create the table testlines as follows

CREATE TABLE testlines
(
  gid integer,
  the_geom geometry
)
WITH (OIDS=TRUE);
ALTER TABLE testlines OWNER TO postgres;
INSERT INTO testlines(gid, the_geom) VALUES (1,  
st_geomfromtext('LINESTRING(1972865.08581219  
378326.311285453,1975599.79273051 379853.261981628)',-1));
INSERT INTO testlines(gid, the_geom) VALUES (2,  
st_geomfromtext('LINESTRING(1972773.34674946  
377707.210612508,1972913.11215175 377573.688032513)',-1));
INSERT INTO testlines(gid, the_geom) VALUES (3,  
st_geomfromtext('LINESTRING(1972765.56033513  
378288.726667813,1972865.08581219 378326.311279507)',-1));
INSERT INTO testlines(gid, the_geom) VALUES (4,  
st_geomfromtext('LINESTRING(1972865.08581219  
378326.311279507,1972817.2530921 378237.264198899)',-1));

I want to split the following polygon using the linestrings in the  
table testlines.

POLYGON((1975538.39350359 377623.361866549,1972852.28369938  
377613.359472095,1972847.53554394 380259.639618443,1975537.28833463  
380263.247556028,1975538.39350359 377623.361866549))

I am using the following select statement to try to accomplish this.

SELECT st_astext((st_dump(st_polygonize(linesgeo))).geom) as thegeos  
from (select  
st_union(st_boundary(st_geomfromtext('MULTIPOLYGON(((1975538.39350359  
377623.361866549,1972852.28369938 377613.359472095,1972847.53554394  
380259.639618443,1975537.28833463 380263.247556028,1975538.39350359  
377623.361866549)))',-1)),st_union(the_geom)) as linesgeo from  
testlines) as foo;

my output is

POLYGON((1975538.39350359 377623.361866549,1972871.51093682  
377613.431069471,1972852.25055609 377631.831157651,1972851.05134661  
378300.184222845,1972865.08581219 378326.311279507,1972851.01400234  
378320.997228024,1972847.53554394 380259.639618443,1975537.28833463  
380263.247556028,1975537.4745392 379818.466002222,1975538.39350359  
377623.361866549))
POLYGON((1972871.51093682 377613.431069471,1972852.28369938  
377613.359472095,1972852.25055609 377631.831157651,1972871.51093682  
377613.431069471))
POLYGON((1972851.05134661 378300.184222845,1972851.01400234  
378320.997228024,1972865.08581219 378326.311279507,1972851.05134661  
378300.184222845))

This is wrong because there should be 4 polygons created by the split.

I then create a 2nd table called testlines2 with the same linestrings  
without the decimals removed as follows.

CREATE TABLE testlines2
(
  gid integer,
  the_geom geometry
)
WITH (OIDS=TRUE);
INSERT INTO testlines2(gid, the_geom) VALUES (1,  
st_geomfromtext('LINESTRING(1972865 378326,1975599 379853)',-1));
INSERT INTO testlines2(gid, the_geom) VALUES (2,  
st_geomfromtext('LINESTRING(1972773 377707,1972913 377573)',-1));
INSERT INTO testlines2(gid, the_geom) VALUES (3,  
st_geomfromtext('LINESTRING(1972765 378288,1972865 378326)',-1));
INSERT INTO testlines2(gid, the_geom) VALUES (4,  
st_geomfromtext('LINESTRING(1972865 378326,1972817 378237)',-1));

I then use the same sql statement except that it is using the  
testlines2 table.

SELECT st_astext((st_dump(st_polygonize(linesgeo))).geom) as thegeos  
from (select  
st_union(st_boundary(st_geomfromtext('MULTIPOLYGON(((1975538.39350359  
377623.361866549,1972852.28369938 377613.359472095,1972847.53554394  
380259.639618443,1975537.28833463 380263.247556028,1975538.39350359  
377623.361866549)))',-1)),st_union(the_geom)) as linesgeo from  
testlines2) as foo;

I get the expected output this time with 4 polygons.

POLYGON((1975538.39350359 377623.361866549,1972870.76149981  
377613.428278757,1972852.25178775 377631.144717438,1972851.05143129  
378300.137028843,1972865 378326,1975537.47446777  
379818.636617514,1975538.39350359 377623.361866549))
POLYGON((1972870.76149981 377613.428278757,1972852.28369938  
377613.359472095,1972852.25178775 377631.144717438,1972870.76149981  
377613.428278757))
POLYGON((1972851.05143129 378300.137028843,1972851.01456161  
378320.685533412,1972865 378326,1972851.05143129 378300.137028843))
POLYGON((1972851.01456161 378320.685533412,1972847.53554394  
380259.639618443,1975537.28833463 380263.247556028,1975537.47446777  
379818.636617514,1972865 378326,1972851.01456161 378320.685533412))

Is this a bug?




More information about the postgis-users mailing list