forked from etalab/apicarto
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modif module nature et ajout module all WFS
- Loading branch information
Showing
5 changed files
with
264 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
var Router = require('express').Router; | ||
var router = new Router(); | ||
var cors = require('cors'); | ||
const { check } = require('express-validator/check'); | ||
const { matchedData } = require('express-validator/filter'); | ||
|
||
const validateParams = require('../../middlewares/validateParams'); | ||
const {isGeometry,isCodeInsee} = require('../../checker'); | ||
|
||
const gppWfsClient = require('../../middlewares/gppWfsClient'); | ||
|
||
const _ = require('lodash'); | ||
|
||
/** | ||
* Creation d'une chaîne de proxy sur le geoportail | ||
* @param {String} valeurSearch du chemin le nom de la couche WFS | ||
*/ | ||
function createRpgProxy() { | ||
return [ | ||
gppWfsClient, | ||
validateParams, | ||
function(req,res){ | ||
var params = matchedData(req); | ||
var featureTypeName= params.source; | ||
console.log('value:'+req.query.apikey); | ||
if (typeof req.query.apikey == 'undefined') { | ||
return res.status(400).send({ | ||
code: 400, | ||
message: 'La clé ign (apikey) doit être renseignée' | ||
}) | ||
} | ||
params = _.omit(params,'source'); | ||
params = _.omit(params,'apikey'); | ||
/* 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; | ||
} | ||
}); | ||
return featureCollection; | ||
}) | ||
.then(function(featureCollection) { | ||
res.json(featureCollection); | ||
}) | ||
.catch(function(err) { | ||
console.log(err); | ||
res.status(500).json(err); | ||
}) | ||
; | ||
} | ||
]; | ||
} | ||
|
||
|
||
var corsOptionsGlobal = function(origin,callback) { | ||
var corsOptions; | ||
if (origin) { | ||
corsOptions = { | ||
origin: origin, | ||
optionsSuccessStatus: 200, | ||
methods: 'GET,POST', | ||
credentials: true | ||
} | ||
} else { | ||
corsOptions = { | ||
origin : '*', | ||
optionsSuccessStatus : 200, | ||
methods: 'GET,POST', | ||
credentials: true | ||
} | ||
} | ||
callback(null, corsOptions); | ||
} | ||
|
||
/** | ||
* Permet d'alerter en cas de paramètre ayant changer de nom | ||
* | ||
* TODO Principe à valider (faire un middleware de renommage des paramètres si l'approche est trop violente) | ||
*/ | ||
var moduleValidator = [ | ||
check('apikey').exists().withMessage('Le paramètre apikey pour le nom de la couche WFS géoportail est obligatoire'), | ||
check('source').exists().withMessage('Le paramètre source pour le nom de la couche WFS géoportail est obligatoire'), | ||
check('geom').optional().custom(isGeometry), | ||
check('_limit').optional().isNumeric(), | ||
check('_start').optional().isNumeric() | ||
]; | ||
|
||
|
||
|
||
router.get('/search', cors(corsOptionsGlobal),moduleValidator, createRpgProxy()); | ||
|
||
|
||
|
||
module.exports=router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
swagger: '2.0' | ||
|
||
info: | ||
title: Module pour rechercher dans tous les flux WFS Géoportail (Version Beta) | ||
description: > | ||
Ce module permet d'interroger n'importe quelle ressource WFS qui intersecte une géométrie( géométie dans le référentiel correspondant à la couche) et selon vos droits sur cette ressource. | ||
Il faut mettre en paramètre une géométrie et le nom de la ressource WFS Géoportail. | ||
Toutes les requêtes du module RPG peuvent se faire en POST ou en GET. | ||
Sur cette page, vous pouvez uniquement tester les modules avec des requêtes en GET. | ||
## Clé WFS géoportail (apikey) | ||
Ce service se repose sur l'appel à des services WFS de l'API géoportail de l'IGN. | ||
Si cette clé n'est pas définie sur le serveur APICARTO, il faut passer une clé IGN en paramètre sous le nom `apikey`. | ||
Pour obtenir une clé geoportail, vous devez vous connecter au site : http://professionnels.ign.fr/ . | ||
Vous ne pourrez interroger que les couches dont vous avez les droits sur votre clé IGN. | ||
Attention il faut bien vérifier la représentation géométrique de chaque couche pour passer la géométrie dans le bon référentiel. | ||
Exemple de géométrie : (format EPSG:4326) | ||
* Point : `{"type": "Point","coordinates":[-1.691634,48.104237]}` | ||
* MultiPolygon : `{"type":"MultiPolygon","coordinates":[[[[-0.288863182067871,48.963666607295977],[-0.299592018127441,48.959299208576141],[-0.296330451965332,48.955325952385039],[-0.282125473022461,48.950675995388366],[-0.279722213745117,48.967019382922331],[-0.288863182067871,48.963666607295977]]]]}` | ||
version: '1.0' | ||
|
||
|
||
consumes: | ||
- application/json | ||
produces: | ||
- application/json | ||
|
||
basePath: /api | ||
|
||
paths: | ||
/all-wfs-ign/search: | ||
get: | ||
description: | | ||
Prend une geometrie de type GeoJSON en paramètre d'entrée et renvoie les informations intersectant cette géométrie | ||
Prend une date qui sera une valeur comprise entre 2010 et 2013 inclus | ||
Paramètres de sorties : Retourne un résultat de Type "FeatureCollection" | ||
parameters: | ||
- name: apikey | ||
in: query | ||
description: Clé WFS géoportail | ||
type: string | ||
required: true | ||
|
||
- name: source | ||
in: query | ||
description: Source des données WFS Géoportail | ||
type: string | ||
required: true | ||
|
||
- name: geom | ||
in: query | ||
required: true | ||
schema: | ||
$ref: "#/definitions/Geometry" | ||
|
||
- name: _limit | ||
in: query | ||
description: Limite de résultats à afficher (chiffre entre 1 et 1000) | ||
type: integer | ||
required: false | ||
|
||
- name: _start | ||
in: query | ||
description: Position pour le début de la recherche | ||
type: integer | ||
required: false | ||
|
||
responses: | ||
'200': | ||
description: "Succès" | ||
|
||
definitions: | ||
|
||
# import definitions | ||
FeatureCollection: | ||
$ref: './schema/geojson.yml#definitions/FeatureCollection' | ||
Feature: | ||
$ref: './schema/geojson.yml#definitions/Feature' | ||
Geometry: | ||
$ref: './schema/geojson.yml#definitions/Geometry' | ||
MultiPolygon: | ||
$ref: './schema/geojson.yml#definitions/MultiPolygon' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters