provider-geo-lookup
Lookup a Lambda based on a PostGIS database
Usage
npm install provider-geo-lookup
- Configure
config.js
or set environment variables like soPOSTGRESQL_DB_URL
- connection string starting withpostgres://
and not including databasePOSTGRESQL_DB_NAME
- the PostGIS database to use
var geolookup = require('provider-geo-lookup')
API
flushDB()
Drops the PostGIS table used by the module
geolookup.flushDB().then(function() {
console.log('Table dropped')
},function(err) {
console.log('Error flushing', err)
})
initDB([params])
Creates the table and loads data from taxi.json
var params = { createExtension: false, importData: false };
geolookup.initDB(params).then(function(){ // params is optional
console.log('Table created')
},function(err) {
console.log('Error creating DB', err)
})
providerForLocation(providerType, geoLocation)
Does the geo lookup for a given provider type, and a given lat,lng
string
geolookup.providerForLocation('ondemand',"60.3463,24.245").then(
function(providers) {
console.log('Provider:', providers)
},function(err) {
console.log('Error fetching provider', err)
})
selectAllProviders([providerType],[point])
Return all providers up to a limit, sorted by distance. Arguments can both be null or both must be supplied.
geolookup.selectAllProviders("ondemand", "65.18303007291382,29.9267578125").then(
function(providers) {
console.log('Provider:', providers)
},function(err) {
console.log('Error fetching provider', err)
})
### insertProvider({...})
Add a provider to the database. Provider must be in the format as below.
Note that the database only supports Polygon
shapes, a MultiPolygon
or LineString
will fail.
var provider = {
"maasProviderType": "ondemand",
"maasProviderName": "MaaS-provider-ondemand-mytaxiprovider",
"priority": 1,
"location": {"type":"Polygon","coordinates":[...]}
}
geolookup.insertProvider(provider).then(
function(provider) {
console.log('Inserted:', provider)
},function(err) {
console.log('Error inserting provider', err)
})
Deleting data?
Not implemented :)