[postgis-devel] ST_MakePolygon returns null geometry when passedNULL or empty array

Obe, Regina robe.dnd at cityofboston.gov
Wed Jul 9 04:00:00 PDT 2008


On the robust side of things should we be concerned that if we feed it
closed line strings that are not contained in the shell (or is the
shell) and/or overlap each other.  The function happily returns you an
invalid geometry.

 SELECT ST_IsValid(the_geom), ST_AsText(the_geom)
FROM (
   SELECT ST_MakePolygon(
     'LINESTRING(0 0, 0 8, 8 8, 8 0, 0 0)'::geometry,
     ARRAY['LINESTRING(0 0, 0 8, 8 8, 9 0, 0 0)'::geometry]) AS the_geom
   ) AS foo;

seems like it should give you a NOTICE or something.

-----Original Message-----
From: postgis-devel-bounces at postgis.refractions.net
[mailto:postgis-devel-bounces at postgis.refractions.net] On Behalf Of
Kevin Neufeld
Sent: Tuesday, July 08, 2008 11:42 AM
To: PostGIS Development Discussion
Subject: Re: [postgis-devel] ST_MakePolygon returns null geometry when
passedNULL or empty array

I think the current assumption is that if you choose to supply a set of 
interior rings that make up the polygon, they should form simple linear 
rings.  Hence the "input geometries must be closed LINESTRINGs" phrase 
in the docs.

You're right, this doesn't work:
postgis=# SELECT ST_IsValid(the_geom), ST_AsText(the_geom)
FROM (
   SELECT ST_MakePolygon(
     'LINESTRING(0 0, 0 8, 8 8, 8 0, 0 0)'::geometry,
     ARRAY[NULL]) AS the_geom
   ) AS foo;
ERROR:  Hole 0 is not a line

I suppose we could add "make this function more robust" to the TODO
list.

In any case, the docs definitely should be clarified.

Cheers,
-- Kevin

Obe, Regina wrote:
> I'm not sure if this expected behavior or not, but it surprised me.
> 
> In formulating ST_MakePolygon examples for the docs, I noticed if I
> passed in NULL or an empty array 
> for the ST_MakePolygon second arg, I get back a null geometry.
> 
> Shouldn't it just return a polygon formed from the first argument?
> 
> Thanks,
> Regina
> -----------------------------------------
> The substance of this message, including any attachments, may be
> confidential, legally privileged and/or exempt from disclosure
> pursuant to Massachusetts law. It is intended
> solely for the addressee. If you received this in error, please
> contact the sender and delete the material from any computer.
> 
> _______________________________________________
> postgis-devel mailing list
> postgis-devel at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-devel
_______________________________________________
postgis-devel mailing list
postgis-devel at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-devel



More information about the postgis-devel mailing list