From b5d3f2a250f84abb10cd9b21b5d367f1a162e50f Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Wed, 7 Apr 2021 12:49:54 +0200
Subject: Database: more thorough consistency checks on extent of coordinate
 operations

---
 data/sql/commit.sql | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

(limited to 'data/sql/commit.sql')

diff --git a/data/sql/commit.sql b/data/sql/commit.sql
index 8f88abc0..9ea2935d 100644
--- a/data/sql/commit.sql
+++ b/data/sql/commit.sql
@@ -245,7 +245,9 @@ FOR EACH ROW BEGIN
                       cu.object_code = c.code AND
                       cu.extent_auth_name = ce.auth_name AND
                       cu.extent_code = ce.code AND
-                      NOT (ce.south_lat < ve.north_lat AND ve.south_lat < ce.north_lat));
+                      NOT ((ce.south_lat < ve.north_lat AND ve.south_lat < ce.north_lat) OR
+                          (ce.west_lon < ce.east_lon AND ve.west_lon < ve.east_lon AND
+                              NOT (ce.west_lon < ve.east_lon AND ve.west_lon < ce.east_lon))) );
     SELECT RAISE(ABORT, 'The area of use of at least one coordinate_operation does not intersect the one of its target CRS')
         WHERE EXISTS (SELECT * FROM coordinate_operation_view v, crs_view c, usage vu, extent ve, usage cu, extent ce WHERE
                       v.deprecated = 0 AND
@@ -263,7 +265,9 @@ FOR EACH ROW BEGIN
                       cu.object_code = c.code AND
                       cu.extent_auth_name = ce.auth_name AND
                       cu.extent_code = ce.code AND
-                      NOT (ce.south_lat < ve.north_lat AND ve.south_lat < ce.north_lat));
+                      NOT ((ce.south_lat < ve.north_lat AND ve.south_lat < ce.north_lat) OR
+                          (ce.west_lon < ce.east_lon AND ve.west_lon < ve.east_lon AND
+                              NOT (ce.west_lon < ve.east_lon AND ve.west_lon < ce.east_lon))) );
 
     -- check geoid_model table
     SELECT RAISE(ABORT, 'missing GEOID99 in geoid_model')
-- 
cgit v1.2.3

