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

Commit

Permalink
feat(surface): remplace turf/area par PostGIS pour calculer la surfac…
Browse files Browse the repository at this point in the history
…e des titres (#904)
  • Loading branch information
vmaubert committed Feb 21, 2022
1 parent aa9a5c1 commit f80c17d
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
@@ -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
2 changes: 1 addition & 1 deletion docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion docker-compose.local.yml
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion docker-compose.localhost.yml
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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}
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
@@ -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",
2 changes: 1 addition & 1 deletion src/api/graphql/resolvers/points.ts
Original file line number Diff line number Diff line change
@@ -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,
16 changes: 10 additions & 6 deletions src/tools/geojson.ts
Original file line number Diff line number Diff line change
@@ -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'
@@ -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 {

0 comments on commit f80c17d

Please sign in to comment.