Skip to content

Commit

Permalink
consistency_checks_triggers.sql: check that transformations with Geog…
Browse files Browse the repository at this point in the history
…3D to Geog2D+GravityRelatedHeight/Depth family of methods are properly registered
  • Loading branch information
rouault committed Mar 24, 2024
1 parent 165c98d commit 8b0a936
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions data/sql/consistency_checks_triggers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,36 @@ FOR EACH ROW BEGIN
NEW.source_crs_code = crs.code AND
crs.type = 'geographic 3D');

-- check that transformations with Geog3D to Geog2D+GravityRelatedHeight/Depth family of methods are properly registered
SELECT RAISE(ABORT, 'insert on grid_transformation violates constraint: a transformation Geog3D to Geog2D+GravityRelatedHeight/Depth must have a geog3D CRS as source')
WHERE NEW.deprecated = 0 AND
NEW.method_name LIKE 'Geog3D to Geog2D+%' AND
NOT EXISTS (SELECT 1 FROM geodetic_crs gcrs WHERE
gcrs.auth_name = NEW.source_crs_auth_name AND gcrs.code = NEW.source_crs_code
AND gcrs.type = 'geographic 3D');

SELECT RAISE(ABORT, 'insert on grid_transformation violates constraint: a transformation Geog3D to Geog2D+GravityRelatedHeight/Depth must have a compound CRS with a geog2D CRS as target')
WHERE NEW.deprecated = 0 AND
NEW.method_name LIKE 'Geog3D to Geog2D+%' AND
NOT EXISTS (SELECT 1 FROM compound_crs ccrs
LEFT JOIN geodetic_crs gcrs ON
gcrs.auth_name = horiz_crs_auth_name AND gcrs.code = horiz_crs_code
WHERE
ccrs.auth_name = NEW.target_crs_auth_name AND ccrs.code = NEW.target_crs_code
AND gcrs.type = 'geographic 2D');

SELECT RAISE(ABORT, 'insert on grid_transformation violates constraint: a transformation Geog3D to Geog2D+GravityRelatedHeight/Depth must use the same geodetic datum for the source and target CRS')
WHERE NEW.deprecated = 0 AND
NEW.method_name LIKE 'Geog3D to Geog2D+%' AND
NOT EXISTS (SELECT 1 FROM compound_crs ccrs
LEFT JOIN geodetic_crs target_gcrs ON
target_gcrs.auth_name = horiz_crs_auth_name AND target_gcrs.code = horiz_crs_code
LEFT JOIN geodetic_crs source_gcrs ON
source_gcrs.auth_name = NEW.source_crs_auth_name AND source_gcrs.code = NEW.source_crs_code
WHERE
ccrs.auth_name = NEW.target_crs_auth_name AND ccrs.code = NEW.target_crs_code
AND source_gcrs.name = target_gcrs.name);

-- check that grids with 'Vertical Offset by Grid Interpolation' methods are properly registered
SELECT RAISE(ABORT, 'insert on grid_transformation violates constraint: grid_transformation with Vertical Offset by Grid Interpolation must have its source_crs in vertical_crs table')
WHERE NEW.method_name LIKE 'Vertical Offset by Grid Interpolation%' AND
Expand Down

0 comments on commit 8b0a936

Please sign in to comment.