-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1115 from Vizzuality/fix/db/bbox_calc
Antimeridian and bbox calc fix
- Loading branch information
Showing
19 changed files
with
207 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,8 @@ VALUES | |
('[email protected]', 'b', 'b', 'User B B', true, false, crypt('bbuserpassword', gen_salt('bf'))), | ||
('[email protected]', 'c', 'c', 'User C C', true, false, crypt('ccuserpassword', gen_salt('bf'))), | ||
('[email protected]', 'd', 'd', 'User D D', true, false, crypt('dduserpassword', gen_salt('bf'))); | ||
|
||
INSERT INTO organizations (name, created_by) | ||
VALUES | ||
('Example Org 1', (SELECT id FROM users WHERE email = '[email protected]')), | ||
('Example Org 2', (SELECT id FROM users WHERE email = '[email protected]')); |
72 changes: 72 additions & 0 deletions
72
...ing/src/migrations/geoprocessing/1653565019335-ModifyBboxCalculationTakingAntimeridian.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class ModifyBboxCalculationTakingAntimeridian1653565019335 | ||
implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
CREATE OR REPLACE FUNCTION mx_bbox2json(geom geometry) | ||
returns jsonb | ||
language plpgsql | ||
as | ||
$function$ | ||
DECLARE | ||
-- variable declaration | ||
both_hemispheres RECORD; | ||
BEGIN | ||
-- logic https://github.com/mapbox/carmen/blob/03fac2d7397ecdfcb4f0828fcfd9d8a54c845f21/lib/util/bbox.js#L59 | ||
-- json form of the bbox should be in Nominatim bbox [xmin, xmax, ymin, ymax] [W, E, S, N]. | ||
execute 'with region as (select st_intersection($1, geom) as the_geom, | ||
st_intersects($1, geom) intersects, pos | ||
from (values (ST_MakeEnvelope(-180, -90, 0, 90, 4326), ''west''), | ||
(ST_MakeEnvelope(0, -90, 180, 90, 4326), ''east'')) as t(geom, pos)), | ||
data as (select ST_XMax(the_geom), ST_XMin(the_geom), | ||
ST_YMax(the_geom),ST_YMin(the_geom), pos, intersects, | ||
ST_XMax(the_geom) + ABS(lag(ST_XMin(the_geom), 1) OVER ()) > | ||
(180 - ST_XMin(the_geom)) + (180 - ABS(lag(ST_XMax(the_geom), 1) OVER ())) as pm_am | ||
from region) | ||
select bool_and(intersects) and bool_and(pm_am) result, | ||
jsonb_build_array(max(st_xmax), min(st_xmin), max(st_ymax), min(st_ymin)) if_false, | ||
jsonb_build_array(min(st_xmax), max(st_xmin), max(st_ymax), min(st_ymin))if_true from data;' | ||
into both_hemispheres | ||
using geom; | ||
if both_hemispheres.result then | ||
return both_hemispheres.if_true; | ||
else | ||
return both_hemispheres.if_false; | ||
end if; | ||
end; | ||
$function$; | ||
CREATE OR REPLACE FUNCTION public.tr_getbbox() | ||
RETURNS trigger | ||
LANGUAGE plpgsql | ||
AS $function$ | ||
BEGIN | ||
NEW.bbox := mx_bbox2json(NEW.the_geom); | ||
RETURN NEW; | ||
END; | ||
$function$; | ||
UPDATE admin_regions SET id = id; | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
CREATE OR REPLACE FUNCTION public.tr_getbbox() | ||
RETURNS trigger | ||
LANGUAGE plpgsql | ||
AS $function$ | ||
BEGIN | ||
NEW.bbox := jsonb_build_array(ST_XMax(NEW.the_geom), ST_XMin(NEW.the_geom), | ||
ST_YMax(NEW.the_geom), ST_YMin(NEW.the_geom)); | ||
RETURN NEW; | ||
END; | ||
$function$; | ||
Drop FUNCTION mx_bbox2json(geom geometry); | ||
UPDATE admin_regions SET id = id; | ||
`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
0daef9e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
marxan-storybook – ./app
marxan-storybook-git-main-vizzuality1.vercel.app
marxan-storybook.vercel.app
marxan-storybook-vizzuality1.vercel.app
0daef9e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
marxan – ./app
marxan-git-main-vizzuality1.vercel.app
marxan-production.vercel.app
marxan-vizzuality1.vercel.app