Joey
Joey

Reputation: 6021

Unions of polygons (ST_UNION for Geography type)

I am looking for a function that will return the intersection of 2 or more polygons (geography type).

I am aware of ST_UNION, ST_COLLECT but it works only for geometry type.

Any tip will be really appreciated

Upvotes: 0

Views: 2730

Answers (3)

Paul Ramsey
Paul Ramsey

Reputation: 841

You can cast to geometry and carry out the operation there. You will just have to be careful that your shapes makes sense when evaluated on a cartesian plane. Do they wrap the dateline or poles?

select geography(st_union(a::geometry, b::geometry))

If the shapes have very long edges, then the difference in edge interpolation between the great circle interpolation you want on a sphere and the linear interpolation you get on a plane comes into play, and you have to get fancier to preserve the edge shapes as best you can by working in an appropriate map projection (automatically chosen with the bestsrid function).

select geography(
         st_transform(
           st_union(
             st_transform(a::geometry, _st_bestsrid(a,b)),
             st_transform(b::geometry, _st_bestsrid(a,b))
           ),
           4326
       ))

Enjoy!

Upvotes: 2

Dave Lowther
Dave Lowther

Reputation: 408

Have you considered a ST_Transform into a geometry type nested within the ST_Union or ST_Collect? PostGIS docs (from amercader's link) say they use that function internally for some geography operations.

Upvotes: 0

amercader
amercader

Reputation: 4540

The Geography type supports only a small subset of the PostGIS functions. Here you can check them all and see if any of them suits your needs:

http://postgis.refractions.net/docs/ch08.html#PostGIS_GeographyFunctions

Upvotes: 1

Related Questions