Skip to content

Commit

Permalink
detection nom geometrie module rpg
Browse files Browse the repository at this point in the history
  • Loading branch information
MFrangi committed Sep 17, 2024
1 parent 93a546f commit f7b0bd1
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 53 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ La connexion à la base postgresql est configurée à l'aide des variables d'env
|-----------------------|--------------------|-------------------|--------------------|
| Géoportail | Flux WFS | Cadastre <br/> RPG <br/> Nature <br/> 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) |


Expand Down
24 changes: 11 additions & 13 deletions controllers/nature/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
127 changes: 99 additions & 28 deletions controllers/rpg/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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('<Name>' + 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) {
Expand Down
2 changes: 1 addition & 1 deletion datasets/base-adresse-nationale/config.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion doc/views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
</td>
</tr>
<tr>
<td>WFS-Geoportail (Version bêta)</td>
<td>WFS-Geoportail</td>
<td>
API d'accès à n'importe quel flux WFS du Géoportail
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/views/partial/menu.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<a href="/api/doc/rpg">RPG</a>
</li>
<li>
<a href="/api/doc/wfs-geoportail">WFS-Geoportail (Version Bêta)</a>
<a href="/api/doc/wfs-geoportail">WFS-Geoportail</a>
</li>
<li>
<a href="/api/doc/nature">Nature</a>
Expand Down
2 changes: 1 addition & 1 deletion doc/wfs-geoportail.yml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apicarto",
"version": "v2.7.4",
"version": "v2.7.8",
"main": "index.js",
"type": "module",
"scripts": {
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit f7b0bd1

Please sign in to comment.