Skip to content

Commit

Permalink
Merge pull request #23 from IGNF/modifaoc
Browse files Browse the repository at this point in the history
Modifaoc
  • Loading branch information
vinsag authored Jan 6, 2020
2 parents 78f12d0 + 983941b commit ab50219
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 58 deletions.
89 changes: 51 additions & 38 deletions controllers/aoc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,60 +14,73 @@ var _ = require('lodash');
/**
* Récupération des AOC viticoles par géométrie
*/
router.get('/appellation-viticole', [
router.post('/appellation-viticole', [
check('geom').exists().withMessage('Le paramètre geom est obligatoire'),
check('geom').custom(isGeometry)
], validateParams, pgClient, function(req, res, next) {
var params = matchedData(req);

var sql = format(`
SELECT
id,
new_insee,
new_nomcom,
old_insee,
old_nomcom,
type_ig,
id_app,
appellation,
id_denom,
denomination,
crinao,
ST_AsGeoJSON(geom) as geom
appellation,
idapp,
id_uni,
insee,
segment,
instruction_obligatoire,
granularite,
ST_AsGeoJSON(geom) as geom
FROM
inao.appellation
appellations
WHERE ST_Intersects(
geom,
ST_SetSRID(ST_GeomFromGeoJSON('%s'), 4326)
)
)
LIMIT 1000
`, params.geom );

req.pgClient.query(sql,function(err,result){

var sqlCommunes = format(`
SELECT
NOM_COM as nom,
CODE_INSEE as insee,
ST_Contains(input.geom, communes_ign.geom) AS contains,
ST_AsGeoJSON(communes_ign.geom) AS geom
FROM
communes_ign,
(SELECT ST_SetSRID(ST_GeomFromGeoJSON('%s'), 4326) geom) input
WHERE ST_Intersects(communes_ign.geom, input.geom);
`, params.geom);

req.pgClient.query(sqlCommunes,function(err,result){
if (err)
return next(err);
req.intersectedCommunes = result.rows;
req.pgClient.query(sql,function(err,result){
if (err)
return next(err);

return res.send({
type: 'FeatureCollection',
features: result.rows.map(function (row) {
const feature = {
type: 'Feature',
geometry: JSON.parse(row.geom),
properties: _.omit(row, 'geom')
};
/*
if (row.granularite === 'commune' && !row.instruction_obligatoire) {
const commune = _.find(req.intersectedCommunes, { insee: row.insee });
feature.properties.area = commune.intersect_area;
feature.properties.contains = commune.contains;
feature.geometry = JSON.parse(commune.geom);
}
*/
return feature;
})
});
});
return res.send({
type: 'FeatureCollection',
features: result.rows.map(function (row) {
const feature = {
type: 'Feature',
geometry: JSON.parse(row.geom),
properties: _.omit(row, 'geom')
};
const communetest = _.find(req.intersectedCommunes, { insee: row.insee });

if (row.granularite === 'commune' && !row.instruction_obligatoire) {
const commune = _.find(req.intersectedCommunes, { insee: row.insee });
feature.properties.area = commune.intersect_area;
feature.properties.contains = commune.contains;
feature.geometry = JSON.parse(commune.geom);
}

return feature;
})
});
});
});
});


module.exports = router;
35 changes: 18 additions & 17 deletions doc/aoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ basePath: /api

paths:
/aoc/appellation-viticole:
get:
post:
description: |
Prend une geometrie de type GeoJSON en paramètre d'entrée et renvoie les appellations viticoles intersectantes
Paramètres de sorties : Retourne un résultat de Type "FeatureCollection"
consumes:
- application/x-www-form-urlencoded
Paramètres de sorties : Retourne un résultat de Type "FeatureCollection"
parameters:

- name: geom
Expand Down Expand Up @@ -63,28 +64,28 @@ definitions:
properties:
type: object
properties:
id:
appelation:
type: string
id_app:
type: string
new_insee:
idapp:
type: string
new_nomcom:
id_uni:
type: string
old_insee:
description: corresponds à "segment-idapp-insee"
insee:
type: string
old_nomcom:
segment:
type: string
type_ig:
instruction_obligatoire:
type: boolean
granularite:
type: string
enum:
- commune
- exacte
appellation:
type: string
id_denom:
type: string
denomination:
type: string
crinao:
type: string
contains:
type: boolean
geometry:
$ref: '#/definitions/MultiPolygon'

Expand Down
2 changes: 1 addition & 1 deletion 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": "2.0.0",
"version": "2.1.2",
"main": "index.js",
"scripts": {
"import": "npm run import-inao-appellation",
Expand All @@ -16,7 +16,7 @@
"Vincent Sagniez <[email protected]>",
"Mickael Borne <[email protected]>"
],
"repository": "sgmap/apicarto",
"repository": "IGNF/apicarto",
"license": "AGPL-3.0",
"engines": {
"node": ">=6"
Expand Down

0 comments on commit ab50219

Please sign in to comment.