[postgis-users] unable to assign hole to a shell
Kevin Neufeld
kneufeld at refractions.net
Sat Sep 15 23:22:53 PDT 2007
So you're trying to use ST_Buffer(poly, 0.0) to clean-up your polygon?
A little investigation revealed that your polygon is not as harmless as
you thought. You actually have coincident line segments in the exterior
ring of your polygon.
LineSegment( 9.50351715087891 47.3943328857422 ) occurs three times.
This, as well as other self-intersections, is why st_buffer() was dying
on you.
Be careful using st_buffer() to cleanup geometries. Using 0.0 to trick
the function to not actually buffer at all is really a hack that does
not always work. I think we have planned to build a proper
geometry-cleanup function down the road, but until then, just be careful.
I was able to rebuild your polygon this way:
1. extract the exterior ring - you may want to add to this subquery all
the interior rings if you have any
2. extract all the points of the ext ring as ordered pairs (ie as
point1-point2, point2-point3, point3-point4, ....)
3. recreate line segments from all these ordered point pairs, removing
duplicates.
4. rebuild the polygon using st_buildarea()
-- Rebuild the polygon from all the linework
SELECT ST_BuildArea(geom) AS geom
FROM
(
-- Recreate the line segments (2-point lines) from the ordered points.
SELECT ST_Union(ST_MakeLine(pt1, pt2)) AS geom
FROM
(
-- Extract the points as pairs from the exterior ring of the polygon
SELECT ST_PointN(geom, generate_series(1, ST_NumPoints(geom)-1))
AS pt1,
ST_PointN(geom, generate_series(2, ST_NumPoints(geom))) AS pt2
FROM
(
-- The exterior ring of your polygon
SELECT ST_ExteriorRing(
'POLYGON((
9.50351715087891 47.3943328857422,
9.50386047363281 47.3943328857422,
9.50351715087891 47.3943328857422,
9.50248718261719 47.3943328857422,
9.50214385986328 47.3939895629883,
9.50180053710938 47.3943328857422,
9.50145721435547 47.3939895629883,
9.50111389160156 47.3936462402344,
9.50145721435547 47.3936462402344,
9.50145721435547 47.3939895629883,
9.50214385986328 47.3939895629883,
9.50248718261719 47.3939895629883,
9.50386047363281 47.3943328857422,
9.50351715087891 47.3943328857422))'::geometry) AS geom
) AS ring
) AS point_pairs
) AS line_segments
On a side note, your GEOS version is a little out of date. The new
version doesn't crash when trying to buffer your polygon, but it does
return an empty geometry collection.
Hope this clarifies things.
-- Kevin
-------------
Kevin Neufeld
Software Developer
Refractions Research Inc.
300-1207 Douglas St.
Victoria, B.C., V8W 2E7
Phone: (250) 383-3022
Email: kneufeld at refractions.net
Patrick Valsecchi wrote:
> Hi,
>
> I was trying to play with polygons on PostGIS and I found this one to be quite
> troublesome:
>
> POLYGON((9.50351715087891 47.3943328857422,9.50386047363281
> 47.3943328857422,9.50351715087891 47.3943328857422,9.50248718261719
> 47.3943328857422,9.50214385986328 47.3939895629883,9.50180053710938
> 47.3943328857422,9.50145721435547 47.3939895629883,9.50111389160156
> 47.3936462402344,9.50145721435547 47.3936462402344,9.50145721435547
> 47.3939895629883,9.50214385986328 47.3939895629883,9.50248718261719
> 47.3939895629883,9.50386047363281 47.3943328857422,9.50351715087891
> 47.3943328857422))
>
> When given to st_buffer(), it will throw this error:
>
> NOTICE: AssertionFailedException: unable to assign hole to a shell
> ERROR: GEOS buffer() threw an error!
>
> I don't understand... if you look at it, it looks like an armless polygon.
> More details (picture) can be found here:
> http://patrick.blog.thus.ch/?p=8
>
> I'am using PostgresQL 8.2.4 on a Debian install with:
> POSTGIS="1.3.1" GEOS="2.2.3-CAPI-1.1.1" PROJ="Rel. 4.5.0, 22 Oct 2006"
> USE_STATS
>
> Does anybody have an idea on what my problem is?
>
> Thanks
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
More information about the postgis-users
mailing list