Permalink
Browse files

feat: add useBestMatch geocoder option

  • Loading branch information...
stepankuzmin committed Sep 20, 2018
1 parent 3831dae commit 77c653b5a66703cbabb1febcaa24bf27f2a35c68
Showing with 58 additions and 62 deletions.
  1. +9 −8 index.js
  2. +1 −1 package.json
  3. +0 −1 src/app.js
  4. +3 −3 src/commands/build.js
  5. +11 −6 src/commands/extract.js
  6. +1 −1 test/app.test.js
  7. +33 −42 yarn.lock
View
@@ -12,19 +12,14 @@ const doc = `
Galton. Lightweight Node.js isochrone server.
Usage:
galton extract (<name> | <bbox>)
galton extract [--useBestMatch] <name>
galton build [--profile=<profileName>] <filename>
galton run [options] <filename>
galton extract build run [options] (<name> | <bbox>)
galton extract build run [--useBestMatch --profile=<profileName>] [options] <name>
galton -h | --help
galton --version
Options:
-h --help Show this screen.
--version Show version.
-p --profile=<profileName> OSRM profile name that will be used for graph building
--algorithm=<algorithm> The algorithm to use for routing. Can be 'CH', 'CoreCH' or 'MLD' [default: CH].
--radius=<radius> Isochrone buffer radius [default: ${defaults.radius}].
--cellSize=<cellSize> Distance across each cell [default: ${defaults.cellSize}].
--concavity=<concavity> Concaveman relative measure of concavity [default: ${
defaults.concavity
@@ -39,8 +34,13 @@ Options:
defaults.lengthThreshold
}].
--port=<port> Port to run on [default: 3000].
--radius=<radius> Isochrone buffer radius [default: ${defaults.radius}].
--sharedMemory Use shared memory [default: false].
--units=<units> Either 'kilometers' or 'miles' [default: ${defaults.units}].
--useBestMatch Geocoder will use the best match for the query
-p --profile=<profileName> OSRM profile name that will be used for graph building
-h --help Show this screen.
--version Show version.
`;
const args = docopt(doc, { version: packagejson.version });
@@ -50,7 +50,8 @@ const main = async () => {
if (args.extract) {
try {
const name = args['<name>'];
extractPath = await commands.extract(name);
const useBestMatch = args['--useBestMatch'];
extractPath = await commands.extract(name, useBestMatch);
} catch (error) {
process.stderr.write(`${error.message}\n`);
process.exit(-1);
View
@@ -52,7 +52,7 @@
},
"dependencies": {
"docopt": "^0.6.2",
"isochrone": "^3.0.1",
"isochrone": "^3.0.2",
"koa": "^2.5.3",
"koa-router": "^7.4.0",
"ora": "^3.0.0",
View
@@ -6,7 +6,6 @@ const createApp = (config) => {
const app = new Koa();
app.context.osrm = new OSRM({
algorithm: config.algorithm,
path: config.osrmPath,
shared_memory: config.sharedMemory
});
View
@@ -23,15 +23,15 @@ const build = async (extractPath, profile) => {
throw new Error(`Couldn't find profile ${profileName}`);
}
spinner.text = 'Extracting graph';
spinner.text = `Extracting graph using ${profileName} profile`;
spinner.start();
const graphPath = await extract(extractPath, profileName).catch((error) => {
spinner.fail(`Couldn't extract graph: ${error.message}`);
throw error;
});
spinner.succeed(`Extracted graph into ${graphPath}`);
spinner.succeed();
spinner.text = 'Contracting graph';
spinner.start();
@@ -41,7 +41,7 @@ const build = async (extractPath, profile) => {
throw error;
});
spinner.succeed(`Contracted graph into ${graphPath}`);
spinner.succeed(`Graph contracted into ${graphPath}`);
return graphPath;
};
View
@@ -1,10 +1,12 @@
/* eslint-disable prefer-destructuring */
const fs = require('fs');
const ora = require('ora');
const path = require('path');
const { geocode, extractWithQuery, buildAreaQuery } = require('osm-extractor');
const { select } = require('./utils');
const extract = async (name) => {
const extract = async (name, useBestMatch = false) => {
const spinner = ora('Geocoding').start();
const results = await geocode(name).catch((error) => {
@@ -20,14 +22,17 @@ const extract = async (name) => {
let result;
if (results.length === 1) {
spinner.succeed();
/* eslint-disable prefer-destructuring */
result = results[0];
} else {
spinner.succeed();
spinner.info(`Found ${results.length} results:`);
const options = results.map(r => r.display_name);
const selectedOptions = await select(options);
result = results[selectedOptions[0].value];
if (useBestMatch) {
result = results[0];
} else {
spinner.info(`Found ${results.length} results:`);
const options = results.map(r => r.display_name);
const selectedOptions = await select(options);
result = results[selectedOptions[0].value];
}
}
spinner.text = 'Extracting';
View
@@ -22,7 +22,7 @@ const points = [[7.41337, 43.72956], [7.41546, 43.73077], [7.41862, 43.73216]];
test.each(points)('isochrone(%f, %f)', async (lng, lat) => {
try {
const response = await request(app)
.get(`/api?lng=${lng}&lat=${lat}`)
.get(`/isochrones?lng=${lng}&lat=${lat}`)
.expect(200)
.expect('Content-Type', /json/);
const errors = geojsonhint.hint(response.text);
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 77c653b

Please sign in to comment.