Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

Commit

Permalink
Merge b0eebe7 into f6be1eb
Browse files Browse the repository at this point in the history
  • Loading branch information
vmaubert authored Feb 4, 2022
2 parents f6be1eb + b0eebe7 commit 4a45cf1
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:12
image: postgis/postgis:12-3.2
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ services:
restart: unless-stopped
db:
container_name: camino_api_db
image: postgres:12
image: postgis/postgis:12-3.2
environment:
PGUSER: ${PGUSER}
POSTGRES_USER: ${PGUSER}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ services:

db:
container_name: camino_api_db
image: postgres:12
image: postgis/postgis:12-3.2
environment:
PGUSER: ${PGUSER}
POSTGRES_USER: ${PGUSER}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.localhost.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ services:

db:
container_name: camino_api_db
image: postgres:12
image: postgis/postgis:12-3.2
environment:
PGUSER: ${PGUSER}
POSTGRES_USER: ${PGUSER}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ services:
restart: unless-stopped
db:
container_name: camino_api_db
image: postgres:12
image: postgis/postgis:12-3.2
environment:
PGUSER: ${PGUSER}
POSTGRES_USER: ${PGUSER}
Expand Down
22 changes: 0 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
"@sentry/node": "^6.16.1",
"@sentry/types": "^6.16.1",
"@sindresorhus/slugify": "^1.1.2",
"@turf/area": "^6.5.0",
"@turf/center": "^6.5.0",
"@turf/intersect": "^6.5.0",
"@types/basic-auth": "^1.1.3",
Expand Down
2 changes: 1 addition & 1 deletion src/api/graphql/resolvers/points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ const sdomZonesInformationsGet = async (
}
const geojsonFeatures = geojsonFeatureMultiPolygon(points as ITitrePoint[])

const surface = geojsonSurface(geojsonFeatures as Feature)
const surface = await geojsonSurface(geojsonFeatures as Feature)

const documentTypeIds = documentTypeIdsBySdomZonesGet(
etapeSdomZones,
Expand Down
16 changes: 10 additions & 6 deletions src/tools/geojson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import rewind from 'geojson-rewind'
import center from '@turf/center'

import { ITitrePoint, IGeometry } from '../types'
import area from '@turf/area'
import { Feature, FeatureCollection, Geometry } from '@turf/helpers'
import { Feature } from '@turf/helpers'
import { knex } from '../knex'

// convertit des points
// en un geojson de type 'MultiPolygon'
Expand Down Expand Up @@ -84,10 +84,14 @@ const geojsonCenter = (points: ITitrePoint[]) => {
return center(geojson).geometry.coordinates
}

const geojsonSurface = (
geojson: Feature<any> | FeatureCollection<any> | Geometry
) => {
return Number.parseFloat((area(geojson) / 1000000).toFixed(2))
const geojsonSurface = async (geojson: Feature<any>) => {
const result: { rows: { area: number }[] } = await knex.raw(
`select ST_AREA(
ST_GeomFromGeoJSON('${JSON.stringify(geojson.geometry)}'), true) as area`
)
const area = result.rows[0].area

return Number.parseFloat((area / 1000000).toFixed(2))
}

export {
Expand Down

0 comments on commit 4a45cf1

Please sign in to comment.