Skip to content

Commit

Permalink
Merge pull request #114 from IGNF/issue_40_issue_52
Browse files Browse the repository at this point in the history
Issue 40 issue 52
  • Loading branch information
MFrangi authored Sep 23, 2024
2 parents 55421fe + f52ccf2 commit 96f9374
Show file tree
Hide file tree
Showing 14 changed files with 290 additions and 104 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.0.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
14 changes: 14 additions & 0 deletions controllers/cadastre/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion controllers/er/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
21 changes: 20 additions & 1 deletion controllers/nature/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,31 @@ function createNaturaProxy(featureTypeName){

/* requête WFS GPP*/
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);
});
})
;
}
];
}
Expand Down
115 changes: 101 additions & 14 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,24 +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){
return featureCollection;
})
.then(function(featureCollection) {
res.json(featureCollection);
})
.catch(function(err) {
res.status(500).json(err);
})
;

//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;
}
}
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
125 changes: 106 additions & 19 deletions controllers/wfs-geoportail/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();

Expand All @@ -19,34 +21,119 @@ 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.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;

//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;
}
}
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;
}
}
}
});
return featureCollection;
})
.then(function(featureCollection) {
res.json(featureCollection);
})
.catch(function(err) {
res.status(500).json(err);
})
;

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){
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;
Expand Down
2 changes: 1 addition & 1 deletion datasets/appellations-viticoles/config.js
Original file line number Diff line number Diff line change
@@ -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'
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.0.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
Loading

0 comments on commit 96f9374

Please sign in to comment.