[postgis-users] Create POLYGON from Several LINESTRINGs
Randall, Eric
ERandall at eriecountygov.org
Tue Jun 22 12:26:04 PDT 2010
I think perhaps st_buildarea and st_collect might be what you want. Below is what I used to create a hexagon out of points->lines which was then translated (using generate_series) across X and Y to create a hexagonal grid for the County. There's probably a simpler way to make a hexagon but it illustrates the st_buildarea. Maybe that helps.
-Eric
--let's make a hexagon with 1000 foot sides and position it with it's
--center at 1210000, 610000 (the lower left of the pamap tile extent for Erie County)
--and create a table
drop table if exists hex1000;
create table hex1000 as
select translate(st_buildarea(st_collect(geom)),1210000, 610000) as geom from
(select makeline(st_endpoint(makeline(makepoint(0, 0),makepoint(0, - 1000))),st_endpoint(rotate(makeline(makepoint(0, 0),makepoint(0, -1000)), radians(300)))) as geom
union select makeline(st_endpoint(rotate(makeline(makepoint(0, 0),makepoint(0, -1000)), radians(300))),st_endpoint(rotate(makeline(makepoint(0, 0),makepoint(0, -1000)), radians(240)))) as geom
union select makeline(st_endpoint(rotate(makeline(makepoint(0, 0),makepoint(0, -1000)), radians(240))),st_endpoint(rotate(makeline(makepoint(0, 0),makepoint(0, -1000)), radians(180)))) as geom
union select makeline(st_endpoint(rotate(makeline(makepoint(0, 0),makepoint(0, -1000)), radians(180))),st_endpoint(rotate(makeline(makepoint(0, 0),makepoint(0, -1000)), radians(120)))) as geom
union select makeline(st_endpoint(rotate(makeline(makepoint(0, 0),makepoint(0, -1000)), radians(120))),st_endpoint(rotate(makeline(makepoint(0, 0),makepoint(0, -1000)), radians(60)))) as geom
union select makeline(st_endpoint(rotate(makeline(makepoint(0, 0),makepoint(0, -1000)), radians(60))),st_endpoint(rotate(makeline(makepoint(0, 0),makepoint(0, -1000)), radians(0)))) as geom
) as t1;
-----Original Message-----
From: postgis-users-bounces at postgis.refractions.net [mailto:postgis-users-bounces at postgis.refractions.net]On Behalf Of Avery Penniston
Sent: Tuesday, June 22, 2010 2:38 PM
To: postgis-users at postgis.refractions.net
Subject: Re: [postgis-users] Create POLYGON from Several LINESTRINGs
I'm trying to create 'pie wedge' shaped polygons by building them in a Postgres function. I am able to create the 2 straight chords and the arc as separate LINESTRINGs, and I have verified that each LINESTRING shares its endpoints with the other two LINESTRINGs. However, I am having trouble putting the individual parts together to form a POLYGON.
I tried to ST_UNION the 3 LINESTRINGs together, and the result is a MULTILINESTRING. I then call ST_LINEMERGE to convert the MULTILINESTRING to a single LINESTRING so I can pass it to the ST_POLYGON function, but the result of the ST_LINEMERGE is a MULTILINESTRING.
I tried using ST_COLLECT instead of ST_UNION, but then I got a GEOMETRYCOLLECTION containing a MULTILINESTRING and a LINESTRING.
Does anybody have some advice for creating a POLYGON from 3 or more separate LINESTRINGs?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20100622/835f981f/attachment.html>
More information about the postgis-users
mailing list