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