From dc286513f8e62cba7a3dc40b1bcd631815499afd Mon Sep 17 00:00:00 2001 From: MFrangi Date: Thu, 25 Jul 2024 09:51:55 +0000 Subject: [PATCH 1/9] in progress --- controllers/wfs-geoportail/index.js | 73 ++++++++++++++++++++++++----- package-lock.json | 20 ++++++++ package.json | 1 + 3 files changed, 83 insertions(+), 11 deletions(-) diff --git a/controllers/wfs-geoportail/index.js b/controllers/wfs-geoportail/index.js index 921aad9..3d1baf5 100644 --- a/controllers/wfs-geoportail/index.js +++ b/controllers/wfs-geoportail/index.js @@ -26,18 +26,69 @@ function createWfsProxy() { if( typeof params._limit == 'undefined') {params._limit = 1000;} /* requête WFS GPP*/ - req.gppWfsClient.getFeatures(featureTypeName, params) - /* uniformisation des attributs en sortie */ - .then(function(featureCollection){ - featureCollection.features.forEach(function(feature){ - if ( ! feature.properties.code_insee ){ - feature.properties.code_insee = feature.properties.code_dep+feature.properties.code_com; - } - }); - return featureCollection; - }) + req.gppWfsClient.getDescribeFeatureType(featureTypeName) + //récupération du geomFieldName .then(function(featureCollection) { - res.json(featureCollection); + var nom_geom = false; + for(var i in featureCollection.featureTypes[0].properties) { + if(featureCollection.featureTypes[0].properties[i].name == "geom" + || featureCollection.featureTypes[0].properties[i].name == "the_geom") + { + nom_geom = featureCollection.featureTypes[0].properties[i].name; + break; + } + } + if(!nom_geom) { + for(var i in featureCollection.featureTypes[0].properties) { + if(featureCollection.featureTypes[0].properties[i].type.match("Point") + || featureCollection.featureTypes[0].properties[i].type.match("Polygon") + || featureCollection.featureTypes[0].properties[i].type.match("LineString")) + { + nom_geom = featureCollection.featureTypes[0].properties[i].name; + } + } + } + + req.gppWfsClient.defaultGeomFieldName = nom_geom; + + //récupération du CRS + req.gppWfsClient.getCapabilities() + .then(function(response){ + var crs = "urn:ogc:def:crs:EPSG::4326"; + var regexp = new RegExp("" + featureTypeName + ".*?<\/DefaultCRS>"); + if(response.match(regexp)) { + var feat = response.match(regexp)[0]; + if(feat.match(/EPSG::[0-9]{4,5}/)) { + crs = feat.match(/EPSG::[0-9]{4,5}/)[0].replace("::",":"); + } + } + req.gppWfsClient.defaultCRS = crs; + + //récupération des features + req.gppWfsClient.getFeatures(featureTypeName, params) + /* uniformisation des attributs en sortie */ + .then(function(featureCollection){ + featureCollection.features.forEach(function(feature){ + if ( ! feature.properties.code_insee ){ + feature.properties.code_insee = feature.properties.code_dep+feature.properties.code_com; + } + }); + return featureCollection; + }) + .then(function(featureCollection) { + res.json(featureCollection); + }) + .catch(function(err) { + res.status(500).json(err); + }) + ; + }) + .catch(function(err) { + res.status(500).json(err); + }) + ; + + }) .catch(function(err) { res.status(500).json(err); diff --git a/package-lock.json b/package-lock.json index 1304d8e..7714732 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,6 +27,7 @@ "http-proxy-agent": "^7.0.2", "https-proxy-agent": "^7.0.4", "lodash": "^4.17.21", + "node-cache": "^5.1.2", "pg": "^8.11.5", "pg-format": "^1.0.4", "shelljs": "^0.8.5", @@ -3070,6 +3071,14 @@ "node": ">=8" } }, + "node_modules/clone": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz", + "integrity": "sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w==", + "engines": { + "node": ">=0.8" + } + }, "node_modules/codes-postaux": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/codes-postaux/-/codes-postaux-4.1.0.tgz", @@ -5508,6 +5517,17 @@ "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==" }, + "node_modules/node-cache": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/node-cache/-/node-cache-5.1.2.tgz", + "integrity": "sha512-t1QzWwnk4sjLWaQAS8CHgOJ+RAfmHpxFWmc36IWTiWHQfs0w5JDMBS1b1ZxQteo0vVVuWJvIUKHDkkeK7vIGCg==", + "dependencies": { + "clone": "2.x" + }, + "engines": { + "node": ">= 8.0.0" + } + }, "node_modules/node-preload": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/node-preload/-/node-preload-0.2.1.tgz", diff --git a/package.json b/package.json index 586a962..09ce881 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "http-proxy-agent": "^7.0.2", "https-proxy-agent": "^7.0.4", "lodash": "^4.17.21", + "node-cache": "^5.1.2", "pg": "^8.11.5", "pg-format": "^1.0.4", "shelljs": "^0.8.5", From f0bc08d0125347b6c92aba587bb1813d7ebeeab0 Mon Sep 17 00:00:00 2001 From: MFrangi Date: Fri, 26 Jul 2024 08:31:34 +0000 Subject: [PATCH 2/9] getFeatureType/getCapabilities/gestion du cache --- controllers/wfs-geoportail/index.js | 42 ++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/controllers/wfs-geoportail/index.js b/controllers/wfs-geoportail/index.js index 3d1baf5..d1769db 100644 --- a/controllers/wfs-geoportail/index.js +++ b/controllers/wfs-geoportail/index.js @@ -5,7 +5,9 @@ import validateParams from '../../middlewares/validateParams.js'; import isGeometry from '../../checker/isGeometry.js'; import gppWfsClient from '../../middlewares/gppWfsClient.js'; import _ from 'lodash'; +import NodeCache from "node-cache" +const myCache = new NodeCache(); var router = new Router(); @@ -19,14 +21,39 @@ function createWfsProxy() { validateParams, function(req,res){ var params = matchedData(req); - var featureTypeName= params.source; + var featureTypeName = params.source; params = _.omit(params,'source'); /* Value default pour _limit an _start */ if ( typeof params._start == 'undefined' ) {params._start = 0;} if( typeof params._limit == 'undefined') {params._limit = 1000;} - - /* requête WFS GPP*/ - req.gppWfsClient.getDescribeFeatureType(featureTypeName) + + //recherche dans le cache + if(myCache.get(featureTypeName)) { + req.gppWfsClient.defaultGeomFieldName = myCache.get(featureTypeName)[0]; + req.gppWfsClient.defaultCRS = myCache.get(featureTypeName)[1]; + + //récupération des features + req.gppWfsClient.getFeatures(featureTypeName, params) + /* uniformisation des attributs en sortie */ + .then(function(featureCollection){ + featureCollection.features.forEach(function(feature){ + if ( ! feature.properties.code_insee ){ + feature.properties.code_insee = feature.properties.code_dep+feature.properties.code_com; + } + }); + return featureCollection; + }) + .then(function(featureCollection) { + res.json(featureCollection); + }) + .catch(function(err) { + res.status(500).json(err); + }) + ; + } + else { + /* requête WFS GPP*/ + req.gppWfsClient.getDescribeFeatureType(featureTypeName) //récupération du geomFieldName .then(function(featureCollection) { var nom_geom = false; @@ -62,8 +89,14 @@ function createWfsProxy() { crs = feat.match(/EPSG::[0-9]{4,5}/)[0].replace("::",":"); } } + if(crs == "EPSG:4326") { + crs = "urn:ogc:def:crs:EPSG::4326"; + } req.gppWfsClient.defaultCRS = crs; + //maj du cache + myCache.set(featureTypeName, [nom_geom, crs]); + //récupération des features req.gppWfsClient.getFeatures(featureTypeName, params) /* uniformisation des attributs en sortie */ @@ -94,6 +127,7 @@ function createWfsProxy() { res.status(500).json(err); }) ; + } } ]; } From afe159ae87f634ef9f8c9433b6b659480708d584 Mon Sep 17 00:00:00 2001 From: MFrangi Date: Fri, 26 Jul 2024 08:51:58 +0000 Subject: [PATCH 3/9] links --- controllers/wfs-geoportail/index.js | 104 +++++++++++++++++++--------- 1 file changed, 70 insertions(+), 34 deletions(-) diff --git a/controllers/wfs-geoportail/index.js b/controllers/wfs-geoportail/index.js index d1769db..142b91c 100644 --- a/controllers/wfs-geoportail/index.js +++ b/controllers/wfs-geoportail/index.js @@ -33,23 +33,24 @@ function createWfsProxy() { req.gppWfsClient.defaultCRS = myCache.get(featureTypeName)[1]; //récupération des features - req.gppWfsClient.getFeatures(featureTypeName, params) - /* uniformisation des attributs en sortie */ - .then(function(featureCollection){ - featureCollection.features.forEach(function(feature){ - if ( ! feature.properties.code_insee ){ - feature.properties.code_insee = feature.properties.code_dep+feature.properties.code_com; - } - }); - return featureCollection; - }) - .then(function(featureCollection) { - res.json(featureCollection); - }) - .catch(function(err) { - res.status(500).json(err); - }) - ; + getFeat(req, res, featureTypeName, params); + // req.gppWfsClient.getFeatures(featureTypeName, params) + // /* uniformisation des attributs en sortie */ + // .then(function(featureCollection){ + // featureCollection.features.forEach(function(feature){ + // if ( ! feature.properties.code_insee ){ + // feature.properties.code_insee = feature.properties.code_dep+feature.properties.code_com; + // } + // }); + // return featureCollection; + // }) + // .then(function(featureCollection) { + // res.json(featureCollection); + // }) + // .catch(function(err) { + // res.status(500).json(err); + // }) + // ; } else { /* requête WFS GPP*/ @@ -98,23 +99,24 @@ function createWfsProxy() { myCache.set(featureTypeName, [nom_geom, crs]); //récupération des features - req.gppWfsClient.getFeatures(featureTypeName, params) - /* uniformisation des attributs en sortie */ - .then(function(featureCollection){ - featureCollection.features.forEach(function(feature){ - if ( ! feature.properties.code_insee ){ - feature.properties.code_insee = feature.properties.code_dep+feature.properties.code_com; - } - }); - return featureCollection; - }) - .then(function(featureCollection) { - res.json(featureCollection); - }) - .catch(function(err) { - res.status(500).json(err); - }) - ; + getFeat(req, res, featureTypeName, params); + // req.gppWfsClient.getFeatures(featureTypeName, params) + // /* uniformisation des attributs en sortie */ + // .then(function(featureCollection){ + // featureCollection.features.forEach(function(feature){ + // if ( ! feature.properties.code_insee ){ + // feature.properties.code_insee = feature.properties.code_dep+feature.properties.code_com; + // } + // }); + // return featureCollection; + // }) + // .then(function(featureCollection) { + // res.json(featureCollection); + // }) + // .catch(function(err) { + // res.status(500).json(err); + // }) + // ; }) .catch(function(err) { res.status(500).json(err); @@ -132,6 +134,40 @@ function createWfsProxy() { ]; } +var getFeat = function(req, res, featureTypeName, params) { + req.gppWfsClient.getFeatures(featureTypeName, params) + /* uniformisation des attributs en sortie */ + .then(function(featureCollection){ + featureCollection.features.forEach(function(feature){ + if ( ! feature.properties.code_insee ){ + feature.properties.code_insee = feature.properties.code_dep+feature.properties.code_com; + } + }); + if(featureCollection.links && featureCollection.links.length) { + for(let i in featureCollection.links) { + if(featureCollection.links[i].href && featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)) { + let num = featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)[0].replace("STARTINDEX=",""); + let href = req.gppWfsClient.headers.Referer.replace(/\/api.*/, "") + req.originalUrl; + if(href.match("_start")) { + href = href.replace(/_start\=[0-9]*/, "_start=" + num); + } else { + href += "&_start=" + num; + } + featureCollection.links[i].href = href; + } + } + } + return featureCollection; + }) + .then(function(featureCollection) { + res.json(featureCollection); + }) + .catch(function(err) { + res.status(500).json(err); + }) + ; +}; + var corsOptionsGlobal = function(origin,callback) { var corsOptions; From 848a31648404b5265129b6d41947b5d1ba87522c Mon Sep 17 00:00:00 2001 From: MFrangi Date: Fri, 26 Jul 2024 09:00:59 +0000 Subject: [PATCH 4/9] issue_40/issue_52 --- controllers/cadastre/index.js | 14 ++++++++++++++ controllers/nature/index.js | 23 ++++++++++++++++++++++- controllers/rpg/index.js | 16 ++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/controllers/cadastre/index.js b/controllers/cadastre/index.js index 5a645cc..23136bc 100644 --- a/controllers/cadastre/index.js +++ b/controllers/cadastre/index.js @@ -74,6 +74,20 @@ function createCadastreProxy(featureTypeName){ feature.properties.code_insee = feature.properties.code_dep+feature.properties.code_com; } }); + if(featureCollection.links && featureCollection.links.length) { + for(let i in featureCollection.links) { + if(featureCollection.links[i].href && featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)) { + let num = featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)[0].replace("STARTINDEX=",""); + let href = req.gppWfsClient.headers.Referer.replace(/\/api.*/, "") + req.originalUrl; + if(href.match("_start")) { + href = href.replace(/_start\=[0-9]*/, "_start=" + num); + } else { + href += "&_start=" + num; + } + featureCollection.links[i].href = href; + } + } + } return featureCollection; }) .then(function(featureCollection) { diff --git a/controllers/nature/index.js b/controllers/nature/index.js index b17ddc6..d67591f 100644 --- a/controllers/nature/index.js +++ b/controllers/nature/index.js @@ -27,12 +27,33 @@ function createNaturaProxy(featureTypeName){ /* requête WFS GPP*/ req.gppWfsClient.getFeatures(featureTypeName, params) + /* uniformisation des attributs en sortie */ + .then(function(featureCollection){ + featureCollection.features.forEach(function(feature){ + if(featureCollection.links && featureCollection.links.length) { + for(let i in featureCollection.links) { + if(featureCollection.links[i].href && featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)) { + let num = featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)[0].replace("STARTINDEX=",""); + let href = req.gppWfsClient.headers.Referer.replace(/\/api.*/, "") + req.originalUrl; + if(href.match("_start")) { + href = href.replace(/_start\=[0-9]*/, "_start=" + num); + } else { + href += "&_start=" + num; + } + featureCollection.links[i].href = href; + } + } + } + }); + return featureCollection; + }) .then(function(featureCollection) { res.json(featureCollection); }) .catch(function(err) { res.status(500).json(err); - }); + }) + ; } ]; } diff --git a/controllers/rpg/index.js b/controllers/rpg/index.js index 909838c..26fb2aa 100644 --- a/controllers/rpg/index.js +++ b/controllers/rpg/index.js @@ -55,6 +55,22 @@ function createRpgProxy(valeurSearch) { req.gppWfsClient.getFeatures(featureTypeName, params) /* uniformisation des attributs en sortie */ .then(function(featureCollection){ + featureCollection.features.forEach(function(feature){ + if(featureCollection.links && featureCollection.links.length) { + for(let i in featureCollection.links) { + if(featureCollection.links[i].href && featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)) { + let num = featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)[0].replace("STARTINDEX=",""); + let href = req.gppWfsClient.headers.Referer.replace(/\/api.*/, "") + req.originalUrl; + if(href.match("_start")) { + href = href.replace(/_start\=[0-9]*/, "_start=" + num); + } else { + href += "&_start=" + num; + } + featureCollection.links[i].href = href; + } + } + } + }); return featureCollection; }) .then(function(featureCollection) { From 3600daf237a1c023d4286b7264c42bcc850d1660 Mon Sep 17 00:00:00 2001 From: MFrangi Date: Thu, 12 Sep 2024 08:49:40 +0000 Subject: [PATCH 5/9] nettoyage et bug recherche par code postal module ER --- controllers/cadastre/index.js | 10 +- controllers/er/index.js | 2 +- controllers/nature/index.js | 10 +- controllers/rpg/index.js | 10 +- controllers/wfs-geoportail/index.js | 188 +++++++++++---------------- test/controllers/er/category.js | 1 + test/controllers/er/product.js | 1 + test/controllers/gpu/municipality.js | 79 +++++------ 8 files changed, 135 insertions(+), 166 deletions(-) diff --git a/controllers/cadastre/index.js b/controllers/cadastre/index.js index 23136bc..63eed67 100644 --- a/controllers/cadastre/index.js +++ b/controllers/cadastre/index.js @@ -77,12 +77,12 @@ function createCadastreProxy(featureTypeName){ if(featureCollection.links && featureCollection.links.length) { for(let i in featureCollection.links) { if(featureCollection.links[i].href && featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)) { - let num = featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)[0].replace("STARTINDEX=",""); - let href = req.gppWfsClient.headers.Referer.replace(/\/api.*/, "") + req.originalUrl; - if(href.match("_start")) { - href = href.replace(/_start\=[0-9]*/, "_start=" + num); + let num = featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)[0].replace('STARTINDEX=',''); + let href = req.gppWfsClient.headers.Referer.replace(/\/api.*/, '') + req.originalUrl; + if(href.match('_start')) { + href = href.replace(/_start\=[0-9]*/, '_start=' + num); } else { - href += "&_start=" + num; + href += '&_start=' + num; } featureCollection.links[i].href = href; } diff --git a/controllers/er/index.js b/controllers/er/index.js index fe1c722..e3e5f10 100644 --- a/controllers/er/index.js +++ b/controllers/er/index.js @@ -127,7 +127,7 @@ function createErProxy(featureTypeName,typeSearch){ params.title = params.title.toUpperCase(); } if (params.zip_codes) { - params.zip_codes = '"[\\"'+ params.zip_codes.replace(',' , ',\\"') + '\\"]"'; + params.zip_codes = '["'+ params.zip_codes.replace(',' , '","') + '"]'; } } /* Value default pour _limit an _start */ diff --git a/controllers/nature/index.js b/controllers/nature/index.js index d67591f..b326f37 100644 --- a/controllers/nature/index.js +++ b/controllers/nature/index.js @@ -33,12 +33,12 @@ function createNaturaProxy(featureTypeName){ if(featureCollection.links && featureCollection.links.length) { for(let i in featureCollection.links) { if(featureCollection.links[i].href && featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)) { - let num = featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)[0].replace("STARTINDEX=",""); - let href = req.gppWfsClient.headers.Referer.replace(/\/api.*/, "") + req.originalUrl; - if(href.match("_start")) { - href = href.replace(/_start\=[0-9]*/, "_start=" + num); + let num = featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)[0].replace('STARTINDEX=',''); + let href = req.gppWfsClient.headers.Referer.replace(/\/api.*/, '') + req.originalUrl; + if(href.match('_start')) { + href = href.replace(/_start\=[0-9]*/, '_start=' + num); } else { - href += "&_start=" + num; + href += '&_start=' + num; } featureCollection.links[i].href = href; } diff --git a/controllers/rpg/index.js b/controllers/rpg/index.js index 26fb2aa..21a402c 100644 --- a/controllers/rpg/index.js +++ b/controllers/rpg/index.js @@ -59,12 +59,12 @@ function createRpgProxy(valeurSearch) { if(featureCollection.links && featureCollection.links.length) { for(let i in featureCollection.links) { if(featureCollection.links[i].href && featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)) { - let num = featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)[0].replace("STARTINDEX=",""); - let href = req.gppWfsClient.headers.Referer.replace(/\/api.*/, "") + req.originalUrl; - if(href.match("_start")) { - href = href.replace(/_start\=[0-9]*/, "_start=" + num); + let num = featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)[0].replace('STARTINDEX=',''); + let href = req.gppWfsClient.headers.Referer.replace(/\/api.*/, '') + req.originalUrl; + if(href.match('_start')) { + href = href.replace(/_start\=[0-9]*/, '_start=' + num); } else { - href += "&_start=" + num; + href += '&_start=' + num; } featureCollection.links[i].href = href; } diff --git a/controllers/wfs-geoportail/index.js b/controllers/wfs-geoportail/index.js index 142b91c..5e8b83e 100644 --- a/controllers/wfs-geoportail/index.js +++ b/controllers/wfs-geoportail/index.js @@ -5,7 +5,7 @@ import validateParams from '../../middlewares/validateParams.js'; import isGeometry from '../../checker/isGeometry.js'; import gppWfsClient from '../../middlewares/gppWfsClient.js'; import _ from 'lodash'; -import NodeCache from "node-cache" +import NodeCache from 'node-cache'; const myCache = new NodeCache(); @@ -34,101 +34,67 @@ function createWfsProxy() { //récupération des features getFeat(req, res, featureTypeName, params); - // req.gppWfsClient.getFeatures(featureTypeName, params) - // /* uniformisation des attributs en sortie */ - // .then(function(featureCollection){ - // featureCollection.features.forEach(function(feature){ - // if ( ! feature.properties.code_insee ){ - // feature.properties.code_insee = feature.properties.code_dep+feature.properties.code_com; - // } - // }); - // return featureCollection; - // }) - // .then(function(featureCollection) { - // res.json(featureCollection); - // }) - // .catch(function(err) { - // res.status(500).json(err); - // }) - // ; } else { /* requête WFS GPP*/ req.gppWfsClient.getDescribeFeatureType(featureTypeName) //récupération du geomFieldName - .then(function(featureCollection) { - var nom_geom = false; - for(var i in featureCollection.featureTypes[0].properties) { - if(featureCollection.featureTypes[0].properties[i].name == "geom" - || featureCollection.featureTypes[0].properties[i].name == "the_geom") - { - nom_geom = featureCollection.featureTypes[0].properties[i].name; - break; - } - } - if(!nom_geom) { + .then(function(featureCollection) { + var nom_geom = false; for(var i in featureCollection.featureTypes[0].properties) { - if(featureCollection.featureTypes[0].properties[i].type.match("Point") - || featureCollection.featureTypes[0].properties[i].type.match("Polygon") - || featureCollection.featureTypes[0].properties[i].type.match("LineString")) + if(featureCollection.featureTypes[0].properties[i].name == 'geom' + || featureCollection.featureTypes[0].properties[i].name == 'the_geom') { nom_geom = featureCollection.featureTypes[0].properties[i].name; + break; } - } - } + } + if(!nom_geom) { + for(var i in featureCollection.featureTypes[0].properties) { + if(featureCollection.featureTypes[0].properties[i].type.match('Point') + || featureCollection.featureTypes[0].properties[i].type.match('Polygon') + || featureCollection.featureTypes[0].properties[i].type.match('LineString')) + { + nom_geom = featureCollection.featureTypes[0].properties[i].name; + } + } + } - req.gppWfsClient.defaultGeomFieldName = nom_geom; - - //récupération du CRS - req.gppWfsClient.getCapabilities() - .then(function(response){ - var crs = "urn:ogc:def:crs:EPSG::4326"; - var regexp = new RegExp("" + featureTypeName + ".*?<\/DefaultCRS>"); - if(response.match(regexp)) { - var feat = response.match(regexp)[0]; - if(feat.match(/EPSG::[0-9]{4,5}/)) { - crs = feat.match(/EPSG::[0-9]{4,5}/)[0].replace("::",":"); + req.gppWfsClient.defaultGeomFieldName = nom_geom; + + //récupération du CRS + req.gppWfsClient.getCapabilities() + .then(function(response){ + var crs = 'urn:ogc:def:crs:EPSG::4326'; + var regexp = new RegExp('' + featureTypeName + '.*?<\/DefaultCRS>'); + if(response.match(regexp)) { + var feat = response.match(regexp)[0]; + if(feat.match(/EPSG::[0-9]{4,5}/)) { + crs = feat.match(/EPSG::[0-9]{4,5}/)[0].replace('::',':'); + } } - } - if(crs == "EPSG:4326") { - crs = "urn:ogc:def:crs:EPSG::4326"; - } - req.gppWfsClient.defaultCRS = crs; - - //maj du cache - myCache.set(featureTypeName, [nom_geom, crs]); - - //récupération des features - getFeat(req, res, featureTypeName, params); - // req.gppWfsClient.getFeatures(featureTypeName, params) - // /* uniformisation des attributs en sortie */ - // .then(function(featureCollection){ - // featureCollection.features.forEach(function(feature){ - // if ( ! feature.properties.code_insee ){ - // feature.properties.code_insee = feature.properties.code_dep+feature.properties.code_com; - // } - // }); - // return featureCollection; - // }) - // .then(function(featureCollection) { - // res.json(featureCollection); - // }) - // .catch(function(err) { - // res.status(500).json(err); - // }) - // ; - }) - .catch(function(err) { - res.status(500).json(err); - }) - ; - - - }) - .catch(function(err) { - res.status(500).json(err); - }) - ; + if(crs == 'EPSG:4326') { + crs = 'urn:ogc:def:crs:EPSG::4326'; + } + req.gppWfsClient.defaultCRS = crs; + + //maj du cache + myCache.set(featureTypeName, [nom_geom, crs]); + + //récupération des features + getFeat(req, res, featureTypeName, params); + }) + .catch(function(err) { + res.status(500).json(err); + }) + ; + + + }) + .catch(function(err) { + res.status(500).json(err); + }) + ; } } ]; @@ -136,35 +102,35 @@ function createWfsProxy() { var getFeat = function(req, res, featureTypeName, params) { req.gppWfsClient.getFeatures(featureTypeName, params) - /* uniformisation des attributs en sortie */ - .then(function(featureCollection){ - featureCollection.features.forEach(function(feature){ - if ( ! feature.properties.code_insee ){ - feature.properties.code_insee = feature.properties.code_dep+feature.properties.code_com; - } - }); - if(featureCollection.links && featureCollection.links.length) { - for(let i in featureCollection.links) { - if(featureCollection.links[i].href && featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)) { - let num = featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)[0].replace("STARTINDEX=",""); - let href = req.gppWfsClient.headers.Referer.replace(/\/api.*/, "") + req.originalUrl; - if(href.match("_start")) { - href = href.replace(/_start\=[0-9]*/, "_start=" + num); - } else { - href += "&_start=" + num; + /* uniformisation des attributs en sortie */ + .then(function(featureCollection){ + featureCollection.features.forEach(function(feature){ + if ( ! feature.properties.code_insee ){ + feature.properties.code_insee = feature.properties.code_dep+feature.properties.code_com; + } + }); + if(featureCollection.links && featureCollection.links.length) { + for(let i in featureCollection.links) { + if(featureCollection.links[i].href && featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)) { + let num = featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)[0].replace('STARTINDEX=',''); + let href = req.gppWfsClient.headers.Referer.replace(/\/api.*/, '') + req.originalUrl; + if(href.match('_start')) { + href = href.replace(/_start\=[0-9]*/, '_start=' + num); + } else { + href += '&_start=' + num; + } + featureCollection.links[i].href = href; } - featureCollection.links[i].href = href; } } - } - return featureCollection; - }) - .then(function(featureCollection) { - res.json(featureCollection); - }) - .catch(function(err) { - res.status(500).json(err); - }) + return featureCollection; + }) + .then(function(featureCollection) { + res.json(featureCollection); + }) + .catch(function(err) { + res.status(500).json(err); + }) ; }; diff --git a/test/controllers/er/category.js b/test/controllers/er/category.js index 2183ae2..adef71a 100644 --- a/test/controllers/er/category.js +++ b/test/controllers/er/category.js @@ -25,6 +25,7 @@ const EXPECTED_PROPERTIES = [ "front_image", "full_description", "has_geometry", + "is_manufactured", "keywords", "name", "name_complement", diff --git a/test/controllers/er/product.js b/test/controllers/er/product.js index 811a16c..d2ee0b2 100644 --- a/test/controllers/er/product.js +++ b/test/controllers/er/product.js @@ -25,6 +25,7 @@ const EXPECTED_PROPERTIES = [ "front_image", "full_description", "has_geometry", + "is_manufactured", "keywords", "name", "name_complement", diff --git a/test/controllers/gpu/municipality.js b/test/controllers/gpu/municipality.js index fc1bf62..40cbea9 100644 --- a/test/controllers/gpu/municipality.js +++ b/test/controllers/gpu/municipality.js @@ -3,46 +3,47 @@ import request from 'supertest'; import expect from 'expect.js'; import { app } from '../../../app.js'; -describe('/api/gpu/municipality', function() { - describe('without filtering parameter', function() { - it('should reply with 400', function(done) { - request(app) - .get('/api/gpu/municipality') - .expect(200) - .expect(res => { - expect(res.body.features.length).to.be.greaterThan(10); - }) - .end(done); - }); - }); - - describe('with insee=25349', function() { - it('should reply with a valid feature', function(done) { - request(app) - .get('/api/gpu/municipality?insee=25349') - .expect(200) - .expect(res => { - expect(res.body.features.length).to.eql(1); - const feature = res.body.features[0]; - expect(feature.properties.name).to.eql('LORAY'); - }) - .end(done); - ; - }); +describe('with insee=25349', function() { + it('should reply with a valid feature', function(done) { + request(app) + .get('/api/gpu/municipality?insee=25349') + .expect(200) + .expect(res => { + expect(res.body.features.length).to.eql(1); + const feature = res.body.features[0]; + expect(feature.properties.name).to.eql('LORAY'); + }) + .end(done); + ; }); +}); - describe('with point at [1.654399,48.112235] (Rennes)', function() { - it('should reply a FeatureCollection containing a valid Feature', function(done) { - request(app) - .get('/api/gpu/municipality?geom={"type":"Point","coordinates":[1.654399,48.112235]}') - .expect(200) - .expect(res => { - expect(res.body.features.length).to.eql(1); - const feature = res.body.features[0]; - expect(feature.properties.is_rnu).to.eql(false); - }) - .end(done); - ; - }); +describe('with point at [1.654399,48.112235] (Rennes)', function() { + it('should reply a FeatureCollection containing a valid Feature', function(done) { + request(app) + .get('/api/gpu/municipality?geom={"type":"Point","coordinates":[1.654399,48.112235]}') + .expect(200) + .expect(res => { + expect(res.body.features.length).to.eql(1); + const feature = res.body.features[0]; + expect(feature.properties.is_rnu).to.eql(false); + }) + .end(done); + ; }); }); + +// describe('/api/gpu/municipality', function() { +// describe('without filtering parameter', function() { +// it('should reply with 400', function(done) { +// request(app) +// .get('/api/gpu/municipality') +// .expect(200) +// .expect(res => { +// expect(res.body.features.length).to.be.greaterThan(10); +// }) +// .end(done); +// }); +// }); + +// }); \ No newline at end of file From cd837dd59700a6d754c1ac32c23f915882e67005 Mon Sep 17 00:00:00 2001 From: MFrangi Date: Thu, 12 Sep 2024 08:50:42 +0000 Subject: [PATCH 6/9] maj package.json --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7714732..acfd74a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,7 @@ "ejs": "^3.1.10", "express": "^4.19.2", "express-validator": "^7.1.0", - "geoportal-wfs-client": "https://github.com/IGNF/geoportal-wfs-client#v1.0.0", + "geoportal-wfs-client": "https://github.com/IGNF/geoportal-wfs-client#v1.0.3", "handlebars": "^4.7.7", "http-proxy-agent": "^7.0.2", "https-proxy-agent": "^7.0.4", diff --git a/package.json b/package.json index 09ce881..a673305 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "ejs": "^3.1.10", "express": "^4.19.2", "express-validator": "^7.1.0", - "geoportal-wfs-client": "https://github.com/IGNF/geoportal-wfs-client#v1.0.0", + "geoportal-wfs-client": "https://github.com/IGNF/geoportal-wfs-client#v1.0.3", "handlebars": "^4.7.7", "http-proxy-agent": "^7.0.2", "https-proxy-agent": "^7.0.4", From 0ba47fd35594cf69efce51d6536641e1b0fb8903 Mon Sep 17 00:00:00 2001 From: MFrangi Date: Thu, 12 Sep 2024 09:16:32 +0000 Subject: [PATCH 7/9] update geoportal wfs client --- package-lock.json | 75 +++++++++++------------------------------------ 1 file changed, 17 insertions(+), 58 deletions(-) diff --git a/package-lock.json b/package-lock.json index acfd74a..b03e17b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -824,14 +824,6 @@ "resolved": "https://registry.npmjs.org/@terraformer/wkt/-/wkt-2.2.1.tgz", "integrity": "sha512-XDUsW/lvbMzFi7GIuRD9+UqR4QyP+5C+TugeJLMDczKIRbaHoE9J3N8zLSdyOGmnJL9B6xTS3YMMlBnMU0Ar5A==" }, - "node_modules/@tootallnate/once": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz", - "integrity": "sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==", - "engines": { - "node": ">= 10" - } - }, "node_modules/@turf/along": { "version": "6.5.0", "resolved": "https://registry.npmjs.org/@turf/along/-/along-6.5.0.tgz", @@ -4165,66 +4157,23 @@ } }, "node_modules/geoportal-wfs-client": { - "version": "1.0.0", - "resolved": "git+ssh://git@github.com/IGNF/geoportal-wfs-client.git#8a34ce5bd805ffea13617f94bbcbef1ddc41538d", + "version": "1.0.3", + "resolved": "git+ssh://git@github.com/IGNF/geoportal-wfs-client.git#b1b50caef6622c6bd3673eb8c03b00357494174d", "dependencies": { "@turf/flip": "^6.5.0", "@turf/meta": "6.5.0", "@turf/turf": "^6.5.0", "@xmldom/xmldom": "^0.8.2", - "axios": "^0.27.2", - "http-proxy-agent": "^5.0.0", - "https-proxy-agent": "^5.0.1", + "axios": "^1.7.2", + "http-proxy-agent": "^7.0.0", + "https-proxy-agent": "^7.0.2", + "net": "^1.0.2", "proj4": "^2.8.0", "terraformer-wkt-parser": "^1.1.2", + "tls": "^0.0.1", "xpath": "0.0.32" } }, - "node_modules/geoportal-wfs-client/node_modules/agent-base": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", - "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", - "dependencies": { - "debug": "4" - }, - "engines": { - "node": ">= 6.0.0" - } - }, - "node_modules/geoportal-wfs-client/node_modules/axios": { - "version": "0.27.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", - "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", - "dependencies": { - "follow-redirects": "^1.14.9", - "form-data": "^4.0.0" - } - }, - "node_modules/geoportal-wfs-client/node_modules/http-proxy-agent": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-5.0.0.tgz", - "integrity": "sha512-n2hY8YdoRE1i7r6M0w9DIw5GgZN0G25P8zLCRQ8rjXtTU3vsNFBI/vWK/UIeE6g5MUUz6avwAPXmL6Fy9D/90w==", - "dependencies": { - "@tootallnate/once": "2", - "agent-base": "6", - "debug": "4" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/geoportal-wfs-client/node_modules/https-proxy-agent": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", - "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", - "dependencies": { - "agent-base": "6", - "debug": "4" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -5517,6 +5466,11 @@ "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==" }, + "node_modules/net": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/net/-/net-1.0.2.tgz", + "integrity": "sha512-kbhcj2SVVR4caaVnGLJKmlk2+f+oLkjqdKeQlmUtz6nGzOpbcobwVIeSURNgraV/v3tlmGIX82OcPCl0K6RbHQ==" + }, "node_modules/node-cache": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/node-cache/-/node-cache-5.1.2.tgz", @@ -7222,6 +7176,11 @@ "resolved": "https://registry.npmjs.org/tinyqueue/-/tinyqueue-2.0.3.tgz", "integrity": "sha512-ppJZNDuKGgxzkHihX8v9v9G5f+18gzaTfrukGrq6ueg0lmH4nqVnA2IPG0AEH3jKEk2GRJCUhDoqpoiw3PHLBA==" }, + "node_modules/tls": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/tls/-/tls-0.0.1.tgz", + "integrity": "sha512-GzHpG+hwupY8VMR6rYsnAhTHqT/97zT45PG8WD5eTT1lq+dFE0nN+1PYpsoBcHJgSmTz5ceK2Cv88IkPmIPOtQ==" + }, "node_modules/to-fast-properties": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", From 93a546fbb02402af8e89113e20263e5221d55834 Mon Sep 17 00:00:00 2001 From: MFrangi Date: Mon, 16 Sep 2024 08:09:53 +0000 Subject: [PATCH 8/9] maj doc --- README.md | 2 +- datasets/appellations-viticoles/config.js | 2 +- datasets/base-adresse-nationale/config.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 78a21cb..6c57fa2 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ La connexion à la base postgresql est configurée à l'aide des variables d'env |-----------------------|--------------------|-------------------|--------------------| | Géoportail | Flux WFS | Cadastre
RPG
Nature
WFS-Geoportail | [Geoservices](https://geoservices.ign.fr/services-web-experts) | | GPU | Flux WFS | GPU | [Géoportail de l'urbanisme](https://www.geoportail-urbanisme.gouv.fr/) | -| Base adresse nationale | v4.0.0 | Codes Postaux | [BAN](https://github.com/baseadressenationale/codes-postaux) | +| Base adresse nationale | v4.1.0 | Codes Postaux | [BAN](https://github.com/baseadressenationale/codes-postaux) | | Base des appellations viticoles | Flux WFS | Appellations viticoles | [FranceAgriMer](https://www.franceagrimer.fr/filieres-Vin-et-cidre/Vin/Professionnels/Teleprocedures) | diff --git a/datasets/appellations-viticoles/config.js b/datasets/appellations-viticoles/config.js index ed78389..e79fd9e 100644 --- a/datasets/appellations-viticoles/config.js +++ b/datasets/appellations-viticoles/config.js @@ -1,5 +1,5 @@ var aocConfig = { - version: '8 mars 2023', + version: '16 mai 2024', modules: ["Appellations viticoles"], nom_url :"FranceAgriMer", url: 'https://www.franceagrimer.fr/filieres-vin-et-cidre/vin/professionnels/teleprocedures' diff --git a/datasets/base-adresse-nationale/config.js b/datasets/base-adresse-nationale/config.js index 789f2c2..d3f00ea 100644 --- a/datasets/base-adresse-nationale/config.js +++ b/datasets/base-adresse-nationale/config.js @@ -1,5 +1,5 @@ var banConfig = { - version: 'v4.0.0', + version: 'v4.1.0', modules: ["Codes Postaux"], nom_url :"BAN", url: 'https://github.com/baseadressenationale/codes-postaux' From f7b0bd1fe4aaa7c4107f6957f084f6592bca174f Mon Sep 17 00:00:00 2001 From: MFrangi Date: Tue, 17 Sep 2024 07:27:46 +0000 Subject: [PATCH 9/9] detection nom geometrie module rpg --- README.md | 2 +- controllers/nature/index.js | 24 ++-- controllers/rpg/index.js | 127 +++++++++++++++++----- datasets/base-adresse-nationale/config.js | 2 +- doc/views/index.ejs | 2 +- doc/views/partial/menu.ejs | 2 +- doc/wfs-geoportail.yml | 2 +- package-lock.json | 10 +- package.json | 4 +- 9 files changed, 122 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 6c57fa2..07857bc 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ La connexion à la base postgresql est configurée à l'aide des variables d'env |-----------------------|--------------------|-------------------|--------------------| | Géoportail | Flux WFS | Cadastre
RPG
Nature
WFS-Geoportail | [Geoservices](https://geoservices.ign.fr/services-web-experts) | | GPU | Flux WFS | GPU | [Géoportail de l'urbanisme](https://www.geoportail-urbanisme.gouv.fr/) | -| Base adresse nationale | v4.1.0 | Codes Postaux | [BAN](https://github.com/baseadressenationale/codes-postaux) | +| Base adresse nationale | v4.1.1 | Codes Postaux | [BAN](https://github.com/baseadressenationale/codes-postaux) | | Base des appellations viticoles | Flux WFS | Appellations viticoles | [FranceAgriMer](https://www.franceagrimer.fr/filieres-Vin-et-cidre/Vin/Professionnels/Teleprocedures) | diff --git a/controllers/nature/index.js b/controllers/nature/index.js index b326f37..f71757c 100644 --- a/controllers/nature/index.js +++ b/controllers/nature/index.js @@ -29,22 +29,20 @@ function createNaturaProxy(featureTypeName){ req.gppWfsClient.getFeatures(featureTypeName, params) /* uniformisation des attributs en sortie */ .then(function(featureCollection){ - featureCollection.features.forEach(function(feature){ - if(featureCollection.links && featureCollection.links.length) { - for(let i in featureCollection.links) { - if(featureCollection.links[i].href && featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)) { - let num = featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)[0].replace('STARTINDEX=',''); - let href = req.gppWfsClient.headers.Referer.replace(/\/api.*/, '') + req.originalUrl; - if(href.match('_start')) { - href = href.replace(/_start\=[0-9]*/, '_start=' + num); - } else { - href += '&_start=' + num; - } - featureCollection.links[i].href = href; + if(featureCollection.links && featureCollection.links.length) { + for(let i in featureCollection.links) { + if(featureCollection.links[i].href && featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)) { + let num = featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)[0].replace('STARTINDEX=',''); + let href = req.gppWfsClient.headers.Referer.replace(/\/api.*/, '') + req.originalUrl; + if(href.match('_start')) { + href = href.replace(/_start\=[0-9]*/, '_start=' + num); + } else { + href += '&_start=' + num; } + featureCollection.links[i].href = href; } } - }); + } return featureCollection; }) .then(function(featureCollection) { diff --git a/controllers/rpg/index.js b/controllers/rpg/index.js index 21a402c..a474cb7 100644 --- a/controllers/rpg/index.js +++ b/controllers/rpg/index.js @@ -5,7 +5,9 @@ import validateParams from '../../middlewares/validateParams.js'; import isGeometry from '../../checker/isGeometry.js'; import gppWfsClient from '../../middlewares/gppWfsClient.js'; import _ from 'lodash'; +import NodeCache from 'node-cache'; +const myCache = new NodeCache(); var router = new Router(); const lastYearRPG = 2022; @@ -50,40 +52,109 @@ function createRpgProxy(valeurSearch) { /* Value default pour _limit an _start */ if ( typeof params._start == 'undefined' ) {params._start = 0;} if( typeof params._limit == 'undefined') {params._limit = 1000;} - - /* requête WFS GPP*/ - req.gppWfsClient.getFeatures(featureTypeName, params) - /* uniformisation des attributs en sortie */ - .then(function(featureCollection){ - featureCollection.features.forEach(function(feature){ - if(featureCollection.links && featureCollection.links.length) { - for(let i in featureCollection.links) { - if(featureCollection.links[i].href && featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)) { - let num = featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)[0].replace('STARTINDEX=',''); - let href = req.gppWfsClient.headers.Referer.replace(/\/api.*/, '') + req.originalUrl; - if(href.match('_start')) { - href = href.replace(/_start\=[0-9]*/, '_start=' + num); - } else { - href += '&_start=' + num; - } - featureCollection.links[i].href = href; - } + + //recherche dans le cache + if(myCache.get(featureTypeName)) { + req.gppWfsClient.defaultGeomFieldName = myCache.get(featureTypeName)[0]; + req.gppWfsClient.defaultCRS = myCache.get(featureTypeName)[1]; + + //récupération des features + getFeat(req, res, featureTypeName, params); + } + else { + /* requête WFS GPP*/ + req.gppWfsClient.getDescribeFeatureType(featureTypeName) + //récupération du geomFieldName + .then(function(featureCollection) { + var nom_geom = false; + for(var i in featureCollection.featureTypes[0].properties) { + if(featureCollection.featureTypes[0].properties[i].name == 'geom' + || featureCollection.featureTypes[0].properties[i].name == 'the_geom') + { + nom_geom = featureCollection.featureTypes[0].properties[i].name; + break; } } - }); - return featureCollection; - }) - .then(function(featureCollection) { - res.json(featureCollection); - }) - .catch(function(err) { - res.status(500).json(err); - }) - ; + if(!nom_geom) { + for(var i in featureCollection.featureTypes[0].properties) { + if(featureCollection.featureTypes[0].properties[i].type.match('Point') + || featureCollection.featureTypes[0].properties[i].type.match('Polygon') + || featureCollection.featureTypes[0].properties[i].type.match('LineString')) + { + nom_geom = featureCollection.featureTypes[0].properties[i].name; + } + } + } + + req.gppWfsClient.defaultGeomFieldName = nom_geom; + + //récupération du CRS + req.gppWfsClient.getCapabilities() + .then(function(response){ + var crs = 'urn:ogc:def:crs:EPSG::4326'; + var regexp = new RegExp('' + featureTypeName + '.*?<\/DefaultCRS>'); + if(response.match(regexp)) { + var feat = response.match(regexp)[0]; + if(feat.match(/EPSG::[0-9]{4,5}/)) { + crs = feat.match(/EPSG::[0-9]{4,5}/)[0].replace('::',':'); + } + } + if(crs == 'EPSG:4326') { + crs = 'urn:ogc:def:crs:EPSG::4326'; + } + req.gppWfsClient.defaultCRS = crs; + + //maj du cache + myCache.set(featureTypeName, [nom_geom, crs]); + + //récupération des features + getFeat(req, res, featureTypeName, params); + }) + .catch(function(err) { + res.status(500).json(err); + }) + ; + + + }) + .catch(function(err) { + res.status(500).json(err); + }) + ; + } } ]; } +var getFeat = function(req, res, featureTypeName, params) { + req.gppWfsClient.getFeatures(featureTypeName, params) + /* uniformisation des attributs en sortie */ + .then(function(featureCollection){ + if(featureCollection.links && featureCollection.links.length) { + for(let i in featureCollection.links) { + if(featureCollection.links[i].href && featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)) { + let num = featureCollection.links[i].href.match(/STARTINDEX\=[0-9]*/)[0].replace('STARTINDEX=',''); + let href = req.gppWfsClient.headers.Referer.replace(/\/api.*/, '') + req.originalUrl; + if(href.match('_start')) { + href = href.replace(/_start\=[0-9]*/, '_start=' + num); + } else { + href += '&_start=' + num; + } + featureCollection.links[i].href = href; + } + } + } + return featureCollection; + }) + .then(function(featureCollection) { + res.json(featureCollection); + }) + .catch(function(err) { + res.status(500).json(err); + }) + ; +}; + var corsOptionsGlobal = function(origin,callback) { var corsOptions; if (origin) { diff --git a/datasets/base-adresse-nationale/config.js b/datasets/base-adresse-nationale/config.js index d3f00ea..2cce12d 100644 --- a/datasets/base-adresse-nationale/config.js +++ b/datasets/base-adresse-nationale/config.js @@ -1,5 +1,5 @@ var banConfig = { - version: 'v4.1.0', + version: 'v4.1.1', modules: ["Codes Postaux"], nom_url :"BAN", url: 'https://github.com/baseadressenationale/codes-postaux' diff --git a/doc/views/index.ejs b/doc/views/index.ejs index 18f63b3..f813c0c 100644 --- a/doc/views/index.ejs +++ b/doc/views/index.ejs @@ -95,7 +95,7 @@ - WFS-Geoportail (Version bêta) + WFS-Geoportail API d'accès à n'importe quel flux WFS du Géoportail diff --git a/doc/views/partial/menu.ejs b/doc/views/partial/menu.ejs index 1b0d2bb..713b823 100644 --- a/doc/views/partial/menu.ejs +++ b/doc/views/partial/menu.ejs @@ -34,7 +34,7 @@ RPG
  • - WFS-Geoportail (Version Bêta) + WFS-Geoportail
  • Nature diff --git a/doc/wfs-geoportail.yml b/doc/wfs-geoportail.yml index 86fef85..cb73ed9 100644 --- a/doc/wfs-geoportail.yml +++ b/doc/wfs-geoportail.yml @@ -1,7 +1,7 @@ swagger: '2.0' info: - title: Module pour rechercher dans tous les flux WFS Géoportail (Version Bêta) + title: Module pour rechercher dans tous les flux WFS Géoportail description: > Ce module permet d’intersecter toute couche WFS du géoportail exprimée dans le référentiel géographique WGS84 **EPSG:4326** avec la géométrie passée en paramètre. diff --git a/package-lock.json b/package-lock.json index b03e17b..fffa203 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "apicarto", - "version": "v2.7.4", + "version": "v2.7.8", "lockfileVersion": 3, "requires": true, "packages": { @@ -16,7 +16,7 @@ "axios": "^1.7.2", "body-parser": "^1.20.0", "bunyan": "^1.8.15", - "codes-postaux": "^4.1.0", + "codes-postaux": "^4.1.1", "cors": "^2.8.5", "debug": "^4.3.4", "ejs": "^3.1.10", @@ -3072,9 +3072,9 @@ } }, "node_modules/codes-postaux": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/codes-postaux/-/codes-postaux-4.1.0.tgz", - "integrity": "sha512-RBLXsQatRnmNI+o6SztWarb38tvkWoW3v8kpT3yBlr/J5gMKYZWn4NEa9LdIC7GU3GTqVwLS9foQMJl8CI/fFA==", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/codes-postaux/-/codes-postaux-4.1.1.tgz", + "integrity": "sha512-u9gL6QFgoAhz8q99Z3TCMgOAE2MOWbJahqnu3QBYFjS6dtuakYMM5+ubCIfe7TzalHhDyahXBgWCqiOY3qG6SQ==", "dependencies": { "lodash": "^4.17.21" }, diff --git a/package.json b/package.json index a673305..e3f10ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apicarto", - "version": "v2.7.4", + "version": "v2.7.8", "main": "index.js", "type": "module", "scripts": { @@ -29,7 +29,7 @@ "axios": "^1.7.2", "body-parser": "^1.20.0", "bunyan": "^1.8.15", - "codes-postaux": "^4.1.0", + "codes-postaux": "^4.1.1", "cors": "^2.8.5", "debug": "^4.3.4", "ejs": "^3.1.10",