Skip to content

Commit

Permalink
feat(geoprocessing): pu-inclusion: process geojson
Browse files Browse the repository at this point in the history
  • Loading branch information
kgajowy committed Jun 10, 2021
1 parent 6ec7340 commit 0d24735
Show file tree
Hide file tree
Showing 12 changed files with 604 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { GeoJSON } from 'geojson';
import { FeatureCollection, MultiPolygon, Polygon } from 'geojson';

export interface AdjustPlanningUnitsInput {
include?: {
pu?: string[];
geo?: GeoJSON[];
shape?: GeoJSON[];
geo?: FeatureCollection<Polygon | MultiPolygon>[];
};
exclude?: {
pu?: string[];
geo?: GeoJSON[];
shape?: GeoJSON[];
geo?: FeatureCollection<Polygon | MultiPolygon>[];
};
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { GeoJSON, MultiPolygon } from 'geojson';
import { FeatureCollection, MultiPolygon } from 'geojson';

const MultipolygonGeometry: MultiPolygon = Object.freeze({
type: 'MultiPolygon',
coordinates: [[[[0, 0]]]],
});

export const validGeoJson = (): GeoJSON => ({
export const validGeoJson = (): FeatureCollection<MultiPolygon> => ({
type: 'FeatureCollection',
features: [
{
Expand Down
6 changes: 3 additions & 3 deletions api/apps/api/src/modules/scenarios/dto/__mocks__/geometry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FeatureCollection } from 'geojson';
import { FeatureCollection, MultiPolygon } from 'geojson';

export const invalidMultiPolygon = (): FeatureCollection => ({
export const invalidMultiPolygon = (): FeatureCollection<MultiPolygon> => ({
type: 'FeatureCollection',
features: [
{
Expand All @@ -22,7 +22,7 @@ export const invalidMultiPolygon = (): FeatureCollection => ({
],
});

export const sampleMultiPolygonJson = (): FeatureCollection => ({
export const sampleMultiPolygonJson = (): FeatureCollection<MultiPolygon> => ({
type: 'FeatureCollection',
features: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IsOptional, IsUUID, ValidateNested } from 'class-validator';
import { ApiPropertyOptional } from '@nestjs/swagger';
import { FeatureCollection } from 'geojson';
import { FeatureCollection, MultiPolygon, Polygon } from 'geojson';
import { Type } from 'class-transformer';
import { IsFeatureCollectionOfPolygons } from './is-feature-collection-of-polygons';

Expand All @@ -20,12 +20,12 @@ export class PlanningUnitsByGeoJsonUpdateDto {
@ApiPropertyOptional()
@IsOptional()
@IsFeatureCollectionOfPolygons({ each: true })
include?: FeatureCollection[];
include?: FeatureCollection<MultiPolygon | Polygon>[];

@ApiPropertyOptional()
@IsOptional()
@IsFeatureCollectionOfPolygons({ each: true })
exclude?: FeatureCollection[];
exclude?: FeatureCollection<MultiPolygon | Polygon>[];
}

export class UpdateScenarioPlanningUnitLockStatusDto {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,47 @@
* @todo move the planningUnitsGeom entity to the api
*/
import { ApiProperty } from '@nestjs/swagger';
import { Column, Entity, PrimaryColumn } from 'typeorm';
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { Geometry } from 'geojson';
import { defaultSrid } from '@marxan/utils/geo';

export enum ShapeType {
Square = 'square',
Hexagon = 'hexagon',
Irregular = 'irregular',
}

@Entity('planning_units_geom')
export class PlanningUnitsGeom {
/**
* id
*/
@ApiProperty()
@PrimaryColumn('uuid', { name: 'id' })
@PrimaryGeneratedColumn('uuid', { name: 'id' })
id!: string;

/**
* geometry column.
*/
@ApiProperty()
@Column('geometry', { name: 'the_geom', select: false })
theGeom!: any;
@Column('geometry', {
name: 'the_geom',
select: false,
spatialFeatureType: 'MultiPolygon',
srid: defaultSrid,
})
theGeom!: Geometry;

@Column({
enum: ShapeType,
type: 'enum',
name: 'type',
})
type!: ShapeType;

@Column({
nullable: true,
type: 'int',
})
size?: number | undefined | null;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0d24735

Please sign in to comment.