Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const sql = require('alasql')
const geohash = require('ngeohash')
const centroid = require('@turf/centroid').default
const _ = require('lodash')
const projectCoordinates = require('./geometry/project-coordinates')
const reducePrecision = require('./geometry/reduce-precision')
// Try to require farmhash, as it is an optional depenecy we can fall back to JavaScript only hashing library
let hashFunction
try {
hashFunction = require('farmhash').hash32
} catch (e) {
hashFunction = require('string-hash')
}
sql.MAXSQLCACHESIZE = 0
sql.fn.ST_Within = function (feature = {}, filterGeom = {}) {
if (!(feature && feature.type && feature.coordinates && feature.coordinates.length > 0)) return false
const filter = new Terraformer.Primitive(filterGeom)
const TfFeature = new Terraformer.Primitive(feature)
return TfFeature.within(filter)
}
sql.fn.ST_Contains = function (feature = {}, filterGeom = {}) {
if (!(feature && feature.type && feature.coordinates && feature.coordinates.length > 0)) return false
const filter = new Terraformer.Primitive(filterGeom)
const TfFeature = new Terraformer.Primitive(feature)
return filter.contains(TfFeature)
}
sql.fn.ST_Intersects = function (feature = {}, filterGeom = {}) {