Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 53 additions & 4 deletions API/Backend/Geodatasets/routes/geodatasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,17 @@ function get(reqtype, req, res, next) {
if (filters != null && filters.length > 0) {
let filterSQL = [];
filters.forEach((f, i) => {
replacements[`filter_key_${i}`] = f.key;
let fkey = f.key;
let derivedKey = false;
if (fkey === "Latitude (Centroid)") {
fkey = `ST_Y(ST_Centroid(geom))`;
derivedKey = true;
} else if (fkey === "Longitude (Centroid)") {
fkey = `ST_X(ST_Centroid(geom))`;
derivedKey = true;
}

replacements[`filter_key_${i}`] = fkey;
replacements[`filter_value_${i}`] = f.value;
let op = "=";
switch (f.op) {
Expand Down Expand Up @@ -271,17 +281,48 @@ function get(reqtype, req, res, next) {
}
if (f.type === "number") {
filterSQL.push(
`(properties->>:filter_key_${i})::FLOAT ${op} ${value}`
`${
derivedKey === true
? `${fkey}`
: `(properties->>:filter_key_${i})`
}::FLOAT ${op} ${value}`
);
} else {
filterSQL.push(`properties->>:filter_key_${i} ${op} ${value}`);
filterSQL.push(
`${
derivedKey === true
? `${fkey}`
: `properties->>:filter_key_${i}`
} ${op} ${value}`
);
}
});
q += `${
q.indexOf(" WHERE ") == -1 ? " WHERE " : " AND "
q.indexOf(" WHERE ") === -1 ? " WHERE " : " AND "
}${filterSQL.join(` AND `)}`;
}

if (
spatialFilter?.lat != null &&
spatialFilter?.lng != null &&
spatialFilter?.radius != null
) {
// prettier-ignore
q += `${
q.indexOf(" WHERE ") === -1 ? " WHERE " : " AND "
}ST_Intersects(
geom,
ST_Transform(
ST_Buffer(
ST_Transform(
ST_SetSRID(ST_MakePoint(${parseFloat(spatialFilter.lng)}, ${parseFloat(spatialFilter.lat)}), 4326), 3857
),
${parseFloat(spatialFilter.radius)}
),
4326
))`;
}

if (req.query?.limited) {
q += ` ORDER BY id DESC LIMIT 3`;
}
Expand Down Expand Up @@ -739,6 +780,14 @@ router.get("/aggregations", function (req, res, next) {
});
aggs[agg].aggs = sortedAggs;
});
aggs["Latitude (Centroid)"] = {
type: "number",
aggs: {},
};
aggs["Longitude (Centroid)"] = {
type: "number",
aggs: {},
};

res.send({ status: "success", aggregations: aggs });
})
Expand Down
4 changes: 2 additions & 2 deletions src/essence/Basics/Layers_/Filtering/Filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ const Filtering = {
"</div>",
"<div id='layerTool_filtering_filters'>",
"<ul id='layerTool_filtering_filters_list'></ul>",
Filtering.current.needsToQueryGeodataset === true ? null : [`<ul id='layerTool_filtering_filters_spatial' class='${spatialActive ? 'drawn' : ''}'>`,
`<ul id='layerTool_filtering_filters_spatial' class='${spatialActive ? 'drawn' : ''}'>`,
`<div id='layerTool_filtering_filters_spatial_draw' class='mmgisButton5' title='Place a point on the map to enable a spatial filter.'><i class='mdi mdi-pencil mdi-14px'></i><div>${spatialActive ? 'Active' : 'Place Point'}</div></div>`,
"<div id='layerTool_filtering_filters_spatial_radius_wrapper' title='Radius\n= 0: Queries for features that contain this point.\n> 0: Queries for features intersecting this circle.'>",
"<div>R:</div>",
`<input id='layerTool_filtering_filters_spatial_radius' type='number' placeholder='Radius' value='${Filtering.filters[layerName].spatial.radius || 0}' min='0'></input>`,
"<div>m</div>",
"</div>",
"<div id='layerTool_filtering_filters_spatial_clear' class='mmgisButton5 layerTool_filtering_filters_clear'><i class='mdi mdi-close mdi-18px'></i></div>",
"</ul>"].join('\n'),
"</ul>",
"</div>",
`<div id='layersTool_filtering_footer'>`,
"<div id='layersTool_filtering_clear' class='mmgisButton5'><div>Clear Filter</div></div>",
Expand Down
18 changes: 12 additions & 6 deletions src/essence/Basics/Layers_/Filtering/GeodatasetFilterer.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ const GeodatasetFilterer = {
if (L_.layers.data[layerName]._filter) {
let fspatial = L_.layers.data[layerName]._filter.spatial
let fvalues = L_.layers.data[layerName]._filter.values
if (fspatial != null && fspatial.radius > 0)
if (
fspatial != null &&
fspatial.radius > 0 &&
fspatial.center?.lat != null &&
fspatial.center?.lng != null
)
L_.layers.data[
layerName
]._filterEncoded.spatialFilter = `${fspatial.center.lat},${fspatial.center.lng},${fspatial.radius}`
Expand All @@ -81,11 +86,12 @@ const GeodatasetFilterer = {
if (fvalues.length > 0) {
let encoded = []
fvalues.forEach((v) => {
encoded.push(
`${v.key}+${v.op === ',' ? 'in' : v.op}+${
v.type
}+${v.value.replaceAll(',', '$')}`
)
if (v.value != null && v.key != null)
encoded.push(
`${v.key}+${v.op === ',' ? 'in' : v.op}+${
v.type
}+${v.value.replaceAll(',', '$')}`
)
})
L_.layers.data[layerName]._filterEncoded.filters =
encoded.join(',')
Expand Down