[postgis-users] Calculating center point for geographic polygon that crosses IDL
bhazuka at usgs.gov
Tue Sep 1 08:55:55 PDT 2015
I am fairly new to PostGIS and I am hoping some one can provide me a hand
with an issue relating to scenes crossing the International Date Line (IDL)
and finding the center point.
I currently maintain a PostgreSQL database that contains footprints for
satellite scenes. The scenes have global coverage and range in size from
~1500Km squared down to ~100Km squared. The footprints are stored in a
geography column as basic polygons as seen below.
I need to be able to determine the center point of each scene in order to
provide some additional information to various applications using the data.
Based on forums and various other web resources, it appears the way to
calculate the center point is by converting geography to geometry and using
the ST_CENTROID function as seen below.
Using my polygon example from above, the function call would look like the
Here is where the problem lies. In the above example, the centroid returns
a center point value of the following:
Note that the centroid longitude is -0.148022213748242. The footprint I
provided crosses the IDL. The scene center longitude should be ~179.8181.
I was able to hack together an inelegant solution that will correct for the
IDL on a Cartesian system up to a point. I have provided the code below.
The code appears to work but will breakdown if the scene footprint is to
large and I am sure I have not accounted for everything.
CREATE FUNCTION test (in i_wkt varchar)
( centerlat FLOAT
, centerlon FLOAT
-- See if the scene crossesthe IDL if so correct the negative value
IF (abs(l_lonmin) + abs(l_lonmax)) > 180 THEN
l_lontmp := 360 + l_lonmin;
l_ctrlon := ((l_lonmax + l_lontmp)/2);
-- Determine which side of the IDL the longitude belongs on
IF l_ctrlon > 180 THEN
l_ctrlon := l_lonctr - 360;
SELECT l_ctrlat AS centerlat
, l_ctrlon AS centerlon;
Is there a way to determine the center point for a geographic scene that
crosses the IDL using current PostGIS functions that will remain true for
any foot print size that does not require additional code? If so, what
combination of functions do I need to use?
Do I need to re-project the scene prior to determining the center point
with ST_CENTROID since I move the footprint to a Cartesian geometry type?
If no functions are available, is there a preferred method for determining
center point of a polygon that crosses the IDL that will better allow for
larger sizes of polygons in a geographic system?
I am currently running PostgreSQL 9.3.4 with PostGIS extension 2.1.0.
Any help you could provide would be appreciated.
Bradley J. Hazuka
Contractor to the U.S. Geological Survey (USGS)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the postgis-users