Skip to content

Commit

Permalink
Update cost surface tiles endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
yulia-bel committed Oct 6, 2023
1 parent da38b1a commit 5ae6386
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,5 +315,4 @@ export class CostSurfaceService {
static defaultCostSurfaceName(): string {
return `Default Cost Surface`;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import {
forwardRef,
Get,
Inject,
Param, ParseIntPipe,
Param,
ParseIntPipe,
ParseUUIDPipe,
Patch,
Post,
Req,
Res,
UploadedFile,
UseGuards
} from "@nestjs/common";
UseGuards,
} from '@nestjs/common';
import {
ApiForbiddenResponse,
ApiOkResponse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import { BBox } from 'geojson';

import { Response } from 'express';
import { setTileResponseHeadersForSuccessfulRequests } from '@marxan/tiles';
import { CostSurfaceService, CostSurfaceTileRequest } from "@marxan-geoprocessing/modules/cost-surface/cost-surface.service";
import {
CostSurfaceService,
CostSurfaceTileRequest,
} from '@marxan-geoprocessing/modules/cost-surface/cost-surface.service';

@Controller(`${apiGlobalPrefixes.v1}/cost-surfaces`)
export class FeaturesController {
Expand Down Expand Up @@ -66,9 +69,7 @@ export class FeaturesController {
@Param() TileSpecification: CostSurfaceTileRequest,
@Res() response: Response,
): Promise<Response> {
const tile: Buffer = await this.service.findTile(
TileSpecification
);
const tile: Buffer = await this.service.findTile(TileSpecification);
setTileResponseHeadersForSuccessfulRequests(response);
return response.send(tile);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { Injectable, Logger, Inject } from '@nestjs/common';
import { TileService } from '@marxan-geoprocessing/modules/tile/tile.service';
import { InjectRepository } from '@nestjs/typeorm';
import { Brackets, Repository } from "typeorm";
import { GeoFeatureGeometry } from '@marxan/geofeatures';
import { IsArray, IsNumber, IsString, IsOptional, IsDefined } from "class-validator";
import { Repository } from 'typeorm';
import {
IsArray,
IsNumber,
IsString,
IsOptional,
} from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { BBox } from 'geojson';
import { antimeridianBbox, nominatim2bbox } from '@marxan/utils/geo';

import { TileRequest } from '@marxan/tiles';
import { ProtectedAreaTileRequest } from "@marxan-geoprocessing/modules/protected-areas/protected-area-tile-request";
import { QueryResult } from "pg";
import { TileSpecification } from "@marxan-geoprocessing/modules/features/features.service";
import { CostSurfacePuDataEntity } from "@marxan/cost-surfaces";

import { CostSurfacePuDataEntity } from '@marxan/cost-surfaces';
export class CostSurfaceTileRequest extends TileRequest {
@ApiProperty()
@IsString()
Expand All @@ -32,19 +34,17 @@ export class CostSurfaceFilters {
bbox?: BBox;
}


@Injectable()
export class CostSurfaceService {
private readonly logger: Logger = new Logger(CostSurfaceService.name);

constructor(
@InjectRepository(GeoFeatureGeometry)
@InjectRepository(CostSurfacePuDataEntity)
private readonly costSurfaceDataRepository: Repository<CostSurfacePuDataEntity>,
private readonly tileService: TileService,
) {}


buildFeaturesWhereQuery(id: string, bbox?: BBox): string {
buildCostSurfacesWhereQuery(id: string, bbox?: BBox): string {
let whereQuery = `cost_surface_id = '${id}'`;

if (bbox) {
Expand Down Expand Up @@ -76,7 +76,7 @@ export class CostSurfaceService {
from "${this.costSurfaceDataRepository.metadata.tableName}")
inner join projects_pu on project_pu.id = cost_surface_pu_dat.projects_pu_id`;

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

0 comments on commit 5ae6386

Please sign in to comment.