diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 46c1f633..24918fa9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 7cfe2580..9baed5ee 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -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} diff --git a/docker-compose.local.yml b/docker-compose.local.yml index 091ca374..85782566 100644 --- a/docker-compose.local.yml +++ b/docker-compose.local.yml @@ -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} diff --git a/docker-compose.localhost.yml b/docker-compose.localhost.yml index 71902cb8..7142beae 100644 --- a/docker-compose.localhost.yml +++ b/docker-compose.localhost.yml @@ -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} diff --git a/docker-compose.yml b/docker-compose.yml index 94579f3f..6f69a1a2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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} diff --git a/package-lock.json b/package-lock.json index 9ab32f55..eb2a6005 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,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", @@ -2815,18 +2814,6 @@ "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.2.tgz", "integrity": "sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==" }, - "node_modules/@turf/area": { - "version": "6.5.0", - "resolved": "https://registry.npmjs.org/@turf/area/-/area-6.5.0.tgz", - "integrity": "sha512-xCZdiuojokLbQ+29qR6qoMD89hv+JAgWjLrwSEWL+3JV8IXKeNFl6XkEJz9HGkVpnXvQKJoRz4/liT+8ZZ5Jyg==", - "dependencies": { - "@turf/helpers": "^6.5.0", - "@turf/meta": "^6.5.0" - }, - "funding": { - "url": "https://opencollective.com/turf" - } - }, "node_modules/@turf/bbox": { "version": "6.5.0", "resolved": "https://registry.npmjs.org/@turf/bbox/-/bbox-6.5.0.tgz", @@ -22846,15 +22833,6 @@ "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.2.tgz", "integrity": "sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==" }, - "@turf/area": { - "version": "6.5.0", - "resolved": "https://registry.npmjs.org/@turf/area/-/area-6.5.0.tgz", - "integrity": "sha512-xCZdiuojokLbQ+29qR6qoMD89hv+JAgWjLrwSEWL+3JV8IXKeNFl6XkEJz9HGkVpnXvQKJoRz4/liT+8ZZ5Jyg==", - "requires": { - "@turf/helpers": "^6.5.0", - "@turf/meta": "^6.5.0" - } - }, "@turf/bbox": { "version": "6.5.0", "resolved": "https://registry.npmjs.org/@turf/bbox/-/bbox-6.5.0.tgz", diff --git a/package.json b/package.json index c0a00b0c..1d3dd195 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/api/graphql/resolvers/points.ts b/src/api/graphql/resolvers/points.ts index 32f8f8b3..d0302da0 100644 --- a/src/api/graphql/resolvers/points.ts +++ b/src/api/graphql/resolvers/points.ts @@ -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, diff --git a/src/tools/geojson.ts b/src/tools/geojson.ts index f7336ffc..72427ee7 100644 --- a/src/tools/geojson.ts +++ b/src/tools/geojson.ts @@ -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 | FeatureCollection | Geometry -) => { - return Number.parseFloat((area(geojson) / 1000000).toFixed(2)) +const geojsonSurface = async (geojson: Feature) => { + 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 {