-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from pelias/osm_addresses_v2
osm addresses v2
- Loading branch information
Showing
27 changed files
with
1,581 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
|
||
var sqlite3 = require('sqlite3'), | ||
polyline = require('polyline'), | ||
requireDir = require('require-dir'), | ||
query = requireDir('../query'), | ||
project = require('../lib/project'), | ||
proximity = require('../lib/proximity'); | ||
|
||
// polyline precision | ||
var PRECISION = 6; | ||
|
||
// export setup method | ||
function setup( streetDbPath ){ | ||
|
||
// connect to db | ||
sqlite3.verbose(); | ||
// @todo: this is required as the query uses the 'street.' prefix for tables | ||
var db = new sqlite3.Database( ':memory:', sqlite3.OPEN_READONLY ); | ||
|
||
// attach street database | ||
query.attach( db, streetDbPath, 'street' ); | ||
|
||
// query method | ||
var q = function( coord, cb ){ | ||
|
||
var point = { | ||
lat: parseFloat( coord.lat ), | ||
lon: parseFloat( coord.lon ) | ||
}; | ||
|
||
// error checking | ||
if( isNaN( point.lat ) ){ return cb( 'invalid latitude' ); } | ||
if( isNaN( point.lon ) ){ return cb( 'invalid longitude' ); } | ||
|
||
// perform a db lookup for nearby streets | ||
query.near( db, point, function( err, res ){ | ||
|
||
// an error occurred or no results were found | ||
if( err || !res || !res.length ){ return cb( err, null ); } | ||
|
||
// decode polylines | ||
res.forEach( function( street, i ){ | ||
res[i].coordinates = project.dedupe( polyline.toGeoJSON(street.line, PRECISION).coordinates ); | ||
}); | ||
|
||
// order streets by proximity from point (by projecting it on to each line string) | ||
var ordered = proximity.nearest.street( res, [ point.lon, point.lat ] ); | ||
|
||
// return streets ordered ASC by distance from point | ||
cb( null, ordered ); | ||
}); | ||
}; | ||
|
||
// return methods | ||
return { | ||
query: q, | ||
close: db.close.bind( db ), | ||
}; | ||
} | ||
|
||
module.exports = setup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
curved roads, OSM (Lavender Sweep, London) | ||
http://localhost:3000/demo/#18/51.46254/-0.16404 | ||
|
||
good coverage, OSM(Fentiman Road, London) | ||
http://localhost:3000/demo/#18/51.48022/-0.11724 | ||
|
||
http://localhost:3000/demo/#18/51.49117/-0.19861 | ||
|
||
cul-de-sac | ||
http://interpolation.wiz.co.nz/demo/#17/39.75060/-76.66723 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
set -e; | ||
export LC_ALL=en_US.UTF-8; | ||
|
||
# install the latest version of sqlite3 | ||
|
||
# you can fetch the latest version from http://www.sqlite.org/download.html | ||
# look for the version which says "C source code as an amalgamation. Also includes a "configure" script" | ||
|
||
# remove version provided by package manager | ||
sudo apt-get remove sqlite3; | ||
|
||
# download and extract source code | ||
SOURCE="http://www.sqlite.org/2016/sqlite-autoconf-3150100.tar.gz"; | ||
wget -q $SOURCE; | ||
tar xvfz $(basename "$SOURCE"); | ||
|
||
# compile source | ||
cd $(basename "$SOURCE" ".tar.gz"); | ||
./configure; | ||
make -j4; | ||
|
||
# install | ||
sudo make install; | ||
|
||
# echo new version | ||
sqlite3 -version; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
set -e; | ||
export LC_ALL=en_US.UTF-8; | ||
|
||
# import osm data directly from PBF file | ||
|
||
# location of this file in filesystem | ||
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ); | ||
|
||
ADDRESS_DB="/tmp/addr.db"; | ||
STREET_DB="/data/street.db"; | ||
|
||
# location of pbf2json binary | ||
# download from: https://github.com/pelias/pbf2json | ||
PBF2JSON="/var/www/pelias/pbf2json/build/pbf2json.linux-x64"; | ||
|
||
# PBF extract | ||
PBFFILE="/data/extract/greater-london-latest.osm.pbf"; | ||
|
||
# clean up | ||
rm -rf $ADDRESS_DB; | ||
|
||
# run import | ||
$PBF2JSON -tags="addr:housenumber+addr:street" $PBFFILE | $DIR/../interpolate osm $ADDRESS_DB $STREET_DB; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,42 @@ | ||
#!/bin/bash | ||
|
||
# search address table records for max 3 records required to perform interpolation | ||
# search address table records for records required to perform interpolation | ||
|
||
ADDRESS_DB="/data/address.db"; | ||
STREET_DB="/data/street.db"; | ||
|
||
P1="174.766843"; | ||
P2="-41.288788"; | ||
LON="174.766843"; | ||
LAT="-41.288788"; | ||
|
||
NAME="glasgow street"; | ||
NUMBER="18"; | ||
|
||
sqlite3 $ADDRESS_DB "ATTACH DATABASE '$STREET_DB' as 'street'; \ | ||
WITH base AS ( | ||
SELECT address.* FROM street.rtree | ||
JOIN street.names ON street.names.id = street.rtree.id | ||
JOIN address ON address.id = street.rtree.id | ||
WHERE ( | ||
street.rtree.minX<=$P1 AND street.rtree.maxX>=$P1 AND | ||
street.rtree.minY<=$P2 AND street.rtree.maxY>=$P2 | ||
) | ||
AND ( names.name='$NAME' ) | ||
ORDER BY address.housenumber ASC | ||
) | ||
SELECT * FROM ( | ||
(SELECT * FROM base WHERE housenumber < '$NUMBER' ORDER BY housenumber DESC LIMIT 1) | ||
) UNION SELECT * FROM ( | ||
(SELECT * FROM base WHERE housenumber >= '$NUMBER' ORDER BY housenumber ASC LIMIT 2) | ||
) | ||
ORDER BY housenumber ASC | ||
LIMIT 3;"; | ||
WITH base AS ( \ | ||
SELECT address.* FROM street.rtree \ | ||
JOIN street.names ON street.names.id = street.rtree.id \ | ||
JOIN address ON address.id = street.rtree.id \ | ||
WHERE ( \ | ||
street.rtree.minX<=$LON AND street.rtree.maxX>=$LON AND \ | ||
street.rtree.minY<=$LAT AND street.rtree.maxY>=$LAT \ | ||
) \ | ||
AND ( street.names.name='$NAME' ) \ | ||
ORDER BY address.housenumber ASC \ | ||
) \ | ||
SELECT * FROM ( \ | ||
( \ | ||
SELECT * FROM base \ | ||
WHERE housenumber < $NUMBER \ | ||
GROUP BY id HAVING( MAX( housenumber ) ) \ | ||
ORDER BY housenumber DESC \ | ||
) \ | ||
) UNION SELECT * FROM ( \ | ||
( \ | ||
SELECT * FROM base \ | ||
WHERE housenumber >= $NUMBER \ | ||
GROUP BY id HAVING( MIN( housenumber ) ) \ | ||
ORDER BY housenumber ASC \ | ||
) \ | ||
) \ | ||
ORDER BY housenumber ASC \ | ||
LIMIT 20;"; |
Oops, something went wrong.