Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const TfFeature = new Terraformer.Primitive(feature)
return filter.intersects(TfFeature)
}
sql.fn.ST_EnvelopeIntersects = function (feature = {}, filterGeom = {}) {
if (!feature) return false
if (!(feature.type || feature.coordinates)) feature = convertFromEsri(feature) // TODO: remove ? temporary esri geometry conversion
if (!(feature.type && feature.coordinates && feature.coordinates.length > 0)) return false
if (feature.type === 'Point') return sql.fn.ST_Contains(feature, filterGeom)
const filter = new Terraformer.Primitive(filterGeom)
const envelope = transformArray(new Terraformer.Primitive(feature).bbox())
const TfFeature = new Terraformer.Polygon(envelope)
return filter.intersects(TfFeature)
}
sql.fn.geohash = function (geometry = {}, precision) {
if (!geometry || !geometry.type || !geometry.coordinates) return
precision = precision || 8
if (geometry.type !== 'Point') geometry = centroid(geometry).geometry
const pnt = geometry.coordinates
return geohash.encode(pnt[1], pnt[0], precision)
}
sql.fn.pick = function (properties, fields) {
const parsedFields = fields.split(',')
return _.pick(properties, parsedFields)
}
/**
* Select a subset of properties and modify propterties to fit ESRI specs
* @param {object} properties GeoJSON properties
* @param {object} geometry GeoJSON geometry
module.exports = (http) => {
const io = require ('socket.io')(http);
const ConspectioNode = require('./conspectioNode.js');
const alasql = require('alasql');
// custom function that returns array length
alasql.fn.arrlen = function(arr) { return arr.length; };
//create nodeTracker table instead of nodeTracker[] due to compatiability with alasql CRUD operations
alasql('CREATE TABLE nodeTracker');
//max number of leechers per broadcast relayer
const maxRelayers = 1;
const maxBroadcasters = 3;
io.on('connection', (socket) => {
console.log('socket connected', socket.id);
// NOTE: handle more than 1 broadcaster per eventId
//listens for event tag from broadcaster
socket.on('addBroadcaster', (eventId) => {
// add a new broadcaster asssociated with that event id into nodeTracker table
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 = {}) {
if (!feature) return false
if (!(feature.type || feature.coordinates)) feature = convertFromEsri(feature) // TODO: remove ? temporary esri geometry conversion
sql.fn.ST_Intersects = function (feature = {}, filterGeom = {}) {
if (!feature) return false
if (!(feature.type || feature.coordinates)) feature = convertFromEsri(feature) // TODO: remove ? temporary esri geometry conversion
if (!(feature.type && feature.coordinates && feature.coordinates.length > 0)) return false
if (feature.type === 'Point') return sql.fn.ST_Contains(feature, filterGeom)
const filter = new Terraformer.Primitive(filterGeom)
const TfFeature = new Terraformer.Primitive(feature)
return filter.intersects(TfFeature)
}
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 = {}) {
if (!feature) return false
if (!(feature.type || feature.coordinates)) feature = convertFromEsri(feature) // TODO: remove ? temporary esri geometry conversion
if (!(feature.type && feature.coordinates && feature.coordinates.length > 0)) return false
if (feature.type === 'Point') return sql.fn.ST_Contains(feature, filterGeom)
const filter = new Terraformer.Primitive(filterGeom)
const TfFeature = new Terraformer.Primitive(feature)
return filter.intersects(TfFeature)
}
sql.fn.ST_EnvelopeIntersects = function (feature = {}, filterGeom = {}) {
if (!feature) return false
if (!(feature.type || feature.coordinates)) feature = convertFromEsri(feature) // TODO: remove ? temporary esri geometry conversion
if (!(feature.type && feature.coordinates && feature.coordinates.length > 0)) return false
if (feature.type === 'Point') return sql.fn.ST_Contains(feature, filterGeom)
const filter = new Terraformer.Primitive(filterGeom)
const envelope = transformArray(new Terraformer.Primitive(feature).bbox())
if (feature.type === 'Point') return sql.fn.ST_Contains(feature, filterGeom)
const filter = new Terraformer.Primitive(filterGeom)
const envelope = transformArray(new Terraformer.Primitive(feature).bbox())
const TfFeature = new Terraformer.Polygon(envelope)
return filter.intersects(TfFeature)
}
sql.fn.geohash = function (geometry = {}, precision) {
if (!geometry || !geometry.type || !geometry.coordinates) return
precision = precision || 8
if (geometry.type !== 'Point') geometry = centroid(geometry).geometry
const pnt = geometry.coordinates
return geohash.encode(pnt[1], pnt[0], precision)
}
sql.fn.pick = function (properties, fields) {
const parsedFields = fields.split(',')
return _.pick(properties, parsedFields)
}
/**
* Select a subset of properties and modify propterties to fit ESRI specs
* @param {object} properties GeoJSON properties
* @param {object} geometry GeoJSON geometry
* @param {string} dateFields comma-delimited list of date fields
* @param {string} requiresObjectId boolean-string flagging requirement of OBJECTID as part of properties
* @param {string} idField name of attribute to be used as OBJECTID
*/
sql.fn.pickAndEsriFy = function (properties, geometry, fields, dateFields, requiresObjectId, idField) {
const parsedFields = fields.split(',')
const esriProperties = esriFy(properties, geometry, dateFields, requiresObjectId, idField)
return _.pick(esriProperties, parsedFields)
}
sql.fn.pick = function (properties, fields) {
const parsedFields = fields.split(',')
return _.pick(properties, parsedFields)
}
/**
* Select a subset of properties and modify propterties to fit ESRI specs
* @param {object} properties GeoJSON properties
* @param {object} geometry GeoJSON geometry
* @param {string} dateFields comma-delimited list of date fields
* @param {string} requiresObjectId boolean-string flagging requirement of OBJECTID as part of properties
* @param {string} idField name of attribute to be used as OBJECTID
*/
sql.fn.pickAndEsriFy = function (properties, geometry, fields, dateFields, requiresObjectId, idField) {
const parsedFields = fields.split(',')
const esriProperties = esriFy(properties, geometry, dateFields, requiresObjectId, idField)
return _.pick(esriProperties, parsedFields)
}
sql.fn.esriFy = esriFy
sql.fn.esriGeom = function (geometry) {
if (geometry && geometry.type) {
return convertToEsri(geometry)
}
}
sql.fn.project = function (geometry, projection) {
if (!(geometry && geometry.coordinates) || !projection) return geometry
try {
* Select a subset of properties and modify propterties to fit ESRI specs
* @param {object} properties GeoJSON properties
* @param {object} geometry GeoJSON geometry
* @param {string} dateFields comma-delimited list of date fields
* @param {string} requiresObjectId boolean-string flagging requirement of OBJECTID as part of properties
* @param {string} idField name of attribute to be used as OBJECTID
*/
sql.fn.pickAndEsriFy = function (properties, geometry, fields, dateFields, requiresObjectId, idField) {
const parsedFields = fields.split(',')
const esriProperties = esriFy(properties, geometry, dateFields, requiresObjectId, idField)
return _.pick(esriProperties, parsedFields)
}
sql.fn.esriFy = esriFy
sql.fn.esriGeom = function (geometry) {
if (geometry && geometry.type) {
return convertToEsri(geometry)
}
}
sql.fn.project = function (geometry, projection) {
if (!(geometry && geometry.coordinates) || !projection) return geometry
try {
return {
type: geometry.type,
coordinates: projectCoordinates(geometry.coordinates, { toSR: projection })
}
} catch (e) {
return null
}
}
*/
sql.fn.pickAndEsriFy = function (properties, geometry, fields, dateFields, requiresObjectId, idField) {
const parsedFields = fields.split(',')
const esriProperties = esriFy(properties, geometry, dateFields, requiresObjectId, idField)
return _.pick(esriProperties, parsedFields)
}
sql.fn.esriFy = esriFy
sql.fn.esriGeom = function (geometry) {
if (geometry && geometry.type) {
return convertToEsri(geometry)
}
}
sql.fn.project = function (geometry, projection) {
if (!(geometry && geometry.coordinates) || !projection) return geometry
try {
return {
type: geometry.type,
coordinates: projectCoordinates(geometry.coordinates, { toSR: projection })
}
} catch (e) {
return null
}
}
sql.fn.reducePrecision = function (geometry, precision) {
if (!(geometry && geometry.coordinates)) return geometry
return {
type: geometry.type,
coordinates: reducePrecision(geometry.coordinates, precision)
}
}
sql.fn.project = function (geometry, projection) {
if (!(geometry && geometry.coordinates) || !projection) return geometry
try {
return {
type: geometry.type,
coordinates: projectCoordinates(geometry.coordinates, { toSR: projection })
}
} catch (e) {
return null
}
}
sql.fn.reducePrecision = function (geometry, precision) {
if (!(geometry && geometry.coordinates)) return geometry
return {
type: geometry.type,
coordinates: reducePrecision(geometry.coordinates, precision)
}
}
sql.aggr.hash = function (value, obj, acc) {
obj = obj || {}
if (obj[value]) obj[value]++
else obj[value] = 1
return obj
}
/**
* Modify propterties to fit ESRI specs