Skip to content

Commit

Permalink
feat(adm2): add query for adm level 2
Browse files Browse the repository at this point in the history
  • Loading branch information
willian-viana committed Oct 8, 2024
1 parent ed4cd22 commit 708cacd
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions services/geostore.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ const fetchGeostoreFromRWApi = ({ url, token }) =>

const fetchGeostoreFromDataApi = ({ adm0, adm1, adm2, token }) => {
const COUNTRY = adm0 ? `gid_0='${adm0}'` : '';
const REGION = adm1 ? `AND gid_1='${adm1}_1'` : '';
const SUBREGION = adm2 ? `AND gid_2='${adm2}_1'` : '';
const REGION = adm1 ? ` AND gid_1='${adm0}.${adm1}_1'` : '';
const SUBREGION = adm2 ? ` AND gid_2 LIKE '${adm0}.${adm1}.${adm2}_%'` : '';

const query = `SELECT country, gfw_bbox, gfw_geostore_id,
ST_AsGeoJSON(ST_SimplifyPreserveTopology(ST_RemoveRepeatedPoints(geom, 0.05), 0.05)) AS gfw_geojson
FROM gadm_administrative_boundaries
WHERE ${COUNTRY} ${REGION} ${SUBREGION} limit 1`;
const admLevel = (adm1 && adm2 ? 2 : 1) || 0;
const query = `SELECT gfw_bbox, gfw_geostore_id,
ST_AsGeoJSON(ST_SimplifyPreserveTopology(ST_RemoveRepeatedPoints(geom, 0.005), 0.005)) AS gfw_geojson
FROM gadm_administrative_boundaries WHERE adm_level='${admLevel}' AND ${COUNTRY}${REGION}${SUBREGION} limit 1`;

return getDatasetQuery({
dataset: 'gadm_administrative_boundaries',
Expand All @@ -66,17 +66,15 @@ const fetchGeostoreFromDataApi = ({ adm0, adm1, adm2, token }) => {
id: gfw_geostore_id,
bbox: gfw_bbox,
geojson: {
crs: {},
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: {
...parsed_gfw_geojson,
},
properties: null,
type: 'Feature',
},
],
type: 'FeatureCollection',
},
};
});
Expand Down

0 comments on commit 708cacd

Please sign in to comment.