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