Skip to content

Commit

Permalink
Add minor fixes for cost surface tile endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
yulia-bel committed Oct 10, 2023
1 parent 72dddce commit 5d9efbf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,10 @@ export class ProjectCostSurfaceController {
throw new ForbiddenException();
}

req.url = req.url.replace(`projects/${projectId}/cost-surface/`, `cost-surfaces/`)

console.log(req.url)
req.url = req.url.replace(
`projects/${projectId}/cost-surface/`,
`cost-surfaces/`,
);

return await this.proxyService.proxyTileRequest(req, response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import { PuCostExtractor } from './adapters/pu-cost-extractor';
import { AvailablePlanningUnitsRepository } from './adapters/available-planning-units-repository';
import { ScenariosPuCostDataGeo } from '@marxan/scenarios-planning-unit';
import { CostSurfacePuDataEntity } from '@marxan/cost-surfaces';
import { CostSurfaceService } from "@marxan-geoprocessing/modules/cost-surface/cost-surface.service";
import { CostSurfaceController } from "@marxan-geoprocessing/modules/cost-surface/cost-surface.controller";
import { TileService } from "@marxan-geoprocessing/modules/tile/tile.service";
import { CostSurfaceService } from '@marxan-geoprocessing/modules/cost-surface/cost-surface.service';
import { CostSurfaceController } from '@marxan-geoprocessing/modules/cost-surface/cost-surface.controller';
import { TileService } from '@marxan-geoprocessing/modules/tile/tile.service';

@Module({
imports: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import { Injectable, Logger, Inject } from '@nestjs/common';
import { TileService } from '@marxan-geoprocessing/modules/tile/tile.service';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import {
IsArray,
IsNumber,
IsString,
IsOptional,
} from 'class-validator';
import { IsArray, IsNumber, IsString, IsOptional } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { BBox } from 'geojson';
Expand Down Expand Up @@ -63,19 +58,22 @@ export class CostSurfaceService {
return whereQuery;
}

/** TODO: 'bbox' is an optional parameter here, confirm if we can remove it, since cost surface will always be
* within the project grid
*/
public findTile(
tileSpecification: CostSurfaceTileRequest,
bbox?: BBox,
): Promise<Buffer> {
const { z, x, y, costSurfaceId } = tileSpecification;
const simplificationLevel = 360 / (Math.pow(2, z + 1) * 100);
const attributes = 'cost_surface_id, cost';
const table = `(select ST_RemoveRepeatedPoints((st_dump(the_geom)).geom, ${simplificationLevel}) as the_geom,
const attributes = 'cost';
const table = `(SELECT ST_RemoveRepeatedPoints((st_dump(the_geom)).geom, ${simplificationLevel}) AS the_geom,
cost,
cost_surface_id
from cost_surface_pu_data
inner join projects_pu ppu on ppu.id=cost_surface_pu_data.projects_pu_id
inner join planning_units_geom pug on pug.id=ppu.geom_id)`;
FROM cost_surface_pu_data
INNER JOIN projects_pu ppu on ppu.id=cost_surface_pu_data.projects_pu_id
INNER JOIN planning_units_geom pug on pug.id=ppu.geom_id)`;

const customQuery = this.buildCostSurfacesWhereQuery(costSurfaceId, bbox);
return this.tileService.getTile({
Expand Down

0 comments on commit 5d9efbf

Please sign in to comment.