[postgis-users] Making a Polygon from Points

David Potts dave.potts at pinan.co.uk
Sun Dec 6 04:04:28 PST 2009


Thanks Jan,

Worked a treat:-)

Dave.
> 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.
>>
>


-- 
Any views expressed in this message are those of the individual sender,
except where the sender specifically states them to be the views of the
Pinan Software





More information about the postgis-users mailing list