views:

38

answers:

3

Hi everyone,

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

+1  A: 

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

amercader
By the way, you may find more expert answers to GIS related questions in the dedicated site http://gis.stackexchange.com/
amercader
A: 

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.

Dave Lowther
A: 

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!

Paul Ramsey
Why wouldn't PostGIS allow these operations on geography types and return errors if the shapes do not make sense on cartesian plane?
Dave Lowther
No geographies make sense on a cartesian plane, it's a matter of degrees (ha ha). The line between two points in spherical geometry is a great circle, while the line between two points in cartesian geometry is a straight line. As the points get closer and closer the straight line becomes a better and better approximation of the arc, but it is never exact.
Paul Ramsey