Skip to content

Instantly share code, notes, and snippets.

@jdesboeufs
Created November 10, 2015 13:38
Show Gist options
  • Save jdesboeufs/59442fc1621b8abe11ae to your computer and use it in GitHub Desktop.
Save jdesboeufs/59442fc1621b8abe11ae to your computer and use it in GitHub Desktop.
Requêtes Appellations APICarto
SELECT
ST_AsGeoJSON(appellation.geom) AS geom,
ST_AREA(ST_INTERSECTION(input_geom, appellation.geom)::geography) / 10000 AS area,
appellation,
id_uni,
ST_CONTAINS(input_geom, appellation.geom) AS contains
FROM
(
SELECT
communes.insee,
input.geom AS input_geom
FROM
communes,
(SELECT ST_SetSRID(ST_GeomFromGeoJSON('%s'), 4326) geom) input
WHERE ST_Intersects(communes.geom, input.geom)
) AS matching_communes,
appellation
WHERE matching_communes.insee = appellation.insee;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment