Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Antimeridian and bbox calc fix #1115

Merged
merged 7 commits into from
Jun 1, 2022
Merged

Antimeridian and bbox calc fix #1115

merged 7 commits into from
Jun 1, 2022

Conversation

aagm
Copy link
Member

@aagm aagm commented May 26, 2022

Take with care

This fix is touching almost all intersections based on bbox in the application

Overview

So this applies 2 different fixes altogether:
BBox crosses the antimeridian, we are overpassing this in 2 steps, first, we properly calculate min and max longitude values by dividing the bbox in 2 bases on the east and west semihemisphers.
After that both FE and backend will follow the next rule: if min long is > than max long, that means that the bbox crosses the antimeridian and we subdivide them.

Regarding the grid. So as we are already setting the equal area cost surface, I did take the license to every grid that is crossing the antimeridian will be cut in order to avoid it crossing the antimeridian. with this in place calculations should work as expected.

Also, small fixes were applied to everything that depends on bbox filtering in order to be able to overpass the bbox at the antimeridian situation. The only problem here might be a small overhead due to subdividing it into the east and west suboxes.

Testing instructions

Up locally and setup a project in Fiji and in any other place

Feature relevant tickets

Link to the related task manager tickets
https://vizzuality.atlassian.net/browse/MARXAN-985


Checklist before submitting

  • [x ] Meaningful commits and code rebased on develop.
  • If this PR adds feature that should be tested for regressions when
    deploying to staging/production, please add brief testing instructions
    to the deploy checklist (docs/deployment-checklist.md)
  • Update CHANGELOG file

@aagm aagm requested a review from hotzevzl May 26, 2022 14:33
@vercel
Copy link

vercel bot commented May 26, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
marxan ✅ Ready (Inspect) Visit Preview May 31, 2022 at 3:39PM (UTC)
marxan-storybook ✅ Ready (Inspect) Visit Preview May 31, 2022 at 3:39PM (UTC)

Copy link
Member

@hotzevzl hotzevzl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job on this one, and painstaking patience - thank you! 🚀 🙌🏼

Mostly cosmetic/expressiveness notes from my side just because I can't help 😅

st_makeenvelope(:xmin, :ymin, :xmax, :ymax, 4326),
`(st_intersects(
st_intersection(st_makeenvelope(:...eastBbox, 4326),
ST_MakeEnvelope(0, -90, 180, 90, 4326)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to do anything in this PR about this, from my point of view, but these could be good candidates for a named constant that allows to avoid "magic numbers" that may take a little while for the inexperienced reader to figure out when they look at this code out of context (for example, not knowing that it was introduced while splitting semihemispheres)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes in the future we will need to revisit some of this, as well as at some point pay the debt in regarding sql formulation

*/
public findTile(
tileSpecification: TileSpecification,
bbox?: BBox,
): Promise<Buffer> {
const { z, x, y, id } = tileSpecification;
const attributes = 'feature_id, properties';
const table = `(select (st_dump(the_geom)).geom as the_geom, properties, feature_id from "${this.featuresRepository.metadata.tableName}")`;
const table = `(select ST_RemoveRepeatedPoints((st_dump(the_geom)).geom, 0.1) as the_geom, properties, feature_id from "${this.featuresRepository.metadata.tableName}")`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

* to Nominatim bbox [xmin, xmax, ymin, ymax].
*
*/
export function bbox2Nominatim(bbox: BBox): BBox {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could consider aliasing BBox as NominatimBBox to improve type expressiveness in function signatures, even though in practice it's still just an array of 4 or 6 numbers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing to do here though, unless you wish to, of course 😃

@aagm aagm merged commit 0daef9e into develop Jun 1, 2022
@aagm aagm deleted the fix/db/bbox_calc branch June 1, 2022 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Everything related the api bug Something isn't working Ready to review PR ready to review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants