Use ST_DWithin()

This commit is contained in:
Daniel García Aubert 2019-12-16 12:30:28 +01:00
parent 1829a634e9
commit da07d550d2

View File

@ -1,24 +1,16 @@
'use strict';
const debug = require('debug')('windshaft:filter:circle');
function filterQueryTpl ({ sql, column, srid, lng, lat, radius } = {}) {
function filterQueryTpl ({ sql, column, srid, lng, lat, radiusInMeters } = {}) {
return `
SELECT
*
FROM (${sql}) _cdb_circle_filter
WHERE
ST_Intersects(
${column},
ST_Transform(
ST_Buffer(
ST_Transform(
ST_SetSRID(ST_Point(${lng},${lat}), 3857),
4326
)::geography,
${radius}
)::geometry,
${srid}
)
ST_DWithin(
${srid === 3857 ? `ST_Transform(${column}, 4326)::geography` : `${column}::geography`},
ST_SetSRID(ST_Point(${lng}, ${lat}), 4326)::geography,
${radiusInMeters}
)
`;
}
@ -51,7 +43,7 @@ module.exports = class CircleFilter {
srid: this.srid,
lng: this.lng,
lat: this.lat,
radius: this.radius
radiusInMeters: this.radius
});
debug(circleSql);