[postgis-users] Making a Polygon from Points

Jan Hartmann j.l.h.hartmann at uva.nl
Sun Dec 6 02:48:44 PST 2009


Hi David,

I do it like this:

select geometryfromtext
('Polygon (('  || array_to_string
    (array
        (
            (select x(crd) || ' ' || y(crd)
                  from points
                  order by nr
            )
            union all
            (select x(crd) || ' ' || y(crd)
                 from points
                 order by nr
                 limit 1
            )
       ),','
    ) || '))',srid
) as the_geom

First put the points in an array, add the first point at the last 
position, and convert the array to a GEOMETRY string. You need a column 
to orders the points (nr in this case).

Jan


David Potts wrote:
> Hi
>
> I trying to make a polygon or closed linestring from a list of points.
>
> I can say something like
>
>
>  insert into lines(the_geom) select ST_MakeLine(foo.the_geom) from(select
> the_geom from hack where generation=1 and circle=0 ) as foo;
>
> This results in a open line that runs through all off the points,  I am
> trying to generate either a closed line or a polygon.
>
> Using functions like  ST_Polygonize, generate an empty goetry collection.
>
> Does anybody have any suggestions on how I generate a closed linestring or
> a polygon?
> regards
>
> Dave.
>   



More information about the postgis-users mailing list