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

[api] Cost surfaces tiles endpoint [MRXN23-118] #1539

Merged
merged 9 commits into from
Oct 11, 2023

Conversation

yulia-bel
Copy link
Contributor

@yulia-bel yulia-bel commented Oct 6, 2023

Add Cost surfaces tiles endpoint

Overview

New endpoint in ProjectCostSurfaceController to retrieve Cost Surface tiles.
Implementation is similar to the endpoint for tiles for Geo Features

Designs

Link to the related design prototypes (if applicable)

Testing instructions

Please explain how to test the PR: ID of a dataset, steps to reach the feature, etc.

Feature relevant tickets

Link to the related task manager tickets


Checklist before submitting

  • 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

@vercel
Copy link

vercel bot commented Oct 6, 2023

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

Name Status Preview Comments Updated (UTC)
marxan ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 10, 2023 2:56pm

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.

thanks @yulia-bel, overall all is good and it works as expected as far as I could check.

Besides adding OpenAPI docs decorators to the main API (because that's what FE devs use as reference - in theory we could even drop openapi docs from the geoprocessing service altogether!), my only other comment is about something happening even with the newest simplification algorithm backported from Alicia's recent implementation - I'm getting simplification artifacts for a tile such as 6/34/34 for an Okavango test project: the end result looks kind of neat, but it's not what users will expect:

pattern

Comment on lines 35 to 65
@ApiParam({
name: 'z',
description: 'The zoom level ranging from 0 - 20',
type: Number,
required: true,
})
@ApiParam({
name: 'x',
description: 'The tile x offset on Mercator Projection',
type: Number,
required: true,
})
@ApiParam({
name: 'y',
description: 'The tile y offset on Mercator Projection',
type: Number,
required: true,
})
@ApiParam({
name: 'id',
description: 'Specific id of the cost surface',
type: String,
required: true,
})
@ApiQuery({
name: 'bbox',
description: 'Bounding box of the project',
type: [Number],
required: false,
example: [-1, 40, 1, 42],
})
Copy link
Member

Choose a reason for hiding this comment

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

we should have this OpenAPI documentation in the api controller, besides what is there already

const { z, x, y, costSurfaceId } = tileSpecification;
const simplificationLevel = 360 / (Math.pow(2, z + 1) * 100);
const attributes = 'cost';
const table = `(SELECT ST_RemoveRepeatedPoints((st_dump(the_geom)).geom, ${simplificationLevel}) AS the_geom,
Copy link
Member

Choose a reason for hiding this comment

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

about my earlier comment on simplification artifacts - maybe we could avoid applying simplification altogether here? what do you think @aagm?

in a way, we're dealing with one single set of geometries, those of a project's grid, and so I think this is less crucial than when dealing with features, where each can have their own intricated and extensive geometries. In the case of regular (hex/square) grids, geometries will end up being quite simple overall (though we may have very many, in some cases); in the case of user-uploaded grids, things can indeed be more complicated, though.

@hotzevzl
Copy link
Member

@yulia-bel if you end up doing more changes (bbox, openapi docs, whatnot), please give a final cleanup (unused imports or parameters) - no need to touch these if you're not going to make any other changes (so that we don't have to wait for CI to run again - or if you do cosmetic cleanups only, let's consider the latest good CI run as good enough as in, we can assume that cosmetic changes won't break anything 😬)

@@ -263,7 +263,6 @@ export class ProjectCostSurfaceController {

@ImplementsAcl()
@UseGuards(JwtAuthGuard)
@TilesOpenApi()
Copy link
Member

Choose a reason for hiding this comment

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

@yulia-bel apologies, I had completely missed that this decorator was in place (and I had actually completely forgotten about it even existing). This was correct, we had all the params documented via this decorator. I just meant that we would not necessarily need OpenAPI docs for the geoprocessing endpoint, but here all was correct - sorry!

The only glitch here is that @TilesOpenApi() includes the @ApiQuery decorator for bbox, which we may not want here. If we wanted to optionally exclude the bbox param (so that we don't have to touch any of the existing uses of the @TilesOpenApi() decorator), we could change the decorator with something like the patch below

diff --git a/api/libs/tiles/src/tiles-api-doc.ts b/api/libs/tiles/src/tiles-api-doc.ts
index 7beb84368..965d0ca5f 100644
--- a/api/libs/tiles/src/tiles-api-doc.ts
+++ b/api/libs/tiles/src/tiles-api-doc.ts
@@ -7,7 +7,16 @@ import {
   ApiUnauthorizedResponse,
 } from '@nestjs/swagger';

-export const TilesOpenApi = () =>
+export const TilesOpenApi = (excludeBbox: boolean) => {
+  const bboxDecorator = excludeBbox ? [] : [
+      ApiQuery({
+        name: 'bbox',
+        description: 'Bounding box of the project [xMin, xMax, yMin, yMax]',
+        type: [Number],
+        required: false,
+        example: [-1, 40, 1, 42],
+      }),
+  ];
   applyDecorators(
     ...[
       ApiParam({
@@ -35,13 +44,6 @@ export const TilesOpenApi = () =>
         required: false,
         example: 'e5c3b978-908c-49d3-b1e3-89727e9f999c',
       }),
-      ApiQuery({
-        name: 'bbox',
-        description: 'Bounding box of the project [xMin, xMax, yMin, yMax]',
-        type: [Number],
-        required: false,
-        example: [-1, 40, 1, 42],
-      }),
       ApiOkResponse({
         description: 'Binary protobuffer mvt tile',
         type: String,
@@ -49,4 +51,6 @@ export const TilesOpenApi = () =>
       ApiBadRequestResponse(),
       ApiUnauthorizedResponse(),
     ],
-  );
+    ...bboxDecorator
+    );
+  };

@yulia-bel yulia-bel force-pushed the feature/api/MRXN23-118-cost-surfaces-tiles branch from a3c2a37 to 582fec6 Compare October 10, 2023 14:54
@yulia-bel yulia-bel merged commit b7d57b8 into develop Oct 11, 2023
62 checks passed
@yulia-bel yulia-bel deleted the feature/api/MRXN23-118-cost-surfaces-tiles branch October 11, 2023 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants