mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-14 01:47:57 +00:00
Compare commits
956 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee8915f2b6 | ||
|
|
5475bf7b9c | ||
|
|
95e2d8c846 | ||
|
|
7552818866 | ||
|
|
db3991af74 | ||
|
|
4523b9aaed | ||
|
|
8b1cabebd6 | ||
|
|
0cf636a80c | ||
|
|
c2cb6722fe | ||
|
|
f8337bedb2 | ||
|
|
efc09a5cfc | ||
|
|
86ad9efa8a | ||
|
|
d984100e23 | ||
|
|
499110f549 | ||
|
|
267e5dac0d | ||
|
|
32d3eb46d5 | ||
|
|
c8a0dc8af1 | ||
|
|
14ecfc7834 | ||
|
|
cad44eb00c | ||
|
|
f76dbb0a16 | ||
|
|
8dd218a1d0 | ||
|
|
501e13483e | ||
|
|
b1d25e404f | ||
|
|
71fceb6854 | ||
|
|
a06e123d70 | ||
|
|
df6f70d223 | ||
|
|
9058dabf1a | ||
|
|
2535780282 | ||
|
|
48333bfbd4 | ||
|
|
99cf552c17 | ||
|
|
ad214753fc | ||
|
|
0d500d4bd1 | ||
|
|
b1e5265d33 | ||
|
|
e2a9b5fdf7 | ||
|
|
eeb3d5dd0a | ||
|
|
a75dd32f75 | ||
|
|
e1e8182c72 | ||
|
|
59bce26afe | ||
|
|
d1b7c14f79 | ||
|
|
59416178bd | ||
|
|
70e351c528 | ||
|
|
1eed2fa395 | ||
|
|
438b8fed35 | ||
|
|
4760e8341b | ||
|
|
639630d5fe | ||
|
|
5b40aa579b | ||
|
|
fbb6edfdaf | ||
|
|
2b87c016db | ||
|
|
a894e0f3a4 | ||
|
|
046665f8d9 | ||
|
|
d9b4d1591d | ||
|
|
0862671104 | ||
|
|
416e70b97e | ||
|
|
494640c535 | ||
|
|
abe9737229 | ||
|
|
5d237a06ea | ||
|
|
d5bfab02c2 | ||
|
|
79836e51d6 | ||
|
|
0770eaa5d0 | ||
|
|
c172ca8c6c | ||
|
|
4e59efa178 | ||
|
|
9cf5970e22 | ||
|
|
4cce681ead | ||
|
|
c4a726c96b | ||
|
|
a408da4ccc | ||
|
|
e0318344f6 | ||
|
|
02364ce6c8 | ||
|
|
bf683d434b | ||
|
|
f1ba285319 | ||
|
|
98c1b923fc | ||
|
|
fd1f2bc719 | ||
|
|
689bcbd6ea | ||
|
|
3acd7df5c4 | ||
|
|
7d418da564 | ||
|
|
04d5f674eb | ||
|
|
23369ce970 | ||
|
|
20d0fb35ce | ||
|
|
754ff15ebd | ||
|
|
7c9002cae7 | ||
|
|
1a64c3bfcd | ||
|
|
2735ea768a | ||
|
|
ae8694a6a6 | ||
|
|
5ec07321d4 | ||
|
|
d77aa7dfc9 | ||
|
|
122ecd4626 | ||
|
|
1f07967787 | ||
|
|
8c14df55a6 | ||
|
|
af756d61dd | ||
|
|
2d115ea412 | ||
|
|
981b879830 | ||
|
|
6415c9cf95 | ||
|
|
7b21354a8a | ||
|
|
ad50016c49 | ||
|
|
b9e4563beb | ||
|
|
2c0f2e1ede | ||
|
|
ea98317370 | ||
|
|
2fe8b98d55 | ||
|
|
6299afcad7 | ||
|
|
5160a1d577 | ||
|
|
83013f819b | ||
|
|
15eb7f0bb1 | ||
|
|
b2dc01ad81 | ||
|
|
c2aa7a9b43 | ||
|
|
90e207a497 | ||
|
|
d856788bf5 | ||
|
|
f960a9bf7f | ||
|
|
188c770f5c | ||
|
|
a690605a96 | ||
|
|
290c22a153 | ||
|
|
4825a0bda3 | ||
|
|
b54ff7d766 | ||
|
|
9734bbf240 | ||
|
|
d4f3eda314 | ||
|
|
74c39267d9 | ||
|
|
b87d6226fb | ||
|
|
e92e03e2e6 | ||
|
|
9545f0bf80 | ||
|
|
c4f30de7a3 | ||
|
|
7717bbf59d | ||
|
|
7ba5152493 | ||
|
|
6bc044d9c7 | ||
|
|
06683edaae | ||
|
|
979aebbfcd | ||
|
|
3734f1d0b8 | ||
|
|
a66c063314 | ||
|
|
fe0ade81f5 | ||
|
|
f52212abbd | ||
|
|
8f30a32466 | ||
|
|
157c3cccd1 | ||
|
|
3e6be0b0be | ||
|
|
882fb16881 | ||
|
|
72be143cef | ||
|
|
086116b3a1 | ||
|
|
ed7f0d9e46 | ||
|
|
b5a6d7a4a6 | ||
|
|
7f11de0db9 | ||
|
|
f535340d5a | ||
|
|
c7d80a2cc8 | ||
|
|
0efdd1b9a6 | ||
|
|
fd9437277e | ||
|
|
968f1cd453 | ||
|
|
adce7261ac | ||
|
|
b01a836d1e | ||
|
|
c2594aca40 | ||
|
|
8b41b80bff | ||
|
|
feb8cc29a5 | ||
|
|
1cd8ffad0b | ||
|
|
d648561a87 | ||
|
|
8e8f7a641b | ||
|
|
69369c08c8 | ||
|
|
fdb3fc2f7b | ||
|
|
054efc8311 | ||
|
|
d7cf81c047 | ||
|
|
19eb4d91a0 | ||
|
|
5a61d3d5f6 | ||
|
|
52ee5dc73c | ||
|
|
0c25e80be0 | ||
|
|
4e0602919c | ||
|
|
d22ca186e4 | ||
|
|
4f4a288757 | ||
|
|
14cc047cf4 | ||
|
|
043d52821c | ||
|
|
3905dd68dd | ||
|
|
bd0316b5c3 | ||
|
|
fd33ef92dc | ||
|
|
6527b7cdcd | ||
|
|
3cc20581ae | ||
|
|
a2a44b875a | ||
|
|
a14ab1c08c | ||
|
|
0ba3d01982 | ||
|
|
f6e792f31b | ||
|
|
882f182374 | ||
|
|
d1e7b85cc5 | ||
|
|
6b1c32893b | ||
|
|
474a22cb3b | ||
|
|
8e46458d9e | ||
|
|
7282d816c8 | ||
|
|
7cf21f8caf | ||
|
|
738e99ce71 | ||
|
|
e104115134 | ||
|
|
f0390cfe85 | ||
|
|
a4d7cdd2ad | ||
|
|
2914284a83 | ||
|
|
a97bfaf26c | ||
|
|
cfe5284f64 | ||
|
|
2048009600 | ||
|
|
d47acbc18a | ||
|
|
f5fd2f0e7a | ||
|
|
c8d45972bb | ||
|
|
474aea61da | ||
|
|
67462e0953 | ||
|
|
804fb5f93e | ||
|
|
f52097c064 | ||
|
|
d336b81293 | ||
|
|
507c0286da | ||
|
|
04a3f39371 | ||
|
|
bc75e5626e | ||
|
|
0add25e335 | ||
|
|
253dc7d7cd | ||
|
|
221b5cd8a2 | ||
|
|
9659afbade | ||
|
|
3742fa2929 | ||
|
|
71249bd94a | ||
|
|
e3353deee0 | ||
|
|
00563a1fa2 | ||
|
|
b8686c19a0 | ||
|
|
b89144dcb2 | ||
|
|
8e5a19b392 | ||
|
|
5d12121f6d | ||
|
|
24f103dcbe | ||
|
|
0109f167f9 | ||
|
|
b63633857e | ||
|
|
8cb0d5b262 | ||
|
|
e51973f8b1 | ||
|
|
c314a3092c | ||
|
|
8dafd8bcb6 | ||
|
|
ecf4693a79 | ||
|
|
fa1c402b47 | ||
|
|
4da4cbfe27 | ||
|
|
139cea5720 | ||
|
|
e2416f90af | ||
|
|
1e88321371 | ||
|
|
a93ec09932 | ||
|
|
9abf2c248e | ||
|
|
ab746eebaf | ||
|
|
3ba330c948 | ||
|
|
aef1357066 | ||
|
|
5d302a03a6 | ||
|
|
3a8c5df82d | ||
|
|
44d5148e5f | ||
|
|
63da70685a | ||
|
|
2bab0ca060 | ||
|
|
c903559415 | ||
|
|
6511821001 | ||
|
|
75abf237a6 | ||
|
|
dc7c11a9d1 | ||
|
|
44fface92a | ||
|
|
6e89310a92 | ||
|
|
0fb4fe8e4d | ||
|
|
b0067a0345 | ||
|
|
4c72cdaa86 | ||
|
|
350bb0e1cd | ||
|
|
ad95ff1d06 | ||
|
|
90eea6b909 | ||
|
|
5b02cd22b9 | ||
|
|
60b03d506f | ||
|
|
5c7073901e | ||
|
|
b33afee468 | ||
|
|
6a748204ff | ||
|
|
9889c72c55 | ||
|
|
01f0f453dd | ||
|
|
7f0d969d71 | ||
|
|
a47fa07558 | ||
|
|
2b3ea0abb7 | ||
|
|
755ae0ef94 | ||
|
|
ccb5cf155d | ||
|
|
7080a13c54 | ||
|
|
cf2697f8f4 | ||
|
|
a6b829e4a0 | ||
|
|
f92e580293 | ||
|
|
bc84db6460 | ||
|
|
77631f90fd | ||
|
|
332de72045 | ||
|
|
a2cf6db61b | ||
|
|
82a98f3780 | ||
|
|
7fb3ef4633 | ||
|
|
8f3845660f | ||
|
|
d2bf986eae | ||
|
|
9410263485 | ||
|
|
82970e2b4f | ||
|
|
f923304eea | ||
|
|
1a0f851d0d | ||
|
|
28444d9435 | ||
|
|
8c54f9d704 | ||
|
|
c24dc56c65 | ||
|
|
5c4c98d17e | ||
|
|
657aae5f1b | ||
|
|
38798bba13 | ||
|
|
05eb1d5f42 | ||
|
|
fe873ad0e2 | ||
|
|
bdded69ab6 | ||
|
|
9f42c3f3b8 | ||
|
|
424ebd7fe9 | ||
|
|
78c19bc006 | ||
|
|
e53eb79923 | ||
|
|
c39fc5d180 | ||
|
|
a96b6a1289 | ||
|
|
8f6f113e1c | ||
|
|
436aff2fd3 | ||
|
|
44922af20e | ||
|
|
4315debff5 | ||
|
|
ace84ed0e3 | ||
|
|
ff3230a7f3 | ||
|
|
07b7fd1dbb | ||
|
|
bb5de9b955 | ||
|
|
40b87bbadf | ||
|
|
1c195eb1e4 | ||
|
|
9c48726691 | ||
|
|
4fa349315b | ||
|
|
50beac8305 | ||
|
|
9de6bdd7dd | ||
|
|
6e688a0113 | ||
|
|
dc7cfd1708 | ||
|
|
e5a5f02666 | ||
|
|
11ced26025 | ||
|
|
edb1eec46d | ||
|
|
63eacc5589 | ||
|
|
e929693cae | ||
|
|
ae7c584e28 | ||
|
|
4d5faf9423 | ||
|
|
b7eea4d53a | ||
|
|
dd2c794de5 | ||
|
|
3b6d35fc12 | ||
|
|
9fa73cfb15 | ||
|
|
62b7670e0c | ||
|
|
d7bb449e74 | ||
|
|
247065ff6f | ||
|
|
9a84adef59 | ||
|
|
1879cf902c | ||
|
|
019a68a4bb | ||
|
|
110491011f | ||
|
|
36b1660121 | ||
|
|
56201feb28 | ||
|
|
c6d40d4bf4 | ||
|
|
a4f2e6a893 | ||
|
|
b427fc7965 | ||
|
|
e264604894 | ||
|
|
3a5d9f0377 | ||
|
|
8be27015b2 | ||
|
|
100391fb8e | ||
|
|
dc1baaa0af | ||
|
|
7205491b84 | ||
|
|
918fec73c6 | ||
|
|
b6df486525 | ||
|
|
8bd8a040e0 | ||
|
|
781e83ddc3 | ||
|
|
5afd96d210 | ||
|
|
cf49a070fd | ||
|
|
4aba36c5ac | ||
|
|
ca6e65fff1 | ||
|
|
1e0025b095 | ||
|
|
173e85c9e6 | ||
|
|
ffb467028e | ||
|
|
05fad607ff | ||
|
|
19360a9552 | ||
|
|
b087f3ab7b | ||
|
|
2c8fb31381 | ||
|
|
b2d3f0a8b3 | ||
|
|
bd8025feab | ||
|
|
4c19762e33 | ||
|
|
1015ac40ae | ||
|
|
4ce13f5c1f | ||
|
|
2833362cf6 | ||
|
|
bc51378aee | ||
|
|
39039e2a55 | ||
|
|
f523c01571 | ||
|
|
81eed0680c | ||
|
|
33c0f249b1 | ||
|
|
76eadc562c | ||
|
|
3cc3e3b2e3 | ||
|
|
f07f8530a8 | ||
|
|
103800a732 | ||
|
|
f9ba7a465a | ||
|
|
fed46240d5 | ||
|
|
2703442fd2 | ||
|
|
2813bf18e6 | ||
|
|
dcebea376d | ||
|
|
b3a2b3d484 | ||
|
|
7321e66d08 | ||
|
|
9627352ee4 | ||
|
|
bfc7acbb18 | ||
|
|
e0ca2ce6ec | ||
|
|
b969c5a62f | ||
|
|
28f7e51279 | ||
|
|
d35eb4105e | ||
|
|
b2afe3ce3e | ||
|
|
7337898b84 | ||
|
|
4305160c91 | ||
|
|
dc52d0954e | ||
|
|
d3a575319f | ||
|
|
2592bf1954 | ||
|
|
88d7ffa274 | ||
|
|
474d4230b8 | ||
|
|
10a5424a71 | ||
|
|
7eb04f67e2 | ||
|
|
1d7e078a2c | ||
|
|
f03ec3ea12 | ||
|
|
8e90fa3395 | ||
|
|
02af0a2c87 | ||
|
|
fa4e5513d1 | ||
|
|
93afe5a7c3 | ||
|
|
af85ad390f | ||
|
|
ab45db5360 | ||
|
|
89094cf92e | ||
|
|
3f5484f48f | ||
|
|
ff06b64329 | ||
|
|
6d39563b87 | ||
|
|
0d840c8d4e | ||
|
|
381bd0b576 | ||
|
|
b5c61e0b5b | ||
|
|
df6eddebcd | ||
|
|
b6c8c0e72b | ||
|
|
b06f5fddcb | ||
|
|
8791c6cb69 | ||
|
|
615b166c68 | ||
|
|
c41f2fed21 | ||
|
|
05e47fbb28 | ||
|
|
1b7c8240ba | ||
|
|
c4fd3ab97f | ||
|
|
8c7140d92b | ||
|
|
3969ce0f55 | ||
|
|
4f5f5ea8fc | ||
|
|
5f7cc91cf9 | ||
|
|
424c1f0d41 | ||
|
|
cff05394a1 | ||
|
|
638b40c3ec | ||
|
|
53d2050dc5 | ||
|
|
97ac036df5 | ||
|
|
482f7fe3ba | ||
|
|
567c31ab6a | ||
|
|
7d28fc35d1 | ||
|
|
c06f902398 | ||
|
|
59ae63e6f5 | ||
|
|
9c7d947fd1 | ||
|
|
58db0ad6d8 | ||
|
|
3b09c39dbf | ||
|
|
db917cb0d4 | ||
|
|
ba6cdd875d | ||
|
|
d231ff60ed | ||
|
|
c74904d075 | ||
|
|
22204050f2 | ||
|
|
667197a47e | ||
|
|
e8b866aa88 | ||
|
|
e7b8e1a2c2 | ||
|
|
279b4fd6d2 | ||
|
|
b7c83d3580 | ||
|
|
d4018f2e3b | ||
|
|
38369ca3cf | ||
|
|
cc0bdd34e9 | ||
|
|
8e71ff329c | ||
|
|
b4e3d0ea44 | ||
|
|
992703b15e | ||
|
|
ba5ec80611 | ||
|
|
1c1447e709 | ||
|
|
3c32c0354a | ||
|
|
8a2c6067a2 | ||
|
|
d60a45715a | ||
|
|
3c7a28dab0 | ||
|
|
0c72a434e0 | ||
|
|
32e7b59b1f | ||
|
|
f448423727 | ||
|
|
b2319e52ff | ||
|
|
25279d009a | ||
|
|
3f72ca4bca | ||
|
|
70dc4957dc | ||
|
|
d8ed565bce | ||
|
|
a7f5c6c8f5 | ||
|
|
a8b023e57e | ||
|
|
47ca56f21b | ||
|
|
580a7b032f | ||
|
|
8fcc2bb7f5 | ||
|
|
d6fe58f84e | ||
|
|
2d54de09bb | ||
|
|
4e4d29f653 | ||
|
|
195c13ee8a | ||
|
|
ac5ef64701 | ||
|
|
e7dc24c026 | ||
|
|
155f26060d | ||
|
|
a87fe8d8bf | ||
|
|
158df6b2e8 | ||
|
|
b8db76c925 | ||
|
|
fffdfc9b88 | ||
|
|
6478409b05 | ||
|
|
ee556fd42e | ||
|
|
9a1b8a67d6 | ||
|
|
383e3ccd25 | ||
|
|
b4ce1fb599 | ||
|
|
2bf8e62580 | ||
|
|
afb439b089 | ||
|
|
78a87ad16b | ||
|
|
5bf55a69a5 | ||
|
|
ca782e2f20 | ||
|
|
308de35802 | ||
|
|
a9ac68a729 | ||
|
|
84d6b481ae | ||
|
|
613c8635a8 | ||
|
|
899a04ad26 | ||
|
|
d8dca2a3a9 | ||
|
|
8216899a9a | ||
|
|
b1d419f458 | ||
|
|
0417946153 | ||
|
|
1149578e8f | ||
|
|
37488ee82b | ||
|
|
06bbd501fd | ||
|
|
07e6c5cf69 | ||
|
|
d0c91e4acf | ||
|
|
114cdafe7e | ||
|
|
837bdecde8 | ||
|
|
d9d0e70e5b | ||
|
|
1255efba7f | ||
|
|
6ad397d4a9 | ||
|
|
570ca22d71 | ||
|
|
418f381b49 | ||
|
|
2cae37ccde | ||
|
|
650fbc2563 | ||
|
|
9ec26c60ff | ||
|
|
06204dfcd8 | ||
|
|
fbe40e005d | ||
|
|
e9efef9095 | ||
|
|
95c3181a35 | ||
|
|
12dbfb0777 | ||
|
|
b62dbd1f92 | ||
|
|
5011fde176 | ||
|
|
54cb9a33b1 | ||
|
|
f1fbcd863d | ||
|
|
b00b16aa3a | ||
|
|
0f19695225 | ||
|
|
7fcbe13669 | ||
|
|
87c91ec5c4 | ||
|
|
0e10916b07 | ||
|
|
21df87dedc | ||
|
|
fd26310d6a | ||
|
|
5762a5bc80 | ||
|
|
8106e67f14 | ||
|
|
f029fb3c65 | ||
|
|
44da684d1d | ||
|
|
64c1a4fc8c | ||
|
|
ec47459410 | ||
|
|
c55c3657c3 | ||
|
|
8b56b55761 | ||
|
|
9056c9276f | ||
|
|
09ae312f09 | ||
|
|
d6960c72e4 | ||
|
|
b529e054cf | ||
|
|
b4a4ca81d1 | ||
|
|
c284df2dc9 | ||
|
|
18b2a4c204 | ||
|
|
e1303fb592 | ||
|
|
bd25cf04ed | ||
|
|
ce1f4cbbdc | ||
|
|
e0aea0f27a | ||
|
|
9848c4c56c | ||
|
|
cb8149f8ea | ||
|
|
0e74e82a38 | ||
|
|
15e09f2b24 | ||
|
|
2de8256863 | ||
|
|
aff43fb1a3 | ||
|
|
cafd8e2b1e | ||
|
|
3794080327 | ||
|
|
4e2683f068 | ||
|
|
6e5f595d48 | ||
|
|
2c24ba6d2d | ||
|
|
3bb27fbee6 | ||
|
|
ef1b52eee5 | ||
|
|
f917fa67aa | ||
|
|
386b4c82da | ||
|
|
a987f22cfb | ||
|
|
558c42ec83 | ||
|
|
309ac46b98 | ||
|
|
399b04596e | ||
|
|
75513a23a8 | ||
|
|
e672de036e | ||
|
|
6533af6a91 | ||
|
|
d3372e69ec | ||
|
|
f3809a52e8 | ||
|
|
c5f5ab5363 | ||
|
|
26dfb868e9 | ||
|
|
d5b6042118 | ||
|
|
1115705cbc | ||
|
|
161d17d85b | ||
|
|
5a2ebfcd4a | ||
|
|
06a974df36 | ||
|
|
2762c45569 | ||
|
|
fd85483ce3 | ||
|
|
0a2d0c3b5c | ||
|
|
de7f9a4bd9 | ||
|
|
c5836c8090 | ||
|
|
dcdda314e2 | ||
|
|
a9edd57fe2 | ||
|
|
cbd9fad94b | ||
|
|
bc1009f8c2 | ||
|
|
719b66e5ed | ||
|
|
5f09ba4e10 | ||
|
|
517a0cb673 | ||
|
|
7c79b07817 | ||
|
|
23eed4ff2f | ||
|
|
4559886d83 | ||
|
|
bfc706a596 | ||
|
|
9805a461eb | ||
|
|
bcf8433ba8 | ||
|
|
746dd057b9 | ||
|
|
b710297d05 | ||
|
|
0a8e8cec0f | ||
|
|
96e5a23727 | ||
|
|
611b925368 | ||
|
|
cab2a74740 | ||
|
|
fa3ac22a8f | ||
|
|
95d1048789 | ||
|
|
38b2b8a143 | ||
|
|
3d0bc85b4d | ||
|
|
25a391070b | ||
|
|
926c4a7d04 | ||
|
|
5683f55646 | ||
|
|
671f4e943e | ||
|
|
282c0da941 | ||
|
|
78648f1faf | ||
|
|
8d9b5e4775 | ||
|
|
996026e5ed | ||
|
|
2c7e1db5f6 | ||
|
|
2171b38551 | ||
|
|
afdbdb02a1 | ||
|
|
8adeaa2c7e | ||
|
|
d15f605129 | ||
|
|
252fe42612 | ||
|
|
67e1c7dc72 | ||
|
|
c29ffc38e6 | ||
|
|
4d61cc87cf | ||
|
|
2350018106 | ||
|
|
8fc3dd9457 | ||
|
|
d97ca9fcb2 | ||
|
|
e523da9e12 | ||
|
|
67706cec4e | ||
|
|
fac8c32cda | ||
|
|
1c6f426363 | ||
|
|
8cba65809c | ||
|
|
77ed4f98bb | ||
|
|
848e5ac5de | ||
|
|
9448c5e16f | ||
|
|
0722495434 | ||
|
|
d545c6d73c | ||
|
|
f69fea4210 | ||
|
|
4cd0a4ced4 | ||
|
|
0804cc0cff | ||
|
|
faeee7528f | ||
|
|
261e0cfd5a | ||
|
|
66ecb56cea | ||
|
|
79bd54f610 | ||
|
|
30cef4d5fd | ||
|
|
8d52032263 | ||
|
|
4a5786334b | ||
|
|
587698a6f3 | ||
|
|
927d2cc824 | ||
|
|
7f9cb4e68d | ||
|
|
d48ea4f22c | ||
|
|
412bd2ec20 | ||
|
|
1c189060c2 | ||
|
|
4a00a3c0f5 | ||
|
|
8366e4ca83 | ||
|
|
283db76e45 | ||
|
|
8a36ed4f6f | ||
|
|
d0f45155c8 | ||
|
|
9fc235d670 | ||
|
|
42c549274f | ||
|
|
2e56182a7f | ||
|
|
7932b1849b | ||
|
|
886374d779 | ||
|
|
d42e2e391f | ||
|
|
f264eaeda2 | ||
|
|
35fd74af6d | ||
|
|
4b53cf1464 | ||
|
|
26e78efbb9 | ||
|
|
157f0b8a83 | ||
|
|
d743cf308e | ||
|
|
f4cdcb995c | ||
|
|
75139961a3 | ||
|
|
3e2dd59a94 | ||
|
|
c01386b5b4 | ||
|
|
f59a072aa6 | ||
|
|
9cb8447673 | ||
|
|
e67355ab0e | ||
|
|
9cb9b670d1 | ||
|
|
3e725bb2db | ||
|
|
cc45930ef9 | ||
|
|
3266daa8fd | ||
|
|
ce17b0eeca | ||
|
|
17a65d82bb | ||
|
|
cc7646665c | ||
|
|
82216ebf8b | ||
|
|
49e0d83d5d | ||
|
|
673c3c7a55 | ||
|
|
5135041405 | ||
|
|
42631b85c7 | ||
|
|
9f6f12cfeb | ||
|
|
6c4c9ec1f2 | ||
|
|
4bb4db0668 | ||
|
|
505fdd02ca | ||
|
|
a873f260cf | ||
|
|
b45f761227 | ||
|
|
d7a3039c2a | ||
|
|
6c5589c9d2 | ||
|
|
645ea5a057 | ||
|
|
2755ebe883 | ||
|
|
4b829b5ff9 | ||
|
|
ed19340af0 | ||
|
|
2d05ff0190 | ||
|
|
0d338fa4c0 | ||
|
|
15a66e7b7d | ||
|
|
3a21999a17 | ||
|
|
08dcd05d7b | ||
|
|
2337cc653b | ||
|
|
0deb9262c9 | ||
|
|
9bc5be837b | ||
|
|
b79d5494f9 | ||
|
|
ded2c5bf68 | ||
|
|
bd2c64876f | ||
|
|
7c66fef63f | ||
|
|
4ad8818809 | ||
|
|
2f4342810d | ||
|
|
36df56b093 | ||
|
|
d0a1e8e311 | ||
|
|
1b50381852 | ||
|
|
3443d2c129 | ||
|
|
1f83efa8f2 | ||
|
|
a7bd39b62a | ||
|
|
1177b30a60 | ||
|
|
10e56e0de7 | ||
|
|
6f3339cc49 | ||
|
|
771be0e056 | ||
|
|
71ad4fc406 | ||
|
|
6a5695d059 | ||
|
|
aaf0e7db06 | ||
|
|
7aa0aba382 | ||
|
|
9af190a43c | ||
|
|
2e46bc0aea | ||
|
|
a413aae8a3 | ||
|
|
317cc5c544 | ||
|
|
41bf162306 | ||
|
|
43c27dffd2 | ||
|
|
8f299838f7 | ||
|
|
146a0b29c0 | ||
|
|
964bc7fbe0 | ||
|
|
75aa3cc9bd | ||
|
|
0843fefad3 | ||
|
|
371a780ef4 | ||
|
|
c7db69a30c | ||
|
|
b48cda7173 | ||
|
|
0608cf1476 | ||
|
|
f335e78d1e | ||
|
|
dcfb228c9a | ||
|
|
dc99bbb0af | ||
|
|
c42273a4db | ||
|
|
3bf489cd7c | ||
|
|
d8240f9ee4 | ||
|
|
2448cf2a14 | ||
|
|
004883bdb1 | ||
|
|
11a1191ba0 | ||
|
|
ff66595f7a | ||
|
|
9de2a342e8 | ||
|
|
562f8bc84a | ||
|
|
d69411f414 | ||
|
|
39ccb15880 | ||
|
|
d2c56f9f96 | ||
|
|
7f1a0ce94a | ||
|
|
32dbf83747 | ||
|
|
d9d8b9c526 | ||
|
|
9036bf3398 | ||
|
|
bef5cea48e | ||
|
|
84abf7c95a | ||
|
|
1f0e1bec0e | ||
|
|
8f88613a6b | ||
|
|
e5f332bd71 | ||
|
|
07589cfc34 | ||
|
|
68e0306e62 | ||
|
|
5751686fdc | ||
|
|
2af20f8df8 | ||
|
|
60c1301fca | ||
|
|
b8a7319212 | ||
|
|
6ef4d04b46 | ||
|
|
1dce2b98b4 | ||
|
|
86c4897c9b | ||
|
|
2237603677 | ||
|
|
6e81596609 | ||
|
|
4607c7ed04 | ||
|
|
63638eb447 | ||
|
|
c92ac84679 | ||
|
|
ed9cd9f0e5 | ||
|
|
7d30dbebc5 | ||
|
|
8f03c80ce8 | ||
|
|
ee0366af88 | ||
|
|
683a3cb3ec | ||
|
|
f8bca4fbcb | ||
|
|
1e2a1d9ce5 | ||
|
|
1feac2069b | ||
|
|
26ee6b6dde | ||
|
|
c150ca4889 | ||
|
|
e717e349d0 | ||
|
|
e158017086 | ||
|
|
36d068871d | ||
|
|
6c67a4b500 | ||
|
|
86b43dc605 | ||
|
|
300921a93e | ||
|
|
35b52c4656 | ||
|
|
878302a622 | ||
|
|
55277738d4 | ||
|
|
2f54732500 | ||
|
|
41da298b18 | ||
|
|
ebcf8c2b6b | ||
|
|
1facfd019b | ||
|
|
00e3a752c9 | ||
|
|
d03fd3f883 | ||
|
|
fa3d13ac7e | ||
|
|
434bd5a5bb | ||
|
|
9aca389bda | ||
|
|
69ce42b22c | ||
|
|
114cc776be | ||
|
|
5e5cff897f | ||
|
|
a8bedb6ab9 | ||
|
|
81430bd3bd | ||
|
|
93203f355a | ||
|
|
b730d286ad | ||
|
|
3f2296e3ea | ||
|
|
2b7eb4906a | ||
|
|
db1aa4d02e | ||
|
|
ad88d7a3e0 | ||
|
|
e42c1c9c7a | ||
|
|
556bb2386d | ||
|
|
1e58cef174 | ||
|
|
01010e443f | ||
|
|
da0a7a765e | ||
|
|
9769a0dcdb | ||
|
|
fbff4fa218 | ||
|
|
d17ec56e54 | ||
|
|
9a5f75dba7 | ||
|
|
ca149fb796 | ||
|
|
08f19e074b | ||
|
|
36388cafe9 | ||
|
|
8191c747b9 | ||
|
|
d078763fa1 | ||
|
|
412ead5f2d | ||
|
|
513175ce23 | ||
|
|
8db6dd995a | ||
|
|
4be6970bd4 | ||
|
|
fa681ce246 | ||
|
|
dd5cd97713 | ||
|
|
89d47d26f0 | ||
|
|
d574ceb598 | ||
|
|
92e2f5ca8e | ||
|
|
f2bc792178 | ||
|
|
8ed096f938 | ||
|
|
3405dbf90e | ||
|
|
ee0c5e24bb | ||
|
|
b320f1c7e3 | ||
|
|
6c6b1c0606 | ||
|
|
a5f5add630 | ||
|
|
8557105c40 | ||
|
|
24e7ffb289 | ||
|
|
0b9bcfe01d | ||
|
|
1a0e8f810b | ||
|
|
7698f0672d | ||
|
|
da064ea702 | ||
|
|
0c65289a80 | ||
|
|
95c90a785f | ||
|
|
42c3754dcd | ||
|
|
b742200442 | ||
|
|
3ac70f7cc2 | ||
|
|
104722a56a | ||
|
|
1924beeb20 | ||
|
|
70f6f9a711 | ||
|
|
f1ceefe9a6 | ||
|
|
e1fc1566f3 | ||
|
|
189f74a40d | ||
|
|
370c9b38c0 | ||
|
|
df65c10360 | ||
|
|
4573389da7 | ||
|
|
5c55c1d8a1 | ||
|
|
a1d4e53eb8 | ||
|
|
16b6484c65 | ||
|
|
2156fd4909 | ||
|
|
7f5fbe1dc7 | ||
|
|
2e9090d121 | ||
|
|
23f2690c54 | ||
|
|
5226cd2a0b | ||
|
|
c7e8a82d68 | ||
|
|
77bec1261e | ||
|
|
dfcb24061e | ||
|
|
f85b0c6208 | ||
|
|
e490a30a4a | ||
|
|
654b652530 | ||
|
|
8f4426fbc8 | ||
|
|
32c1e59622 | ||
|
|
e56957f047 | ||
|
|
3cc357bffa | ||
|
|
388faa2c54 | ||
|
|
ce9ed993c8 | ||
|
|
929a13d4cd | ||
|
|
56f0d678e3 | ||
|
|
02645277c8 | ||
|
|
5f4e98e0d9 | ||
|
|
e9e14834bc | ||
|
|
5a57d6308e | ||
|
|
cb73d562d5 | ||
|
|
6c61690ef3 | ||
|
|
bf1f6a997c | ||
|
|
90b29aa808 | ||
|
|
31d0468cd2 | ||
|
|
38f467bae3 | ||
|
|
5c7c4bb9a8 | ||
|
|
9646ec4edd | ||
|
|
c665796c52 | ||
|
|
a72e2ecb3f | ||
|
|
0c47558729 | ||
|
|
93b9288c30 | ||
|
|
9d31a67116 | ||
|
|
cf19036ce6 | ||
|
|
7219ee6532 | ||
|
|
d7bc846c3c | ||
|
|
1adb0a9886 | ||
|
|
8aa01c9c8e | ||
|
|
23dabad0b0 | ||
|
|
45c675bd78 | ||
|
|
860c6ecbcc | ||
|
|
3f38091421 | ||
|
|
7704b3fc7b | ||
|
|
151b3c4021 | ||
|
|
610af95ed1 | ||
|
|
018ef5bd53 | ||
|
|
200eae3bc0 | ||
|
|
9321e425a4 | ||
|
|
9395c0dadc | ||
|
|
a40065878b | ||
|
|
e8d3c0a99a | ||
|
|
2e6ff1b750 | ||
|
|
15f9e397dd | ||
|
|
87a109d0e9 | ||
|
|
f3ffbe167d | ||
|
|
89a34e7508 | ||
|
|
f6fc750f08 | ||
|
|
c32f686c62 | ||
|
|
2ca83efc36 | ||
|
|
06796745ff | ||
|
|
093d531509 | ||
|
|
a915815e4d | ||
|
|
de3c28104c | ||
|
|
d9d13a6204 | ||
|
|
d1f5820711 | ||
|
|
7592f8f189 | ||
|
|
ffbb61713a | ||
|
|
6f51c1ba33 | ||
|
|
cd861345b7 | ||
|
|
823502a40a | ||
|
|
4efad0bb95 | ||
|
|
922352e215 | ||
|
|
8a0b2dc0be | ||
|
|
7eced34e20 | ||
|
|
64d00c1c8e | ||
|
|
6d48798d45 | ||
|
|
0e186835b9 | ||
|
|
b607eb9678 | ||
|
|
85a68f1e56 | ||
|
|
45d13bc295 | ||
|
|
2231401483 | ||
|
|
2abe9e6fd9 | ||
|
|
20f56dfc77 | ||
|
|
67664406da | ||
|
|
0ed60d29cb | ||
|
|
244b6fcef6 |
7
.codespellrc
Normal file
7
.codespellrc
Normal file
@@ -0,0 +1,7 @@
|
||||
# https://github.com/codespell-project/codespell
|
||||
|
||||
[codespell]
|
||||
skip = ./man/nominatim.1,data,./docs/styles.css,lib-php,module,munin,osm2pgsql,./test,./settings/*.lua,./settings/*.yaml,./settings/**/*.yaml,./settings/icu-rules,./nominatim/tokenizer/token_analysis/config_variants.py
|
||||
# Need to be lowercase in the list
|
||||
# Unter = Unter den Linden (an example address)
|
||||
ignore-words-list = inout,unter
|
||||
8
.flake8
Normal file
8
.flake8
Normal file
@@ -0,0 +1,8 @@
|
||||
[flake8]
|
||||
max-line-length = 100
|
||||
max-doc-length = 100
|
||||
extend-ignore =
|
||||
# something == None constructs are needed for SQLAlchemy
|
||||
E711
|
||||
per-file-ignores =
|
||||
__init__.py: F401
|
||||
3
.github/ISSUE_TEMPLATE/config.yml
vendored
3
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -2,3 +2,6 @@ contact_links:
|
||||
- name: Nominatim Discussions
|
||||
url: https://github.com/osm-search/Nominatim/discussions
|
||||
about: Ask questions, get support, share ideas and discuss with community members.
|
||||
- name: Discussions about OpenStreetMap data
|
||||
url: https://community.openstreetmap.org/
|
||||
about: Ask questions about the data used by Nominatim and discuss with the OSM community.
|
||||
|
||||
@@ -17,11 +17,11 @@ assignees: ''
|
||||
|
||||
## What result did you expect?
|
||||
|
||||
**When the result in the right place and just named wrongly:**
|
||||
**When the result is in the right place and just named wrongly:**
|
||||
|
||||
<!-- Please tell us the display name you expected. -->
|
||||
|
||||
**When the result missing completely:**
|
||||
**When the result is missing completely:**
|
||||
|
||||
<!-- Make sure that the data you are looking for is in OpenStreetMap. Provide a link to the OpenStreetMap object or if you cannot get it, a link to the map on https://openstreetmap.org where you expect the result to be.
|
||||
|
||||
|
||||
@@ -7,10 +7,13 @@ assignees: ''
|
||||
|
||||
---
|
||||
|
||||
<!-- Note: if you are installing Nominatim through a docker image, you should report issues with the installation process with the docker repository first. -->
|
||||
<!-- Note: if you are installing Nominatim through a docker image, you should report issues with the installation process with the docker repository first.
|
||||
|
||||
Do not send screen shots! Copy any console output directly into the issue.
|
||||
-->
|
||||
|
||||
**Describe the bug**
|
||||
<!-- A clear and concise description of what the bug is. -->
|
||||
<!-- A clear and concise description of what the bug is.-->
|
||||
|
||||
**To Reproduce**
|
||||
<!-- Please describe what you did to get to the issue. -->
|
||||
@@ -25,12 +28,15 @@ assignees: ''
|
||||
- RAM:
|
||||
- number of CPUs:
|
||||
- type and size of disks:
|
||||
- bare metal/AWS/other cloud service:
|
||||
|
||||
**Postgresql Configuration:**
|
||||
|
||||
<!-- List any configuration items you changed in your postgresql configuration. -->
|
||||
|
||||
**Nominatim Configuration:**
|
||||
|
||||
<!-- List the contents of your customized `.env` file. -->
|
||||
|
||||
**Additional context**
|
||||
|
||||
<!-- Add any other context about the problem here. -->
|
||||
|
||||
57
.github/actions/build-nominatim/action.yml
vendored
57
.github/actions/build-nominatim/action.yml
vendored
@@ -1,18 +1,10 @@
|
||||
name: 'Build Nominatim'
|
||||
|
||||
inputs:
|
||||
ubuntu:
|
||||
description: 'Version of Ubuntu to install on'
|
||||
dependencies:
|
||||
description: 'Where to install dependencies from (pip/apt)'
|
||||
required: false
|
||||
default: '20'
|
||||
cmake-args:
|
||||
description: 'Additional options to hand to cmake'
|
||||
required: false
|
||||
default: ''
|
||||
lua:
|
||||
description: 'Version of Lua to use'
|
||||
required: false
|
||||
default: '5.3'
|
||||
default: 'pip'
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
@@ -23,29 +15,30 @@ runs:
|
||||
sudo rm -rf /opt/hostedtoolcache/go /opt/hostedtoolcache/CodeQL /usr/lib/jvm /usr/local/share/chromium /usr/local/lib/android
|
||||
df -h
|
||||
shell: bash
|
||||
- name: Install prerequisites
|
||||
- name: Install general prerequisites
|
||||
run: |
|
||||
sudo apt-get install -y -qq libboost-system-dev libboost-filesystem-dev libexpat1-dev zlib1g-dev libbz2-dev libpq-dev libproj-dev libicu-dev liblua${LUA_VERSION}-dev lua${LUA_VERSION}
|
||||
if [ "x$UBUNTUVER" == "x18" ]; then
|
||||
pip3 install python-dotenv psycopg2==2.7.7 jinja2==2.8 psutil==5.4.2 pyicu==2.9 osmium PyYAML==5.1 datrie
|
||||
else
|
||||
sudo apt-get install -y -qq python3-icu python3-datrie python3-pyosmium python3-jinja2 python3-psutil python3-psycopg2 python3-dotenv python3-yaml
|
||||
fi
|
||||
sudo apt-get install -y -qq libspatialite-dev libsqlite3-mod-spatialite libicu-dev virtualenv python3-dev osm2pgsql
|
||||
shell: bash
|
||||
env:
|
||||
UBUNTUVER: ${{ inputs.ubuntu }}
|
||||
CMAKE_ARGS: ${{ inputs.cmake-args }}
|
||||
LUA_VERSION: ${{ inputs.lua }}
|
||||
|
||||
- name: Configure
|
||||
run: mkdir build && cd build && cmake $CMAKE_ARGS ../Nominatim
|
||||
shell: bash
|
||||
env:
|
||||
CMAKE_ARGS: ${{ inputs.cmake-args }}
|
||||
|
||||
- name: Build
|
||||
- name: Install prerequisites from apt
|
||||
run: |
|
||||
make -j2 all
|
||||
sudo make install
|
||||
sudo apt-get install -y -qq python3-icu python3-datrie python3-jinja2 python3-psutil python3-dotenv python3-yaml python3-sqlalchemy python3-psycopg python3-asyncpg
|
||||
shell: bash
|
||||
if: inputs.dependencies == 'apt'
|
||||
|
||||
- name: Setup virtual environment (for pip)
|
||||
run: |
|
||||
virtualenv venv
|
||||
./venv/bin/pip install -U pip
|
||||
shell: bash
|
||||
if: inputs.dependencies == 'pip'
|
||||
|
||||
- name: Setup virtual environment (for apt)
|
||||
run: |
|
||||
virtualenv venv --system-site-packages
|
||||
shell: bash
|
||||
if: inputs.dependencies == 'apt'
|
||||
|
||||
- name: Build nominatim
|
||||
run: ./venv/bin/pip install Nominatim/packaging/nominatim-{api,db}
|
||||
shell: bash
|
||||
working-directory: build
|
||||
|
||||
6
.github/actions/setup-postgresql/action.yml
vendored
6
.github/actions/setup-postgresql/action.yml
vendored
@@ -4,9 +4,6 @@ inputs:
|
||||
postgresql-version:
|
||||
description: 'Version of PostgreSQL to install'
|
||||
required: true
|
||||
postgis-version:
|
||||
description: 'Version of Postgis to install'
|
||||
required: true
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
@@ -24,11 +21,10 @@ runs:
|
||||
|
||||
- name: Install PostgreSQL
|
||||
run: |
|
||||
sudo apt-get install -y -qq --no-install-suggests --no-install-recommends postgresql-client-${PGVER} postgresql-${PGVER}-postgis-${POSTGISVER} postgresql-${PGVER}-postgis-${POSTGISVER}-scripts postgresql-contrib-${PGVER} postgresql-${PGVER}
|
||||
sudo apt-get install -y -qq --no-install-suggests --no-install-recommends postgresql-client-${PGVER} postgresql-${PGVER}-postgis-3 postgresql-${PGVER}-postgis-3-scripts postgresql-contrib-${PGVER} postgresql-${PGVER}
|
||||
shell: bash
|
||||
env:
|
||||
PGVER: ${{ inputs.postgresql-version }}
|
||||
POSTGISVER: ${{ inputs.postgis-version }}
|
||||
|
||||
- name: Adapt postgresql configuration
|
||||
run: |
|
||||
|
||||
298
.github/workflows/ci-tests.yml
vendored
298
.github/workflows/ci-tests.yml
vendored
@@ -7,11 +7,11 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- uses: actions/cache@v3
|
||||
- uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
data/country_osm_grid.sql.gz
|
||||
@@ -27,7 +27,7 @@ jobs:
|
||||
mv nominatim-src.tar.bz2 Nominatim
|
||||
|
||||
- name: 'Upload Artifact'
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: full-source
|
||||
path: nominatim-src.tar.bz2
|
||||
@@ -37,168 +37,106 @@ jobs:
|
||||
needs: create-archive
|
||||
strategy:
|
||||
matrix:
|
||||
ubuntu: [18, 20, 22]
|
||||
flavour: ["ubuntu-20", "ubuntu-24"]
|
||||
include:
|
||||
- ubuntu: 18
|
||||
postgresql: 9.6
|
||||
postgis: 2.5
|
||||
pytest: pytest
|
||||
php: 7.2
|
||||
- ubuntu: 20
|
||||
postgresql: 13
|
||||
postgis: 3
|
||||
pytest: py.test-3
|
||||
php: 7.4
|
||||
- ubuntu: 22
|
||||
postgresql: 15
|
||||
postgis: 3
|
||||
pytest: py.test-3
|
||||
php: 8.1
|
||||
- flavour: ubuntu-20
|
||||
ubuntu: 20
|
||||
postgresql: 12
|
||||
lua: '5.1'
|
||||
dependencies: pip
|
||||
- flavour: ubuntu-24
|
||||
ubuntu: 24
|
||||
postgresql: 17
|
||||
lua: '5.3'
|
||||
dependencies: apt
|
||||
|
||||
runs-on: ubuntu-${{ matrix.ubuntu }}.04
|
||||
|
||||
steps:
|
||||
- uses: actions/download-artifact@v3
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: full-source
|
||||
|
||||
- name: Unpack Nominatim
|
||||
run: tar xf nominatim-src.tar.bz2
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php }}
|
||||
tools: phpunit:9, phpcs, composer
|
||||
ini-values: opcache.jit=disable
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: 3.6
|
||||
if: matrix.ubuntu == 18
|
||||
|
||||
- uses: ./Nominatim/.github/actions/setup-postgresql
|
||||
with:
|
||||
postgresql-version: ${{ matrix.postgresql }}
|
||||
postgis-version: ${{ matrix.postgis }}
|
||||
|
||||
- uses: ./Nominatim/.github/actions/build-nominatim
|
||||
with:
|
||||
ubuntu: ${{ matrix.ubuntu }}
|
||||
dependencies: ${{ matrix.dependencies }}
|
||||
|
||||
- name: Install test prerequsites
|
||||
run: sudo apt-get install -y -qq python3-pytest python3-behave
|
||||
if: matrix.ubuntu == 20
|
||||
- name: Compile osm2pgsql
|
||||
run: |
|
||||
sudo apt-get install -y -qq libboost-system-dev libboost-filesystem-dev libexpat1-dev zlib1g-dev libbz2-dev libpq-dev libproj-dev libicu-dev liblua${LUA_VERSION}-dev lua-dkjson nlohmann-json3-dev
|
||||
mkdir osm2pgsql-build
|
||||
cd osm2pgsql-build
|
||||
git clone https://github.com/osm2pgsql-dev/osm2pgsql
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ../osm2pgsql
|
||||
make
|
||||
sudo make install
|
||||
cd ../..
|
||||
rm -rf osm2pgsql-build
|
||||
if: matrix.ubuntu == '20'
|
||||
env:
|
||||
LUA_VERSION: ${{ matrix.lua }}
|
||||
|
||||
- name: Install test prerequsites
|
||||
run: pip3 install pylint pytest behave==1.2.6
|
||||
if: ${{ (matrix.ubuntu == 18) || (matrix.ubuntu == 22) }}
|
||||
- name: Install test prerequisites
|
||||
run: ./venv/bin/pip install behave==1.2.6
|
||||
|
||||
- name: Install test prerequsites
|
||||
run: sudo apt-get install -y -qq python3-pytest
|
||||
if: matrix.ubuntu == 22
|
||||
- name: Install test prerequisites (apt)
|
||||
run: sudo apt-get install -y -qq python3-pytest python3-pytest-asyncio uvicorn python3-falcon python3-aiosqlite python3-pyosmium
|
||||
if: matrix.dependencies == 'apt'
|
||||
|
||||
- name: Install latest pylint/mypy
|
||||
run: pip3 install -U pylint mypy types-PyYAML types-jinja2 types-psycopg2 types-psutil types-requests typing-extensions
|
||||
if: matrix.ubuntu == 22
|
||||
- name: Install test prerequisites (pip)
|
||||
run: ./venv/bin/pip install pytest-asyncio falcon starlette asgi_lifespan aiosqlite osmium uvicorn
|
||||
if: matrix.dependencies == 'pip'
|
||||
|
||||
- name: PHP linting
|
||||
run: phpcs --report-width=120 .
|
||||
working-directory: Nominatim
|
||||
if: matrix.ubuntu == 22
|
||||
- name: Install latest flake8
|
||||
run: ./venv/bin/pip install -U flake8
|
||||
|
||||
- name: Python linting
|
||||
run: pylint nominatim
|
||||
run: ../venv/bin/python -m flake8 src
|
||||
working-directory: Nominatim
|
||||
if: matrix.ubuntu == 22
|
||||
|
||||
- name: Install mypy and typechecking info
|
||||
run: ./venv/bin/pip install -U mypy types-PyYAML types-jinja2 types-psutil types-requests types-ujson types-Pygments typing-extensions
|
||||
if: matrix.dependencies == 'pip'
|
||||
|
||||
- name: Python static typechecking
|
||||
run: mypy --strict nominatim
|
||||
run: ../venv/bin/python -m mypy --strict --python-version 3.8 src
|
||||
working-directory: Nominatim
|
||||
if: matrix.ubuntu == 22
|
||||
|
||||
|
||||
- name: PHP unit tests
|
||||
run: phpunit ./
|
||||
working-directory: Nominatim/test/php
|
||||
if: ${{ (matrix.ubuntu == 20) || (matrix.ubuntu == 22) }}
|
||||
if: matrix.dependencies == 'pip'
|
||||
|
||||
- name: Python unit tests
|
||||
run: $PYTEST test/python
|
||||
run: ../venv/bin/python -m pytest test/python
|
||||
working-directory: Nominatim
|
||||
env:
|
||||
PYTEST: ${{ matrix.pytest }}
|
||||
|
||||
- name: BDD tests
|
||||
run: |
|
||||
behave -DREMOVE_TEMPLATE=1 -DBUILDDIR=$GITHUB_WORKSPACE/build --format=progress3
|
||||
../../../venv/bin/python -m behave -DREMOVE_TEMPLATE=1 --format=progress3
|
||||
working-directory: Nominatim/test/bdd
|
||||
|
||||
|
||||
legacy-test:
|
||||
needs: create-archive
|
||||
runs-on: ubuntu-20.04
|
||||
|
||||
steps:
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: full-source
|
||||
|
||||
- name: Unpack Nominatim
|
||||
run: tar xf nominatim-src.tar.bz2
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: 7.4
|
||||
|
||||
- uses: ./Nominatim/.github/actions/setup-postgresql
|
||||
with:
|
||||
postgresql-version: 13
|
||||
postgis-version: 3
|
||||
|
||||
- name: Install Postgresql server dev
|
||||
run: sudo apt-get install postgresql-server-dev-13
|
||||
|
||||
- uses: ./Nominatim/.github/actions/build-nominatim
|
||||
with:
|
||||
ubuntu: 20
|
||||
cmake-args: -DBUILD_MODULE=on
|
||||
|
||||
- name: Install test prerequsites
|
||||
run: sudo apt-get install -y -qq python3-behave
|
||||
|
||||
- name: BDD tests (legacy tokenizer)
|
||||
run: |
|
||||
behave -DREMOVE_TEMPLATE=1 -DBUILDDIR=$GITHUB_WORKSPACE/build -DTOKENIZER=legacy --format=progress3
|
||||
working-directory: Nominatim/test/bdd
|
||||
|
||||
|
||||
install:
|
||||
runs-on: ubuntu-latest
|
||||
needs: create-archive
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
name: [Ubuntu-18, Ubuntu-20, Ubuntu-22]
|
||||
name: [Ubuntu-22, Ubuntu-24]
|
||||
include:
|
||||
- name: Ubuntu-18
|
||||
flavour: ubuntu
|
||||
image: "ubuntu:18.04"
|
||||
ubuntu: 18
|
||||
install_mode: install-nginx
|
||||
- name: Ubuntu-20
|
||||
flavour: ubuntu
|
||||
image: "ubuntu:20.04"
|
||||
ubuntu: 20
|
||||
install_mode: install-apache
|
||||
- name: Ubuntu-22
|
||||
flavour: ubuntu
|
||||
image: "ubuntu:22.04"
|
||||
ubuntu: 22
|
||||
install_mode: install-apache
|
||||
- name: Ubuntu-24
|
||||
image: "ubuntu:24.04"
|
||||
ubuntu: 24
|
||||
install_mode: install-apache
|
||||
|
||||
container:
|
||||
image: ${{ matrix.image }}
|
||||
@@ -218,14 +156,6 @@ jobs:
|
||||
apt-get install -y git sudo wget
|
||||
ln -snf /usr/share/zoneinfo/$CONTAINER_TIMEZONE /etc/localtime && echo $CONTAINER_TIMEZONE > /etc/timezone
|
||||
shell: bash
|
||||
if: matrix.flavour == 'ubuntu'
|
||||
|
||||
- name: Prepare container (CentOS)
|
||||
run: |
|
||||
dnf update -y
|
||||
dnf install -y sudo glibc-langpack-en
|
||||
shell: bash
|
||||
if: matrix.flavour == 'centos'
|
||||
|
||||
- name: Setup import user
|
||||
run: |
|
||||
@@ -237,7 +167,7 @@ jobs:
|
||||
OS: ${{ matrix.name }}
|
||||
INSTALL_MODE: ${{ matrix.install_mode }}
|
||||
|
||||
- uses: actions/download-artifact@v3
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: full-source
|
||||
path: /home/nominatim
|
||||
@@ -259,22 +189,26 @@ jobs:
|
||||
mkdir data-env-reverse
|
||||
working-directory: /home/nominatim
|
||||
|
||||
- name: Prepare import environment (CentOS)
|
||||
- name: Add nominatim to path
|
||||
run: |
|
||||
sudo ln -s /usr/local/bin/nominatim /usr/bin/nominatim
|
||||
echo NOMINATIM_DATABASE_WEBUSER="apache" > nominatim-project/.env
|
||||
cp nominatim-project/.env data-env-reverse/.env
|
||||
working-directory: /home/nominatim
|
||||
if: matrix.flavour == 'centos'
|
||||
sudo ln -s /home/nominatim/nominatim-venv/bin/nominatim /usr/local/bin/nominatim
|
||||
|
||||
- name: Need lua binary
|
||||
run: |
|
||||
sudo apt-get install -y lua5.4 lua-dkjson
|
||||
|
||||
- name: Print version
|
||||
run: nominatim --version
|
||||
working-directory: /home/nominatim/nominatim-project
|
||||
|
||||
- name: Print taginfo
|
||||
run: lua ./nominatim-venv/lib/*/site-packages/nominatim_db/resources/lib-lua/taginfo.lua
|
||||
working-directory: /home/nominatim
|
||||
|
||||
- name: Collect host OS information
|
||||
run: nominatim admin --collect-os-info
|
||||
working-directory: /home/nominatim/nominatim-project
|
||||
|
||||
|
||||
- name: Import
|
||||
run: nominatim import --osm-file ../test.pbf
|
||||
working-directory: /home/nominatim/nominatim-project
|
||||
@@ -291,14 +225,12 @@ jobs:
|
||||
run: nominatim admin --warm
|
||||
working-directory: /home/nominatim/nominatim-project
|
||||
|
||||
- name: Prepare update (Ubuntu)
|
||||
run: apt-get install -y python3-pip
|
||||
shell: bash
|
||||
if: matrix.flavour == 'ubuntu'
|
||||
- name: Install osmium
|
||||
run: |
|
||||
/home/nominatim/nominatim-venv/bin/pip install osmium
|
||||
|
||||
- name: Run update
|
||||
run: |
|
||||
pip3 install --user osmium
|
||||
nominatim replication --init
|
||||
NOMINATIM_REPLICATION_MAX_DIFF=1 nominatim replication --once
|
||||
working-directory: /home/nominatim/nominatim-project
|
||||
@@ -320,3 +252,91 @@ jobs:
|
||||
- name: Clean up database (reverse-only import)
|
||||
run: nominatim refresh --postcodes --word-tokens
|
||||
working-directory: /home/nominatim/nominatim-project
|
||||
|
||||
install-no-superuser:
|
||||
runs-on: ubuntu-24.04
|
||||
needs: create-archive
|
||||
|
||||
steps:
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: full-source
|
||||
|
||||
- name: Unpack Nominatim
|
||||
run: tar xf nominatim-src.tar.bz2
|
||||
|
||||
- uses: ./Nominatim/.github/actions/setup-postgresql
|
||||
with:
|
||||
postgresql-version: 16
|
||||
|
||||
- uses: ./Nominatim/.github/actions/build-nominatim
|
||||
|
||||
- name: Prepare import environment
|
||||
run: |
|
||||
mv Nominatim/test/testdb/apidb-test-data.pbf test.pbf
|
||||
rm -rf Nominatim
|
||||
|
||||
- name: Prepare Database
|
||||
run: |
|
||||
./venv/bin/nominatim import --prepare-database
|
||||
|
||||
- name: Create import user
|
||||
run: |
|
||||
sudo -u postgres createuser osm-import
|
||||
psql -d nominatim -c "ALTER USER \"osm-import\" WITH PASSWORD 'osm-import'"
|
||||
psql -d nominatim -c 'GRANT CREATE ON SCHEMA public TO "osm-import"'
|
||||
|
||||
- name: Run import
|
||||
run: |
|
||||
NOMINATIM_DATABASE_DSN="pgsql:host=127.0.0.1;dbname=nominatim;user=osm-import;password=osm-import" ./venv/bin/nominatim import --continue import-from-file --osm-file test.pbf
|
||||
|
||||
- name: Check full import
|
||||
run: ./venv/bin/nominatim admin --check-database
|
||||
|
||||
migrate:
|
||||
runs-on: ubuntu-24.04
|
||||
needs: create-archive
|
||||
|
||||
steps:
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: full-source
|
||||
|
||||
- name: Unpack Nominatim
|
||||
run: tar xf nominatim-src.tar.bz2
|
||||
|
||||
- uses: ./Nominatim/.github/actions/setup-postgresql
|
||||
with:
|
||||
postgresql-version: 17
|
||||
|
||||
- name: Install Python dependencies
|
||||
run: |
|
||||
sudo apt-get install --no-install-recommends virtualenv osm2pgsql
|
||||
|
||||
- name: Install Nominatim master version
|
||||
run: |
|
||||
virtualenv master
|
||||
cd Nominatim
|
||||
../master/bin/pip install packaging/nominatim-db
|
||||
|
||||
- name: Install Nominatim from pypi
|
||||
run: |
|
||||
virtualenv release
|
||||
./release/bin/pip install nominatim-db
|
||||
|
||||
- name: Import Nominatim database using release
|
||||
run: |
|
||||
./release/bin/nominatim import --osm-file Nominatim/test/testdb/apidb-test-data.pbf
|
||||
./release/bin/nominatim add-data --file Nominatim/test/testdb/additional_api_test.data.osm
|
||||
|
||||
- name: Migrate to master version
|
||||
run: |
|
||||
./master/bin/nominatim admin --migrate
|
||||
./release/bin/nominatim add-data --file Nominatim/test/testdb/additional_api_test.data.osm
|
||||
|
||||
codespell:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: codespell-project/actions-codespell@v2
|
||||
with:
|
||||
only_warn: 1
|
||||
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,9 +1,13 @@
|
||||
*.log
|
||||
*.pyc
|
||||
*.swp
|
||||
|
||||
docs/develop/*.png
|
||||
site-html
|
||||
|
||||
build
|
||||
dist
|
||||
.coverage
|
||||
|
||||
.vagrant
|
||||
data/country_osm_grid.sql.gz
|
||||
|
||||
4
.gitmodules
vendored
4
.gitmodules
vendored
@@ -1,4 +0,0 @@
|
||||
[submodule "osm2pgsql"]
|
||||
path = osm2pgsql
|
||||
url = https://github.com/openstreetmap/osm2pgsql.git
|
||||
ignore = dirty
|
||||
|
||||
12
.mypy.ini
12
.mypy.ini
@@ -1,9 +1,13 @@
|
||||
[mypy]
|
||||
plugins = sqlalchemy.ext.mypy.plugin
|
||||
|
||||
[mypy-sanic_cors.*]
|
||||
ignore_missing_imports = True
|
||||
|
||||
[mypy-icu.*]
|
||||
ignore_missing_imports = True
|
||||
|
||||
[mypy-osmium.*]
|
||||
[mypy-asyncpg.*]
|
||||
ignore_missing_imports = True
|
||||
|
||||
[mypy-datrie.*]
|
||||
@@ -11,3 +15,9 @@ ignore_missing_imports = True
|
||||
|
||||
[mypy-dotenv.*]
|
||||
ignore_missing_imports = True
|
||||
|
||||
[mypy-falcon.*]
|
||||
ignore_missing_imports = True
|
||||
|
||||
[mypy-geoalchemy2.*]
|
||||
ignore_missing_imports = True
|
||||
|
||||
18
.pylintrc
18
.pylintrc
@@ -1,18 +0,0 @@
|
||||
[MASTER]
|
||||
|
||||
extension-pkg-whitelist=osmium
|
||||
ignored-modules=icu,datrie
|
||||
|
||||
[MESSAGES CONTROL]
|
||||
|
||||
[TYPECHECK]
|
||||
|
||||
# closing added here because it sometimes triggers a false positive with
|
||||
# 'with' statements.
|
||||
ignored-classes=NominatimArgs,closing
|
||||
# 'too-many-ancestors' is triggered already by deriving from UserDict
|
||||
# 'not-context-manager' disabled because it causes false positives once
|
||||
# typed Python is enabled. See also https://github.com/PyCQA/pylint/issues/5273
|
||||
disable=too-few-public-methods,duplicate-code,too-many-ancestors,bad-option-value,no-self-use,not-context-manager,use-dict-literal
|
||||
|
||||
good-names=i,x,y,m,fd,db,cc
|
||||
292
CMakeLists.txt
292
CMakeLists.txt
@@ -1,292 +0,0 @@
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# CMake Config
|
||||
#
|
||||
# Nominatim
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# Project version
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
project(nominatim)
|
||||
|
||||
set(NOMINATIM_VERSION_MAJOR 4)
|
||||
set(NOMINATIM_VERSION_MINOR 2)
|
||||
set(NOMINATIM_VERSION_PATCH 3)
|
||||
|
||||
set(NOMINATIM_VERSION "${NOMINATIM_VERSION_MAJOR}.${NOMINATIM_VERSION_MINOR}.${NOMINATIM_VERSION_PATCH}")
|
||||
|
||||
add_definitions(-DNOMINATIM_VERSION="${NOMINATIM_VERSION}")
|
||||
|
||||
# Setting GIT_HASH
|
||||
find_package(Git)
|
||||
if (GIT_FOUND)
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" log -1 --format=%h
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
||||
OUTPUT_VARIABLE GIT_HASH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_QUIET
|
||||
)
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Configuration
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
set(BUILD_IMPORTER on CACHE BOOL "Build everything for importing/updating the database")
|
||||
set(BUILD_API on CACHE BOOL "Build everything for the API server")
|
||||
set(BUILD_MODULE off CACHE BOOL "Build PostgreSQL module for legacy tokenizer")
|
||||
set(BUILD_TESTS on CACHE BOOL "Build test suite")
|
||||
set(BUILD_DOCS on CACHE BOOL "Build documentation")
|
||||
set(BUILD_MANPAGE on CACHE BOOL "Build Manual Page")
|
||||
set(BUILD_OSM2PGSQL on CACHE BOOL "Build osm2pgsql (expert only)")
|
||||
set(INSTALL_MUNIN_PLUGINS on CACHE BOOL "Install Munin plugins for supervising Nominatim")
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# osm2pgsql (imports/updates only)
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
if (BUILD_IMPORTER AND BUILD_OSM2PGSQL)
|
||||
if (NOT EXISTS "${CMAKE_SOURCE_DIR}/osm2pgsql/CMakeLists.txt")
|
||||
message(FATAL_ERROR "The osm2pgsql directory is empty.\
|
||||
Did you forget to check out Nominatim recursively?\
|
||||
\nTry updating submodules with: git submodule update --init")
|
||||
endif()
|
||||
set(BUILD_TESTS_SAVED "${BUILD_TESTS}")
|
||||
set(BUILD_TESTS off)
|
||||
add_subdirectory(osm2pgsql)
|
||||
set(BUILD_TESTS ${BUILD_TESTS_SAVED})
|
||||
endif()
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# python (imports/updates only)
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
if (BUILD_IMPORTER)
|
||||
find_package(PythonInterp 3.6 REQUIRED)
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# PHP
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
# Setting PHP binary variable as to command line (prevailing) or auto detect
|
||||
|
||||
if (BUILD_API OR BUILD_IMPORTER)
|
||||
if (NOT PHP_BIN)
|
||||
find_program (PHP_BIN php)
|
||||
endif()
|
||||
# sanity check if PHP binary exists
|
||||
if (NOT EXISTS ${PHP_BIN})
|
||||
message(FATAL_ERROR "PHP binary not found. Install php or provide location with -DPHP_BIN=/path/php ")
|
||||
else()
|
||||
message (STATUS "Using PHP binary " ${PHP_BIN})
|
||||
endif()
|
||||
if (NOT PHPCGI_BIN)
|
||||
find_program (PHPCGI_BIN php-cgi)
|
||||
endif()
|
||||
# sanity check if PHP binary exists
|
||||
if (NOT EXISTS ${PHPCGI_BIN})
|
||||
message(WARNING "php-cgi binary not found. nominatim tool will not provide query functions.")
|
||||
set (PHPCGI_BIN "")
|
||||
else()
|
||||
message (STATUS "Using php-cgi binary " ${PHPCGI_BIN})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# import scripts and utilities (importer only)
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
if (BUILD_IMPORTER)
|
||||
find_file(COUNTRY_GRID_FILE country_osm_grid.sql.gz
|
||||
PATHS ${PROJECT_SOURCE_DIR}/data
|
||||
NO_DEFAULT_PATH
|
||||
DOC "Location of the country grid file."
|
||||
)
|
||||
|
||||
if (NOT COUNTRY_GRID_FILE)
|
||||
message(FATAL_ERROR "\nYou need to download the country_osm_grid first:\n"
|
||||
" wget -O ${PROJECT_SOURCE_DIR}/data/country_osm_grid.sql.gz https://www.nominatim.org/data/country_grid.sql.gz")
|
||||
endif()
|
||||
|
||||
configure_file(${PROJECT_SOURCE_DIR}/cmake/tool.tmpl
|
||||
${PROJECT_BINARY_DIR}/nominatim)
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Tests
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
if (BUILD_TESTS)
|
||||
include(CTest)
|
||||
|
||||
set(TEST_BDD db osm2pgsql api)
|
||||
|
||||
find_program(PYTHON_BEHAVE behave)
|
||||
find_program(PYLINT NAMES pylint3 pylint)
|
||||
find_program(PYTEST NAMES pytest py.test-3 py.test)
|
||||
find_program(PHPCS phpcs)
|
||||
find_program(PHPUNIT phpunit)
|
||||
|
||||
if (PYTHON_BEHAVE)
|
||||
message(STATUS "Using Python behave binary ${PYTHON_BEHAVE}")
|
||||
foreach (test ${TEST_BDD})
|
||||
add_test(NAME bdd_${test}
|
||||
COMMAND ${PYTHON_BEHAVE} ${test}
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test/bdd)
|
||||
set_tests_properties(bdd_${test}
|
||||
PROPERTIES ENVIRONMENT "NOMINATIM_DIR=${PROJECT_BINARY_DIR}")
|
||||
endforeach()
|
||||
else()
|
||||
message(WARNING "behave not found. BDD tests disabled." )
|
||||
endif()
|
||||
|
||||
if (PHPUNIT)
|
||||
message(STATUS "Using phpunit binary ${PHPUNIT}")
|
||||
add_test(NAME php
|
||||
COMMAND ${PHPUNIT} ./
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test/php)
|
||||
else()
|
||||
message(WARNING "phpunit not found. PHP unit tests disabled." )
|
||||
endif()
|
||||
|
||||
if (PHPCS)
|
||||
message(STATUS "Using phpcs binary ${PHPCS}")
|
||||
add_test(NAME phpcs
|
||||
COMMAND ${PHPCS} --report-width=120 --colors lib-php
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
||||
else()
|
||||
message(WARNING "phpcs not found. PHP linting tests disabled." )
|
||||
endif()
|
||||
|
||||
if (PYLINT)
|
||||
message(STATUS "Using pylint binary ${PYLINT}")
|
||||
add_test(NAME pylint
|
||||
COMMAND ${PYLINT} nominatim
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
||||
else()
|
||||
message(WARNING "pylint not found. Python linting tests disabled.")
|
||||
endif()
|
||||
|
||||
if (PYTEST)
|
||||
message(STATUS "Using pytest binary ${PYTEST}")
|
||||
add_test(NAME pytest
|
||||
COMMAND ${PYTEST} test/python
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
||||
else()
|
||||
message(WARNING "pytest not found. Python tests disabled." )
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Postgres module
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
if (BUILD_MODULE)
|
||||
add_subdirectory(module)
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Documentation
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
if (BUILD_DOCS)
|
||||
add_subdirectory(docs)
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Manual page
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
if (BUILD_MANPAGE)
|
||||
add_subdirectory(man)
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Installation
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
include(GNUInstallDirs)
|
||||
set(NOMINATIM_DATADIR ${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME})
|
||||
set(NOMINATIM_LIBDIR ${CMAKE_INSTALL_FULL_LIBDIR}/${PROJECT_NAME})
|
||||
set(NOMINATIM_CONFIGDIR ${CMAKE_INSTALL_FULL_SYSCONFDIR}/${PROJECT_NAME})
|
||||
set(NOMINATIM_MUNINDIR ${CMAKE_INSTALL_FULL_DATADIR}/munin/plugins)
|
||||
|
||||
if (BUILD_IMPORTER)
|
||||
configure_file(${PROJECT_SOURCE_DIR}/cmake/tool-installed.tmpl installed.bin)
|
||||
install(PROGRAMS ${PROJECT_BINARY_DIR}/installed.bin
|
||||
DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
RENAME nominatim)
|
||||
|
||||
install(DIRECTORY nominatim
|
||||
DESTINATION ${NOMINATIM_LIBDIR}/lib-python
|
||||
FILES_MATCHING PATTERN "*.py"
|
||||
PATTERN __pycache__ EXCLUDE)
|
||||
install(DIRECTORY lib-sql DESTINATION ${NOMINATIM_LIBDIR})
|
||||
|
||||
install(FILES ${COUNTRY_GRID_FILE}
|
||||
data/words.sql
|
||||
DESTINATION ${NOMINATIM_DATADIR})
|
||||
endif()
|
||||
|
||||
if (BUILD_OSM2PGSQL)
|
||||
if (${CMAKE_VERSION} VERSION_LESS 3.13)
|
||||
# Installation of subdirectory targets was only introduced in 3.13.
|
||||
# So just copy the osm2pgsql file for older versions.
|
||||
install(PROGRAMS ${PROJECT_BINARY_DIR}/osm2pgsql/osm2pgsql
|
||||
DESTINATION ${NOMINATIM_LIBDIR})
|
||||
else()
|
||||
install(TARGETS osm2pgsql RUNTIME DESTINATION ${NOMINATIM_LIBDIR})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (BUILD_MODULE)
|
||||
install(PROGRAMS ${PROJECT_BINARY_DIR}/module/nominatim.so
|
||||
DESTINATION ${NOMINATIM_LIBDIR}/module)
|
||||
endif()
|
||||
|
||||
if (BUILD_API)
|
||||
install(DIRECTORY lib-php DESTINATION ${NOMINATIM_LIBDIR})
|
||||
endif()
|
||||
|
||||
install(FILES settings/env.defaults
|
||||
settings/address-levels.json
|
||||
settings/phrase-settings.json
|
||||
settings/import-admin.style
|
||||
settings/import-street.style
|
||||
settings/import-address.style
|
||||
settings/import-full.style
|
||||
settings/import-extratags.style
|
||||
settings/import-admin.lua
|
||||
settings/import-street.lua
|
||||
settings/import-address.lua
|
||||
settings/import-full.lua
|
||||
settings/import-extratags.lua
|
||||
settings/flex-base.lua
|
||||
settings/icu_tokenizer.yaml
|
||||
settings/country_settings.yaml
|
||||
DESTINATION ${NOMINATIM_CONFIGDIR})
|
||||
|
||||
install(DIRECTORY settings/icu-rules
|
||||
DESTINATION ${NOMINATIM_CONFIGDIR})
|
||||
install(DIRECTORY settings/country-names
|
||||
DESTINATION ${NOMINATIM_CONFIGDIR})
|
||||
|
||||
if (INSTALL_MUNIN_PLUGINS)
|
||||
install(FILES munin/nominatim_importlag
|
||||
munin/nominatim_query_speed
|
||||
munin/nominatim_requests
|
||||
DESTINATION ${NOMINATIM_MUNINDIR})
|
||||
endif()
|
||||
@@ -30,6 +30,19 @@ feature pull requests. If you plan to make larger changes, please open
|
||||
an issue first or comment on the appropriate issue already existing so
|
||||
that duplicate work can be avoided.
|
||||
|
||||
### Using AI-assisted code generators
|
||||
|
||||
PRs that include AI-generated content, may that be in code, in the PR
|
||||
description or in documentation need to
|
||||
|
||||
1. clearly mark the AI-generated sections as such, for example, by
|
||||
mentioning all use of AI in the PR description, and
|
||||
2. include proof that you have run the generated code on an actual
|
||||
installation of Nominatim. Adding and excuting tests will not be
|
||||
sufficient. You need to show that the code actually solves the problem
|
||||
the PR claims to solve.
|
||||
|
||||
|
||||
## Coding style
|
||||
|
||||
Nominatim historically hasn't followed a particular coding style but we
|
||||
@@ -46,14 +59,11 @@ are in process of consolidating the style. The following rules apply:
|
||||
* no spaces after opening and before closing bracket
|
||||
* leave out space between a function name and bracket
|
||||
but add one between control statement(if, while, etc.) and bracket
|
||||
* for PHP variables use CamelCase with a prefixing letter indicating the type
|
||||
(i - integer, f - float, a - array, s - string, o - object)
|
||||
|
||||
The coding style is enforced with PHPCS and pylint. It can be tested with:
|
||||
The coding style is enforced with flake8. It can be tested with:
|
||||
|
||||
```
|
||||
phpcs --report-width=120 --colors .
|
||||
pylint3 --extension-pkg-whitelist=osmium nominatim
|
||||
make lint
|
||||
```
|
||||
|
||||
## Testing
|
||||
@@ -61,32 +71,34 @@ pylint3 --extension-pkg-whitelist=osmium nominatim
|
||||
Before submitting a pull request make sure that the tests pass:
|
||||
|
||||
```
|
||||
cd build
|
||||
make test
|
||||
make tests
|
||||
```
|
||||
|
||||
## Releases
|
||||
|
||||
Nominatim follows semantic versioning. Major releases are done for large changes
|
||||
that require (or at least strongly recommend) a reimport of the databases.
|
||||
Minor releases can usually be applied to exisiting databases Patch releases
|
||||
Minor releases can usually be applied to existing databases. Patch releases
|
||||
contain bug fixes only and are released from a separate branch where the
|
||||
relevant changes are cherry-picked from the master branch.
|
||||
|
||||
Checklist for releases:
|
||||
|
||||
* [ ] increase version in `nominatim/version.py` and CMakeLists.txt
|
||||
* [ ] increase versions in
|
||||
* `src/nominatim_api/version.py`
|
||||
* `src/nominatim_db/version.py`
|
||||
* [ ] update `ChangeLog` (copy information from patch releases from release branch)
|
||||
* [ ] complete `docs/admin/Migration.md`
|
||||
* [ ] update EOL dates in `SECURITY.md`
|
||||
* [ ] commit and make sure CI tests pass
|
||||
* [ ] update OSMF production repo and release new version -post1 there
|
||||
* [ ] test migration
|
||||
* download, build and import previous version
|
||||
* migrate using master version
|
||||
* run updates using master version
|
||||
* [ ] prepare tarball:
|
||||
* `git clone --recursive https://github.com/osm-search/Nominatim` (switch to right branch!)
|
||||
* `rm -r .git* osm2pgsql/.git*`
|
||||
* `git clone https://github.com/osm-search/Nominatim` (switch to right branch!)
|
||||
* `rm -r .git*`
|
||||
* copy country data into `data/`
|
||||
* add version to base directory and package
|
||||
* [ ] upload tarball to https://nominatim.org
|
||||
@@ -100,3 +112,4 @@ Checklist for releases:
|
||||
* compile and import Nominatim
|
||||
* run `nominatim --version` to confirm correct version
|
||||
* [ ] tag new release and add a release on github.com
|
||||
* [ ] build pip packages and upload to pypi
|
||||
|
||||
457
COPYING
457
COPYING
@@ -1,339 +1,232 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
Copyright © 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
|
||||
Preamble
|
||||
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
Preamble
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
The GNU General Public License is a free, copyleft license for software and other kinds of works.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
The precise terms and conditions for copying, distribution and modification follow.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
0. Definitions.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
“This License” refers to version 3 of the GNU General Public License.
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
A “covered work” means either the unmodified Program or a work based on the Program.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
1. Source Code.
|
||||
The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work.
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
The Corresponding Source for a work in source code form is that same work.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
2. Basic Permissions.
|
||||
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
4. Conveying Verbatim Copies.
|
||||
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
5. Conveying Modified Source Versions.
|
||||
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.
|
||||
|
||||
NO WARRANTY
|
||||
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
6. Conveying Non-Source Forms.
|
||||
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
|
||||
|
||||
“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
|
||||
|
||||
An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”.
|
||||
|
||||
A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
|
||||
|
||||
A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read <https://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
|
||||
142
ChangeLog
142
ChangeLog
@@ -1,3 +1,135 @@
|
||||
5.0.0
|
||||
* increase required versions for PostgreSQL (12+), PostGIS (3.0+)
|
||||
* remove installation via cmake and debundle osm2pgsql
|
||||
* remove deprecated PHP frontend
|
||||
* remove deprecated legacy tokenizer
|
||||
* add configurable pre-processing of queries
|
||||
* add query pre-processor to split up Japanese addresses
|
||||
* rewrite of osm2pgsql style implementation
|
||||
(also adds support for osm2pgsql-themepark)
|
||||
* reduce the number of SQL queries needed to complete a 'lookup' call
|
||||
* improve computation of centroid for lines with only two points
|
||||
* improve bbox output for postcode areas
|
||||
* improve result order by returning the largest object when other things are
|
||||
equal
|
||||
* add fallback for reverse geocoding to default country tables
|
||||
* exclude postcode areas from reverse geocoding
|
||||
* disable search endpoint when database is reverse-only (regression)
|
||||
* minor performance improvements to area split algorithm
|
||||
* switch table and index creation to use autocommit mode to avoid deadlocks
|
||||
* drop overly long ways during import
|
||||
* restrict automatic migrations to versions 4.3+
|
||||
* switch linting from pylint to flake8
|
||||
* switch tests to use a wikimedia test file in the new CSV style
|
||||
* various fixes and improvements to documentation
|
||||
|
||||
4.5.0
|
||||
* allow building Nominatim as a pip package
|
||||
* make osm2pgsql building optional
|
||||
* switch importer to psycopg3
|
||||
* allow output format of web search to be customized in self-installations
|
||||
* look up potential postcode areas for postcode results
|
||||
* add word usage statistics for address terms
|
||||
* implement more light-weight CSV format for wiki importance tables
|
||||
* rewrite SQL for place search to use window functions
|
||||
* increase search radius when filtering by postcode
|
||||
* prefer POI points over POI areas
|
||||
* reintroduce full terms for address terms in search_name table
|
||||
* reindex postcodes when their parent is deleted
|
||||
* indexing: precompute counts of affected rows
|
||||
* ensure consistent country assignments for overlapping countries
|
||||
* make Nominatim[Async]API context manager to ensure proper calling of
|
||||
close()
|
||||
* make usage of project dir optional for library
|
||||
* drop interpolations when no parent can be found
|
||||
* style tweaks to reflect OSM usage (man_made, highway and others)
|
||||
* deprecation of: bundled osm2pgsql, legacy tokenizer, PHP frontend
|
||||
* make documentation buildable without CMake
|
||||
* various fixes and improvements to documentation
|
||||
|
||||
4.4.1
|
||||
* fix geocodejson output: admin level output should only print boundaries
|
||||
* updating: restrict invalidation of child objects on large street features
|
||||
* restrict valid interpolation house numbers to 0-999999
|
||||
* fix import error when SQLAlchemy 1.4 and psycopg3 are installed
|
||||
* various typo fixes in the documentation
|
||||
|
||||
4.4.0
|
||||
* add export to SQLite database and SQLite support for the frontend
|
||||
* switch to Python frontend as the default frontend
|
||||
* update to osm2pgsql 1.11.0
|
||||
* add support for new osm2pgsql middle table format
|
||||
* simplify geometry for large polygon objects not used in addresses
|
||||
* various performance tweaks for search in Python frontend
|
||||
* fix regression in search with categories where it was confused with near
|
||||
search
|
||||
* partially roll back use of SQLAlchemy lambda statements due to bugs
|
||||
in SQLAlchemy
|
||||
* fix handling of timezones for timestamps from the database
|
||||
* fix handling of full address searches in connection with a viewbox
|
||||
* fix postcode computation of highway areas
|
||||
* fix handling of timeout errors for Python <= 3.10
|
||||
* fix address computation for postcode areas
|
||||
* fix variable shadowing in osm2pgsql flex script, causing bugs with LuaJIT
|
||||
* make sure extratags are always null when empty
|
||||
* reduce importance of places without wikipedia reference
|
||||
* improve performance of word count computations
|
||||
* drop support for wikipedia tags with full URLs
|
||||
* replace get_addressdata() SQL implementation with a Python function
|
||||
* improve display name for non-address features
|
||||
* fix postcode validation for postcodes with country code
|
||||
(thanks @pawel-wroniszewski)
|
||||
* add possibility to run imports without superuser database rights
|
||||
(thanks @robbe-haesendonck)
|
||||
* new CLI command for cleaning deleted relations (thanks @lujoh)
|
||||
* add check for database version in the CLI check command
|
||||
* updates to import styles ignoring more unused objects
|
||||
* various typo fixes (thanks @kumarUjjawal)
|
||||
|
||||
4.3.2
|
||||
* fix potential SQL injection issue for 'nominatim admin --collect-os-info'
|
||||
* PHP frontend: fix on-the-fly lookup of postcode areas near boundaries
|
||||
* Python frontend: improve handling of viewbox
|
||||
* Python frontend: correct deployment instructions
|
||||
|
||||
4.3.1
|
||||
* reintroduce result rematching
|
||||
* improve search of multi-part names
|
||||
* fix accidentally switched meaning of --reverse-only and --search-only in
|
||||
warm command
|
||||
|
||||
4.3.0
|
||||
* fix failing importance recalculation command
|
||||
* fix merging of linked names into unnamed boundaries
|
||||
* fix a number of corner cases with interpolation splitting resulting in
|
||||
invalid geometries
|
||||
* fix failure in website generation when password contains curly brackets
|
||||
* fix broken use of ST_Project in PostGIS 3.4
|
||||
* new NOMINATIM_SEARCH_WITHIN_COUNTRIES setting to restrict reverse lookups
|
||||
to known countries (thanks @alfmarcua)
|
||||
* allow negative OSM IDs (thanks @alfmarcua)
|
||||
* disallow import of Tiger data in a frozen DB
|
||||
* avoid UPDATE to change settings to be compatible with r/o DBs (thanks @t-tomek)
|
||||
* update bundled osm2pgsql to 1.9.2
|
||||
* reorganise osm2pgsql flex style and make it the default
|
||||
* exclude names ending in :wikipedia from indexing
|
||||
* no longer accept comma as a list separator in name tags
|
||||
* process forward dependencies on update to catch updates in geometries
|
||||
of ways and relations
|
||||
* fix handling of isolated silent letters during transliteration
|
||||
* no longer assign postcodes to large linear features like rivers
|
||||
* introduce nominatim.paths module for finding data and libraries
|
||||
* documentation layout changed to material theme
|
||||
* new documentation section for library
|
||||
* various smaller fixes to existing documentation
|
||||
(thanks @woodpeck, @bloom256, @biswajit-k)
|
||||
* updates to vagrant install scripts, drop support for Ubuntu 18
|
||||
(thanks @n-timofeev)
|
||||
* removed obsolete configuration variables from env.defaults
|
||||
* add script for generating a taginfo description (thanks @biswajit-k)
|
||||
* modernize Python code around BDD test and add testing of Python frontend
|
||||
* lots of new BDD tests for API output
|
||||
|
||||
4.2.3
|
||||
|
||||
* fix deletion handling for 'nominatim add-data'
|
||||
@@ -208,7 +340,7 @@
|
||||
* increase splitting for large geometries to improve indexing speed
|
||||
* remove deprecated get_magic_quotes_gpc() function
|
||||
* make sure that all postcodes have an entry in word and are thus searchable
|
||||
* remove use of ST_Covers in conjunction woth ST_Intersects,
|
||||
* remove use of ST_Covers in conjunction with ST_Intersects,
|
||||
causes bad query planning and slow updates in Postgis3
|
||||
* update osm2pgsql
|
||||
|
||||
@@ -265,7 +397,7 @@
|
||||
* exclude postcode ranges separated by colon from centre point calculation
|
||||
* update osm2pgsql, better handling of imports without flatnode file
|
||||
* switch to more efficient algorithm for word set computation
|
||||
* use only boundries for country and state parts of addresses
|
||||
* use only boundaries for country and state parts of addresses
|
||||
* improve updates of addresses with housenumbers and interpolations
|
||||
* remove country from place_addressline table and use country_code instead
|
||||
* optimise indexes on search_name partition tables
|
||||
@@ -304,7 +436,7 @@
|
||||
|
||||
* complete rewrite of reverse search algorithm
|
||||
* add new geojson and geocodejson output formats
|
||||
* add simple export script to exprot addresses to CSV
|
||||
* add simple export script to export addresses to CSV
|
||||
* remove is_in terms from address computation
|
||||
* remove unused search_name_country tables
|
||||
* various smaller fixes to query parsing
|
||||
@@ -369,7 +501,7 @@
|
||||
* move installation documentation into this repo
|
||||
* add self-documenting vagrant scripts
|
||||
* remove --create-website, recommend to use website directory in build
|
||||
* add accessor functions for URL parameters and improve erro checking
|
||||
* add accessor functions for URL parameters and improve error checking
|
||||
* remove IP blocking and rate-limiting code
|
||||
* enable CI via travis
|
||||
* reformatting for more consistent coding style
|
||||
@@ -380,7 +512,7 @@
|
||||
* update to refactored osm2pgsql which use libosmium based types
|
||||
* switch from osmosis to pyosmium for updates
|
||||
* be more strict when matching against special search terms
|
||||
* handle postcode entries with mutliple values correctly
|
||||
* handle postcode entries with multiple values correctly
|
||||
|
||||
2.5
|
||||
|
||||
|
||||
202
LICENSES/Apache-2.0.txt
Normal file
202
LICENSES/Apache-2.0.txt
Normal file
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
339
LICENSES/GPL-2.0-only.txt
Normal file
339
LICENSES/GPL-2.0-only.txt
Normal file
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
44
Makefile
Normal file
44
Makefile
Normal file
@@ -0,0 +1,44 @@
|
||||
all:
|
||||
|
||||
# Building of wheels
|
||||
|
||||
build: clean-build build-db build-api
|
||||
|
||||
clean-build:
|
||||
rm -f dist/*
|
||||
|
||||
build-db:
|
||||
python3 -m build packaging/nominatim-db --outdir dist/
|
||||
|
||||
build-api:
|
||||
python3 -m build packaging/nominatim-api --outdir dist/
|
||||
|
||||
# Tests
|
||||
|
||||
tests: mypy lint pytest bdd
|
||||
|
||||
mypy:
|
||||
mypy --strict --python-version 3.8 src
|
||||
|
||||
pytest:
|
||||
pytest test/python
|
||||
|
||||
lint:
|
||||
flake8 src
|
||||
|
||||
bdd:
|
||||
cd test/bdd; behave -DREMOVE_TEMPLATE=1
|
||||
|
||||
# Documentation
|
||||
|
||||
doc:
|
||||
mkdocs build
|
||||
|
||||
serve-doc:
|
||||
mkdocs serve
|
||||
|
||||
manpage:
|
||||
argparse-manpage --pyfile man/create-manpage.py --function get_parser --project-name Nominatim --url https://nominatim.org > man/nominatim.1 --author 'the Nominatim developer community' --author-email info@nominatim.org
|
||||
|
||||
|
||||
.PHONY: tests mypy pytest lint bdd build clean-build build-db build-api doc serve-doc manpage
|
||||
42
README.md
42
README.md
@@ -1,5 +1,4 @@
|
||||
[](https://github.com/osm-search/Nominatim/actions?query=workflow%3A%22CI+Tests%22)
|
||||
[](https://codecov.io/gh/osm-search/Nominatim)
|
||||
|
||||
Nominatim
|
||||
=========
|
||||
@@ -28,40 +27,51 @@ can be found at nominatim.org as well.
|
||||
|
||||
A quick summary of the necessary steps:
|
||||
|
||||
1. Compile Nominatim:
|
||||
1. Create a Python virtualenv and install the packages:
|
||||
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
sudo make install
|
||||
python3 -m venv nominatim-venv
|
||||
./nominatim-venv/bin/pip install packaging/nominatim-{api,db}
|
||||
|
||||
2. Create a project directory, get OSM data and import:
|
||||
|
||||
mkdir nominatim-project
|
||||
cd nominatim-project
|
||||
nominatim import --osm-file <your planet file>
|
||||
../nominatim-venv/bin/nominatim import --osm-file <your planet file>
|
||||
|
||||
3. Point your webserver to the nominatim-project/website directory.
|
||||
3. Start the webserver:
|
||||
|
||||
./nominatim-venv/bin/pip install uvicorn falcon
|
||||
../nominatim-venv/bin/nominatim serve
|
||||
|
||||
|
||||
License
|
||||
=======
|
||||
|
||||
The source code is available under a GPLv2 license.
|
||||
The Python source code is available under a GPL license version 3 or later.
|
||||
The Lua configuration files for osm2pgsql are released under the
|
||||
Apache License, Version 2.0. All other files are under a GPLv2 license.
|
||||
|
||||
|
||||
Contributing
|
||||
============
|
||||
|
||||
Contributions, bugreport and pull requests are welcome.
|
||||
For details see [contribution guide](CONTRIBUTING.md).
|
||||
Contributions, bug reports and pull requests are welcome. When reporting a
|
||||
bug, please use one of the
|
||||
[issue templates](https://github.com/osm-search/Nominatim/issues/new/choose)
|
||||
and make sure to provide all the information requested. If you are not
|
||||
sure if you have really found a bug, please ask for help in the forums
|
||||
first (see 'Questions' below).
|
||||
|
||||
For details on contributing, have a look at the
|
||||
[contribution guide](CONTRIBUTING.md).
|
||||
|
||||
|
||||
Questions and help
|
||||
==================
|
||||
|
||||
For questions, community help and discussions you can use the
|
||||
[Github discussions forum](https://github.com/osm-search/Nominatim/discussions)
|
||||
or join the
|
||||
[geocoding mailing list](https://lists.openstreetmap.org/listinfo/geocoding).
|
||||
If you have questions about search results and the OpenStreetMap data
|
||||
used in the search, use the [OSM Forum](https://community.openstreetmap.org/).
|
||||
|
||||
For questions, community help and discussions around the software and
|
||||
your own installation of Nominatim, use the
|
||||
[Github discussions forum](https://github.com/osm-search/Nominatim/discussions).
|
||||
|
||||
11
SECURITY.md
11
SECURITY.md
@@ -9,11 +9,10 @@ versions.
|
||||
|
||||
| Version | End of support for security updates |
|
||||
| ------- | ----------------------------------- |
|
||||
| 4.2.x | 2024-11-24 |
|
||||
| 4.1.x | 2024-08-05 |
|
||||
| 4.0.x | 2023-11-02 |
|
||||
| 3.7.x | 2023-04-05 |
|
||||
| 3.6.x | 2022-12-12 |
|
||||
| 5.0.x | 2027-02-06
|
||||
| 4.5.x | 2026-09-12 |
|
||||
| 4.4.x | 2026-03-07 |
|
||||
| 4.3.x | 2025-09-07 |
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
@@ -37,4 +36,6 @@ incident. Announcements will also be published at the
|
||||
|
||||
## List of Previous Incidents
|
||||
|
||||
* 2023-11-20 - [SQL injection vulnerability](https://nominatim.org/2023/11/20/release-432.html)
|
||||
* 2023-02-21 - [cross-site scripting vulnerability](https://nominatim.org/2023/02/21/release-421.html)
|
||||
* 2020-05-04 - [SQL injection issue on /details endpoint](https://lists.openstreetmap.org/pipermail/geocoding/2020-May/002012.html)
|
||||
|
||||
90
VAGRANT.md
90
VAGRANT.md
@@ -1,6 +1,6 @@
|
||||
# Install Nominatim in a virtual machine for development and testing
|
||||
|
||||
This document describes how you can install Nominatim inside a Ubuntu 22
|
||||
This document describes how you can install Nominatim inside a Ubuntu 24
|
||||
virtual machine on your desktop/laptop (host machine). The goal is to give
|
||||
you a development environment to easily edit code and run the test suite
|
||||
without affecting the rest of your system.
|
||||
@@ -15,29 +15,22 @@ is.
|
||||
|
||||
2. [Vagrant](https://www.vagrantup.com/downloads.html)
|
||||
|
||||
3. Nominatim
|
||||
|
||||
git clone --recursive https://github.com/openstreetmap/Nominatim.git
|
||||
|
||||
If you forgot `--recursive`, it you can later load the submodules using
|
||||
|
||||
git submodule init
|
||||
git submodule update
|
||||
|
||||
3. Nominatim
|
||||
|
||||
git clone https://github.com/openstreetmap/Nominatim.git
|
||||
|
||||
## Installation
|
||||
|
||||
1. Start the virtual machine
|
||||
|
||||
vagrant up ubuntu
|
||||
vagrant up ubuntu24-nginx
|
||||
|
||||
2. Log into the virtual machine
|
||||
|
||||
vagrant ssh ubuntu
|
||||
vagrant ssh ubuntu24-nginx
|
||||
|
||||
3. Import a small country (Monaco)
|
||||
|
||||
|
||||
See the FAQ how to skip this step and point Nominatim to an existing database.
|
||||
|
||||
```
|
||||
@@ -61,73 +54,22 @@ see Nominatim in action on [localhost:8089](http://localhost:8089/nominatim/).
|
||||
You edit code on your host machine in any editor you like. There is no need to
|
||||
restart any software: just refresh your browser window.
|
||||
|
||||
Note that the webserver uses files from the /build directory. If you change
|
||||
files in Nominatim/website or Nominatim/utils for example you first need to
|
||||
copy them into the /build directory by running the `cmake` step from the
|
||||
installation.
|
||||
|
||||
PHP errors are written to `/var/log/apache2/error.log`.
|
||||
|
||||
With `echo` and `var_dump()` you write into the output (HTML/XML/JSON) when
|
||||
you either add `&debug=1` to the URL.
|
||||
Use the functions of the `log()` object to create temporary debug output.
|
||||
Add `&debug=1` to the URL to see the output.
|
||||
|
||||
In the Python BDD test you can use `logger.info()` for temporary debug
|
||||
statements.
|
||||
|
||||
|
||||
|
||||
## Running unit tests
|
||||
|
||||
cd ~/Nominatim/tests/php
|
||||
phpunit ./
|
||||
|
||||
|
||||
## Running PHP code style tests
|
||||
|
||||
cd ~/Nominatim
|
||||
phpcs --colors .
|
||||
|
||||
|
||||
## Running functional tests
|
||||
|
||||
Tests in `test/bdd/db` and `test/bdd/osm2pgsql` have to pass 100%. Other
|
||||
tests might require full planet-wide data. Sadly even if you have your own
|
||||
planet-wide data there will be enough differences to the openstreetmap.org
|
||||
installation to cause false positives in the other tests (see FAQ).
|
||||
|
||||
To run the full test suite
|
||||
|
||||
cd ~/Nominatim/test/bdd
|
||||
behave -DBUILDDIR=/home/vagrant/build/ db osm2pgsql
|
||||
|
||||
To run a single file
|
||||
|
||||
behave -DBUILDDIR=/home/vagrant/build/ api/lookup/simple.feature
|
||||
|
||||
Or a single test by line number
|
||||
|
||||
behave -DBUILDDIR=/home/vagrant/build/ api/lookup/simple.feature:34
|
||||
|
||||
To run specific groups of tests you can add tags just before the `Scenario line`, e.g.
|
||||
|
||||
@bug-34
|
||||
Scenario: address lookup for non-existing or invalid node, way, relation
|
||||
|
||||
and then
|
||||
|
||||
behave -DBUILDDIR=/home/vagrant/build/ --tags @bug-34
|
||||
|
||||
|
||||
|
||||
|
||||
For more information on running tests, see
|
||||
https://nominatim.org/release-docs/develop/develop/Testing/
|
||||
|
||||
|
||||
## FAQ
|
||||
|
||||
##### Will it run on Windows?
|
||||
|
||||
Yes, Vagrant and Virtualbox can be installed on MS Windows just fine. You need a 64bit
|
||||
version of Windows.
|
||||
Yes, Vagrant and Virtualbox can be installed on MS Windows just fine. You need
|
||||
a 64bit version of Windows.
|
||||
|
||||
##### Will it run on Apple Silicon?
|
||||
|
||||
@@ -136,11 +78,11 @@ There is no free/open source version of Parallels.
|
||||
|
||||
##### Why Monaco, can I use another country?
|
||||
|
||||
Of course! The Monaco import takes less than 30 minutes and works with 2GB RAM.
|
||||
Of course! The Monaco import takes less than 10 minutes and works with 2GB RAM.
|
||||
|
||||
##### Will the results be the same as those from nominatim.openstreetmap.org?
|
||||
|
||||
No. Long running Nominatim installations will differ once new import features (or
|
||||
No. Long-running Nominatim installations will differ once new import features (or
|
||||
bug fixes) get added since those usually only get applied to new/changed data.
|
||||
|
||||
Also this document skips the optional Wikipedia data import which affects ranking
|
||||
@@ -188,7 +130,3 @@ e.g. `psql --host localhost --port 9999 nominatim_it`
|
||||
|
||||
Yes. It's possible to start the virtual machine on [Amazon AWS (plugin)](https://github.com/mitchellh/vagrant-aws)
|
||||
or [DigitalOcean (plugin)](https://github.com/smdahlen/vagrant-digitalocean).
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
78
Vagrantfile
vendored
78
Vagrantfile
vendored
@@ -17,6 +17,14 @@ Vagrant.configure("2") do |config|
|
||||
checkout = "no"
|
||||
end
|
||||
|
||||
config.vm.provider "hyperv" do |hv, override|
|
||||
hv.memory = 2048
|
||||
hv.linked_clone = true
|
||||
if ENV['CHECKOUT'] != 'y' then
|
||||
override.vm.synced_folder ".", "/home/vagrant/Nominatim", type: "smb", smb_host: ENV['SMB_HOST'] || ENV['COMPUTERNAME']
|
||||
end
|
||||
end
|
||||
|
||||
config.vm.provider "virtualbox" do |vb, override|
|
||||
vb.gui = false
|
||||
vb.memory = 2048
|
||||
@@ -26,85 +34,77 @@ Vagrant.configure("2") do |config|
|
||||
end
|
||||
end
|
||||
|
||||
config.vm.provider "parallels" do |prl, override|
|
||||
prl.update_guest_tools = false
|
||||
prl.memory = 2048
|
||||
if ENV['CHECKOUT'] != 'y' then
|
||||
override.vm.synced_folder ".", "/home/vagrant/Nominatim"
|
||||
end
|
||||
end
|
||||
|
||||
config.vm.provider "libvirt" do |lv, override|
|
||||
lv.memory = 2048
|
||||
lv.nested = true
|
||||
if ENV['CHECKOUT'] != 'y' then
|
||||
override.vm.synced_folder ".", "/home/vagrant/Nominatim", type: 'nfs'
|
||||
override.vm.synced_folder ".", "/home/vagrant/Nominatim", type: 'nfs', nfs_udp: false
|
||||
end
|
||||
end
|
||||
|
||||
config.vm.define "ubuntu", primary: true do |sub|
|
||||
sub.vm.box = "generic/ubuntu2004"
|
||||
config.vm.define "ubuntu22", primary: true do |sub|
|
||||
sub.vm.box = "generic/ubuntu2204"
|
||||
sub.vm.provision :shell do |s|
|
||||
s.path = "vagrant/Install-on-Ubuntu-20.sh"
|
||||
s.path = "vagrant/Install-on-Ubuntu-22.sh"
|
||||
s.privileged = false
|
||||
s.args = [checkout]
|
||||
end
|
||||
end
|
||||
|
||||
config.vm.define "ubuntu-apache" do |sub|
|
||||
sub.vm.box = "generic/ubuntu2004"
|
||||
config.vm.define "ubuntu22-apache" do |sub|
|
||||
sub.vm.box = "generic/ubuntu2204"
|
||||
sub.vm.provision :shell do |s|
|
||||
s.path = "vagrant/Install-on-Ubuntu-20.sh"
|
||||
s.path = "vagrant/Install-on-Ubuntu-22.sh"
|
||||
s.privileged = false
|
||||
s.args = [checkout, "install-apache"]
|
||||
end
|
||||
end
|
||||
|
||||
config.vm.define "ubuntu-nginx" do |sub|
|
||||
sub.vm.box = "generic/ubuntu2004"
|
||||
config.vm.define "ubuntu22-nginx" do |sub|
|
||||
sub.vm.box = "generic/ubuntu2204"
|
||||
sub.vm.provision :shell do |s|
|
||||
s.path = "vagrant/Install-on-Ubuntu-20.sh"
|
||||
s.path = "vagrant/Install-on-Ubuntu-22.sh"
|
||||
s.privileged = false
|
||||
s.args = [checkout, "install-nginx"]
|
||||
end
|
||||
end
|
||||
|
||||
config.vm.define "ubuntu18" do |sub|
|
||||
sub.vm.box = "generic/ubuntu1804"
|
||||
config.vm.define "ubuntu24" do |sub|
|
||||
sub.vm.box = "bento/ubuntu-24.04"
|
||||
if RUBY_PLATFORM.include?('darwin') && RUBY_PLATFORM.include?('arm64')
|
||||
# Apple M processor
|
||||
sub.vm.box = 'gutehall/ubuntu24-04'
|
||||
end
|
||||
sub.vm.provision :shell do |s|
|
||||
s.path = "vagrant/Install-on-Ubuntu-18.sh"
|
||||
s.path = "vagrant/Install-on-Ubuntu-24.sh"
|
||||
s.privileged = false
|
||||
s.args = [checkout]
|
||||
end
|
||||
end
|
||||
|
||||
config.vm.define "ubuntu18-apache" do |sub|
|
||||
sub.vm.box = "generic/ubuntu1804"
|
||||
config.vm.define "ubuntu24-apache" do |sub|
|
||||
sub.vm.box = "bento/ubuntu-24.04"
|
||||
sub.vm.provision :shell do |s|
|
||||
s.path = "vagrant/Install-on-Ubuntu-18.sh"
|
||||
s.path = "vagrant/Install-on-Ubuntu-24.sh"
|
||||
s.privileged = false
|
||||
s.args = [checkout, "install-apache"]
|
||||
end
|
||||
end
|
||||
|
||||
config.vm.define "ubuntu18-nginx" do |sub|
|
||||
sub.vm.box = "generic/ubuntu1804"
|
||||
config.vm.define "ubuntu24-nginx" do |sub|
|
||||
sub.vm.box = "bento/ubuntu-24.04"
|
||||
sub.vm.provision :shell do |s|
|
||||
s.path = "vagrant/Install-on-Ubuntu-18.sh"
|
||||
s.path = "vagrant/Install-on-Ubuntu-24.sh"
|
||||
s.privileged = false
|
||||
s.args = [checkout, "install-nginx"]
|
||||
end
|
||||
end
|
||||
|
||||
config.vm.define "centos7" do |sub|
|
||||
sub.vm.box = "centos/7"
|
||||
sub.vm.provision :shell do |s|
|
||||
s.path = "vagrant/Install-on-Centos-7.sh"
|
||||
s.privileged = false
|
||||
s.args = [checkout]
|
||||
end
|
||||
end
|
||||
|
||||
config.vm.define "centos" do |sub|
|
||||
sub.vm.box = "generic/centos8"
|
||||
sub.vm.provision :shell do |s|
|
||||
s.path = "vagrant/Install-on-Centos-8.sh"
|
||||
s.privileged = false
|
||||
s.args = [checkout]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(1, '@NOMINATIM_LIBDIR@/lib-python')
|
||||
|
||||
os.environ['NOMINATIM_NOMINATIM_TOOL'] = os.path.abspath(__file__)
|
||||
|
||||
from nominatim import cli
|
||||
from nominatim import version
|
||||
|
||||
version.GIT_COMMIT_HASH = '@GIT_HASH@'
|
||||
|
||||
exit(cli.nominatim(module_dir='@NOMINATIM_LIBDIR@/module',
|
||||
osm2pgsql_path='@NOMINATIM_LIBDIR@/osm2pgsql',
|
||||
phplib_dir='@NOMINATIM_LIBDIR@/lib-php',
|
||||
sqllib_dir='@NOMINATIM_LIBDIR@/lib-sql',
|
||||
data_dir='@NOMINATIM_DATADIR@',
|
||||
config_dir='@NOMINATIM_CONFIGDIR@',
|
||||
phpcgi_path='@PHPCGI_BIN@'))
|
||||
@@ -1,20 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(1, '@CMAKE_SOURCE_DIR@')
|
||||
|
||||
os.environ['NOMINATIM_NOMINATIM_TOOL'] = os.path.abspath(__file__)
|
||||
|
||||
from nominatim import cli
|
||||
from nominatim import version
|
||||
|
||||
version.GIT_COMMIT_HASH = '@GIT_HASH@'
|
||||
|
||||
exit(cli.nominatim(module_dir='@CMAKE_BINARY_DIR@/module',
|
||||
osm2pgsql_path='@CMAKE_BINARY_DIR@/osm2pgsql/osm2pgsql',
|
||||
phplib_dir='@CMAKE_SOURCE_DIR@/lib-php',
|
||||
sqllib_dir='@CMAKE_SOURCE_DIR@/lib-sql',
|
||||
data_dir='@CMAKE_SOURCE_DIR@/data',
|
||||
config_dir='@CMAKE_SOURCE_DIR@/settings',
|
||||
phpcgi_path='@PHPCGI_BIN@'))
|
||||
@@ -1,35 +0,0 @@
|
||||
# Auto-generated vagrant install documentation
|
||||
|
||||
|
||||
# build the actual documentation
|
||||
|
||||
configure_file(mkdocs.yml ../mkdocs.yml)
|
||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/appendix)
|
||||
|
||||
set (DOC_SOURCES
|
||||
admin
|
||||
develop
|
||||
api
|
||||
customize
|
||||
index.md
|
||||
extra.css
|
||||
styles.css
|
||||
)
|
||||
|
||||
foreach (src ${DOC_SOURCES})
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/${src} ${CMAKE_CURRENT_BINARY_DIR}/${src}
|
||||
)
|
||||
endforeach()
|
||||
|
||||
ADD_CUSTOM_TARGET(doc
|
||||
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bash2md.sh ${PROJECT_SOURCE_DIR}/vagrant/Install-on-Ubuntu-18.sh ${CMAKE_CURRENT_BINARY_DIR}/appendix/Install-on-Ubuntu-18.md
|
||||
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bash2md.sh ${PROJECT_SOURCE_DIR}/vagrant/Install-on-Ubuntu-20.sh ${CMAKE_CURRENT_BINARY_DIR}/appendix/Install-on-Ubuntu-20.md
|
||||
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bash2md.sh ${PROJECT_SOURCE_DIR}/vagrant/Install-on-Ubuntu-22.sh ${CMAKE_CURRENT_BINARY_DIR}/appendix/Install-on-Ubuntu-22.md
|
||||
COMMAND PYTHONPATH=${PROJECT_SOURCE_DIR} mkdocs build -d ${CMAKE_CURRENT_BINARY_DIR}/../site-html -f ${CMAKE_CURRENT_BINARY_DIR}/../mkdocs.yml
|
||||
)
|
||||
|
||||
ADD_CUSTOM_TARGET(serve-doc
|
||||
COMMAND PYTHONPATH=${PROJECT_SOURCE_DIR} mkdocs serve
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
)
|
||||
@@ -5,6 +5,35 @@ your Nominatim database. It is assumed that you have already successfully
|
||||
installed the Nominatim software itself, if not return to the
|
||||
[installation page](Installation.md).
|
||||
|
||||
## Importing with a database user without superuser rights
|
||||
|
||||
Nominatim usually creates its own PostgreSQL database at the beginning of the
|
||||
import process. This makes usage easier for the user but means that the
|
||||
database user doing the import needs the appropriate rights.
|
||||
|
||||
If you prefer to run the import with a database user with limited rights,
|
||||
you can do so by changing the import process as follows:
|
||||
|
||||
1. Run the command for database preparation with a database user with
|
||||
superuser rights. For example, to use a db user 'dbadmin' for a
|
||||
database 'nominatim', execute:
|
||||
|
||||
```
|
||||
NOMINATIM_DATABASE_DSN="pgsql:dbname=nominatim;user=dbadmin" nominatim import --prepare-database
|
||||
```
|
||||
|
||||
2. Grant the import user the right to create tables. For example, foe user 'import-user':
|
||||
|
||||
```
|
||||
psql -d nominatim -c 'GRANT CREATE ON SCHEMA public TO "import-user"'
|
||||
```
|
||||
|
||||
3. Now run the reminder of the import with the import user:
|
||||
|
||||
```
|
||||
NOMINATIM_DATABASE_DSN="pgsql:dbname=nominatim;user=import-user" nominatim import --continue import-from-file --osm-file file.pbf
|
||||
```
|
||||
|
||||
## Importing multiple regions (without updates)
|
||||
|
||||
To import multiple regions in your database you can simply give multiple
|
||||
@@ -36,16 +65,15 @@ which has the following structure:
|
||||
|
||||
```bash
|
||||
update
|
||||
├── europe
|
||||
│ ├── andorra
|
||||
│ │ └── sequence.state
|
||||
│ └── monaco
|
||||
│ └── sequence.state
|
||||
└── tmp
|
||||
└── europe
|
||||
├── andorra-latest.osm.pbf
|
||||
└── monaco-latest.osm.pbf
|
||||
|
||||
├── europe
|
||||
│ ├── andorra
|
||||
│ │ └── sequence.state
|
||||
│ └── monaco
|
||||
│ └── sequence.state
|
||||
└── tmp
|
||||
└── europe
|
||||
├── andorra-latest.osm.pbf
|
||||
└── monaco-latest.osm.pbf
|
||||
|
||||
```
|
||||
|
||||
@@ -99,80 +127,17 @@ Change into the project directory and run the following command:
|
||||
|
||||
This will get diffs from the replication server, import diffs and index
|
||||
the database. The default replication server in the
|
||||
script([Geofabrik](https://download.geofabrik.de)) provides daily updates.
|
||||
script ([Geofabrik](https://download.geofabrik.de)) provides daily updates.
|
||||
|
||||
## Using an external PostgreSQL database
|
||||
|
||||
You can install Nominatim using a database that runs on a different server when
|
||||
you have physical access to the file system on the other server. Nominatim
|
||||
uses a custom normalization library that needs to be made accessible to the
|
||||
PostgreSQL server. This section explains how to set up the normalization
|
||||
library.
|
||||
|
||||
!!! note
|
||||
The external module is only needed when using the legacy tokenizer.
|
||||
If you have chosen the ICU tokenizer, then you can ignore this section
|
||||
and follow the standard import documentation.
|
||||
|
||||
### Option 1: Compiling the library on the database server
|
||||
|
||||
The most sure way to get a working library is to compile it on the database
|
||||
server. From the prerequisites you need at least cmake, gcc and the
|
||||
PostgreSQL server package.
|
||||
|
||||
Clone or unpack the Nominatim source code, enter the source directory and
|
||||
create and enter a build directory.
|
||||
|
||||
```sh
|
||||
cd Nominatim
|
||||
mkdir build
|
||||
cd build
|
||||
```
|
||||
|
||||
Now configure cmake to only build the PostgreSQL module and build it:
|
||||
|
||||
```
|
||||
cmake -DBUILD_IMPORTER=off -DBUILD_API=off -DBUILD_TESTS=off -DBUILD_DOCS=off -DBUILD_OSM2PGSQL=off ..
|
||||
make
|
||||
```
|
||||
|
||||
When done, you find the normalization library in `build/module/nominatim.so`.
|
||||
Copy it to a place where it is readable and executable by the PostgreSQL server
|
||||
process.
|
||||
|
||||
### Option 2: Compiling the library on the import machine
|
||||
|
||||
You can also compile the normalization library on the machine from where you
|
||||
run the import.
|
||||
|
||||
!!! important
|
||||
You can only do this when the database server and the import machine have
|
||||
the same architecture and run the same version of Linux. Otherwise there is
|
||||
no guarantee that the compiled library is compatible with the PostgreSQL
|
||||
server running on the database server.
|
||||
|
||||
Make sure that the PostgreSQL server package is installed on the machine
|
||||
**with the same version as on the database server**. You do not need to install
|
||||
the PostgreSQL server itself.
|
||||
|
||||
Download and compile Nominatim as per standard instructions. Once done, you find
|
||||
the normalization library in `build/module/nominatim.so`. Copy the file to
|
||||
the database server at a location where it is readable and executable by the
|
||||
PostgreSQL server process.
|
||||
|
||||
### Running the import
|
||||
|
||||
On the client side you now need to configure the import to point to the
|
||||
correct location of the library **on the database server**. Add the following
|
||||
line to your your `.env` file:
|
||||
|
||||
```php
|
||||
NOMINATIM_DATABASE_MODULE_PATH="<directory on the database server where nominatim.so resides>"
|
||||
```
|
||||
|
||||
Now change the `NOMINATIM_DATABASE_DSN` to point to your remote server and continue
|
||||
to follow the [standard instructions for importing](Import.md).
|
||||
You can install Nominatim using a database that runs on a different server.
|
||||
Simply point the configuration variable `NOMINATIM_DATABASE_DSN` to the
|
||||
server and follow the standard import documentation.
|
||||
|
||||
The import will be faster, if the import is run directly from the database
|
||||
machine. You can easily switch to a different machine for the query frontend
|
||||
after the import.
|
||||
|
||||
## Moving the database to another machine
|
||||
|
||||
@@ -197,20 +162,9 @@ target machine.
|
||||
data updates but the resulting database is only about a third of the size
|
||||
of a full database.
|
||||
|
||||
Next install Nominatim on the target machine by following the standard installation
|
||||
instructions. Again, make sure to use the same version as the source machine.
|
||||
Next install nominatim-api on the target machine by following the standard
|
||||
installation instructions. Again, make sure to use the same version as the
|
||||
source machine.
|
||||
|
||||
Create a project directory on your destination machine and set up the `.env`
|
||||
file to match the configuration on the source machine. Finally run
|
||||
|
||||
nominatim refresh --website
|
||||
|
||||
to make sure that the local installation of Nominatim will be used.
|
||||
|
||||
If you are using the legacy tokenizer you might also have to switch to the
|
||||
PostgreSQL module that was compiled on your target machine. If you get errors
|
||||
that PostgreSQL cannot find or access `nominatim.so` then rerun
|
||||
|
||||
nominatim refresh --functions
|
||||
|
||||
on the target machine to update the the location of the module.
|
||||
file to match the configuration on the source machine. That's all.
|
||||
|
||||
148
docs/admin/Deployment-Python.md
Normal file
148
docs/admin/Deployment-Python.md
Normal file
@@ -0,0 +1,148 @@
|
||||
# Deploying the Nominatim Python frontend
|
||||
|
||||
Nominatim can be run as a Python-based
|
||||
[ASGI web application](https://asgi.readthedocs.io/en/latest/). You have the
|
||||
choice between [Falcon](https://falcon.readthedocs.io/en/stable/)
|
||||
and [Starlette](https://www.starlette.io/) as the ASGI framework.
|
||||
|
||||
This section gives a quick overview on how to configure Nginx to serve
|
||||
Nominatim. Please refer to the documentation of
|
||||
[Nginx](https://nginx.org/en/docs/) for background information on how
|
||||
to configure it.
|
||||
|
||||
!!! Note
|
||||
Throughout this page, we assume your Nominatim project directory is
|
||||
located in `/srv/nominatim-project`. If you have put it somewhere else,
|
||||
you need to adjust the commands and configuration accordingly.
|
||||
|
||||
|
||||
### Installing the required packages
|
||||
|
||||
The Nominatim frontend is best run from its own virtual environment. If
|
||||
you have already created one for the database backend during the
|
||||
[installation](Installation.md#building-nominatim), you can use that. Otherwise
|
||||
create one now with:
|
||||
|
||||
```sh
|
||||
sudo apt-get install virtualenv
|
||||
virtualenv /srv/nominatim-venv
|
||||
```
|
||||
|
||||
The Nominatim frontend is contained in the 'nominatim-api' package. To
|
||||
install directly from the source tree run:
|
||||
|
||||
```sh
|
||||
cd Nominatim
|
||||
/srv/nominatim-venv/bin/pip install packaging/nominatim-api
|
||||
```
|
||||
|
||||
The recommended way to deploy a Python ASGI application is to run
|
||||
the ASGI runner [uvicorn](https://www.uvicorn.org/)
|
||||
together with [gunicorn](https://gunicorn.org/) HTTP server. We use
|
||||
Falcon here as the web framework.
|
||||
|
||||
Add the necessary packages to your virtual environment:
|
||||
|
||||
``` sh
|
||||
/srv/nominatim-venv/bin/pip install falcon uvicorn gunicorn
|
||||
```
|
||||
|
||||
### Setting up Nominatim as a systemd job
|
||||
|
||||
Next you need to set up the service that runs the Nominatim frontend. This is
|
||||
easiest done with a systemd job.
|
||||
|
||||
First you need to tell systemd to create a socket file to be used by
|
||||
hunicorn. Create the following file `/etc/systemd/system/nominatim.socket`:
|
||||
|
||||
``` systemd
|
||||
[Unit]
|
||||
Description=Gunicorn socket for Nominatim
|
||||
|
||||
[Socket]
|
||||
ListenStream=/run/nominatim.sock
|
||||
SocketUser=www-data
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
Now you can add the systemd service for Nominatim itself.
|
||||
Create the following file `/etc/systemd/system/nominatim.service`:
|
||||
|
||||
``` systemd
|
||||
[Unit]
|
||||
Description=Nominatim running as a gunicorn application
|
||||
After=network.target
|
||||
Requires=nominatim.socket
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=www-data
|
||||
Group=www-data
|
||||
WorkingDirectory=/srv/nominatim-project
|
||||
ExecStart=/srv/nominatim-venv/bin/gunicorn -b unix:/run/nominatim.sock -w 4 -k uvicorn.workers.UvicornWorker "nominatim_api.server.falcon.server:run_wsgi()"
|
||||
ExecReload=/bin/kill -s HUP $MAINPID
|
||||
StandardOutput=append:/var/log/gunicorn-nominatim.log
|
||||
StandardError=inherit
|
||||
PrivateTmp=true
|
||||
TimeoutStopSec=5
|
||||
KillMode=mixed
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
This sets up gunicorn with 4 workers (`-w 4` in ExecStart). Each worker runs
|
||||
its own Python process using
|
||||
[`NOMINATIM_API_POOL_SIZE`](../customize/Settings.md#nominatim_api_pool_size)
|
||||
connections to the database to serve requests in parallel.
|
||||
|
||||
Make the new services known to systemd and start it:
|
||||
|
||||
``` sh
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable nominatim.socket
|
||||
sudo systemctl start nominatim.socket
|
||||
sudo systemctl enable nominatim.service
|
||||
sudo systemctl start nominatim.service
|
||||
```
|
||||
|
||||
This sets the service up, so that Nominatim is automatically started
|
||||
on reboot.
|
||||
|
||||
### Configuring nginx
|
||||
|
||||
To make the service available to the world, you need to proxy it through
|
||||
nginx. Add the following definition to the default configuration:
|
||||
|
||||
``` nginx
|
||||
upstream nominatim_service {
|
||||
server unix:/run/nominatim.sock fail_timeout=0;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
|
||||
root /var/www/html;
|
||||
index /search;
|
||||
|
||||
location / {
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_redirect off;
|
||||
proxy_pass http://nominatim_service;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Reload nginx with
|
||||
|
||||
```
|
||||
sudo systemctl reload nginx
|
||||
```
|
||||
|
||||
and you should be able to see the status of your server under
|
||||
`http://localhost/status`.
|
||||
@@ -1,148 +0,0 @@
|
||||
# Deploying Nominatim
|
||||
|
||||
The Nominatim API is implemented as a PHP application. The `website/` directory
|
||||
in the project directory contains the configured website. You can serve this
|
||||
in a production environment with any web server that is capable to run
|
||||
PHP scripts.
|
||||
|
||||
This section gives a quick overview on how to configure Apache and Nginx to
|
||||
serve Nominatim. It is not meant as a full system administration guide on how
|
||||
to run a web service. Please refer to the documentation of
|
||||
[Apache](http://httpd.apache.org/docs/current/) and
|
||||
[Nginx](https://nginx.org/en/docs/)
|
||||
for background information on configuring the services.
|
||||
|
||||
!!! Note
|
||||
Throughout this page, we assume that your Nominatim project directory is
|
||||
located in `/srv/nominatim-project` and that you have installed Nominatim
|
||||
using the default installation prefix `/usr/local`. If you have put it
|
||||
somewhere else, you need to adjust the commands and configuration
|
||||
accordingly.
|
||||
|
||||
We further assume that your web server runs as user `www-data`. Older
|
||||
versions of CentOS may still use the user name `apache`. You also need
|
||||
to adapt the instructions in this case.
|
||||
|
||||
## Making the website directory accessible
|
||||
|
||||
You need to make sure that the `website` directory is accessible for the
|
||||
web server user. You can check that the permissions are correct by accessing
|
||||
on of the php files as the web server user:
|
||||
|
||||
``` sh
|
||||
sudo -u www-data head -n 1 /srv/nominatim-project/website/search.php
|
||||
```
|
||||
|
||||
If this shows a permission error, then you need to adapt the permissions of
|
||||
each directory in the path so that it is executable for `www-data`.
|
||||
|
||||
If you have SELinux enabled, further adjustments may be necessary to give the
|
||||
web server access. At a minimum the following SELinux labelling should be done
|
||||
for Nominatim:
|
||||
|
||||
``` sh
|
||||
sudo semanage fcontext -a -t httpd_sys_content_t "/usr/local/nominatim/lib/lib-php(/.*)?"
|
||||
sudo semanage fcontext -a -t httpd_sys_content_t "/srv/nominatim-project/website(/.*)?"
|
||||
sudo semanage fcontext -a -t lib_t "/srv/nominatim-project/module/nominatim.so"
|
||||
sudo restorecon -R -v /usr/local/lib/nominatim
|
||||
sudo restorecon -R -v /srv/nominatim-project
|
||||
```
|
||||
|
||||
## Nominatim with Apache
|
||||
|
||||
### Installing the required packages
|
||||
|
||||
With Apache you can use the PHP module to run Nominatim.
|
||||
|
||||
Under Ubuntu/Debian install them with:
|
||||
|
||||
``` sh
|
||||
sudo apt install apache2 libapache2-mod-php
|
||||
```
|
||||
|
||||
### Configuring Apache
|
||||
|
||||
Make sure your Apache configuration contains the required permissions for the
|
||||
directory and create an alias:
|
||||
|
||||
``` apache
|
||||
<Directory "/srv/nominatim-project/website">
|
||||
Options FollowSymLinks MultiViews
|
||||
AddType text/html .php
|
||||
DirectoryIndex search.php
|
||||
Require all granted
|
||||
</Directory>
|
||||
Alias /nominatim /srv/nominatim-project/website
|
||||
```
|
||||
|
||||
After making changes in the apache config you need to restart apache.
|
||||
The website should now be available on `http://localhost/nominatim`.
|
||||
|
||||
## Nominatim with Nginx
|
||||
|
||||
### Installing the required packages
|
||||
|
||||
Nginx has no built-in PHP interpreter. You need to use php-fpm as a daemon for
|
||||
serving PHP cgi.
|
||||
|
||||
On Ubuntu/Debian install nginx and php-fpm with:
|
||||
|
||||
``` sh
|
||||
sudo apt install nginx php-fpm
|
||||
```
|
||||
|
||||
### Configure php-fpm and Nginx
|
||||
|
||||
By default php-fpm listens on a network socket. If you want it to listen to a
|
||||
Unix socket instead, change the pool configuration
|
||||
(`/etc/php/<php version>/fpm/pool.d/www.conf`) as follows:
|
||||
|
||||
``` ini
|
||||
; Replace the tcp listener and add the unix socket
|
||||
listen = /var/run/php-fpm-nominatim.sock
|
||||
|
||||
; Ensure that the daemon runs as the correct user
|
||||
listen.owner = www-data
|
||||
listen.group = www-data
|
||||
listen.mode = 0666
|
||||
```
|
||||
|
||||
Tell nginx that php files are special and to fastcgi_pass to the php-fpm
|
||||
unix socket by adding the location definition to the default configuration.
|
||||
|
||||
``` nginx
|
||||
root /srv/nominatim-project/website;
|
||||
index search.php;
|
||||
location / {
|
||||
try_files $uri $uri/ @php;
|
||||
}
|
||||
|
||||
location @php {
|
||||
fastcgi_param SCRIPT_FILENAME "$document_root$uri.php";
|
||||
fastcgi_param PATH_TRANSLATED "$document_root$uri.php";
|
||||
fastcgi_param QUERY_STRING $args;
|
||||
fastcgi_pass unix:/var/run/php-fpm-nominatim.sock;
|
||||
fastcgi_index index.php;
|
||||
include fastcgi_params;
|
||||
}
|
||||
|
||||
location ~ [^/]\.php(/|$) {
|
||||
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
|
||||
if (!-f $document_root$fastcgi_script_name) {
|
||||
return 404;
|
||||
}
|
||||
fastcgi_pass unix:/var/run/php-fpm-nominatim.sock;
|
||||
fastcgi_index search.php;
|
||||
include fastcgi.conf;
|
||||
}
|
||||
```
|
||||
|
||||
Restart the nginx and php-fpm services and the website should now be available
|
||||
at `http://localhost/`.
|
||||
|
||||
## Nominatim with other webservers
|
||||
|
||||
Users have created instructions for other webservers:
|
||||
|
||||
* [Caddy](https://github.com/osm-search/Nominatim/discussions/2580)
|
||||
|
||||
@@ -37,65 +37,6 @@ nominatim import --continue indexing
|
||||
Otherwise it's best to start the full setup from the beginning.
|
||||
|
||||
|
||||
### PHP "open_basedir restriction in effect" warnings
|
||||
|
||||
PHP Warning: file_get_contents(): open_basedir restriction in effect.
|
||||
|
||||
You need to adjust the
|
||||
[open_basedir](https://www.php.net/manual/en/ini.core.php#ini.open-basedir)
|
||||
setting in your PHP configuration (`php.ini` file). By default this setting may
|
||||
look like this:
|
||||
|
||||
open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/
|
||||
|
||||
Either add reported directories to the list or disable this setting temporarily
|
||||
by adding ";" at the beginning of the line. Don't forget to enable this setting
|
||||
again once you are done with the PHP command line operations.
|
||||
|
||||
|
||||
### PHP timezeone warnings
|
||||
|
||||
The Apache log may contain lots of PHP warnings like this:
|
||||
`PHP Warning: date_default_timezone_set() function.`
|
||||
|
||||
You should set the default time zone as instructed in the warning in
|
||||
your `php.ini` file. Find the entry about timezone and set it to
|
||||
something like this:
|
||||
|
||||
; Defines the default timezone used by the date functions
|
||||
; https://php.net/date.timezone
|
||||
date.timezone = 'America/Denver'
|
||||
|
||||
Or
|
||||
|
||||
```
|
||||
echo "date.timezone = 'America/Denver'" > /etc/php.d/timezone.ini
|
||||
```
|
||||
|
||||
### nominatim.so version mismatch
|
||||
|
||||
When running the import you may get a version mismatch:
|
||||
`COPY_END for place failed: ERROR: incompatible library "/srv/Nominatim/nominatim/build/module/nominatim.so": version mismatch`
|
||||
|
||||
pg_config seems to use bad includes sometimes when multiple versions
|
||||
of PostgreSQL are available in the system. Make sure you remove the
|
||||
server development libraries (`postgresql-server-dev-13` on Ubuntu)
|
||||
and recompile (`cmake .. && make`).
|
||||
|
||||
|
||||
### I see the error "ERROR: permission denied for language c"
|
||||
|
||||
`nominatim.so`, written in C, is required to be installed on the database
|
||||
server. Some managed database (cloud) services like Amazon RDS do not allow
|
||||
this. There is currently no work-around other than installing a database
|
||||
on a non-managed machine.
|
||||
|
||||
|
||||
### I see the error: "function transliteration(text) does not exist"
|
||||
|
||||
Reinstall the nominatim functions with `nominatim refresh --functions`
|
||||
and check for any errors, e.g. a missing `nominatim.so` file.
|
||||
|
||||
### I see the error: "ERROR: mmap (remap) failed"
|
||||
|
||||
This may be a simple out-of-memory error. Try reducing the memory used
|
||||
@@ -137,45 +78,31 @@ for default Ubuntu operating system for example it's `www-data`.
|
||||
GRANT SELECT ON ALL TABLES IN SCHEMA public TO "www-data";
|
||||
```
|
||||
|
||||
### Website reports "Could not load library "nominatim.so"
|
||||
|
||||
Example error message
|
||||
|
||||
```
|
||||
SELECT make_standard_name('3039 E MEADOWLARK LN') [nativecode=ERROR: could not
|
||||
load library "/srv/nominatim/Nominatim-3.1.0/build/module/nominatim.so":
|
||||
/srv/nominatim/Nominatim-3.1.0/build/module/nominatim.so: cannot open shared
|
||||
object file: Permission denied
|
||||
CONTEXT: PL/pgSQL function make_standard_name(text) line 5 at assignment]
|
||||
```
|
||||
|
||||
The PostgreSQL database, i.e. user `postgres`, needs to have access to that file.
|
||||
|
||||
The permission need to be read & executable by everybody, but not writeable
|
||||
by everybody, e.g.
|
||||
|
||||
```
|
||||
-rwxr-xr-x 1 nominatim nominatim 297984 build/module/nominatim.so
|
||||
```
|
||||
|
||||
Try `chmod a+r nominatim.so; chmod a+x nominatim.so`.
|
||||
|
||||
When you recently updated your operating system, updated PostgreSQL to
|
||||
a new version or moved files (e.g. the build directory) you should
|
||||
recreate `nominatim.so`. Try
|
||||
|
||||
```
|
||||
cd build
|
||||
rm -r module/
|
||||
cmake $main_Nominatim_path && make
|
||||
```
|
||||
|
||||
### Setup.php fails with "DB Error: extension not found"
|
||||
### Setup fails with "DB Error: extension not found"
|
||||
|
||||
Make sure you have the PostgreSQL extensions "hstore" and "postgis" installed.
|
||||
See the installation instructions for a full list of required packages.
|
||||
|
||||
|
||||
### UnicodeEncodeError: 'ascii' codec can't encode character
|
||||
|
||||
Make sure that the operating system's locale is UTF-8. With some prebuilt
|
||||
images (e.g. LXC containers from Proxmox, see
|
||||
[discussion](https://github.com/osm-search/Nominatim/discussions/2343)) or
|
||||
images that optimize for size it might be missing.
|
||||
|
||||
On Ubuntu you can check the locale is installed:
|
||||
|
||||
```
|
||||
grep UTF-8 /etc/default/locale
|
||||
```
|
||||
|
||||
And install it using
|
||||
|
||||
```
|
||||
dpkg-reconfigure locales
|
||||
```
|
||||
|
||||
### I forgot to delete the flatnodes file before starting an import.
|
||||
|
||||
That's fine. For each import the flatnodes file get overwritten.
|
||||
@@ -187,4 +114,6 @@ for more information.
|
||||
|
||||
### Can I import negative OSM ids into Nominatim?
|
||||
|
||||
See [this question of Stackoverflow](https://help.openstreetmap.org/questions/64662/nominatim-flatnode-with-negative-id).
|
||||
No, negative IDs are no longer supported by osm2pgsql. You can use
|
||||
large 64-bit IDs that are guaranteed not to clash with OSM IDs. However,
|
||||
you will not able to use a flatnode file with them.
|
||||
|
||||
@@ -14,15 +14,15 @@ to a single Nominatim setup: configuration, extra data, etc. Create a project
|
||||
directory apart from the Nominatim software and change into the directory:
|
||||
|
||||
```
|
||||
mkdir ~/nominatim-planet
|
||||
cd ~/nominatim-planet
|
||||
mkdir ~/nominatim-project
|
||||
cd ~/nominatim-project
|
||||
```
|
||||
|
||||
In the following, we refer to the project directory as `$PROJECT_DIR`. To be
|
||||
able to copy&paste instructions, you can export the appropriate variable:
|
||||
|
||||
```
|
||||
export PROJECT_DIR=~/nominatim-planet
|
||||
export PROJECT_DIR=~/nominatim-project
|
||||
```
|
||||
|
||||
The Nominatim tool assumes per default that the current working directory is
|
||||
@@ -74,15 +74,18 @@ but it will improve the quality of the results if this is installed.
|
||||
This data is available as a binary download. Put it into your project directory:
|
||||
|
||||
cd $PROJECT_DIR
|
||||
wget https://nominatim.org/data/wikimedia-importance.sql.gz
|
||||
wget https://nominatim.org/data/wikimedia-importance.csv.gz
|
||||
wget -O secondary_importance.sql.gz https://nominatim.org/data/wikimedia-secondary-importance.sql.gz
|
||||
|
||||
The file is about 400MB and adds around 4GB to the Nominatim database.
|
||||
The files are about 400MB and add around 4GB to the Nominatim database. For
|
||||
more information about importance,
|
||||
see [Importance Customization](../customize/Importance.md).
|
||||
|
||||
!!! tip
|
||||
If you forgot to download the wikipedia rankings, then you can
|
||||
also add importances after the import. Download the SQL files, then
|
||||
run `nominatim refresh --wiki-data --importance`. Updating
|
||||
importances for a planet will take a couple of hours.
|
||||
run `nominatim refresh --wiki-data --secondary-importance --importance`.
|
||||
Updating importances for a planet will take a couple of hours.
|
||||
|
||||
### External postcodes
|
||||
|
||||
@@ -153,7 +156,7 @@ if you plan to use the installation only for exports to a
|
||||
[photon](https://photon.komoot.io/) database, then you can set up a database
|
||||
without search indexes. Add `--reverse-only` to your setup command above.
|
||||
|
||||
This saves about 5% of disk space.
|
||||
This saves about 5% of disk space, import time won't be significant faster.
|
||||
|
||||
### Filtering Imported Data
|
||||
|
||||
@@ -228,7 +231,7 @@ to load the OSM data into the PostgreSQL database. This step is very demanding
|
||||
in terms of RAM usage. osm2pgsql and PostgreSQL are running in parallel at
|
||||
this point. PostgreSQL blocks at least the part of RAM that has been configured
|
||||
with the `shared_buffers` parameter during
|
||||
[PostgreSQL tuning](Installation.md#postgresql-tuning)
|
||||
[PostgreSQL tuning](Installation.md#tuning-the-postgresql-database)
|
||||
and needs some memory on top of that. osm2pgsql needs at least 2GB of RAM for
|
||||
its internal data structures, potentially more when it has to process very large
|
||||
relations. In addition it needs to maintain a cache for node locations. The size
|
||||
@@ -254,26 +257,51 @@ successfully.
|
||||
nominatim admin --check-database
|
||||
```
|
||||
|
||||
Now you can try out your installation by running:
|
||||
If you have installed the `nominatim-api` package, then you can try out
|
||||
your installation by executing a simple query on the command line:
|
||||
|
||||
```sh
|
||||
``` sh
|
||||
nominatim search --query Berlin
|
||||
```
|
||||
|
||||
or, when you have a reverse-only installation:
|
||||
|
||||
``` sh
|
||||
nominatim reverse --lat 51 --lon 45
|
||||
```
|
||||
|
||||
If you want to run Nominatim as a service, make sure you have installed
|
||||
the right packages as per [Installation](Installation.md#software).
|
||||
|
||||
#### Testing the Python frontend
|
||||
|
||||
To run the test server against the Python frontend, you must choose a
|
||||
web framework to use, either starlette or falcon. Make sure the appropriate
|
||||
packages are installed. Then run
|
||||
|
||||
``` sh
|
||||
nominatim serve
|
||||
```
|
||||
|
||||
This runs a small test server normally used for development. You can use it
|
||||
to verify that your installation is working. Go to
|
||||
`http://localhost:8088/status.php` and you should see the message `OK`.
|
||||
You can also run a search query, e.g. `http://localhost:8088/search.php?q=Berlin`.
|
||||
or, if you prefer to use Starlette instead of Falcon as webserver,
|
||||
|
||||
Note that search query is not supported for reverse-only imports. You can run a
|
||||
reverse query, e.g. `http://localhost:8088/reverse.php?lat=27.1750090510034&lon=78.04209025`.
|
||||
``` sh
|
||||
nominatim serve --engine starlette
|
||||
```
|
||||
|
||||
To run Nominatim via webservers like Apache or nginx, please read the
|
||||
[Deployment chapter](Deployment.md).
|
||||
Go to `http://localhost:8088/status` and you should see the message `OK`.
|
||||
You can also run a search query, e.g. `http://localhost:8088/search?q=Berlin`
|
||||
or, for reverse-only installations a reverse query,
|
||||
e.g. `http://localhost:8088/reverse?lat=27.1750090510034&lon=78.04209025`.
|
||||
|
||||
## Adding search through category phrases
|
||||
Do not use this test server in production.
|
||||
To run Nominatim via webservers like Apache or nginx, please continue reading
|
||||
[Deploy the Python frontend](Deployment-Python.md).
|
||||
|
||||
If you want to be able to search for places by their type through
|
||||
|
||||
## Enabling search by category phrases
|
||||
|
||||
To be able to search for places by their type using
|
||||
[special phrases](https://wiki.openstreetmap.org/wiki/Nominatim/Special_Phrases)
|
||||
you also need to import these key phrases like this:
|
||||
|
||||
|
||||
@@ -4,9 +4,8 @@ This page contains generic installation instructions for Nominatim and its
|
||||
prerequisites. There are also step-by-step instructions available for
|
||||
the following operating systems:
|
||||
|
||||
* [Ubuntu 22.04](../appendix/Install-on-Ubuntu-22.md)
|
||||
* [Ubuntu 20.04](../appendix/Install-on-Ubuntu-20.md)
|
||||
* [Ubuntu 18.04](../appendix/Install-on-Ubuntu-18.md)
|
||||
* [Ubuntu 24.04](Install-on-Ubuntu-24.md)
|
||||
* [Ubuntu 22.04](Install-on-Ubuntu-22.md)
|
||||
|
||||
These OS-specific instructions can also be found in executable form
|
||||
in the `vagrant/` directory.
|
||||
@@ -23,44 +22,38 @@ and can't offer support.
|
||||
|
||||
### Software
|
||||
|
||||
!!! Warning
|
||||
For larger installations you **must have** PostgreSQL 11+ and PostGIS 3+
|
||||
otherwise import and queries will be slow to the point of being unusable.
|
||||
Query performance has marked improvements with PostgreSQL 13+ and PostGIS 3.2+.
|
||||
|
||||
For compiling:
|
||||
|
||||
* [cmake](https://cmake.org/)
|
||||
* [expat](https://libexpat.github.io/)
|
||||
* [proj](https://proj.org/)
|
||||
* [bzip2](http://www.bzip.org/)
|
||||
* [zlib](https://www.zlib.net/)
|
||||
* [ICU](http://site.icu-project.org/)
|
||||
* [Boost libraries](https://www.boost.org/), including system and filesystem
|
||||
* PostgreSQL client libraries
|
||||
* a recent C++ compiler (gcc 5+ or Clang 3.8+)
|
||||
|
||||
For running Nominatim:
|
||||
|
||||
* [PostgreSQL](https://www.postgresql.org) (9.6+ will work, 11+ strongly recommended)
|
||||
* [PostGIS](https://postgis.net) (2.2+ will work, 3.0+ strongly recommended)
|
||||
* [Python 3](https://www.python.org/) (3.6+)
|
||||
* [Psycopg2](https://www.psycopg.org) (2.7+)
|
||||
* [PostgreSQL](https://www.postgresql.org) (12+ will work, 13+ strongly recommended)
|
||||
* [PostGIS](https://postgis.net) (3.0+ will work, 3.2+ strongly recommended)
|
||||
* [osm2pgsql](https://osm2pgsql.org) (1.8+)
|
||||
* [Python 3](https://www.python.org/) (3.7+)
|
||||
|
||||
Furthermore the following Python libraries are required:
|
||||
|
||||
* [Psycopg3](https://www.psycopg.org)
|
||||
* [Python Dotenv](https://github.com/theskumar/python-dotenv)
|
||||
* [psutil](https://github.com/giampaolo/psutil)
|
||||
* [Jinja2](https://palletsprojects.com/p/jinja/)
|
||||
* [PyICU](https://pypi.org/project/PyICU/)
|
||||
* [PyYaml](https://pyyaml.org/) (5.1+)
|
||||
* [datrie](https://github.com/pytries/datrie)
|
||||
* [PHP](https://php.net) (7.0 or later)
|
||||
* PHP-pgsql
|
||||
* PHP-intl (bundled with PHP)
|
||||
* PHP-cgi (for running queries from the command line)
|
||||
|
||||
These will be installed automatically when using pip installation.
|
||||
|
||||
For running continuous updates:
|
||||
|
||||
* [pyosmium](https://osmcode.org/pyosmium/)
|
||||
|
||||
For running the Python frontend:
|
||||
|
||||
* [SQLAlchemy](https://www.sqlalchemy.org/) (1.4.31+ with greenlet support)
|
||||
* [asyncpg](https://magicstack.github.io/asyncpg) (0.8+, only when using SQLAlchemy < 2.0)
|
||||
* one of the following web frameworks:
|
||||
* [falcon](https://falconframework.org/) (3.0+)
|
||||
* [starlette](https://www.starlette.io/)
|
||||
* [uvicorn](https://www.uvicorn.org/)
|
||||
|
||||
For dependencies for running tests and building documentation, see
|
||||
the [Development section](../develop/Development-Environment.md).
|
||||
|
||||
@@ -75,7 +68,7 @@ Take into account that the OSM database is growing fast.
|
||||
Fast disks are essential. Using NVME disks is recommended.
|
||||
|
||||
Even on a well configured machine the import of a full planet takes
|
||||
around 2 days. On traditional spinning disks, 7-8 days are more realistic.
|
||||
around 2.5 days. When using traditional SSDs, 4-5 days are more realistic.
|
||||
|
||||
## Tuning the PostgreSQL database
|
||||
|
||||
@@ -87,14 +80,16 @@ your `postgresql.conf` file.
|
||||
maintenance_work_mem = (10GB)
|
||||
autovacuum_work_mem = 2GB
|
||||
work_mem = (50MB)
|
||||
effective_cache_size = (24GB)
|
||||
synchronous_commit = off
|
||||
max_wal_size = 1GB
|
||||
checkpoint_timeout = 10min
|
||||
checkpoint_timeout = 60min
|
||||
checkpoint_completion_target = 0.9
|
||||
random_page_cost = 1.0
|
||||
wal_level = minimal
|
||||
max_wal_senders = 0
|
||||
|
||||
The numbers in brackets behind some parameters seem to work fine for
|
||||
64GB RAM machine. Adjust to your setup. A higher number for `max_wal_size`
|
||||
128GB RAM machine. Adjust to your setup. A higher number for `max_wal_size`
|
||||
means that PostgreSQL needs to run checkpoints less often but it does require
|
||||
the additional space on your disk.
|
||||
|
||||
@@ -107,14 +102,14 @@ you might consider setting:
|
||||
and even reduce `autovacuum_work_mem` further. This will reduce the amount
|
||||
of memory that autovacuum takes away from the import process.
|
||||
|
||||
For the initial import, you should also set:
|
||||
## Installing the latest release
|
||||
|
||||
fsync = off
|
||||
full_page_writes = off
|
||||
Nominatim is easiest installed directly from Pypi. Make sure you have installed
|
||||
osm2pgsql, PostgreSQL/PostGIS and libICU together with its header files.
|
||||
|
||||
Don't forget to re-enable them after the initial import or you risk database
|
||||
corruption.
|
||||
Then you can install Nominatim with:
|
||||
|
||||
pip install nominatim-db nominatim-api
|
||||
|
||||
## Downloading and building Nominatim
|
||||
|
||||
@@ -125,11 +120,10 @@ The release contains all necessary files. Just unpack it.
|
||||
|
||||
### Downloading the latest development version
|
||||
|
||||
If you want to install latest development version from github, make sure to
|
||||
also check out the osm2pgsql subproject:
|
||||
If you want to install latest development version from github:
|
||||
|
||||
```
|
||||
git clone --recursive https://github.com/openstreetmap/Nominatim.git
|
||||
git clone https://github.com/osm-search/Nominatim.git
|
||||
```
|
||||
|
||||
The development version does not include the country grid. Download it separately:
|
||||
@@ -140,41 +134,14 @@ wget -O Nominatim/data/country_osm_grid.sql.gz https://nominatim.org/data/countr
|
||||
|
||||
### Building Nominatim
|
||||
|
||||
The code must be built in a separate directory. Create the directory and
|
||||
change into it.
|
||||
Nominatim is easiest to run from its own virtual environment. To create one, run:
|
||||
|
||||
```
|
||||
mkdir build
|
||||
cd build
|
||||
```
|
||||
sudo apt-get install virtualenv
|
||||
virtualenv /srv/nominatim-venv
|
||||
|
||||
Nominatim uses cmake and make for building. Assuming that you have created the
|
||||
build at the same level as the Nominatim source directory run:
|
||||
To install Nominatim directly from the source tree into the virtual environment, run:
|
||||
|
||||
```
|
||||
cmake ../Nominatim
|
||||
make
|
||||
sudo make install
|
||||
```
|
||||
/srv/nominatim-venv/bin/pip install packaging/nominatim-{db,api}
|
||||
|
||||
!!! warning
|
||||
The default installation no longer compiles the PostgreSQL module that
|
||||
is needed for the legacy tokenizer from older Nominatim versions. If you
|
||||
are upgrading an older database or want to run the
|
||||
[legacy tokenizer](../customize/Tokenizers.md#legacy-tokenizer) for
|
||||
some other reason, you need to enable the PostgreSQL module via
|
||||
cmake: `cmake -DBUILD_MODULE=on ../Nominatim`. To compile the module
|
||||
you need to have the server development headers for PostgreSQL installed.
|
||||
On Ubuntu/Debian run: `sudo apt install postgresql-server-dev-<postgresql version>`
|
||||
|
||||
|
||||
Nominatim installs itself into `/usr/local` per default. To choose a different
|
||||
installation directory add `-DCMAKE_INSTALL_PREFIX=<install root>` to the
|
||||
cmake command. Make sure that the `bin` directory is available in your path
|
||||
in that case, e.g.
|
||||
|
||||
```
|
||||
export PATH=<install root>/bin:$PATH
|
||||
```
|
||||
|
||||
Now continue with [importing the database](Import.md).
|
||||
|
||||
@@ -60,16 +60,13 @@ to finish the recomputation.
|
||||
|
||||
## Removing large deleted objects
|
||||
|
||||
Command: `nominatim admin --clean-deleted <PostgreSQL Time Interval>`
|
||||
|
||||
Nominatim refuses to delete very large areas because often these deletions are
|
||||
accidental and are reverted within hours. Instead the deletions are logged in
|
||||
the `import_polygon_delete` table and left to the administrator to clean up.
|
||||
|
||||
There is currently no command to do that. You can use the following SQL
|
||||
query to force a deletion on all objects that have been deleted more than
|
||||
a certain timespan ago (here: 1 month):
|
||||
To run this command you will need to pass a PostgreSQL time interval. For example to
|
||||
delete any objects that have been deleted more than a month ago you would run:
|
||||
`nominatim admin --clean-deleted '1 month'`
|
||||
|
||||
```sql
|
||||
SELECT place_force_delete(p.place_id) FROM import_polygon_delete d, placex p
|
||||
WHERE p.osm_type = d.osm_type and p.osm_id = d.osm_id
|
||||
and age(p.indexed_date) > '1 month'::interval
|
||||
```
|
||||
|
||||
@@ -1,19 +1,104 @@
|
||||
# Database Migrations
|
||||
|
||||
Since version 3.7.0 Nominatim offers automatic migrations. Please follow
|
||||
Nominatim offers automatic migrations for versions 4.3+. Please follow
|
||||
the following steps:
|
||||
|
||||
* stop any updates that are potentially running
|
||||
* update Nominatim to the newer version
|
||||
* go to your project directory and run `nominatim admin --migrate`
|
||||
* (optionally) restart updates
|
||||
* Stop any updates that are potentially running
|
||||
* Update the backend: `pip install -U nominatim-db`
|
||||
* Go to your project directory and run `nominatim admin --migrate`
|
||||
* Update the frontend: `pip install -U nominatim-api`
|
||||
* (optionally) Restart updates
|
||||
|
||||
Below you find additional migrations and hints about other structural and
|
||||
breaking changes. **Please read them before running the migration.**
|
||||
|
||||
!!! note
|
||||
If you are migrating from a version <3.6, then you still have to follow
|
||||
the manual migration steps up to 3.6.
|
||||
If you are migrating from a version <4.3, you need to install 4.3
|
||||
and migrate to 4.3 first. Then you can migrate to the current
|
||||
version. It is strongly recommended to do a reimport instead.
|
||||
|
||||
## 4.5.0 -> 5.0.0
|
||||
|
||||
### PHP frontend removed
|
||||
|
||||
The PHP frontend has been completely removed. Please switch to the Python
|
||||
frontend.
|
||||
|
||||
Without the PHP code, the `nominatim refresh --website` command is no longer
|
||||
needed. It currently omits a warning and does otherwise nothing. It will be
|
||||
removed in later versions of Nominatim. So make sure you remove it from your
|
||||
scripts.
|
||||
|
||||
### CMake building removed
|
||||
|
||||
Nominatim can now only be installed via pip. Please follow the installation
|
||||
instructions for the current version to change to pip.
|
||||
|
||||
### osm2pgsql no longer vendored in
|
||||
|
||||
Nominatim no longer ships its own version of osm2pgsql. Please install a
|
||||
stock version of osm2pgsql from your distribution. See the
|
||||
[installation instruction for osm2pgsql](https://osm2pgsql.org/doc/install.html)
|
||||
for details. A minimum version of 1.8 is required. The current stable versions
|
||||
of Ubuntu and Debian already ship with an appropriate versions. For older
|
||||
installation, you may have to compile a newer osm2pgsql yourself.
|
||||
|
||||
### Legacy tokenizer removed
|
||||
|
||||
The `legacy` tokenizer is no longer enabled. This tokenizer has been superseded
|
||||
by the `ICU` tokenizer a long time ago. In the unlikely case that your database
|
||||
still uses the `legacy` tokenizer, you must reimport your database.
|
||||
|
||||
### osm2pgsql style overhauled
|
||||
|
||||
There are some fundamental changes to how customized osm2pgsql styles should
|
||||
be written. The changes are mostly backwards compatible, i.e. custom styles
|
||||
should still work with the new implementation. The only exception is a
|
||||
customization of the `process_tags()` function. This function is no longer
|
||||
considered public and neither are the helper functions used in it.
|
||||
They currently still work but will be removed at some point. If you have
|
||||
been making changes to `process_tags`, please review your style and try
|
||||
to switch to the new convenience functions.
|
||||
|
||||
For more information on the changes, see the
|
||||
[pull request](https://github.com/osm-search/Nominatim/pull/3615)
|
||||
and read the new
|
||||
[customization documentation](https://nominatim.org/release-docs/latest/customize/Import-Styles/).
|
||||
|
||||
## 4.4.0 -> 4.5.0
|
||||
|
||||
### New structure for Python packages
|
||||
|
||||
The nominatim Python package has been split into `nominatim-db` and `nominatim-api`.
|
||||
Any imports need to be adapted accordingly.
|
||||
|
||||
If you are running the Python frontend, change the server module from
|
||||
`nominatim.server.falcon.server` to `nominatim_api.server.falcon.server`.
|
||||
|
||||
If you are using the Nominatim library, all imports need to be changed
|
||||
from `nominatim.api.<module>` to `nominatim_api.<module>`.
|
||||
|
||||
If you have written custom tokenizers or sanitizers, the appropriate modules
|
||||
are now found in `nominatim_db`.
|
||||
|
||||
## 4.2.0 -> 4.3.0
|
||||
|
||||
### New indexes for reverse lookup
|
||||
|
||||
The reverse lookup algorithm has changed slightly to improve performance.
|
||||
This change needs a different index in the database. The required index
|
||||
will be automatically build during migration. Until the new index is available
|
||||
performance of the /reverse endpoint is significantly reduced. You should
|
||||
therefore either remove traffic from the machine before attempting a
|
||||
version update or create the index manually **before** starting the update
|
||||
using the following SQL:
|
||||
|
||||
```sql
|
||||
CREATE INDEX IF NOT EXISTS idx_placex_geometry_reverse_lookupPlaceNode
|
||||
ON placex USING gist (ST_Buffer(geometry, reverse_place_diameter(rank_search)))
|
||||
WHERE rank_address between 4 and 25 AND type != 'postcode'
|
||||
AND name is not null AND linked_place_id is null AND osm_type = 'N';
|
||||
```
|
||||
|
||||
## 4.0.0 -> 4.1.0
|
||||
|
||||
|
||||
@@ -59,47 +59,6 @@ imported multiple country extracts and want to keep them
|
||||
up-to-date, [Advanced installations section](Advanced-Installations.md)
|
||||
contains instructions to set up and update multiple country extracts.
|
||||
|
||||
#### Continuous updates
|
||||
|
||||
This is the easiest mode. Simply run the replication command without any
|
||||
parameters:
|
||||
|
||||
nominatim replication
|
||||
|
||||
The update application keeps running forever and retrieves and applies
|
||||
new updates from the server as they are published.
|
||||
|
||||
You can run this command as a simple systemd service. Create a service
|
||||
description like that in `/etc/systemd/system/nominatim-updates.service`:
|
||||
|
||||
```
|
||||
[Unit]
|
||||
Description=Continuous updates of Nominatim
|
||||
|
||||
[Service]
|
||||
WorkingDirectory=/srv/nominatim
|
||||
ExecStart=nominatim replication
|
||||
StandardOutput=append:/var/log/nominatim-updates.log
|
||||
StandardError=append:/var/log/nominatim-updates.error.log
|
||||
User=nominatim
|
||||
Group=nominatim
|
||||
Type=simple
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
Replace the `WorkingDirectory` with your project directory. Also adapt user
|
||||
and group names as required.
|
||||
|
||||
Now activate the service and start the updates:
|
||||
|
||||
```
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable nominatim-updates
|
||||
sudo systemctl start nominatim-updates
|
||||
```
|
||||
|
||||
#### One-time mode
|
||||
|
||||
When the `--once` parameter is given, then Nominatim will download exactly one
|
||||
@@ -109,10 +68,10 @@ the update interval no new data has been published yet, it will go to sleep
|
||||
until the next expected update and only then attempt to download the next batch.
|
||||
|
||||
The one-time mode is particularly useful if you want to run updates continuously
|
||||
but need to schedule other work in between updates. For example, the main
|
||||
service at osm.org uses it, to regularly recompute postcodes -- a process that
|
||||
must not be run while updates are in progress. Its update script
|
||||
looks like this:
|
||||
but need to schedule other work in between updates. For example, you might
|
||||
want to regularly recompute postcodes -- a process that
|
||||
must not be run while updates are in progress. An update script refreshing
|
||||
postcodes regularly might look like this:
|
||||
|
||||
```sh
|
||||
#!/bin/bash
|
||||
@@ -150,17 +109,19 @@ Unit=nominatim-updates.service
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
And then a similar service definition: `/etc/systemd/system/nominatim-updates.service`:
|
||||
`OnUnitActiveSec` defines how often the individual update command is run.
|
||||
|
||||
Then add a service definition for the timer in `/etc/systemd/system/nominatim-updates.service`:
|
||||
|
||||
```
|
||||
[Unit]
|
||||
Description=Single updates of Nominatim
|
||||
|
||||
[Service]
|
||||
WorkingDirectory=/srv/nominatim
|
||||
ExecStart=nominatim replication --once
|
||||
StandardOutput=append:/var/log/nominatim-updates.log
|
||||
StandardError=append:/var/log/nominatim-updates.error.log
|
||||
WorkingDirectory=/srv/nominatim-project
|
||||
ExecStart=/srv/nominatim-venv/bin/nominatim replication --once
|
||||
StandardOutput=journald
|
||||
StandardError=inherit
|
||||
User=nominatim
|
||||
Group=nominatim
|
||||
Type=simple
|
||||
@@ -169,9 +130,9 @@ Type=simple
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
Replace the `WorkingDirectory` with your project directory. Also adapt user and
|
||||
group names as required. `OnUnitActiveSec` defines how often the individual
|
||||
update command is run.
|
||||
Replace the `WorkingDirectory` with your project directory. `ExecStart` points
|
||||
to the nominatim binary that was installed in your virtualenv earlier.
|
||||
Finally, you might need to adapt user and group names as required.
|
||||
|
||||
Now activate the service and start the updates:
|
||||
|
||||
@@ -181,12 +142,13 @@ sudo systemctl enable nominatim-updates.timer
|
||||
sudo systemctl start nominatim-updates.timer
|
||||
```
|
||||
|
||||
You can stop future data updates, while allowing any current, in-progress
|
||||
You can stop future data updates while allowing any current, in-progress
|
||||
update steps to finish, by running `sudo systemctl stop
|
||||
nominatim-updates.timer` and waiting until `nominatim-updates.service` isn't
|
||||
running (`sudo systemctl is-active nominatim-updates.service`). Current output
|
||||
from the update can be seen like above (`systemctl status
|
||||
nominatim-updates.service`).
|
||||
running (`sudo systemctl is-active nominatim-updates.service`).
|
||||
|
||||
To check the output from the update process, use journalctl: `journalctl -u
|
||||
nominatim-updates.service`
|
||||
|
||||
|
||||
#### Catch-up mode
|
||||
@@ -196,13 +158,13 @@ all changes from the server until the database is up-to-date. The catch-up mode
|
||||
still respects the parameter `NOMINATIM_REPLICATION_MAX_DIFF`. It downloads and
|
||||
applies the changes in appropriate batches until all is done.
|
||||
|
||||
The catch-up mode is foremost useful to bring the database up to speed after the
|
||||
The catch-up mode is foremost useful to bring the database up to date after the
|
||||
initial import. Give that the service usually is not in production at this
|
||||
point, you can temporarily be a bit more generous with the batch size and
|
||||
number of threads you use for the updates by running catch-up like this:
|
||||
|
||||
```
|
||||
cd /srv/nominatim
|
||||
cd /srv/nominatim-project
|
||||
NOMINATIM_REPLICATION_MAX_DIFF=5000 nominatim replication --catch-up --threads 15
|
||||
```
|
||||
|
||||
@@ -214,10 +176,27 @@ replication catch-up at whatever interval you desire.
|
||||
When running scheduled updates with catch-up, it is a good idea to choose
|
||||
a replication source with an update frequency that is an order of magnitude
|
||||
lower. For example, if you want to update once a day, use an hourly updated
|
||||
source. This makes sure that you don't miss an entire day of updates when
|
||||
source. This ensures that you don't miss an entire day of updates when
|
||||
the source is unexpectedly late to publish its update.
|
||||
|
||||
If you want to use the source with the same update frequency (e.g. a daily
|
||||
updated source with daily updates), use the
|
||||
continuous update mode. It ensures to re-request the newest update until it
|
||||
is published.
|
||||
once mode together with a frequently run systemd script as described above.
|
||||
It ensures to re-request the newest update until they have been published.
|
||||
|
||||
|
||||
#### Continuous updates
|
||||
|
||||
!!! danger
|
||||
This mode is no longer recommended to use and will removed in future
|
||||
releases. systemd is much better
|
||||
suited for running regular updates. Please refer to the setup
|
||||
instructions for running one-time mode with systemd above.
|
||||
|
||||
This is the easiest mode. Simply run the replication command without any
|
||||
parameters:
|
||||
|
||||
nominatim replication
|
||||
|
||||
The update application keeps running forever and retrieves and applies
|
||||
new updates from the server as they are published.
|
||||
|
||||
@@ -2,13 +2,17 @@
|
||||
|
||||
Show all details about a single place saved in the database.
|
||||
|
||||
This API endpoint is meant for visual inspection of the data in the database,
|
||||
mainly together with [Nominatim-UI](https://github.com/osm-search/nominatim-ui/).
|
||||
The parameters of the endpoint and the output may change occasionally between
|
||||
versions of Nominatim. Do not rely on the output in scripts or applications.
|
||||
|
||||
!!! warning
|
||||
The details page exists for debugging only. You may not use it in scripts
|
||||
or to automatically query details about a result.
|
||||
The details endpoint at https://nominatim.openstreetmap.org
|
||||
may not used in scripts or bots at all.
|
||||
See [Nominatim Usage Policy](https://operations.osmfoundation.org/policies/nominatim/).
|
||||
|
||||
|
||||
## Parameters
|
||||
|
||||
The details API supports the following two request formats:
|
||||
|
||||
@@ -35,66 +39,88 @@ for a place is different between Nominatim installation (servers) and
|
||||
changes when data gets reimported. Therefore it cannot be used as
|
||||
a permanent id and shouldn't be used in bug reports.
|
||||
|
||||
!!! danger "Deprecation warning"
|
||||
The API can also be used with the URL
|
||||
`https://nominatim.openstreetmap.org/details.php`. This is now deprecated
|
||||
and will be removed in future versions.
|
||||
|
||||
Additional optional parameters are explained below.
|
||||
|
||||
## Parameters
|
||||
|
||||
This section lists additional optional parameters.
|
||||
|
||||
### Output format
|
||||
|
||||
* `json_callback=<string>`
|
||||
|
||||
Wrap JSON output in a callback function (JSONP) i.e. `<string>(<json>)`.
|
||||
|
||||
* `pretty=[0|1]`
|
||||
|
||||
Add indentation to make it more human-readable. (Default: 0)
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| json_callback | function name | _unset_ |
|
||||
|
||||
When set, then JSON output will be wrapped in a callback function with
|
||||
the given name. See [JSONP](https://en.wikipedia.org/wiki/JSONP) for more
|
||||
information.
|
||||
|
||||
### Output details
|
||||
|
||||
* `addressdetails=[0|1]`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| addressdetails | 0 or 1 | 0 |
|
||||
|
||||
Include a breakdown of the address into elements. (Default: 0)
|
||||
When set to 1, include a breakdown of the address into elements.
|
||||
|
||||
* `keywords=[0|1]`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| keywords | 0 or 1 | 0 |
|
||||
|
||||
Include a list of name keywords and address keywords (word ids). (Default: 0)
|
||||
When set to 1, include a list of name keywords and address keywords
|
||||
in the result.
|
||||
|
||||
* `linkedplaces=[0|1]`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| linkedplaces | 0 or 1 | 1 |
|
||||
|
||||
Include a details of places that are linked with this one. Places get linked
|
||||
Include details of places that are linked with this one. Places get linked
|
||||
together when they are different forms of the same physical object. Nominatim
|
||||
links two kinds of objects together: place nodes get linked with the
|
||||
corresponding administrative boundaries. Waterway relations get linked together with their
|
||||
members.
|
||||
(Default: 1)
|
||||
|
||||
* `hierarchy=[0|1]`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| hierarchy | 0 or 1 | 0 |
|
||||
|
||||
Include details of places lower in the address hierarchy. (Default: 0)
|
||||
Include details of POIs and address that depend on the place. Only POIs
|
||||
that use this place to determine their address will be returned.
|
||||
|
||||
* `group_hierarchy=[0|1]`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| group_hierarchy | 0 or 1 | 0 |
|
||||
|
||||
For JSON output will group the places by type. (Default: 0)
|
||||
When set to 1, the output of the address hierarchy will be
|
||||
grouped by type.
|
||||
|
||||
* `polygon_geojson=[0|1]`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| polygon_geojson | 0 or 1 | 0 |
|
||||
|
||||
Include geometry of result. (Default: 0)
|
||||
|
||||
Include geometry of result.
|
||||
|
||||
### Language of results
|
||||
|
||||
* `accept-language=<browser language string>`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| accept-language | browser language string | content of "Accept-Language" HTTP header |
|
||||
|
||||
Preferred language order for showing result, overrides the value
|
||||
specified in the "Accept-Language" HTTP header.
|
||||
Either use a standard RFC2616 accept-language string or a simple
|
||||
comma-separated list of language codes.
|
||||
Preferred language order for showing search results. This may either be
|
||||
a simple comma-separated list of language codes or have the same format
|
||||
as the ["Accept-Language" HTTP header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language).
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
##### JSON
|
||||
|
||||
[https://nominatim.openstreetmap.org/details.php?osmtype=W&osmid=38210407&format=json](https://nominatim.openstreetmap.org/details.php?osmtype=W&osmid=38210407&format=json)
|
||||
[https://nominatim.openstreetmap.org/details?osmtype=W&osmid=38210407&format=json](https://nominatim.openstreetmap.org/details?osmtype=W&osmid=38210407&format=json)
|
||||
|
||||
|
||||
```json
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
The lookup API allows to query the address and other details of one or
|
||||
multiple OSM objects like node, way or relation.
|
||||
|
||||
## Parameters
|
||||
## Endpoint
|
||||
|
||||
The lookup API has the following format:
|
||||
|
||||
@@ -15,75 +15,129 @@ The lookup API has the following format:
|
||||
prefixed with its type, one of node(N), way(W) or relation(R). Up to 50 ids
|
||||
can be queried at the same time.
|
||||
|
||||
Additional optional parameters are explained below.
|
||||
!!! danger "Deprecation warning"
|
||||
The API can also be used with the URL
|
||||
`https://nominatim.openstreetmap.org/lookup.php`. This is now deprecated
|
||||
and will be removed in future versions.
|
||||
|
||||
|
||||
## Parameters
|
||||
|
||||
This section lists additional optional parameters.
|
||||
|
||||
### Output format
|
||||
|
||||
* `format=[xml|json|jsonv2|geojson|geocodejson]`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| format | one of: `xml`, `json`, `jsonv2`, `geojson`, `geocodejson` | `jsonv2` |
|
||||
|
||||
See [Place Output Formats](Output.md) for details on each format. (Default: xml)
|
||||
See [Place Output Formats](Output.md) for details on each format.
|
||||
|
||||
* `json_callback=<string>`
|
||||
|
||||
Wrap JSON output in a callback function (JSONP) i.e. `<string>(<json>)`.
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| json_callback | function name | _unset_ |
|
||||
|
||||
When given, then JSON output will be wrapped in a callback function with
|
||||
the given name. See [JSONP](https://en.wikipedia.org/wiki/JSONP) for more
|
||||
information.
|
||||
|
||||
Only has an effect for JSON output formats.
|
||||
|
||||
|
||||
### Output details
|
||||
|
||||
* `addressdetails=[0|1]`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| addressdetails | 0 or 1 | 0 |
|
||||
|
||||
Include a breakdown of the address into elements. (Default: 0)
|
||||
When set to 1, include a breakdown of the address into elements.
|
||||
The exact content of the address breakdown depends on the output format.
|
||||
|
||||
!!! tip
|
||||
If you are interested in a stable classification of address categories
|
||||
(suburb, city, state, etc), have a look at the `geocodejson` format.
|
||||
All other formats return classifications according to OSM tagging.
|
||||
There is a much larger set of categories and they are not always consistent,
|
||||
which makes them very hard to work with.
|
||||
|
||||
|
||||
* `extratags=[0|1]`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| extratags | 0 or 1 | 0 |
|
||||
|
||||
Include additional information in the result if available,
|
||||
e.g. wikipedia link, opening hours. (Default: 0)
|
||||
When set to 1, the response include any additional information in the result
|
||||
that is available in the database, e.g. wikipedia link, opening hours.
|
||||
|
||||
|
||||
* `namedetails=[0|1]`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| namedetails | 0 or 1 | 0 |
|
||||
|
||||
Include a list of alternative names in the results. These may include
|
||||
language variants, references, operator and brand. (Default: 0)
|
||||
When set to 1, include a full list of names for the result. These may include
|
||||
language variants, older names, references and brand.
|
||||
|
||||
|
||||
### Language of results
|
||||
|
||||
* `accept-language=<browser language string>`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| accept-language | browser language string | content of "Accept-Language" HTTP header |
|
||||
|
||||
Preferred language order for showing search results. This may either be
|
||||
a simple comma-separated list of language codes or have the same format
|
||||
as the ["Accept-Language" HTTP header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language).
|
||||
|
||||
!!! tip
|
||||
First-time users of Nominatim tend to be confused that they get different
|
||||
results when using Nominatim in the browser versus in a command-line tool
|
||||
like wget or curl. The command-line tools
|
||||
usually don't send any Accept-Language header, prompting Nominatim
|
||||
to show results in the local language. Browsers on the contrary always
|
||||
send the currently chosen browser language.
|
||||
|
||||
Preferred language order for showing search results, overrides the value
|
||||
specified in the "Accept-Language" HTTP header.
|
||||
Either use a standard RFC2616 accept-language string or a simple
|
||||
comma-separated list of language codes.
|
||||
|
||||
### Polygon output
|
||||
|
||||
* `polygon_geojson=1`
|
||||
* `polygon_kml=1`
|
||||
* `polygon_svg=1`
|
||||
* `polygon_text=1`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| polygon_geojson | 0 or 1 | 0 |
|
||||
| polygon_kml | 0 or 1 | 0 |
|
||||
| polygon_svg | 0 or 1 | 0 |
|
||||
| polygon_text | 0 or 1 | 0 |
|
||||
|
||||
Output geometry of results as a GeoJSON, KML, SVG or WKT. Only one of these
|
||||
options can be used at a time. (Default: 0)
|
||||
Add the full geometry of the place to the result output. Output formats
|
||||
in GeoJSON, KML, SVG or WKT are supported. Only one of these
|
||||
options can be used at a time.
|
||||
|
||||
* `polygon_threshold=0.0`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| polygon_threshold | floating-point number | 0.0 |
|
||||
|
||||
Return a simplified version of the output geometry. The parameter is the
|
||||
When one of the polygon_* outputs is chosen, return a simplified version
|
||||
of the output geometry. The parameter describes the
|
||||
tolerance in degrees with which the geometry may differ from the original
|
||||
geometry. Topology is preserved in the result. (Default: 0.0)
|
||||
geometry. Topology is preserved in the geometry.
|
||||
|
||||
|
||||
### Other
|
||||
|
||||
* `email=<valid email address>`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| email | valid email address | _unset_ |
|
||||
|
||||
If you are making large numbers of request please include an appropriate email
|
||||
address to identify your requests. See Nominatim's [Usage Policy](https://operations.osmfoundation.org/policies/nominatim/) for more details.
|
||||
address to identify your requests. See Nominatim's
|
||||
[Usage Policy](https://operations.osmfoundation.org/policies/nominatim/) for more details.
|
||||
|
||||
* `debug=[0|1]`
|
||||
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| debug | 0 or 1 | 0 |
|
||||
|
||||
Output assorted developer debug information. Data on internals of Nominatim's
|
||||
"Search Loop" logic, and SQL queries. The output is (rough) HTML format.
|
||||
This overrides the specified machine readable format. (Default: 0)
|
||||
"search loop" logic, and SQL queries. The output is HTML format.
|
||||
This overrides the specified machine readable format.
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
@@ -12,7 +12,7 @@ a single place (for reverse) of the following format:
|
||||
|
||||
```
|
||||
{
|
||||
"place_id": "100149",
|
||||
"place_id": 100149,
|
||||
"licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
|
||||
"osm_type": "node",
|
||||
"osm_id": "107775",
|
||||
@@ -168,7 +168,7 @@ Additional information requested with `addressdetails=1`, `extratags=1` and
|
||||
<searchresults timestamp="Sat, 11 Aug 18 11:55:35 +0000"
|
||||
attribution="Data © OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright"
|
||||
querystring="london" polygon="false" exclude_place_ids="100149"
|
||||
more_url="https://nominatim.openstreetmap.org/search.php?q=london&addressdetails=1&extratags=1&exclude_place_ids=100149&format=xml&accept-language=en-US%2Cen%3Bq%3D0.7%2Cde%3Bq%3D0.3">
|
||||
more_url="https://nominatim.openstreetmap.org/search?q=london&addressdetails=1&extratags=1&exclude_place_ids=100149&format=xml&accept-language=en-US%2Cen%3Bq%3D0.7%2Cde%3Bq%3D0.3">
|
||||
<place place_id="100149" osm_type="node" osm_id="107775" place_rank="15" address_rank="15"
|
||||
boundingbox="51.3473219,51.6673219,-0.2876474,0.0323526" lat="51.5073219" lon="-0.1276474"
|
||||
display_name="London, Greater London, England, SW1A 2DU, United Kingdom"
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
### Nominatim API
|
||||
|
||||
Nominatim indexes named (or numbered) features within the OpenStreetMap (OSM) dataset and a subset of other unnamed features (pubs, hotels, churches, etc).
|
||||
|
||||
Its API has the following endpoints for querying the data:
|
||||
This section describes the API V1 of the Nominatim web service. The
|
||||
service offers the following endpoints:
|
||||
|
||||
* __[/search](Search.md)__ - search OSM objects by name or type
|
||||
* __[/reverse](Reverse.md)__ - search OSM object by their location
|
||||
@@ -12,3 +9,6 @@ Its API has the following endpoints for querying the data:
|
||||
back in Nominatim in case the deletion was accidental
|
||||
* __/polygons__ - list of broken polygons detected by Nominatim
|
||||
* __[/details](Details.md)__ - show internal details for an object (for debugging only)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# Reverse Geocoding
|
||||
|
||||
Reverse geocoding generates an address from a latitude and longitude.
|
||||
Reverse geocoding generates an address from a coordinate given as
|
||||
latitude and longitude.
|
||||
|
||||
## How it works
|
||||
|
||||
@@ -18,8 +19,7 @@ The other issue to be aware of is that the closest OSM object may not always
|
||||
have a similar enough address to the coordinate you were requesting. For
|
||||
example, in dense city areas it may belong to a completely different street.
|
||||
|
||||
|
||||
## Parameters
|
||||
## Endpoint
|
||||
|
||||
The main format of the reverse API is
|
||||
|
||||
@@ -31,57 +31,100 @@ where `lat` and `lon` are latitude and longitude of a coordinate in WGS84
|
||||
projection. The API returns exactly one result or an error when the coordinate
|
||||
is in an area with no OSM data coverage.
|
||||
|
||||
Additional parameters are accepted as listed below.
|
||||
|
||||
!!! warning "Deprecation warning"
|
||||
The reverse API used to allow address lookup for a single OSM object by
|
||||
its OSM id. This use is now deprecated. Use the [Address Lookup API](Lookup.md)
|
||||
instead.
|
||||
!!! tip
|
||||
The reverse API allows a lookup of object by coordinate. If you want
|
||||
to look up an object by ID, use the [Address Lookup API](Lookup.md) instead.
|
||||
|
||||
!!! danger "Deprecation warning"
|
||||
The API can also be used with the URL
|
||||
`https://nominatim.openstreetmap.org/reverse.php`. This is now deprecated
|
||||
and will be removed in future versions.
|
||||
|
||||
|
||||
## Parameters
|
||||
|
||||
This section lists additional parameters to further influence the output.
|
||||
|
||||
### Output format
|
||||
|
||||
* `format=[xml|json|jsonv2|geojson|geocodejson]`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| format | one of: `xml`, `json`, `jsonv2`, `geojson`, `geocodejson` | `xml` |
|
||||
|
||||
See [Place Output Formats](Output.md) for details on each format. (Default: xml)
|
||||
See [Place Output Formats](Output.md) for details on each format.
|
||||
|
||||
* `json_callback=<string>`
|
||||
|
||||
Wrap JSON output in a callback function ([JSONP](https://en.wikipedia.org/wiki/JSONP)) i.e. `<string>(<json>)`.
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| json_callback | function name | _unset_ |
|
||||
|
||||
When given, then JSON output will be wrapped in a callback function with
|
||||
the given name. See [JSONP](https://en.wikipedia.org/wiki/JSONP) for more
|
||||
information.
|
||||
|
||||
Only has an effect for JSON output formats.
|
||||
|
||||
|
||||
### Output details
|
||||
|
||||
* `addressdetails=[0|1]`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| addressdetails | 0 or 1 | 1 |
|
||||
|
||||
Include a breakdown of the address into elements. (Default: 1)
|
||||
When set to 1, include a breakdown of the address into elements.
|
||||
The exact content of the address breakdown depends on the output format.
|
||||
|
||||
!!! tip
|
||||
If you are interested in a stable classification of address categories
|
||||
(suburb, city, state, etc), have a look at the `geocodejson` format.
|
||||
All other formats return classifications according to OSM tagging.
|
||||
There is a much larger set of categories and they are not always consistent,
|
||||
which makes them very hard to work with.
|
||||
|
||||
|
||||
* `extratags=[0|1]`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| extratags | 0 or 1 | 0 |
|
||||
|
||||
Include additional information in the result if available,
|
||||
e.g. wikipedia link, opening hours. (Default: 0)
|
||||
When set to 1, the response include any additional information in the result
|
||||
that is available in the database, e.g. wikipedia link, opening hours.
|
||||
|
||||
|
||||
* `namedetails=[0|1]`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| namedetails | 0 or 1 | 0 |
|
||||
|
||||
Include a list of alternative names in the results. These may include
|
||||
language variants, references, operator and brand. (Default: 0)
|
||||
When set to 1, include a full list of names for the result. These may include
|
||||
language variants, older names, references and brand.
|
||||
|
||||
|
||||
### Language of results
|
||||
|
||||
* `accept-language=<browser language string>`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| accept-language | browser language string | content of "Accept-Language" HTTP header |
|
||||
|
||||
Preferred language order for showing search results, overrides the value
|
||||
specified in the "Accept-Language" HTTP header.
|
||||
Either use a standard RFC2616 accept-language string or a simple
|
||||
comma-separated list of language codes.
|
||||
Preferred language order for showing search results. This may either be
|
||||
a simple comma-separated list of language codes or have the same format
|
||||
as the ["Accept-Language" HTTP header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language).
|
||||
|
||||
### Result limitation
|
||||
!!! tip
|
||||
First-time users of Nominatim tend to be confused that they get different
|
||||
results when using Nominatim in the browser versus in a command-line tool
|
||||
like wget or curl. The command-line tools
|
||||
usually don't send any Accept-Language header, prompting Nominatim
|
||||
to show results in the local language. Browsers on the contrary always
|
||||
send the currently chosen browser language.
|
||||
|
||||
* `zoom=[0-18]`
|
||||
|
||||
Level of detail required for the address. Default: 18. This is a number that
|
||||
### Result restriction
|
||||
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| zoom | 0-18 | 18 |
|
||||
|
||||
Level of detail required for the address. This is a number that
|
||||
corresponds roughly to the zoom level used in XYZ tile sources in frameworks
|
||||
like Leaflet.js, Openlayers etc.
|
||||
In terms of address details the zoom levels are as follows:
|
||||
@@ -92,41 +135,79 @@ In terms of address details the zoom levels are as follows:
|
||||
5 | state
|
||||
8 | county
|
||||
10 | city
|
||||
14 | suburb
|
||||
12 | town / borough
|
||||
13 | village / suburb
|
||||
14 | neighbourhood
|
||||
15 | any settlement
|
||||
16 | major streets
|
||||
17 | major and minor streets
|
||||
18 | building
|
||||
|
||||
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| layer | comma-separated list of: `address`, `poi`, `railway`, `natural`, `manmade` | _unset_ (no restriction) |
|
||||
|
||||
The layer filter allows to select places by themes.
|
||||
|
||||
The `address` layer contains all places that make up an address:
|
||||
address points with house numbers, streets, inhabited places (suburbs, villages,
|
||||
cities, states etc.) and administrative boundaries.
|
||||
|
||||
The `poi` layer selects all point of interest. This includes classic points
|
||||
of interest like restaurants, shops, hotels but also less obvious features
|
||||
like recycling bins, guideposts or benches.
|
||||
|
||||
The `railway` layer includes railway infrastructure like tracks.
|
||||
Note that in Nominatim's standard configuration, only very few railway
|
||||
features are imported into the database.
|
||||
|
||||
The `natural` layer collects features like rivers, lakes and mountains while
|
||||
the `manmade` layer functions as a catch-all for features not covered by the
|
||||
other layers.
|
||||
|
||||
|
||||
### Polygon output
|
||||
|
||||
* `polygon_geojson=1`
|
||||
* `polygon_kml=1`
|
||||
* `polygon_svg=1`
|
||||
* `polygon_text=1`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| polygon_geojson | 0 or 1 | 0 |
|
||||
| polygon_kml | 0 or 1 | 0 |
|
||||
| polygon_svg | 0 or 1 | 0 |
|
||||
| polygon_text | 0 or 1 | 0 |
|
||||
|
||||
Output geometry of results as a GeoJSON, KML, SVG or WKT. Only one of these
|
||||
options can be used at a time. (Default: 0)
|
||||
Add the full geometry of the place to the result output. Output formats
|
||||
in GeoJSON, KML, SVG or WKT are supported. Only one of these
|
||||
options can be used at a time.
|
||||
|
||||
* `polygon_threshold=0.0`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| polygon_threshold | floating-point number | 0.0 |
|
||||
|
||||
Return a simplified version of the output geometry. The parameter is the
|
||||
When one of the polygon_* outputs is chosen, return a simplified version
|
||||
of the output geometry. The parameter describes the
|
||||
tolerance in degrees with which the geometry may differ from the original
|
||||
geometry. Topology is preserved in the result. (Default: 0.0)
|
||||
geometry. Topology is preserved in the geometry.
|
||||
|
||||
|
||||
### Other
|
||||
|
||||
* `email=<valid email address>`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| email | valid email address | _unset_ |
|
||||
|
||||
If you are making a large number of requests, please include an appropriate email
|
||||
address to identify your requests. See Nominatim's [Usage Policy](https://operations.osmfoundation.org/policies/nominatim/) for more details.
|
||||
If you are making large numbers of request please include an appropriate email
|
||||
address to identify your requests. See Nominatim's
|
||||
[Usage Policy](https://operations.osmfoundation.org/policies/nominatim/) for more details.
|
||||
|
||||
|
||||
* `debug=[0|1]`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| debug | 0 or 1 | 0 |
|
||||
|
||||
Output assorted developer debug information. Data on internals of Nominatim's
|
||||
"Search Loop" logic, and SQL queries. The output is (rough) HTML format.
|
||||
This overrides the specified machine readable format. (Default: 0)
|
||||
"search loop" logic, and SQL queries. The output is HTML format.
|
||||
This overrides the specified machine readable format.
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
@@ -8,12 +8,12 @@ The search query may also contain
|
||||
which are translated into specific OpenStreetMap (OSM) tags (e.g. Pub => `amenity=pub`).
|
||||
This can be used to narrow down the kind of objects to be returned.
|
||||
|
||||
!!! warning
|
||||
!!! note
|
||||
Special phrases are not suitable to query all objects of a certain type in an
|
||||
area. Nominatim will always just return a collection of the best matches. To
|
||||
download OSM data by object type, use the [Overpass API](https://overpass-api.de/).
|
||||
|
||||
## Parameters
|
||||
## Endpoint
|
||||
|
||||
The search API has the following format:
|
||||
|
||||
@@ -21,35 +21,62 @@ The search API has the following format:
|
||||
https://nominatim.openstreetmap.org/search?<params>
|
||||
```
|
||||
|
||||
The search term may be specified with two different sets of parameters:
|
||||
!!! danger "Deprecation warning"
|
||||
The API can also be used with the URL
|
||||
`https://nominatim.openstreetmap.org/search.php`. This is now deprecated
|
||||
and will be removed in future versions.
|
||||
|
||||
* `q=<query>`
|
||||
The query term can be given in two different forms: free-form or structured.
|
||||
|
||||
Free-form query string to search for.
|
||||
Free-form queries are processed first left-to-right and then right-to-left if that fails. So you may search for
|
||||
[pilkington avenue, birmingham](https://nominatim.openstreetmap.org/search?q=pilkington+avenue,birmingham) as well as for
|
||||
[birmingham, pilkington avenue](https://nominatim.openstreetmap.org/search?q=birmingham,+pilkington+avenue).
|
||||
Commas are optional, but improve performance by reducing the complexity of the search.
|
||||
### Free-form query
|
||||
|
||||
| Parameter | Value |
|
||||
|-----------| ----- |
|
||||
| q | Free-form query string to search for |
|
||||
|
||||
* `street=<housenumber> <streetname>`
|
||||
* `city=<city>`
|
||||
* `county=<county>`
|
||||
* `state=<state>`
|
||||
* `country=<country>`
|
||||
* `postalcode=<postalcode>`
|
||||
In this form, the query can be unstructured.
|
||||
Free-form queries are processed first left-to-right and then right-to-left if that fails. So you may search for
|
||||
[pilkington avenue, birmingham](https://nominatim.openstreetmap.org/search?q=pilkington+avenue,birmingham) as well as for
|
||||
[birmingham, pilkington avenue](https://nominatim.openstreetmap.org/search?q=birmingham,+pilkington+avenue).
|
||||
Commas are optional, but improve performance by reducing the complexity of the search.
|
||||
|
||||
Alternative query string format split into several parameters for structured requests.
|
||||
Structured requests are faster but are less robust against alternative
|
||||
OSM tagging schemas. **Do not combine with** `q=<query>` **parameter**.
|
||||
The free-form may also contain special phrases to describe the type of
|
||||
place to be returned or a coordinate to search close to a position.
|
||||
|
||||
Both query forms accept the additional parameters listed below.
|
||||
### Structured query
|
||||
|
||||
| Parameter | Value |
|
||||
|----------- | ----- |
|
||||
| amenity | name and/or type of POI |
|
||||
| street | housenumber and streetname |
|
||||
| city | city |
|
||||
| county | county |
|
||||
| state | state |
|
||||
| country | country |
|
||||
| postalcode | postal code |
|
||||
|
||||
The structured form of the search query allows to lookup up an address
|
||||
that is already split into its components. Each parameter represents a field
|
||||
of the address. All parameters are optional. You should only use the ones
|
||||
that are relevant for the address you want to geocode.
|
||||
|
||||
!!! Attention
|
||||
Cannot be combined with the `q=<query>` parameter. Newer versions of
|
||||
the API will return an error if you do so. Older versions simply return
|
||||
unexpected results.
|
||||
|
||||
## Parameters
|
||||
|
||||
The following parameters can be used to further restrict the search and
|
||||
change the output. They are usable for both forms of the search query.
|
||||
|
||||
### Output format
|
||||
|
||||
* `format=[xml|json|jsonv2|geojson|geocodejson]`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| format | one of: `xml`, `json`, `jsonv2`, `geojson`, `geocodejson` | `jsonv2` |
|
||||
|
||||
See [Place Output Formats](Output.md) for details on each format. (Default: jsonv2)
|
||||
See [Place Output Formats](Output.md) for details on each format.
|
||||
|
||||
!!! note
|
||||
The Nominatim service at
|
||||
@@ -57,52 +84,148 @@ See [Place Output Formats](Output.md) for details on each format. (Default: json
|
||||
has a different default behaviour for historical reasons. When the
|
||||
`format` parameter is omitted, the request will be forwarded to the Web UI.
|
||||
|
||||
* `json_callback=<string>`
|
||||
|
||||
Wrap JSON output in a callback function ([JSONP](https://en.wikipedia.org/wiki/JSONP)) i.e. `<string>(<json>)`.
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| json_callback | function name | _unset_ |
|
||||
|
||||
When given, then JSON output will be wrapped in a callback function with
|
||||
the given name. See [JSONP](https://en.wikipedia.org/wiki/JSONP) for more
|
||||
information.
|
||||
|
||||
Only has an effect for JSON output formats.
|
||||
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| limit | number | 10 |
|
||||
|
||||
Limit the maximum number of returned results. Cannot be more than 40.
|
||||
Nominatim may decide to return less results than given, if additional
|
||||
results do not sufficiently match the query.
|
||||
|
||||
|
||||
### Output details
|
||||
|
||||
* `addressdetails=[0|1]`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| addressdetails | 0 or 1 | 0 |
|
||||
|
||||
Include a breakdown of the address into elements. (Default: 0)
|
||||
When set to 1, include a breakdown of the address into elements.
|
||||
The exact content of the address breakdown depends on the output format.
|
||||
|
||||
!!! tip
|
||||
If you are interested in a stable classification of address categories
|
||||
(suburb, city, state, etc), have a look at the `geocodejson` format.
|
||||
All other formats return classifications according to OSM tagging.
|
||||
There is a much larger set of categories and they are not always consistent,
|
||||
which makes them very hard to work with.
|
||||
|
||||
|
||||
* `extratags=[0|1]`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| extratags | 0 or 1 | 0 |
|
||||
|
||||
Include additional information in the result if available,
|
||||
e.g. wikipedia link, opening hours. (Default: 0)
|
||||
When set to 1, the response include any additional information in the result
|
||||
that is available in the database, e.g. wikipedia link, opening hours.
|
||||
|
||||
|
||||
* `namedetails=[0|1]`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| namedetails | 0 or 1 | 0 |
|
||||
|
||||
Include a list of alternative names in the results. These may include
|
||||
language variants, references, operator and brand. (Default: 0)
|
||||
When set to 1, include a full list of names for the result. These may include
|
||||
language variants, older names, references and brand.
|
||||
|
||||
|
||||
### Language of results
|
||||
|
||||
* `accept-language=<browser language string>`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| accept-language | browser language string | content of "Accept-Language" HTTP header |
|
||||
|
||||
Preferred language order for showing search results, overrides the value
|
||||
specified in the ["Accept-Language" HTTP header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language).
|
||||
Either use a standard RFC2616 accept-language string or a simple
|
||||
comma-separated list of language codes.
|
||||
Preferred language order for showing search results. This may either be
|
||||
a simple comma-separated list of language codes or have the same format
|
||||
as the ["Accept-Language" HTTP header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language).
|
||||
|
||||
### Result limitation
|
||||
!!! tip
|
||||
First-time users of Nominatim tend to be confused that they get different
|
||||
results when using Nominatim in the browser versus in a command-line tool
|
||||
like wget or curl. The command-line tools
|
||||
usually don't send any Accept-Language header, prompting Nominatim
|
||||
to show results in the local language. Browsers on the contrary always
|
||||
send the currently chosen browser language.
|
||||
|
||||
* `countrycodes=<countrycode>[,<countrycode>][,<countrycode>]...`
|
||||
### Result restriction
|
||||
|
||||
Limit search results to one or more countries. `<countrycode>` must be the
|
||||
[ISO 3166-1alpha2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) code,
|
||||
e.g. `gb` for the United Kingdom, `de` for Germany.
|
||||
There are two ways to influence the results. *Filters* exclude certain
|
||||
kinds of results completely. *Boost parameters* only change the order of the
|
||||
results and thus give a preference to some results over others.
|
||||
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| countrycodes | comma-separated list of country codes | _unset_ |
|
||||
|
||||
Filter that limits the search results to one or more countries.
|
||||
The country code must be the
|
||||
[ISO 3166-1alpha2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) code
|
||||
of the country, e.g. `gb` for the United Kingdom, `de` for Germany.
|
||||
|
||||
Each place in Nominatim is assigned to one country code based
|
||||
on OSM country boundaries. In rare cases a place may not be in any country
|
||||
at all, for example, in international waters.
|
||||
at all, for example, when it is in international waters. These places are
|
||||
also excluded when the filter is set.
|
||||
|
||||
* `exclude_place_ids=<place_id,[place_id],[place_id]`
|
||||
!!! Note
|
||||
This parameter should not be confused with the 'country' parameter of
|
||||
the structured query. The 'country' parameter contains a search term
|
||||
and will be handled with some fuzziness. The `countrycodes` parameter
|
||||
is a hard filter and as such should be preferred. Having both parameters
|
||||
in the same query will work. If the parameters contradict each other,
|
||||
the search will come up empty.
|
||||
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| layer | comma-separated list of: `address`, `poi`, `railway`, `natural`, `manmade` | _unset_ (no restriction) |
|
||||
|
||||
The layer filter allows to select places by themes.
|
||||
|
||||
The `address` layer contains all places that make up an address:
|
||||
address points with house numbers, streets, inhabited places (suburbs, villages,
|
||||
cities, states tec.) and administrative boundaries.
|
||||
|
||||
The `poi` layer selects all point of interest. This includes classic POIs like
|
||||
restaurants, shops, hotels but also less obvious features like recycling bins,
|
||||
guideposts or benches.
|
||||
|
||||
The `railway` layer includes railway infrastructure like tracks.
|
||||
Note that in Nominatim's standard configuration, only very few railway
|
||||
features are imported into the database.
|
||||
|
||||
The `natural` layer collects features like rivers, lakes and mountains while
|
||||
the `manmade` layer functions as a catch-all for features not covered by the
|
||||
other layers.
|
||||
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| featureType | one of: `country`, `state`, `city`, `settlement` | _unset_ |
|
||||
|
||||
The featureType allows to have a more fine-grained selection for places
|
||||
from the address layer. Results can be restricted to places that make up
|
||||
the 'state', 'country' or 'city' part of an address. A featureType of
|
||||
settlement selects any human inhabited feature from 'state' down to
|
||||
'neighbourhood'.
|
||||
|
||||
When featureType is set, then results are automatically restricted
|
||||
to the address layer (see above).
|
||||
|
||||
!!! tip
|
||||
Instead of using the featureType filters `country`, `state` or `city`,
|
||||
you can also use a structured query without the finer-grained parameters
|
||||
amenity or street.
|
||||
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| exclude_place_ids | comma-separated list of place ids |
|
||||
|
||||
If you do not want certain OSM objects to appear in the search
|
||||
result, give a comma separated list of the `place_id`s you want to skip.
|
||||
@@ -110,180 +233,212 @@ This can be used to retrieve additional search results. For example, if a
|
||||
previous query only returned a few results, then including those here would
|
||||
cause the search to return other, less accurate, matches (if possible).
|
||||
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| viewbox | `<x1>,<y1>,<x2>,<y2>` | _unset_ |
|
||||
|
||||
* `limit=<integer>`
|
||||
Boost parameter which focuses the search on the given area.
|
||||
Any two corner points of the box are accepted as long as they make a proper
|
||||
box. `x` is longitude, `y` is latitude.
|
||||
|
||||
Limit the number of returned results. (Default: 10, Maximum: 50)
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| bounded | 0 or 1 | 0 |
|
||||
|
||||
When set to 1, then it turns the 'viewbox' parameter (see above) into
|
||||
a filter parameter, excluding any results outside the viewbox.
|
||||
|
||||
* `viewbox=<x1>,<y1>,<x2>,<y2>`
|
||||
|
||||
The preferred area to find search results. Any two corner points of the box
|
||||
are accepted as long as they span a real box. `x` is longitude,
|
||||
`y` is latitude.
|
||||
|
||||
|
||||
* `bounded=[0|1]`
|
||||
|
||||
When a viewbox is given, restrict the result to items contained within that
|
||||
viewbox (see above). When `viewbox` and `bounded=1` are given, an amenity
|
||||
only search is allowed. Give the special keyword for the amenity in square
|
||||
When `bounded=1` is given and the viewbox is small enough, then an amenity-only
|
||||
search is allowed. Give the special keyword for the amenity in square
|
||||
brackets, e.g. `[pub]` and a selection of objects of this type is returned.
|
||||
There is no guarantee that the result is complete. (Default: 0)
|
||||
There is no guarantee that the result returns all objects in the area.
|
||||
|
||||
|
||||
### Polygon output
|
||||
|
||||
* `polygon_geojson=1`
|
||||
* `polygon_kml=1`
|
||||
* `polygon_svg=1`
|
||||
* `polygon_text=1`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| polygon_geojson | 0 or 1 | 0 |
|
||||
| polygon_kml | 0 or 1 | 0 |
|
||||
| polygon_svg | 0 or 1 | 0 |
|
||||
| polygon_text | 0 or 1 | 0 |
|
||||
|
||||
Output geometry of results as a GeoJSON, KML, SVG or WKT. Only one of these
|
||||
options can be used at a time. (Default: 0)
|
||||
Add the full geometry of the place to the result output. Output formats
|
||||
in GeoJSON, KML, SVG or WKT are supported. Only one of these
|
||||
options can be used at a time.
|
||||
|
||||
* `polygon_threshold=0.0`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| polygon_threshold | floating-point number | 0.0 |
|
||||
|
||||
Return a simplified version of the output geometry. The parameter is the
|
||||
When one of the polygon_* outputs is chosen, return a simplified version
|
||||
of the output geometry. The parameter describes the
|
||||
tolerance in degrees with which the geometry may differ from the original
|
||||
geometry. Topology is preserved in the result. (Default: 0.0)
|
||||
geometry. Topology is preserved in the geometry.
|
||||
|
||||
### Other
|
||||
|
||||
* `email=<valid email address>`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| email | valid email address | _unset_ |
|
||||
|
||||
If you are making large numbers of request please include an appropriate email
|
||||
address to identify your requests. See Nominatim's [Usage Policy](https://operations.osmfoundation.org/policies/nominatim/) for more details.
|
||||
address to identify your requests. See Nominatim's
|
||||
[Usage Policy](https://operations.osmfoundation.org/policies/nominatim/) for more details.
|
||||
|
||||
* `dedupe=[0|1]`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| dedupe | 0 or 1 | 1 |
|
||||
|
||||
Sometimes you have several objects in OSM identifying the same place or
|
||||
object in reality. The simplest case is a street being split into many
|
||||
different OSM ways due to different characteristics. Nominatim will
|
||||
attempt to detect such duplicates and only return one match unless
|
||||
this parameter is set to 0. (Default: 1)
|
||||
attempt to detect such duplicates and only return one match. Setting
|
||||
this parameter to 0 disables this deduplication mechanism and
|
||||
ensures that all results are returned.
|
||||
|
||||
* `debug=[0|1]`
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| debug | 0 or 1 | 0 |
|
||||
|
||||
Output assorted developer debug information. Data on internals of Nominatim's
|
||||
"Search Loop" logic, and SQL queries. The output is (rough) HTML format.
|
||||
This overrides the specified machine readable format. (Default: 0)
|
||||
|
||||
"search loop" logic, and SQL queries. The output is HTML format.
|
||||
This overrides the specified machine readable format.
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
|
||||
##### XML with kml polygon
|
||||
##### XML with KML polygon
|
||||
|
||||
* [https://nominatim.openstreetmap.org/search?q=135+pilkington+avenue,+birmingham&format=xml&polygon_geojson=1&addressdetails=1](https://nominatim.openstreetmap.org/search?q=135+pilkington+avenue,+birmingham&format=xml&polygon_geojson=1&addressdetails=1)
|
||||
* [https://nominatim.openstreetmap.org/search?q=135+pilkington+avenue,+birmingham&format=xml&polygon_kml=1&addressdetails=1](https://nominatim.openstreetmap.org/search?q=135+pilkington+avenue,+birmingham&format=xml&polygon_kml=1&addressdetails=1)
|
||||
|
||||
```xml
|
||||
<searchresults timestamp="Sat, 07 Nov 09 14:42:10 +0000" querystring="135 pilkington, avenue birmingham" polygon="true">
|
||||
<place
|
||||
place_id="1620612" osm_type="node" osm_id="452010817"
|
||||
boundingbox="52.548641204834,52.5488433837891,-1.81612110137939,-1.81592094898224"
|
||||
lat="52.5487429714954" lon="-1.81602098644987"
|
||||
display_name="135, Pilkington Avenue, Wylde Green, City of Birmingham, West Midlands (county), B72, United Kingdom"
|
||||
class="place" type="house">
|
||||
<geokml>
|
||||
<Polygon>
|
||||
<outerBoundaryIs>
|
||||
<LinearRing>
|
||||
<coordinates>-1.816513,52.548756599999997 -1.816434,52.548747300000002 -1.816429,52.5487629 -1.8163717,52.548756099999999 -1.8163464,52.548834599999999 -1.8164599,52.548848100000001 -1.8164685,52.5488213 -1.8164913,52.548824000000003 -1.816513,52.548756599999997</coordinates>
|
||||
</LinearRing>
|
||||
</outerBoundaryIs>
|
||||
</Polygon>
|
||||
</geokml>
|
||||
<house_number>135</house_number>
|
||||
<road>Pilkington Avenue</road>
|
||||
<village>Wylde Green</village>
|
||||
<town>Sutton Coldfield</town>
|
||||
<city>City of Birmingham</city>
|
||||
<county>West Midlands (county)</county>
|
||||
<postcode>B72</postcode>
|
||||
<country>United Kingdom</country>
|
||||
<country_code>gb</country_code>
|
||||
</place>
|
||||
</searchresults>
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<searchresults timestamp="Tue, 08 Aug 2023 15:45:41 +00:00"
|
||||
attribution="Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright"
|
||||
querystring="135 pilkington avenue, birmingham"
|
||||
more_url="https://nominatim.openstreetmap.org/search?q=135+pilkington+avenue%2C+birmingham&polygon_kml=1&addressdetails=1&limit=20&exclude_place_ids=125279639&format=xml"
|
||||
exclude_place_ids="125279639">
|
||||
<place place_id="125279639"
|
||||
osm_type="way"
|
||||
osm_id="90394480"
|
||||
lat="52.5487921"
|
||||
lon="-1.8164308"
|
||||
boundingbox="52.5487473,52.5488481,-1.8165130,-1.8163464"
|
||||
place_rank="30"
|
||||
address_rank="30"
|
||||
display_name="135, Pilkington Avenue, Maney, Sutton Coldfield, Wylde Green, Birmingham, West Midlands Combined Authority, England, B72 1LH, United Kingdom"
|
||||
class="building"
|
||||
type="residential"
|
||||
importance="9.999999994736442e-08">
|
||||
<geokml>
|
||||
<Polygon>
|
||||
<outerBoundaryIs>
|
||||
<LinearRing>
|
||||
<coordinates>-1.816513,52.5487566 -1.816434,52.5487473 -1.816429,52.5487629 -1.8163717,52.5487561 -1.8163464,52.5488346 -1.8164599,52.5488481 -1.8164685,52.5488213 -1.8164913,52.548824 -1.816513,52.5487566</coordinates>
|
||||
</LinearRing>
|
||||
</outerBoundaryIs>
|
||||
</Polygon>
|
||||
</geokml>
|
||||
<house_number>135</house_number>
|
||||
<road>Pilkington Avenue</road>
|
||||
<hamlet>Maney</hamlet>
|
||||
<town>Sutton Coldfield</town>
|
||||
<village>Wylde Green</village>
|
||||
<city>Birmingham</city>
|
||||
<ISO3166-2-lvl8>GB-BIR</ISO3166-2-lvl8>
|
||||
<state_district>West Midlands Combined Authority</state_district>
|
||||
<state>England</state>
|
||||
<ISO3166-2-lvl4>GB-ENG</ISO3166-2-lvl4>
|
||||
<postcode>B72 1LH</postcode>
|
||||
<country>United Kingdom</country>
|
||||
<country_code>gb</country_code>
|
||||
</place>
|
||||
</searchresults>
|
||||
```
|
||||
|
||||
##### JSON with SVG polygon
|
||||
|
||||
[https://nominatim.openstreetmap.org/search/Unter%20den%20Linden%201%20Berlin?format=json&addressdetails=1&limit=1&polygon_svg=1](https://nominatim.openstreetmap.org/search/Unter%20den%20Linden%201%20Berlin?format=json&addressdetails=1&limit=1&polygon_svg=1)
|
||||
[https://nominatim.openstreetmap.org/search?q=Unter%20den%20Linden%201%20Berlin&format=json&addressdetails=1&limit=1&polygon_svg=1](https://nominatim.openstreetmap.org/search?q=Unter%20den%20Linden%201%20Berlin&format=json&addressdetails=1&limit=1&polygon_svg=1)
|
||||
|
||||
```json
|
||||
{
|
||||
"address": {
|
||||
"city": "Berlin",
|
||||
"city_district": "Mitte",
|
||||
"construction": "Unter den Linden",
|
||||
"continent": "European Union",
|
||||
"country": "Deutschland",
|
||||
"country_code": "de",
|
||||
"house_number": "1",
|
||||
"neighbourhood": "Scheunenviertel",
|
||||
"postcode": "10117",
|
||||
"public_building": "Kommandantenhaus",
|
||||
"state": "Berlin",
|
||||
"suburb": "Mitte"
|
||||
},
|
||||
"boundingbox": [
|
||||
"52.5170783996582",
|
||||
"52.5173187255859",
|
||||
"13.3975105285645",
|
||||
"13.3981599807739"
|
||||
],
|
||||
"class": "amenity",
|
||||
"display_name": "Kommandantenhaus, 1, Unter den Linden, Scheunenviertel, Mitte, Berlin, 10117, Deutschland, European Union",
|
||||
"importance": 0.73606775332943,
|
||||
"lat": "52.51719785",
|
||||
"licence": "Data \u00a9 OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright",
|
||||
"lon": "13.3978352028938",
|
||||
"osm_id": "15976890",
|
||||
"osm_type": "way",
|
||||
"place_id": "30848715",
|
||||
"svg": "M 13.397511 -52.517283599999999 L 13.397829400000001 -52.517299800000004 13.398131599999999 -52.517315099999998 13.398159400000001 -52.517112099999999 13.3975388 -52.517080700000001 Z",
|
||||
"type": "public_building"
|
||||
}
|
||||
[
|
||||
{
|
||||
"address": {
|
||||
"ISO3166-2-lvl4": "DE-BE",
|
||||
"borough": "Mitte",
|
||||
"city": "Berlin",
|
||||
"country": "Deutschland",
|
||||
"country_code": "de",
|
||||
"historic": "Kommandantenhaus",
|
||||
"house_number": "1",
|
||||
"neighbourhood": "Friedrichswerder",
|
||||
"postcode": "10117",
|
||||
"road": "Unter den Linden",
|
||||
"suburb": "Mitte"
|
||||
},
|
||||
"boundingbox": [
|
||||
"52.5170798",
|
||||
"52.5173311",
|
||||
"13.3975116",
|
||||
"13.3981577"
|
||||
],
|
||||
"class": "historic",
|
||||
"display_name": "Kommandantenhaus, 1, Unter den Linden, Friedrichswerder, Mitte, Berlin, 10117, Deutschland",
|
||||
"importance": 0.8135042058306902,
|
||||
"lat": "52.51720765",
|
||||
"licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
|
||||
"lon": "13.397834399325466",
|
||||
"osm_id": 15976890,
|
||||
"osm_type": "way",
|
||||
"place_id": 108681845,
|
||||
"svg": "M 13.3975116 -52.5172905 L 13.397549 -52.5170798 13.397715 -52.5170906 13.3977122 -52.5171064 13.3977392 -52.5171086 13.3977417 -52.5170924 13.3979655 -52.5171069 13.3979623 -52.5171233 13.3979893 -52.5171248 13.3979922 -52.5171093 13.3981577 -52.5171203 13.398121 -52.5173311 13.3978115 -52.5173103 Z",
|
||||
"type": "house"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
##### JSON with address details
|
||||
|
||||
[https://nominatim.openstreetmap.org/?addressdetails=1&q=bakery+in+berlin+wedding&format=json&limit=1](https://nominatim.openstreetmap.org/?addressdetails=1&q=bakery+in+berlin+wedding&format=json&limit=1)
|
||||
[https://nominatim.openstreetmap.org/search?addressdetails=1&q=bakery+in+berlin+wedding&format=jsonv2&limit=1](https://nominatim.openstreetmap.org/search?addressdetails=1&q=bakery+in+berlin+wedding&format=jsonv2&limit=1)
|
||||
|
||||
```json
|
||||
{
|
||||
"address": {
|
||||
"bakery": "B\u00e4cker Kamps",
|
||||
"city_district": "Mitte",
|
||||
"continent": "European Union",
|
||||
"country": "Deutschland",
|
||||
"country_code": "de",
|
||||
"footway": "Bahnsteig U6",
|
||||
"neighbourhood": "Sprengelkiez",
|
||||
"postcode": "13353",
|
||||
"state": "Berlin",
|
||||
"suburb": "Wedding"
|
||||
},
|
||||
"boundingbox": [
|
||||
"52.5460929870605",
|
||||
"52.5460968017578",
|
||||
"13.3591794967651",
|
||||
"13.3591804504395"
|
||||
],
|
||||
"class": "shop",
|
||||
"display_name": "B\u00e4cker Kamps, Bahnsteig U6, Sprengelkiez, Wedding, Mitte, Berlin, 13353, Deutschland, European Union",
|
||||
"icon": "https://nominatim.openstreetmap.org/images/mapicons/shopping_bakery.p.20.png",
|
||||
"importance": 0.201,
|
||||
"lat": "52.5460941",
|
||||
"licence": "Data \u00a9 OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright",
|
||||
"lon": "13.35918",
|
||||
"osm_id": "317179427",
|
||||
"osm_type": "node",
|
||||
"place_id": "1453068",
|
||||
"type": "bakery"
|
||||
}
|
||||
[
|
||||
{
|
||||
"address": {
|
||||
"ISO3166-2-lvl4": "DE-BE",
|
||||
"borough": "Mitte",
|
||||
"city": "Berlin",
|
||||
"country": "Deutschland",
|
||||
"country_code": "de",
|
||||
"neighbourhood": "Sprengelkiez",
|
||||
"postcode": "13347",
|
||||
"road": "Lindower Straße",
|
||||
"shop": "Ditsch",
|
||||
"suburb": "Wedding"
|
||||
},
|
||||
"addresstype": "shop",
|
||||
"boundingbox": [
|
||||
"52.5427201",
|
||||
"52.5427654",
|
||||
"13.3668619",
|
||||
"13.3669442"
|
||||
],
|
||||
"category": "shop",
|
||||
"display_name": "Ditsch, Lindower Straße, Sprengelkiez, Wedding, Mitte, Berlin, 13347, Deutschland",
|
||||
"importance": 9.99999999995449e-06,
|
||||
"lat": "52.54274275",
|
||||
"licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright",
|
||||
"lon": "13.36690305710228",
|
||||
"name": "Ditsch",
|
||||
"osm_id": 437595031,
|
||||
"osm_type": "way",
|
||||
"place_id": 204751033,
|
||||
"place_rank": 30,
|
||||
"type": "bakery"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
##### GeoJSON
|
||||
|
||||
@@ -1,35 +1,50 @@
|
||||
# Status
|
||||
|
||||
Useful for checking if the service and database is running. The JSON output also shows
|
||||
Report on the state of the service and database. Useful for checking if the
|
||||
service is up and running. The JSON output also reports
|
||||
when the database was last updated.
|
||||
|
||||
## Endpoint
|
||||
|
||||
The status API has the following format:
|
||||
|
||||
```
|
||||
https://nominatim.openstreetmap.org/status
|
||||
```
|
||||
|
||||
!!! danger "Deprecation warning"
|
||||
The API can also be used with the URL
|
||||
`https://nominatim.openstreetmap.org/status.php`. This is now deprecated
|
||||
and will be removed in future versions.
|
||||
|
||||
|
||||
## Parameters
|
||||
|
||||
* `format=[text|json]` (defaults to 'text')
|
||||
The status endpoint takes a single optional parameter:
|
||||
|
||||
| Parameter | Value | Default |
|
||||
|-----------| ----- | ------- |
|
||||
| format | one of: `text`, `json` | 'text' |
|
||||
|
||||
Selects the output format. See below.
|
||||
|
||||
|
||||
## Output
|
||||
|
||||
#### Text format
|
||||
|
||||
```
|
||||
https://nominatim.openstreetmap.org/status.php
|
||||
```
|
||||
When everything is okay, a status code 200 is returned and a simple message: `OK`
|
||||
|
||||
will return HTTP status code 200 and print `OK`.
|
||||
|
||||
On error it will return HTTP status code 500 and print a message, e.g.
|
||||
On error it will return HTTP status code 500 and print a detailed error message, e.g.
|
||||
`ERROR: Database connection failed`.
|
||||
|
||||
|
||||
|
||||
#### JSON format
|
||||
|
||||
```
|
||||
https://nominatim.openstreetmap.org/status.php?format=json
|
||||
```
|
||||
Always returns a HTTP code 200, when the status call could be executed.
|
||||
|
||||
will return HTTP code 200 and a structure
|
||||
On success a JSON dictionary with the following structure is returned:
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -45,8 +60,8 @@ The `software_version` field contains the version of Nominatim used to serve
|
||||
the API. The `database_version` field contains the version of the data format
|
||||
in the database.
|
||||
|
||||
On error will also return HTTP status code 200 and a structure with error
|
||||
code and message, e.g.
|
||||
On error will return a shorter JSON dictionary with the error message
|
||||
and status only, e.g.
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -54,14 +69,3 @@ code and message, e.g.
|
||||
"message": "Database connection failed"
|
||||
}
|
||||
```
|
||||
|
||||
Possible status codes are
|
||||
|
||||
| | message | notes |
|
||||
| --- | ------------------------------ | ----------------------------------------------------------------- |
|
||||
| 700 | "No database" | connection failed |
|
||||
| 701 | "Module failed" | database could not load nominatim.so |
|
||||
| 702 | "Module call failed" | nominatim.so loaded but calling a function failed |
|
||||
| 703 | "Query failed" | test query against a database table failed |
|
||||
| 704 | "No value" | test query worked but returned no results |
|
||||
| 705 | "Import date is not available" | No import dates were returned (enabling replication can fix this) |
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Extract markdown-formatted documentation from a source file
|
||||
#
|
||||
# Usage: bash2md.sh <infile> <outfile>
|
||||
|
||||
sed '/^#!/d;s:^#\( \|$\)::;s/.*#DOCS://' $1 > $2
|
||||
@@ -1,153 +1,574 @@
|
||||
## Configuring the Import
|
||||
# Configuring the Import of OSM data
|
||||
|
||||
Which OSM objects are added to the database and which of the tags are used
|
||||
can be configured via the import style configuration file. This
|
||||
is a JSON file which contains a list of rules which are matched against every
|
||||
tag of every object and then assign the tag its specific role.
|
||||
In the very first step of a Nominatim import, OSM data is loaded into the
|
||||
database. Nominatim uses [osm2pgsql](https://osm2pgsql.org) for this task.
|
||||
It comes with a [flex style](https://osm2pgsql.org/doc/manual.html#the-flex-output)
|
||||
specifically tailored to filter and convert OSM data into Nominatim's
|
||||
internal data representation. Nominatim ships with a few preset
|
||||
configurations for this import, each results in a geocoding database of
|
||||
different detail. The
|
||||
[Import section](../admin/Import.md#filtering-imported-data) explains
|
||||
these default configurations in detail.
|
||||
|
||||
The style to use is given by the `NOMINATIM_IMPORT_STYLE` configuration
|
||||
option. There are a number of default styles, which are explained in detail
|
||||
in the [Import section](../admin/Import.md#filtering-imported-data). These
|
||||
standard styles may be referenced by their name.
|
||||
If you want to have more control over which OSM data is added to the database,
|
||||
you can also create your own custom style. Create a new lua style file, put it
|
||||
into your project directory and then set `NOMINATIM_IMPORT_STYLE` to the name
|
||||
of the file. Custom style files can be used to modify the existing preset
|
||||
configurations or to implement your own configuration from scratch.
|
||||
|
||||
You can also create your own custom style. Put the style file into your
|
||||
project directory and then set `NOMINATIM_IMPORT_STYLE` to the name of the file.
|
||||
It is always recommended to start with one of the standard styles and customize
|
||||
those. You find the standard styles under the name `import-<stylename>.style`
|
||||
in the standard Nominatim configuration path (usually `/etc/nominatim` or
|
||||
`/usr/local/etc/nominatim`).
|
||||
The remainder of the page describes how the flex style works and how to
|
||||
customize it.
|
||||
|
||||
The remainder of the page describes the format of the file.
|
||||
## The `flex-base` lua module
|
||||
|
||||
### Configuration Rules
|
||||
The core of Nominatim's flex import configuration is the `flex-base` module.
|
||||
It defines the table layout used by Nominatim and provides standard
|
||||
implementations for the import callbacks that help with customizing
|
||||
how OSM tags are used by Nominatim.
|
||||
|
||||
A single rule looks like this:
|
||||
Every custom style must include this module to make sure that the correct
|
||||
tables are created. Thus start your custom style as follows:
|
||||
|
||||
```json
|
||||
{
|
||||
"keys" : ["key1", "key2", ...],
|
||||
"values" : {
|
||||
"value1" : "prop",
|
||||
"value2" : "prop1,prop2"
|
||||
}
|
||||
}
|
||||
``` lua
|
||||
local flex = require('flex-base')
|
||||
```
|
||||
|
||||
A rule first defines a list of keys to apply the rule to. This is always a list
|
||||
of strings. The string may have four forms. An empty string matches against
|
||||
any key. A string that ends in an asterisk `*` is a prefix match and accordingly
|
||||
matches against any key that starts with the given string (minus the `*`). A
|
||||
suffix match can be defined similarly with a string that starts with a `*`. Any
|
||||
other string constitutes an exact match.
|
||||
### Using preset configurations
|
||||
|
||||
The second part of the rules defines a list of values and the properties that
|
||||
apply to a successful match. Value strings may be either empty, which
|
||||
means that they match any value, or describe an exact match. Prefix
|
||||
or suffix matching of values is not possible.
|
||||
If you want to start with one of the existing presets, then you can import
|
||||
its settings using the `import_topic()` function:
|
||||
|
||||
For a rule to match, it has to find a valid combination of keys and values. The
|
||||
resulting property is that of the matched values.
|
||||
```
|
||||
local flex = require('flex-base')
|
||||
|
||||
The rules in a configuration file are processed sequentially and the first
|
||||
match for each tag wins.
|
||||
flex.import_topic('streets')
|
||||
```
|
||||
|
||||
A rule where key and value are the empty string is special. This defines the
|
||||
fallback when none of the rules match. The fallback is always used as a last
|
||||
resort when nothing else matches, no matter where the rule appears in the file.
|
||||
Defining multiple fallback rules is not allowed. What happens in this case,
|
||||
is undefined.
|
||||
The `import_topic` function takes an optional second configuration
|
||||
parameter. The available options are explained in the
|
||||
[themepark section](#using-osm2pgsql-themepark).
|
||||
|
||||
### Tag Properties
|
||||
!!! note
|
||||
You can also directly import the preset style files, e.g.
|
||||
`local flex = require('import-street')`. It is not possible to
|
||||
set extra configuration this way.
|
||||
|
||||
One or more of the following properties may be given for each tag:
|
||||
### How processing works
|
||||
|
||||
* `main`
|
||||
When Nominatim processes an OSM object, it looks for four kinds of tags:
|
||||
The _main tags_ classify what kind of place the OSM object represents. One
|
||||
OSM object can have more than one main tag. In such case one database entry
|
||||
is created for each main tag. _Name tags_ represent searchable names of the
|
||||
place. _Address tags_ are used to compute the address hierarchy of the place.
|
||||
Address tags are used for searching and for creating a display name of the place.
|
||||
_Extra tags_ are any tags that are not directly related to search but
|
||||
contain interesting additional information.
|
||||
|
||||
A principal tag. A new row will be added for the object with key and value
|
||||
as `class` and `type`.
|
||||
!!! danger
|
||||
Some tags in the extratags category are used by Nominatim to better
|
||||
classify the place. You want to make sure these are always present
|
||||
in custom styles.
|
||||
|
||||
* `with_name`
|
||||
Configuring the style means deciding which key and/or key/value is used
|
||||
in which category.
|
||||
|
||||
When the tag is a principal tag (`main` property set): only really add a new
|
||||
row, if there is any name tag found (a reference tag is not sufficient, see
|
||||
below).
|
||||
## Changing the recognized tags
|
||||
|
||||
* `with_name_key`
|
||||
The flex style offers a number of functions to set the classification of
|
||||
each OSM tag. Most of these functions can also take a preset string instead
|
||||
of a tag description. These presets describe common configurations that
|
||||
are also used in the definition of the predefined styles. This section
|
||||
lists the configuration functions and the accepted presets.
|
||||
|
||||
When the tag is a principal tag (`main` property set): only really add a new
|
||||
row, if there is also a name tag that matches the key of the principal tag.
|
||||
For example, if the main tag is `bridge=yes`, then it will only be added as
|
||||
an extra row, if there is a tag `bridge:name[:XXX]` for the same object.
|
||||
If this property is set, all other names that are not domain-specific are
|
||||
ignored.
|
||||
#### Key match lists
|
||||
|
||||
* `fallback`
|
||||
Some of the following functions take _key match lists_. These lists can
|
||||
contain three kinds of strings to match against tag keys:
|
||||
A string that ends in an asterisk `*` is a prefix match and accordingly matches
|
||||
against any key that starts with the given string (minus the `*`).
|
||||
A suffix match can be defined similarly with a string that starts with a `*`.
|
||||
Any other string is matched exactly against tag keys.
|
||||
|
||||
When the tag is a principal tag (`main` property set): only really add a new
|
||||
row, when no other principal tags for this object have been found. Only one
|
||||
fallback tag can win for an object.
|
||||
### Main tags
|
||||
|
||||
* `operator`
|
||||
`set/modify_main_tags()` allow to define which tags are used as main tags. It
|
||||
takes a lua table parameter which defines for keys and key/value
|
||||
combinations, how they are classified.
|
||||
|
||||
When the tag is a principal tag (`main` property set): also include the
|
||||
`operator` tag in the list of names. This is a special construct for an
|
||||
out-dated tagging practise in OSM. Fuel stations and chain restaurants
|
||||
in particular used to have the name of the chain tagged as `operator`.
|
||||
These days the chain can be more commonly found in the `brand` tag but
|
||||
there is still enough old data around to warrant this special case.
|
||||
The following classifications are recognized:
|
||||
|
||||
* `name`
|
||||
| classification | meaning |
|
||||
| :-------------- | :------ |
|
||||
| always | Unconditionally use this tag as a main tag. |
|
||||
| named | Consider as main tag, when the object has a primary name (see [names](#name-tags) below) |
|
||||
| named_with_key | Consider as main tag, when the object has a primary name with a domain prefix. For example, if the main tag is `bridge=yes`, then it will only be added as an extra entry, if there is a tag `bridge:name[:XXX]` for the same object. If this property is set, all names that are not domain-specific are ignored. |
|
||||
| fallback | Consider as main tag only when no other main tag was found. Fallback always implies `named`, i.e. fallbacks are only tried for objects with primary names. |
|
||||
| delete | Completely ignore the tag in any further processing |
|
||||
| extra | Move the tag to extratags and then ignore it for further processing |
|
||||
| `<function>`| Advanced handling, see [below](#advanced-main-tag-handling) |
|
||||
|
||||
Add tag to the list of names.
|
||||
Each key in the table parameter defines an OSM tag key. The value may
|
||||
be directly a classification as described above. Then the tag will
|
||||
be considered a main tag for any possible value that is not further defined.
|
||||
To further restrict which values are acceptable, give a table with the
|
||||
permitted values and their kind of main tag. If the table contains a simple
|
||||
value without key, then this is used as default for values that are not listed.
|
||||
|
||||
* `ref`
|
||||
`set_main_tags()` will completely replace the current main tag configuration
|
||||
with the new configuration. `modify_main_tags()` will merge the new
|
||||
configuration with the existing one. Otherwise, the two functions do exactly
|
||||
the same.
|
||||
|
||||
Add tag to the list of names as a reference. At the moment this only means
|
||||
that the object is not considered to be named for `with_name`.
|
||||
!!! example
|
||||
``` lua
|
||||
local flex = require('import-full')
|
||||
|
||||
* `address`
|
||||
flex.set_main_tags{
|
||||
boundary = {administrative = 'named'},
|
||||
highway = {'always', street_lamp = 'named', no = 'delete'},
|
||||
landuse = 'fallback'
|
||||
}
|
||||
```
|
||||
|
||||
Add tag to the list of address tags. If the tag starts with `addr:` or
|
||||
`is_in:`, then this prefix is cut off before adding it to the list.
|
||||
In this example an object with a `boundary` tag will only be included
|
||||
when it has a value of `administrative`. Objects with `highway` tags are
|
||||
always included with two exceptions: the troll tag `highway=no` is
|
||||
deleted on the spot. And when the value is `street_lamp` then the object
|
||||
must have a name, too. Finally, if a `landuse` tag is present then
|
||||
it will be used independently of the concrete value when neither boundary
|
||||
nor highway tags were found and the object is named.
|
||||
|
||||
* `postcode`
|
||||
##### Presets
|
||||
|
||||
Add the value as a postcode to the address tags. If multiple tags are
|
||||
candidate for postcodes, one wins out and the others are dropped.
|
||||
| Name | Description |
|
||||
| :----- | :---------- |
|
||||
| admin | Basic tag set collecting places and administrative boundaries. This set is needed also to ensure proper address computation and should therefore always be present. You can disable selected place types like `place=locality` after adding this set, if they are not relevant for your use case. |
|
||||
| all_boundaries | Extends the set of recognized boundaries and places to all available ones. |
|
||||
| natural | Tags for natural features like rivers and mountain peaks. |
|
||||
| street/default | Tags for streets. Major streets are always included, minor ones only when they have a name. |
|
||||
| street/car | Tags for all streets that can be used by a motor vehicle. |
|
||||
| street/all | Includes all highway features named and unnamed. |
|
||||
| poi/delete | Adds most POI features with and without name. Some frequent but very domain-specific values are excluded by deleting them. |
|
||||
| poi/extra | Like 'poi/delete' but excluded values are moved to extratags. |
|
||||
|
||||
* `country`
|
||||
|
||||
Add the value as a country code to the address tags. The value must be a
|
||||
two letter country code, otherwise it is ignored. If there are multiple
|
||||
tags that match, then one wins out and the others are dropped.
|
||||
##### Advanced main tag handling
|
||||
|
||||
* `house`
|
||||
The groups described above are in fact only a preset for a filtering function
|
||||
that is used to make the final decision how a pre-selected main tag is entered
|
||||
into Nominatim's internal table. To further customize handling you may also
|
||||
supply your own filtering function.
|
||||
|
||||
If no principle tags can be found for the object, still add the object with
|
||||
`class`=`place` and `type`=`house`. Use this for address nodes that have no
|
||||
other function.
|
||||
The function takes up to three parameters: a Place object of the object
|
||||
being processed, the key of the main tag and the value of the main tag.
|
||||
The function may return one of three values:
|
||||
|
||||
* `interpolation`
|
||||
* `nil` or `false` causes the entry to be ignored
|
||||
* the Place object causes the place to be added as is
|
||||
* `Place.copy(names=..., address=..., extratags=...) causes the
|
||||
place to be enter into the database but with name/address/extratags
|
||||
set to the given different values.
|
||||
|
||||
Add this object as an address interpolation (appears as `class`=`place` and
|
||||
`type`=`houses` in the database).
|
||||
The Place object has some read-only values that can be used to determine
|
||||
the handling:
|
||||
|
||||
* `extra`
|
||||
* **object** is the original OSM object data handed in by osm2pgsql
|
||||
* **admin_level** is the content of the admin_level tag, parsed into an integer and normalized to a value between 0 and 15
|
||||
* **has_name** is a boolean indicating if the object has a primary name tag
|
||||
* **names** is a table with the collected list of name tags
|
||||
* **address** is a table with the collected list of address tags
|
||||
* **extratags** is a table with the collected list of additional tags to save
|
||||
|
||||
Add tag to the list of extra tags.
|
||||
!!! example
|
||||
``` lua
|
||||
local flex = require('flex-base')
|
||||
|
||||
* `skip`
|
||||
flex.add_topic('street')
|
||||
|
||||
Skip the tag completely. Useful when a custom default fallback is defined
|
||||
or to define exceptions to rules.
|
||||
local function no_sidewalks(place, k, v)
|
||||
if place.object.tags.footway == 'sidewalk' then
|
||||
return false
|
||||
end
|
||||
|
||||
A rule can define as many of these properties for one match as it likes. For
|
||||
example, if the property is `"main,extra"` then the tag will open a new row
|
||||
but also have the tag appear in the list of extra tags.
|
||||
-- default behaviour is to have all footways
|
||||
return place
|
||||
end
|
||||
|
||||
### Changing the Style of Existing Databases
|
||||
flex.modify_main_tags(highway = {'footway' = no_sidewalks}
|
||||
```
|
||||
This script adds a custom handler for `highway=footway`. It only includes
|
||||
them in the database, when the object doesn't have a tag `footway=sidewalk`
|
||||
indicating that it is just part of a larger street which should already
|
||||
be indexed. Note that it is not necessary to check the key and value
|
||||
of the main tag because the function is only used for the specific
|
||||
main tag.
|
||||
|
||||
There is normally no issue changing the style of a database that is already
|
||||
|
||||
### Ignored tags
|
||||
|
||||
The function `ignore_keys()` sets the `delete` classification for keys.
|
||||
This function takes a _key match list_ so that it is possible to exclude
|
||||
groups of keys.
|
||||
|
||||
Note that full matches always take precedence over suffix matches, which
|
||||
in turn take precedence over prefix matches.
|
||||
|
||||
!!! example
|
||||
``` lua
|
||||
local flex = require('flex-base')
|
||||
|
||||
flex.add_topic('admin')
|
||||
flex.ignore_keys{'old_name', 'old_name:*'}
|
||||
```
|
||||
|
||||
This example uses the `admin` preset with the exception that names
|
||||
that are no longer are in current use, are ignored.
|
||||
|
||||
##### Presets
|
||||
|
||||
| Name | Description |
|
||||
| :----- | :---------- |
|
||||
| metatags | Tags with meta information about the OSM tag like source, notes and import sources. |
|
||||
| name | Non-names that actually describe properties or name parts. These names can throw off search and should always be removed. |
|
||||
| address | Extra `addr:*` tags that are not useful for Nominatim. |
|
||||
|
||||
|
||||
### Tags for `extratags`
|
||||
|
||||
The function `add_for_extratags()` sets the `extra` classification for keys.
|
||||
This function takes a
|
||||
_key match list_ so that it is possible to move groups of keys to extratags.
|
||||
|
||||
Note that full matches always take precedence over suffix matches, which
|
||||
in turn take precedence over prefix matches.
|
||||
|
||||
!!! example
|
||||
``` lua
|
||||
local flex = require('flex-base')
|
||||
|
||||
flex.add_topic('street')
|
||||
flex.add_for_extratags{'surface', 'access', 'vehicle', 'maxspeed'}
|
||||
```
|
||||
|
||||
This example uses the `street` preset but adds a couple of tags that
|
||||
are of interest about the condition of the street.
|
||||
|
||||
##### Presets
|
||||
|
||||
| Name | Description |
|
||||
| :----- | :---------- |
|
||||
| required | Tags that Nominatim will use for various computations when present in extratags. Always include these. |
|
||||
|
||||
In addition, all [presets from ignored tags](#presets_1) are accepted.
|
||||
|
||||
### General pre-filtering
|
||||
|
||||
_(deprecated)_ `set_prefilters()` allows to set the `delete` and `extra`
|
||||
classification for main tags.
|
||||
|
||||
This function removes all previously set main tags with `delete` and `extra`
|
||||
classification and then adds the newly defined tags.
|
||||
|
||||
`set_prefilters()` takes a table with four optional fields:
|
||||
|
||||
* __delete_keys__ is a _key match list_ for tags that should be deleted
|
||||
* __delete_tags__ contains a table of tag keys pointing to a list of tag
|
||||
values. Tags with matching key/value pairs are deleted.
|
||||
* __extra_keys__ is a _key match list_ for tags which should be saved into
|
||||
extratags
|
||||
* __extra_tags__ contains a table of tag keys pointing to a list of tag
|
||||
values. Tags with matching key/value pairs are moved to extratags.
|
||||
|
||||
!!! danger "Deprecation warning"
|
||||
Use of this function should be replaced with `modify_main_tags()` to
|
||||
set the data from `delete_tags` and `extra_tags`, with `ignore_keys()`
|
||||
for the `delete_keys` parameter and with `add_for_extratags()` for the
|
||||
`extra_keys` parameter.
|
||||
|
||||
### Name tags
|
||||
|
||||
`set/modify_name_tags()` allow to define the tags used for naming places. Name tags
|
||||
can only be selected by their keys. The import script distinguishes
|
||||
between primary and auxiliary names. A primary name is the given name of
|
||||
a place. Having a primary name makes a place _named_. This is important
|
||||
for main tags that are only included when a name is present. Auxiliary names
|
||||
are identifiers like references. They may be searched for but should not
|
||||
be included on their own.
|
||||
|
||||
The functions take a table with two optional fields `main` and `extra`.
|
||||
They take _key match lists_ for primary and auxiliary names respectively.
|
||||
A third field `house` can contain tags for names that appear in place of
|
||||
house numbers in addresses. This field can only contain complete key names.
|
||||
'house tags' are special in that they cause the OSM object to be added to
|
||||
the database independently of the presence of other main tags.
|
||||
|
||||
`set_name_tags()` overwrites the current configuration, while
|
||||
`modify_name_tags()` replaces the fields that are given. (Be aware that
|
||||
the fields are replaced as a whole. `main = {'foo_name'}` will cause
|
||||
`foo_name` to become the only recognized primary name. Any previously
|
||||
defined primary names are forgotten.)
|
||||
|
||||
!!! example
|
||||
``` lua
|
||||
local flex = require('flex-base')
|
||||
|
||||
flex.set_main_tags{highway = {traffic_light = 'named'}}
|
||||
flex.set_name_tags{main = {'name', 'name:*'},
|
||||
extra = {'ref'}
|
||||
}
|
||||
```
|
||||
|
||||
This example creates a search index over traffic lights but will
|
||||
only include those that have a common name and not those which just
|
||||
have some reference ID from the city.
|
||||
|
||||
##### Presets
|
||||
|
||||
| Name | Description |
|
||||
| :----- | :---------- |
|
||||
| core | Basic set of recognized names for all places. |
|
||||
| address | Additional names useful when indexing full addresses. |
|
||||
| poi | Extended set of recognized names for pois. Use on top of the core set. |
|
||||
|
||||
### Address tags
|
||||
|
||||
`set/modify_address_tags()` defines the tags that will be used to build
|
||||
up the address of an object. Address tags can only be chosen by their key.
|
||||
|
||||
The functions take a table with arbitrary fields, each defining
|
||||
a key list or _key match list_. Some fields have a special meaning:
|
||||
|
||||
| Field | Type | Description |
|
||||
| :---------| :-------- | :-----------|
|
||||
| main | key list | Tags that make a full address object out of the OSM object. This is usually the house number or variants thereof. If a main address tag appears, then the object will always be included, if necessary with a fallback of `place=house`. If the key has a prefix of `addr:` or `is_in:` this will be stripped. |
|
||||
| extra | key match list | Supplementary tags for addresses, tags like `addr:street`, `addr:city` etc. If the key has a prefix of `addr:` or `is_in:` this will be stripped. |
|
||||
| interpolation | key list | Tags that identify address interpolation lines. |
|
||||
| country | key match list | Tags that may contain the country the place is in. The first found value with a two-letter code will be accepted, all other values are discarded. |
|
||||
| _other_ | key match list | Summary field. If a key matches the key match list, then its value will be added to the address tags with the name of the field as key. If multiple tags match, then an arbitrary one wins. |
|
||||
|
||||
`set_address_tags()` overwrites the current configuration, while
|
||||
`modify_address_tags()` replaces the fields that are given. (Be aware that
|
||||
the fields are replaced as a whole.)
|
||||
|
||||
!!! example
|
||||
``` lua
|
||||
local flex = require('import-full')
|
||||
|
||||
flex.set_address_tags{
|
||||
main = {'addr:housenumber'},
|
||||
extra = {'addr:*'},
|
||||
postcode = {'postal_code', 'postcode', 'addr:postcode'},
|
||||
country = {'country_code', 'ISO3166-1'}
|
||||
}
|
||||
```
|
||||
|
||||
In this example all tags which begin with `addr:` will be saved in
|
||||
the address tag list. If one of the tags is `addr:housenumber`, the
|
||||
object will fall back to be entered as a `place=house` in the database
|
||||
unless there is another interested main tag to be found.
|
||||
|
||||
Tags with keys `country_code` and `ISO3166-1` are saved with their
|
||||
value under `country` in the address tag list. The same thing happens
|
||||
to postcodes, they will always be saved under the key `postcode` thus
|
||||
normalizing the multitude of keys that are used in the OSM database.
|
||||
|
||||
##### Presets
|
||||
|
||||
| Name | Description |
|
||||
| :----- | :---------- |
|
||||
| core | Basic set of tags needed to recognize address relationship for any place. Always include this. |
|
||||
| houses | Additional set of tags needed to recognize proper addresses |
|
||||
|
||||
### Handling of unclassified tags
|
||||
|
||||
`set_unused_handling()` defines what to do with tags that remain after all tags
|
||||
have been classified using the functions above. There are two ways in
|
||||
which the function can be used:
|
||||
|
||||
`set_unused_handling(delete_keys = ..., delete_tags = ...)` deletes all
|
||||
keys that match the descriptions in the parameters and moves all remaining
|
||||
tags into the extratags list.
|
||||
|
||||
`set_unused_handling(extra_keys = ..., extra_tags = ...)` moves all tags
|
||||
matching the parameters into the extratags list and then deletes the remaining
|
||||
tags. For the format of the parameters see the description in `set_prefilters()`
|
||||
above.
|
||||
|
||||
When no special handling is set, then unused tags will be discarded with one
|
||||
exception: place tags are kept in extratags for administrative boundaries.
|
||||
When using a custom setting, you should also make sure that the place tag
|
||||
is added for extratags.
|
||||
|
||||
!!! example
|
||||
``` lua
|
||||
local flex = require('import-full')
|
||||
|
||||
flex.set_address_tags{
|
||||
main = {'addr:housenumber'},
|
||||
extra = {'addr:*', 'tiger:county'}
|
||||
}
|
||||
flex.set_unused_handling{delete_keys = {'tiger:*'}}
|
||||
```
|
||||
|
||||
In this example all remaining tags except those beginning with `tiger:`
|
||||
are moved to the extratags list. Note that it is not possible to
|
||||
already delete the tiger tags with `set_prefilters()` because that
|
||||
would remove tiger:county before the address tags are processed.
|
||||
|
||||
## Customizing osm2pgsql callbacks
|
||||
|
||||
osm2pgsql expects the flex style to implement three callbacks, one process
|
||||
function per OSM type. If you want to implement special handling for
|
||||
certain OSM types, you can override the default implementations provided
|
||||
by the flex-base module.
|
||||
|
||||
### Enabling additional relation types
|
||||
|
||||
OSM relations can represent very diverse
|
||||
[types of real-world objects](https://wiki.openstreetmap.org/wiki/Key:type). To
|
||||
be able to process them correctly, Nominatim needs to understand how to
|
||||
create a geometry for each type. By default, the script knows how to
|
||||
process relations of type `multipolygon`, `boundary` and `waterway`. All
|
||||
other relation types are ignored.
|
||||
|
||||
To add other types relations, set `RELATION_TYPES` for
|
||||
the type to the kind of geometry that should be created. The following
|
||||
kinds of geometries can be used:
|
||||
|
||||
* __relation_as_multipolygon__ creates a (Multi)Polygon from the ways in
|
||||
the relation. If the ways do not form a valid area, then the object is
|
||||
silently discarded.
|
||||
* __relation_as_multiline__ creates a (Multi)LineString from the ways in
|
||||
the relations. Ways are combined as much as possible without any regards
|
||||
to their order in the relation.
|
||||
|
||||
!!! Example
|
||||
``` lua
|
||||
local flex = require('import-full')
|
||||
|
||||
flex.RELATION_TYPES['site'] = flex.relation_as_multipolygon
|
||||
```
|
||||
|
||||
With this line relations of `type=site` will be included in the index
|
||||
according to main tags found. This only works when the site relation
|
||||
resolves to a valid area. Nodes in the site relation are not part of the
|
||||
geometry.
|
||||
|
||||
|
||||
### Adding additional logic to processing functions
|
||||
|
||||
The default processing functions are also exported by the flex-base module
|
||||
as `process_node`, `process_way` and `process_relation`. These can be used
|
||||
to implement your own processing functions with some additional processing
|
||||
logic.
|
||||
|
||||
!!! Example
|
||||
``` lua
|
||||
local flex = require('import-full')
|
||||
|
||||
function osm2pgsql.process_relation(object)
|
||||
if object.tags.boundary ~= 'administrative' or object.tags.admin_level ~= '2' then
|
||||
flex.process_relation(object)
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
This example discards all country-level boundaries and uses standard
|
||||
handling for everything else. This can be useful if you want to use
|
||||
your own custom country boundaries.
|
||||
|
||||
|
||||
### Customizing the main processing function
|
||||
|
||||
!!! danger "Deprecation Warning"
|
||||
The style used to allow overwriting the internal processing function
|
||||
`process_tags()`. While this is currently still possible, it is no longer
|
||||
encouraged and may stop working in future versions. The internal
|
||||
`Place` class should now be considered read-only.
|
||||
|
||||
|
||||
## Using osm2pgsql-themepark
|
||||
|
||||
The Nominatim osm2pgsql style is designed so that it can also be used as
|
||||
a theme for [osm2pgsql-themepark](https://osm2pgsql.org/themepark/). This
|
||||
makes it easy to combine Nominatim with other projects like
|
||||
[openstreetmap-carto](https://github.com/gravitystorm/openstreetmap-carto)
|
||||
in the same database.
|
||||
|
||||
To set up one of the preset styles, simply include a topic with the same name:
|
||||
|
||||
```
|
||||
local themepark = require('themepark')
|
||||
themepark:add_topic('nominatim/address')
|
||||
```
|
||||
|
||||
Themepark topics offer two configuration options:
|
||||
|
||||
* **street_theme** allows to choose one of the sub topics for streets:
|
||||
* _default_ - include all major streets and named minor paths
|
||||
* _car_ - include all streets physically usable by cars
|
||||
* _all_ - include all major streets and minor paths
|
||||
* **with_extratags**, when set to a truthy value, then tags that are
|
||||
not specifically used for address or naming are added to the
|
||||
extratags column
|
||||
|
||||
The customization functions described in the
|
||||
[Changing recognized tags](#changing-the-recognized-tags) section
|
||||
are available from the theme. To access the theme you need to explicitly initialize it.
|
||||
|
||||
!!! Example
|
||||
``` lua
|
||||
local themepark = require('themepark')
|
||||
|
||||
themepark:add_topic('nominatim/full', {with_extratags = true})
|
||||
|
||||
local flex = themepark:init_theme('nominatim')
|
||||
|
||||
flex.modify_main_tags{'amenity' = {
|
||||
'waste_basket' = 'delete'}
|
||||
}
|
||||
```
|
||||
This example uses the full Nominatim configuration but disables
|
||||
importing waste baskets.
|
||||
|
||||
You may also write a new configuration from scratch. Simply omit including
|
||||
a Nominatim topic and only call the required customization functions.
|
||||
|
||||
Customizing the osm2pgsql processing functions as explained
|
||||
[above](#adding-additional-logic-to-processing-functions) is not possible
|
||||
when running under themepark. Instead include other topics that make the
|
||||
necessary modifications or add an additional processor before including
|
||||
the Nominatim topic.
|
||||
|
||||
!!! Example
|
||||
``` lua
|
||||
local themepark = require('themepark')
|
||||
|
||||
local function discard_country_boundaries(object)
|
||||
if object.tags.boundary == 'administrative' and object.tags.admin_level == '2' then
|
||||
return 'stop'
|
||||
end
|
||||
end
|
||||
|
||||
themepark:add_proc('relation', discard_country_boundaries)
|
||||
-- Order matters here. The topic needs to be added after the custom callback.
|
||||
themepark:add_topic('nominatim/full', {with_extratags = true})
|
||||
```
|
||||
Discarding country-level boundaries when running under themepark.
|
||||
|
||||
## osm2pgsql gazetteer output
|
||||
|
||||
Nominatim still allows you to configure the gazetteer output to remain
|
||||
backwards compatible with older imports. It will be automatically used
|
||||
when the style file name ends in `.style`. For documentation of the
|
||||
old import style, please refer to the documentation of older releases
|
||||
of Nominatim. Do not use the gazetteer output for new imports. There is no
|
||||
guarantee that new versions of Nominatim are fully compatible with the
|
||||
gazetteer output.
|
||||
|
||||
## Changing the style of existing databases
|
||||
|
||||
There is usually no issue changing the style of a database that is already
|
||||
imported and now kept up-to-date with change files. Just be aware that any
|
||||
change in the style applies to updates only. If you want to change the data
|
||||
that is already in the database, then a reimport is necessary.
|
||||
|
||||
@@ -12,7 +12,7 @@ customize them.
|
||||
The main value for importance is derived from page ranking values for Wikipedia
|
||||
pages for a place. For places that do not have their own
|
||||
Wikipedia page, a formula is used that derives a static importance from the
|
||||
places [search rank](../customize/Ranking.md#search-rank).
|
||||
place's [search rank](../customize/Ranking.md#search-rank).
|
||||
|
||||
In a second step, a secondary importance value is added which is meant to
|
||||
represent how well-known the general area is where the place is located. It
|
||||
@@ -21,7 +21,13 @@ importance values.
|
||||
|
||||
nominatim.org has preprocessed importance tables for the
|
||||
[primary Wikipedia rankings](https://nominatim.org/data/wikimedia-importance.sql.gz)
|
||||
and for a secondary importance based on the number of tile views on openstreetmap.org.
|
||||
and for [secondary importance](https://nominatim.org/data/wikimedia-secondary-importance.sql.gz)
|
||||
based on Wikipedia importance of the administrative areas.
|
||||
|
||||
The source code for creating these files is available in the Github projects
|
||||
[osm-search/wikipedia-wikidata](https://github.com/osm-search/wikipedia-wikidata)
|
||||
and
|
||||
[osm-search/secondary-importance](https://github.com/osm-search/secondary-importance).
|
||||
|
||||
### Customizing secondary importance
|
||||
|
||||
@@ -41,8 +47,8 @@ table will be ignored. You must furthermore create an index as follows:
|
||||
CREATE INDEX ON secondary_importance USING gist(ST_ConvexHull(gist))
|
||||
```
|
||||
|
||||
The following raster2pgsql command will create a table that conforms to
|
||||
the requirements:
|
||||
The following raster2pgsql command will create a table from a tiff file
|
||||
that conforms to the requirements:
|
||||
|
||||
```
|
||||
raster2pgsql -I -C -Y -d -t 128x128 input.tiff public.secondary_importance
|
||||
|
||||
@@ -7,6 +7,8 @@ the following configurable parts:
|
||||
can be set in your local `.env` configuration
|
||||
* [Import styles](Import-Styles.md) explains how to write your own import style
|
||||
in order to control what kind of OSM data will be imported
|
||||
* [API Result Formatting](Result-Formatting.md) shows how to change the
|
||||
output of the Nominatim API
|
||||
* [Place ranking](Ranking.md) describes the configuration around classifing
|
||||
places in terms of their importance and their role in an address
|
||||
* [Tokenizers](Tokenizers.md) describes the configuration of the module
|
||||
|
||||
259
docs/customize/Result-Formatting.md
Normal file
259
docs/customize/Result-Formatting.md
Normal file
@@ -0,0 +1,259 @@
|
||||
# Changing the Appearance of Results in the Server API
|
||||
|
||||
The Nominatim Server API offers a number of formatting options that
|
||||
present search results in [different output formats](../api/Output.md).
|
||||
These results only contain a subset of all the information that Nominatim
|
||||
has about the result. This page explains how to adapt the result output
|
||||
or add additional result formatting.
|
||||
|
||||
## Defining custom result formatting
|
||||
|
||||
To change the result output, you need to place a file `api/v1/format.py`
|
||||
into your project directory. This file needs to define a single variable
|
||||
`dispatch` containing a [FormatDispatcher](#formatdispatcher). This class
|
||||
serves to collect the functions for formatting the different result types
|
||||
and offers helper functions to apply the formatters.
|
||||
|
||||
There are two ways to define the `dispatch` variable. If you want to reuse
|
||||
the default output formatting and just make some changes or add an additional
|
||||
format type, then import the dispatch object from the default API:
|
||||
|
||||
``` python
|
||||
from nominatim_api.v1.format import dispatch as dispatch
|
||||
```
|
||||
|
||||
If you prefer to define a completely new result output, then you can
|
||||
create an empty dispatcher object:
|
||||
|
||||
``` python
|
||||
from nominatim_api import FormatDispatcher
|
||||
|
||||
dispatch = FormatDispatcher()
|
||||
```
|
||||
|
||||
## The formatting function
|
||||
|
||||
The dispatcher organises the formatting functions by format and result type.
|
||||
The format corresponds to the `format` parameter of the API. It can contain
|
||||
one of the predefined format names or you can invent your own new format.
|
||||
|
||||
API calls return data classes or an array of a data class which represent
|
||||
the result. You need to make sure there are formatters defined for the
|
||||
following result types:
|
||||
|
||||
* StatusResult (single object, returned by `/status`)
|
||||
* DetailedResult (single object, returned by `/details`)
|
||||
* SearchResults (list of objects, returned by `/search`)
|
||||
* ReverseResults (list of objects, returned by `/reverse` and `/lookup`)
|
||||
* RawDataList (simple object, returned by `/deletable` and `/polygons`)
|
||||
|
||||
A formatter function has the following signature:
|
||||
|
||||
``` python
|
||||
def format_func(result: ResultType, options: Mapping[str, Any]) -> str
|
||||
```
|
||||
|
||||
The options dictionary contains additional information about the original
|
||||
query. See the [reference below](#options-for-different-result-types)
|
||||
about the possible options.
|
||||
|
||||
To set the result formatter for a certain result type and format, you need
|
||||
to write the format function and decorate it with the
|
||||
[`format_func`](#nominatim_api.FormatDispatcher.format_func)
|
||||
decorator.
|
||||
|
||||
For example, let us extend the result for the status call in text format
|
||||
and add the server URL. Such a formatter would look like this:
|
||||
|
||||
``` python
|
||||
from nominatim_api import StatusResult
|
||||
|
||||
@dispatch.format_func(StatusResult, 'text')
|
||||
def _format_status_text(result, _):
|
||||
header = 'Status for server nominatim.openstreetmap.org'
|
||||
if result.status:
|
||||
return f"{header}\n\nERROR: {result.message}"
|
||||
|
||||
return f"{header}\n\nOK"
|
||||
```
|
||||
|
||||
If your dispatcher is derived from the default one, then this definition
|
||||
will overwrite the original formatter function. This way it is possible
|
||||
to customize the output of selected results.
|
||||
|
||||
## Adding new formats
|
||||
|
||||
You may also define a completely different output format. This is as simple
|
||||
as adding formatting functions for all result types using the custom
|
||||
format name:
|
||||
|
||||
``` python
|
||||
from nominatim_api import StatusResult
|
||||
|
||||
@dispatch.format_func(StatusResult, 'chatty')
|
||||
def _format_status_text(result, _):
|
||||
if result.status:
|
||||
return f"The server is currently not running. {result.message}"
|
||||
|
||||
return "Good news! The server is running just fine."
|
||||
```
|
||||
|
||||
That's all. Nominatim will automatically pick up the new format name and
|
||||
will allow the user to use it. There is no need to implement formatter
|
||||
functions for all the result types, when you invent a new one. The
|
||||
available formats will be determined for each API endpoint separately.
|
||||
To find out which formats are available, you can use the `--list-formats`
|
||||
option of the CLI tool:
|
||||
|
||||
```
|
||||
me@machine:planet-project$ nominatim status --list-formats
|
||||
2024-08-16 19:54:00: Using project directory: /home/nominatim/planet-project
|
||||
text
|
||||
json
|
||||
chatty
|
||||
debug
|
||||
me@machine:planet-project$
|
||||
```
|
||||
|
||||
The `debug` format listed in the last line will always appear. It is a
|
||||
special format that enables debug output via the command line (the same
|
||||
as the `debug=1` parameter enables for the server API). To not clash
|
||||
with this built-in function, you shouldn't name your own format 'debug'.
|
||||
|
||||
### Content type of new formats
|
||||
|
||||
All responses will be returned with the content type application/json by
|
||||
default. If your format produces a different content type, you need
|
||||
to configure the content type with the `set_content_type()` function.
|
||||
|
||||
For example, the 'chatty' format above returns just simple text. So the
|
||||
content type should be set up as:
|
||||
|
||||
``` python
|
||||
from nominatim_api.server.content_types import CONTENT_TEXT
|
||||
|
||||
dispatch.set_content_type('chatty', CONTENT_TEXT)
|
||||
```
|
||||
|
||||
The `content_types` module used above provides constants for the most
|
||||
frequent content types. You set the content type to an arbitrary string,
|
||||
if the content type you need is not available.
|
||||
|
||||
## Formatting error messages
|
||||
|
||||
Any exception thrown during processing of a request is given to
|
||||
a special error formatting function. It takes the requested content type,
|
||||
the status code and the error message. It should return the error message
|
||||
in a form appropriate for the given content type.
|
||||
|
||||
You can overwrite the default formatting function with the decorator
|
||||
`error_format_func`:
|
||||
|
||||
``` python
|
||||
import nominatim_api.server.content_types as ct
|
||||
|
||||
@dispatch.error_format_func
|
||||
def _format_error(content_type: str, msg: str, status: int) -> str:
|
||||
if content_type == ct.CONTENT_XML:
|
||||
return f"""<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<message>{msg}</message>
|
||||
"""
|
||||
if content_type == ct.CONTENT_JSON:
|
||||
return f'"{msg}"'
|
||||
|
||||
return f"ERROR: {msg}"
|
||||
```
|
||||
|
||||
|
||||
## Debugging custom formatters
|
||||
|
||||
The easiest way to try out your custom formatter is by using the Nominatim
|
||||
CLI commands. Custom formats can be chosen with the `--format` parameter:
|
||||
|
||||
```
|
||||
me@machine:planet-project$ nominatim status --format chatty
|
||||
2024-08-16 19:54:00: Using project directory: /home/nominatim/planet-project
|
||||
Good news! The server is running just fine.
|
||||
me@machine:planet-project$
|
||||
```
|
||||
|
||||
They will also emit full error messages when there is a problem with the
|
||||
code you need to debug.
|
||||
|
||||
!!! danger
|
||||
In some cases, when you make an error with your import statement, the
|
||||
CLI will not give you an error but instead tell you, that the API
|
||||
commands are no longer available:
|
||||
|
||||
me@machine: nominatim status
|
||||
usage: nominatim [-h] [--version] {import,freeze,replication,special-phrases,add-data,index,refresh,admin} ...
|
||||
nominatim: error: argument subcommand: invalid choice: 'status'
|
||||
|
||||
This happens because the CLI tool is meant to still work when the
|
||||
nominatim-api package is not installed. Import errors involving
|
||||
`nominatim_api` are interpreted as "package not installed".
|
||||
|
||||
Use the help command to find out which is the offending import that
|
||||
could not be found:
|
||||
|
||||
me@machine: nominatim -h
|
||||
... [other help text] ...
|
||||
Nominatim API package not found (was looking for module: nominatim_api.xxx).
|
||||
|
||||
## Reference
|
||||
|
||||
### FormatDispatcher
|
||||
|
||||
::: nominatim_api.FormatDispatcher
|
||||
options:
|
||||
heading_level: 6
|
||||
group_by_category: False
|
||||
|
||||
### JsonWriter
|
||||
|
||||
::: nominatim_api.utils.json_writer.JsonWriter
|
||||
options:
|
||||
heading_level: 6
|
||||
group_by_category: False
|
||||
|
||||
### Options for different result types
|
||||
|
||||
This section lists the options that may be handed in with the different result
|
||||
types in the v1 version of the Nominatim API.
|
||||
|
||||
#### StatusResult
|
||||
|
||||
_None._
|
||||
|
||||
#### DetailedResult
|
||||
|
||||
| Option | Description |
|
||||
|-----------------|-------------|
|
||||
| locales | [Locale](../library/Result-Handling.md#locale) object for the requested language(s) |
|
||||
| group_hierarchy | Setting of [group_hierarchy](../api/Details.md#output-details) parameter |
|
||||
| icon_base_url | (optional) URL pointing to icons as set in [NOMINATIM_MAPICON_URL](Settings.md#nominatim_mapicon_url) |
|
||||
|
||||
#### SearchResults
|
||||
|
||||
| Option | Description |
|
||||
|-----------------|-------------|
|
||||
| query | Original query string |
|
||||
| more_url | URL for requesting additional results for the same query |
|
||||
| exclude_place_ids | List of place IDs already returned |
|
||||
| viewbox | Setting of [viewbox](../api/Search.md#result-restriction) parameter |
|
||||
| extratags | Setting of [extratags](../api/Search.md#output-details) parameter |
|
||||
| namedetails | Setting of [namedetails](../api/Search.md#output-details) parameter |
|
||||
| addressdetails | Setting of [addressdetails](../api/Search.md#output-details) parameter |
|
||||
|
||||
#### ReverseResults
|
||||
|
||||
| Option | Description |
|
||||
|-----------------|-------------|
|
||||
| query | Original query string |
|
||||
| extratags | Setting of [extratags](../api/Search.md#output-details) parameter |
|
||||
| namedetails | Setting of [namedetails](../api/Search.md#output-details) parameter |
|
||||
| addressdetails | Setting of [addressdetails](../api/Search.md#output-details) parameter |
|
||||
|
||||
#### RawDataList
|
||||
|
||||
_None._
|
||||
60
docs/customize/SQLite.md
Normal file
60
docs/customize/SQLite.md
Normal file
@@ -0,0 +1,60 @@
|
||||
A Nominatim database can be converted into an SQLite database and used as
|
||||
a read-only source for geocoding queries. This sections describes how to
|
||||
create and use an SQLite database.
|
||||
|
||||
!!! danger
|
||||
This feature is in an experimental state at the moment. Use at your own
|
||||
risk.
|
||||
|
||||
## Installing prerequisites
|
||||
|
||||
To use a SQLite database, you need to install:
|
||||
|
||||
* SQLite (>= 3.30)
|
||||
* Spatialite (> 5.0.0)
|
||||
* aiosqlite
|
||||
|
||||
On Ubuntu/Debian, you can run:
|
||||
|
||||
sudo apt install sqlite3 libsqlite3-mod-spatialite libspatialite7
|
||||
|
||||
Install the aiosqlite Python package in your virtual environment:
|
||||
|
||||
/srv/nominatim-venv/bin/pip install aiosqlite
|
||||
|
||||
## Creating a new SQLite database
|
||||
|
||||
Nominatim cannot import directly into SQLite database. Instead you have to
|
||||
first create a geocoding database in PostgreSQL by running a
|
||||
[regular Nominatim import](../admin/Import.md).
|
||||
|
||||
Once this is done, the database can be converted to SQLite with
|
||||
|
||||
nominatim convert -o mydb.sqlite
|
||||
|
||||
This will create a database where all geocoding functions are available.
|
||||
Depending on what functions you need, the database can be made smaller:
|
||||
|
||||
* `--without-reverse` omits indexes only needed for reverse geocoding
|
||||
* `--without-search` omit tables and indexes used for forward search
|
||||
* `--without-details` leaves out extra information only available in the
|
||||
details API
|
||||
|
||||
## Using an SQLite database
|
||||
|
||||
Once you have created the database, you can use it by simply pointing the
|
||||
database DSN to the SQLite file:
|
||||
|
||||
NOMINATIM_DATABASE_DSN=sqlite:dbname=mydb.sqlite
|
||||
|
||||
Please note that SQLite support is only available for the Python frontend. To
|
||||
use the test server with an SQLite database, you therefore need to switch
|
||||
the frontend engine:
|
||||
|
||||
nominatim serve --engine falcon
|
||||
|
||||
You need to install falcon or starlette for this, depending on which engine
|
||||
you choose.
|
||||
|
||||
The CLI query commands and the library interface already use the new Python
|
||||
frontend and therefore work right out of the box.
|
||||
@@ -57,41 +57,20 @@ parameter that is understood by libpq. See the [Postgres documentation](https://
|
||||
| **After Changes:** | cannot be changed after import |
|
||||
|
||||
Defines the name of the database user that will run search queries. Usually
|
||||
this is the user under which the webserver is executed. When running Nominatim
|
||||
via php-fpm, you can also define a separate query user. The Postgres user
|
||||
this is the user under which the webserver is executed. The Postgres user
|
||||
needs to be set up before starting the import.
|
||||
|
||||
Nominatim grants minimal rights to this user to all tables that are needed
|
||||
for running geocoding queries.
|
||||
|
||||
|
||||
#### NOMINATIM_DATABASE_MODULE_PATH
|
||||
|
||||
| Summary | |
|
||||
| -------------- | --------------------------------------------------- |
|
||||
| **Description:** | Directory where to find the PostgreSQL server module |
|
||||
| **Format:** | path |
|
||||
| **Default:** | _empty_ (use `<project_directory>/module`) |
|
||||
| **After Changes:** | run `nominatim refresh --functions` |
|
||||
| **Comment:** | Legacy tokenizer only |
|
||||
|
||||
Defines the directory in which the PostgreSQL server module `nominatim.so`
|
||||
is stored. The directory and module must be accessible by the PostgreSQL
|
||||
server.
|
||||
|
||||
For information on how to use this setting when working with external databases,
|
||||
see [Advanced Installations](../admin/Advanced-Installations.md).
|
||||
|
||||
The option is only used by the Legacy tokenizer and ignored otherwise.
|
||||
|
||||
|
||||
#### NOMINATIM_TOKENIZER
|
||||
|
||||
| Summary | |
|
||||
| -------------- | --------------------------------------------------- |
|
||||
| **Description:** | Tokenizer used for normalizing and parsing queries and names |
|
||||
| **Format:** | string |
|
||||
| **Default:** | legacy |
|
||||
| **Default:** | icu |
|
||||
| **After Changes:** | cannot be changed after import |
|
||||
|
||||
Sets the tokenizer type to use for the import. For more information on
|
||||
@@ -115,20 +94,6 @@ on the file format.
|
||||
If a relative path is given, then the file is searched first relative to the
|
||||
project directory and then in the global settings directory.
|
||||
|
||||
#### NOMINATIM_MAX_WORD_FREQUENCY
|
||||
|
||||
| Summary | |
|
||||
| -------------- | --------------------------------------------------- |
|
||||
| **Description:** | Number of occurrences before a word is considered frequent |
|
||||
| **Format:** | int |
|
||||
| **Default:** | 50000 |
|
||||
| **After Changes:** | cannot be changed after import |
|
||||
| **Comment:** | Legacy tokenizer only |
|
||||
|
||||
The word frequency count is used by the Legacy tokenizer to automatically
|
||||
identify _stop words_. Any partial term that occurs more often then what
|
||||
is defined in this setting, is effectively ignored during search.
|
||||
|
||||
|
||||
#### NOMINATIM_LIMIT_REINDEXING
|
||||
|
||||
@@ -148,29 +113,6 @@ Setting this option to 'yes' means that Nominatim skips reindexing of contained
|
||||
objects when the area becomes too large.
|
||||
|
||||
|
||||
#### NOMINATIM_UPDATE_FORWARD_DEPENDENCIES
|
||||
|
||||
| Summary | |
|
||||
| -------------- | --------------------------------------------------- |
|
||||
| **Description:** | Forward geometry changes to dependet objects |
|
||||
| **Format:** | bool |
|
||||
| **Default:** | no |
|
||||
| **Comment:** | EXPERT ONLY. Must not be enabled after import. |
|
||||
|
||||
The geometry of OSM ways and relations may change when a node that is part
|
||||
of the object is moved around. These changes are not propagated per default.
|
||||
The geometry of ways/relations is only updated the next time that the object
|
||||
itself is touched. When enabling this option, then dependent objects will
|
||||
be marked for update when one of its member objects changes.
|
||||
|
||||
Enabling this option may slow down updates significantly.
|
||||
|
||||
!!! warning
|
||||
If you want to enable this option, it must be set already on import.
|
||||
Do not enable this option on an existing database that was imported with
|
||||
NOMINATIM_UPDATE_FORWARD_DEPENDENCIES=no.
|
||||
Updates will become unusably slow.
|
||||
|
||||
#### NOMINATIM_LANGUAGES
|
||||
|
||||
| Summary | |
|
||||
@@ -186,25 +128,6 @@ codes, to restrict import to a subset of languages.
|
||||
Currently only affects the initial import of country names and special phrases.
|
||||
|
||||
|
||||
#### NOMINATIM_TERM_NORMALIZATION
|
||||
|
||||
| Summary | |
|
||||
| -------------- | --------------------------------------------------- |
|
||||
| **Description:** | Rules for normalizing terms for comparisons |
|
||||
| **Format:** | string: semicolon-separated list of ICU rules |
|
||||
| **Default:** | :: NFD (); [[:Nonspacing Mark:] [:Cf:]] >; :: lower (); [[:Punctuation:][:Space:]]+ > ' '; :: NFC (); |
|
||||
| **Comment:** | Legacy tokenizer only |
|
||||
|
||||
[Special phrases](Special-Phrases.md) have stricter matching requirements than
|
||||
normal search terms. They must appear exactly in the query after this term
|
||||
normalization has been applied.
|
||||
|
||||
Only has an effect on the Legacy tokenizer. For the ICU tokenizer the rules
|
||||
defined in the
|
||||
[normalization section](Tokenizers.md#normalization-and-transliteration)
|
||||
will be used.
|
||||
|
||||
|
||||
#### NOMINATIM_USE_US_TIGER_DATA
|
||||
|
||||
| Summary | |
|
||||
@@ -413,7 +336,7 @@ NOMINATIM_TABLESPACE_SEARCH_INDEX
|
||||
NOMINATIM_TABLESPACE_OSM_DATA
|
||||
: Raw OSM data cache used for import and updates.
|
||||
|
||||
NOMINATIM_TABLESPACE_OSM_DATA
|
||||
NOMINATIM_TABLESPACE_OSM_INDEX
|
||||
: Indexes on the raw OSM data cache.
|
||||
|
||||
NOMINATIM_TABLESPACE_PLACE_DATA
|
||||
@@ -567,35 +490,6 @@ the local languages (in OSM: the name tag without any language suffix) is
|
||||
used.
|
||||
|
||||
|
||||
#### NOMINATIM_SEARCH_BATCH_MODE
|
||||
|
||||
| Summary | |
|
||||
| -------------- | --------------------------------------------------- |
|
||||
| **Description:** | Enable a special batch query mode |
|
||||
| **Format:** | boolean |
|
||||
| **Default:** | no |
|
||||
| **After Changes:** | run `nominatim refresh --website` |
|
||||
|
||||
This feature is currently undocumented and potentially broken.
|
||||
|
||||
|
||||
#### NOMINATIM_SEARCH_NAME_ONLY_THRESHOLD
|
||||
|
||||
| Summary | |
|
||||
| -------------- | --------------------------------------------------- |
|
||||
| **Description:** | Threshold for switching the search index lookup strategy |
|
||||
| **Format:** | integer |
|
||||
| **Default:** | 500 |
|
||||
| **After Changes:** | run `nominatim refresh --website` |
|
||||
|
||||
This setting defines the threshold over which a name is no longer considered
|
||||
as rare. When searching for places with rare names, only the name is used
|
||||
for place lookups. Otherwise the name and any address information is used.
|
||||
|
||||
This setting only has an effect after `nominatim refresh --word-counts` has
|
||||
been called to compute the word frequencies.
|
||||
|
||||
|
||||
#### NOMINATIM_LOOKUP_MAX_COUNT
|
||||
|
||||
| Summary | |
|
||||
@@ -627,6 +521,87 @@ with a single query.
|
||||
|
||||
Setting this parameter to 0 disables polygon output completely.
|
||||
|
||||
|
||||
#### NOMINATIM_SEARCH_WITHIN_COUNTRIES
|
||||
|
||||
| Summary | |
|
||||
| -------------- | --------------------------------------------------- |
|
||||
| **Description:** | Disable search for elements that are not in the country grid |
|
||||
| **Format:** | boolean |
|
||||
| **Default:** | no |
|
||||
| **After Changes:** | run `nominatim refresh --website` |
|
||||
|
||||
Enable to search elements just within countries.
|
||||
|
||||
When enabled, if, despite not finding a point within the static grid of countries, it
|
||||
finds a geometry of a region, do not return the geometry.
|
||||
Return "Unable to geocode" instead.
|
||||
|
||||
|
||||
#### NOMINATIM_SERVE_LEGACY_URLS
|
||||
|
||||
| Summary | |
|
||||
| -------------- | --------------------------------------------------- |
|
||||
| **Description:** | Enable serving via URLs with a .php suffix |
|
||||
| **Format:** | boolean |
|
||||
| **Default:** | yes |
|
||||
| **Comment:** | Python frontend only |
|
||||
|
||||
When enabled, then endpoints are reachable as `/<name>` as well as `/<name>.php`.
|
||||
This can be useful when you want to be backwards-compatible with previous
|
||||
versions of Nominatim.
|
||||
|
||||
|
||||
#### NOMINATIM_API_POOL_SIZE
|
||||
|
||||
| Summary | |
|
||||
| -------------- | --------------------------------------------------- |
|
||||
| **Description:** | Number of parallel database connections per worker |
|
||||
| **Format:** | number |
|
||||
| **Default:** | 10 |
|
||||
| **Comment:** | Python frontend only |
|
||||
|
||||
Sets the maximum number of database connections available for a single instance
|
||||
of Nominatim. When configuring the maximum number of connections that your
|
||||
PostgreSQL database can handle, you need at least
|
||||
`NOMINATIM_API_POOL_SIZE` * `<number of configured workers>` connections.
|
||||
For configuring the number of workers, refer to the section about
|
||||
[Deploying the Python frontend](../admin/Deployment-Python.md).
|
||||
|
||||
#### NOMINATIM_QUERY_TIMEOUT
|
||||
|
||||
| Summary | |
|
||||
| -------------- | --------------------------------------------------- |
|
||||
| **Description:** | Timeout for SQL queries to the database |
|
||||
| **Format:** | number (seconds) |
|
||||
| **Default:** | 10 |
|
||||
| **Comment:** | Python frontend only |
|
||||
|
||||
When this timeout is set, then all SQL queries that run longer than the
|
||||
specified numbers of seconds will be cancelled and the user receives a
|
||||
timeout exceptions. Users of the API see a 503 HTTP error.
|
||||
|
||||
The timeout does ont apply when using the
|
||||
[low-level DB access](../library/Low-Level-DB-Access.md)
|
||||
of the library. A timeout can be manually set, if required.
|
||||
|
||||
|
||||
#### NOMINATIM_REQUEST_TIMEOUT
|
||||
|
||||
| Summary | |
|
||||
| -------------- | --------------------------------------------------- |
|
||||
| **Description:** | Timeout for search queries |
|
||||
| **Format:** | number (seconds) |
|
||||
| **Default:** | 60 |
|
||||
| **Comment:** | Python frontend only |
|
||||
|
||||
When this timeout is set, a search query will finish sending queries
|
||||
to the database after the timeout has passed and immediately return the
|
||||
results gathered so far.
|
||||
|
||||
Note that under high load you may observe that users receive different results
|
||||
than usual without seeing an error. This may cause some confusion.
|
||||
|
||||
### Logging Settings
|
||||
|
||||
#### NOMINATIM_LOG_DB
|
||||
@@ -666,7 +641,25 @@ The entries in the log file have the following format:
|
||||
<request time> <execution time in s> <number of results> <type> "<query string>"
|
||||
|
||||
Request time is the time when the request was started. The execution time is
|
||||
given in seconds and corresponds to the time the query took executing in PHP.
|
||||
given in seconds and includes the entire time the query was queued and executed
|
||||
in the frontend.
|
||||
type contains the name of the endpoint used.
|
||||
|
||||
Can be used as the same time as NOMINATIM_LOG_DB.
|
||||
|
||||
#### NOMINATIM_DEBUG_SQL
|
||||
|
||||
| Summary | |
|
||||
| -------------- | --------------------------------------------------- |
|
||||
| **Description:** | Enable printing of raw SQL by SQLAlchemy |
|
||||
| **Format:** | boolean |
|
||||
| **Default:** | no |
|
||||
| **Comment:** | **For developers only.** |
|
||||
|
||||
This settings enables
|
||||
[SQL debugging](https://docs.sqlalchemy.org/en/20/core/engines.html#dbengine-logging)
|
||||
by SQLAlchemy. This can be helpful when debugging some bugs with internal
|
||||
query handling. It should only be used together with the CLI query functions.
|
||||
Enabling it for server mode may have unintended consequences. Use the `debug`
|
||||
parameter instead, which prints information on how the search is executed
|
||||
including SQL statements.
|
||||
|
||||
@@ -11,16 +11,31 @@ nominatim special-phrases --import-from-wiki
|
||||
|
||||
## Importing custom special phrases
|
||||
|
||||
But, it is also possible to import some phrases from a csv file.
|
||||
To do so, you have access to the following command:
|
||||
Special phrases may also be imported from any custom CSV file. The file needs
|
||||
to have a header line, use comma as delimiter and define the following
|
||||
columns:
|
||||
|
||||
* **phrase**: the keyword to look for
|
||||
* **class**: key of the main tag of the place to find
|
||||
(see [Import styles](Import-Styles.md#how-processing-works)
|
||||
* **type**: value of the main tag
|
||||
* **operator**: type of special phrase, may be one of:
|
||||
* *in*: place is within the place defined by the search term (e.g. "_Hotels in_ Berlin")
|
||||
* *near*: place is near the place defined by the search term (e.g. "_bus stops near_ Big Ben")
|
||||
* *named*: special phrase is a classifier (e.g. "_hotel_ California")
|
||||
* *-*: unspecified, can be any of the above
|
||||
|
||||
If the file contains any other columns, then they are silently ignored
|
||||
|
||||
To import the CSV file, use the following command:
|
||||
|
||||
```sh
|
||||
nominatim special-phrases --import-from-csv <csv file>
|
||||
```
|
||||
|
||||
Note that the two previous import commands will update the phrases from your database.
|
||||
This means that if you import some phrases from a csv file, only the phrases
|
||||
present in the csv file will be kept into the database. All other phrases will
|
||||
This means that if you import some phrases from a CSV file, only the phrases
|
||||
present in the CSV file will be kept in the database. All other phrases will
|
||||
be removed.
|
||||
|
||||
If you want to only add new phrases and not update the other ones you can add
|
||||
@@ -30,5 +45,5 @@ the argument `--no-replace` to the import command. For example:
|
||||
nominatim special-phrases --import-from-csv <csv file> --no-replace
|
||||
```
|
||||
|
||||
This will add the phrases present in the csv file into the database without
|
||||
This will add the phrases present in the CSV file into the database without
|
||||
removing the other ones.
|
||||
|
||||
@@ -4,59 +4,16 @@ The tokenizer module in Nominatim is responsible for analysing the names given
|
||||
to OSM objects and the terms of an incoming query in order to make sure, they
|
||||
can be matched appropriately.
|
||||
|
||||
Nominatim offers different tokenizer modules, which behave differently and have
|
||||
different configuration options. This sections describes the tokenizers and how
|
||||
they can be configured.
|
||||
Nominatim currently offers only one tokenizer module, the ICU tokenizer. This section
|
||||
describes the tokenizer and how it can be configured.
|
||||
|
||||
!!! important
|
||||
The use of a tokenizer is tied to a database installation. You need to choose
|
||||
The selection of tokenizer is tied to a database installation. You need to choose
|
||||
and configure the tokenizer before starting the initial import. Once the import
|
||||
is done, you cannot switch to another tokenizer anymore. Reconfiguring the
|
||||
chosen tokenizer is very limited as well. See the comments in each tokenizer
|
||||
section.
|
||||
|
||||
## Legacy tokenizer
|
||||
|
||||
The legacy tokenizer implements the analysis algorithms of older Nominatim
|
||||
versions. It uses a special Postgresql module to normalize names and queries.
|
||||
This tokenizer is automatically installed and used when upgrading an older
|
||||
database. It should not be used for new installations anymore.
|
||||
|
||||
### Compiling the PostgreSQL module
|
||||
|
||||
The tokeinzer needs a special C module for PostgreSQL which is not compiled
|
||||
by default. If you need the legacy tokenizer, compile Nominatim as follows:
|
||||
|
||||
```
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -DBUILD_MODULE=on
|
||||
make
|
||||
```
|
||||
|
||||
### Enabling the tokenizer
|
||||
|
||||
To enable the tokenizer add the following line to your project configuration:
|
||||
|
||||
```
|
||||
NOMINATIM_TOKENIZER=legacy
|
||||
```
|
||||
|
||||
The Postgresql module for the tokenizer is available in the `module` directory
|
||||
and also installed with the remainder of the software under
|
||||
`lib/nominatim/module/nominatim.so`. You can specify a custom location for
|
||||
the module with
|
||||
|
||||
```
|
||||
NOMINATIM_DATABASE_MODULE_PATH=<path to directory where nominatim.so resides>
|
||||
```
|
||||
|
||||
This is in particular useful when the database runs on a different server.
|
||||
See [Advanced installations](../admin/Advanced-Installations.md#importing-nominatim-to-an-external-postgresql-database) for details.
|
||||
|
||||
There are no other configuration options for the legacy tokenizer. All
|
||||
normalization functions are hard-coded.
|
||||
|
||||
## ICU tokenizer
|
||||
|
||||
The ICU tokenizer uses the [ICU library](http://site.icu-project.org/) to
|
||||
@@ -85,10 +42,19 @@ On import the tokenizer processes names in the following three stages:
|
||||
See the [Token analysis](#token-analysis) section below for more
|
||||
information.
|
||||
|
||||
During query time, only normalization and transliteration are relevant.
|
||||
An incoming query is first split into name chunks (this usually means splitting
|
||||
the string at the commas) and the each part is normalised and transliterated.
|
||||
The result is used to look up places in the search index.
|
||||
During query time, the tokeinzer is responsible for processing incoming
|
||||
queries. This happens in two stages:
|
||||
|
||||
1. During **query preprocessing** the incoming text is split into name
|
||||
chunks and normalised. This usually means applying the same normalisation
|
||||
as during the import process but may involve other processing like,
|
||||
for example, word break detection.
|
||||
2. The **token analysis** step breaks down the query parts into tokens,
|
||||
looks them up in the database and assigns them possible functions and
|
||||
probabilities.
|
||||
|
||||
Query processing can be further customized while the rest of the analysis
|
||||
is hard-coded.
|
||||
|
||||
### Configuration
|
||||
|
||||
@@ -100,9 +66,11 @@ have no effect.
|
||||
Here is an example configuration file:
|
||||
|
||||
``` yaml
|
||||
query-preprocessing:
|
||||
- normalize
|
||||
normalization:
|
||||
- ":: lower ()"
|
||||
- "ß > 'ss'" # German szet is unimbigiously equal to double ss
|
||||
- "ß > 'ss'" # German szet is unambiguously equal to double ss
|
||||
transliteration:
|
||||
- !include /etc/nominatim/icu-rules/extended-unicode-to-asccii.yaml
|
||||
- ":: Ascii ()"
|
||||
@@ -123,12 +91,28 @@ token-analysis:
|
||||
The configuration file contains four sections:
|
||||
`normalization`, `transliteration`, `sanitizers` and `token-analysis`.
|
||||
|
||||
#### Query preprocessing
|
||||
|
||||
The section for `query-preprocessing` defines an ordered list of functions
|
||||
that are applied to the query before the token analysis.
|
||||
|
||||
The following is a list of preprocessors that are shipped with Nominatim.
|
||||
|
||||
##### normalize
|
||||
|
||||
::: nominatim_api.query_preprocessing.normalize
|
||||
options:
|
||||
members: False
|
||||
heading_level: 6
|
||||
docstring_section_style: spacy
|
||||
|
||||
|
||||
#### Normalization and Transliteration
|
||||
|
||||
The normalization and transliteration sections each define a set of
|
||||
ICU rules that are applied to the names.
|
||||
|
||||
The **normalisation** rules are applied after sanitation. They should remove
|
||||
The **normalization** rules are applied after sanitation. They should remove
|
||||
any information that is not relevant for search at all. Usual rules to be
|
||||
applied here are: lower-casing, removing of special characters, cleanup of
|
||||
spaces.
|
||||
@@ -175,53 +159,67 @@ The following is a list of sanitizers that are shipped with Nominatim.
|
||||
|
||||
##### split-name-list
|
||||
|
||||
::: nominatim.tokenizer.sanitizers.split_name_list
|
||||
selection:
|
||||
::: nominatim_db.tokenizer.sanitizers.split_name_list
|
||||
options:
|
||||
members: False
|
||||
rendering:
|
||||
heading_level: 6
|
||||
docstring_section_style: spacy
|
||||
|
||||
##### strip-brace-terms
|
||||
|
||||
::: nominatim.tokenizer.sanitizers.strip_brace_terms
|
||||
selection:
|
||||
::: nominatim_db.tokenizer.sanitizers.strip_brace_terms
|
||||
options:
|
||||
members: False
|
||||
rendering:
|
||||
heading_level: 6
|
||||
docstring_section_style: spacy
|
||||
|
||||
##### tag-analyzer-by-language
|
||||
|
||||
::: nominatim.tokenizer.sanitizers.tag_analyzer_by_language
|
||||
selection:
|
||||
::: nominatim_db.tokenizer.sanitizers.tag_analyzer_by_language
|
||||
options:
|
||||
members: False
|
||||
rendering:
|
||||
heading_level: 6
|
||||
docstring_section_style: spacy
|
||||
|
||||
##### clean-housenumbers
|
||||
|
||||
::: nominatim.tokenizer.sanitizers.clean_housenumbers
|
||||
selection:
|
||||
::: nominatim_db.tokenizer.sanitizers.clean_housenumbers
|
||||
options:
|
||||
members: False
|
||||
rendering:
|
||||
heading_level: 6
|
||||
docstring_section_style: spacy
|
||||
|
||||
##### clean-postcodes
|
||||
|
||||
::: nominatim.tokenizer.sanitizers.clean_postcodes
|
||||
selection:
|
||||
::: nominatim_db.tokenizer.sanitizers.clean_postcodes
|
||||
options:
|
||||
members: False
|
||||
rendering:
|
||||
heading_level: 6
|
||||
docstring_section_style: spacy
|
||||
|
||||
##### clean-tiger-tags
|
||||
|
||||
::: nominatim.tokenizer.sanitizers.clean_tiger_tags
|
||||
selection:
|
||||
::: nominatim_db.tokenizer.sanitizers.clean_tiger_tags
|
||||
options:
|
||||
members: False
|
||||
rendering:
|
||||
heading_level: 6
|
||||
docstring_section_style: spacy
|
||||
|
||||
#### delete-tags
|
||||
|
||||
::: nominatim_db.tokenizer.sanitizers.delete_tags
|
||||
options:
|
||||
members: False
|
||||
heading_level: 6
|
||||
docstring_section_style: spacy
|
||||
|
||||
#### tag-japanese
|
||||
|
||||
::: nominatim_db.tokenizer.sanitizers.tag_japanese
|
||||
options:
|
||||
members: False
|
||||
heading_level: 6
|
||||
docstring_section_style: spacy
|
||||
|
||||
#### Token Analysis
|
||||
|
||||
@@ -380,7 +378,7 @@ The analyzer cannot be customized.
|
||||
##### Postcode token analyzer
|
||||
|
||||
The analyzer `postcodes` is pupose-made to analyze postcodes. It supports
|
||||
a 'lookup' varaint of the token, which produces variants with optional
|
||||
a 'lookup' variant of the token, which produces variants with optional
|
||||
spaces. Use together with the clean-postcodes sanitizer.
|
||||
|
||||
The analyzer cannot be customized.
|
||||
|
||||
@@ -4,19 +4,19 @@ This chapter gives an overview how to set up Nominatim for development
|
||||
and how to run tests.
|
||||
|
||||
!!! Important
|
||||
This guide assumes that you develop under the latest version of Ubuntu. You
|
||||
can of course also use your favourite distribution. You just might have to
|
||||
adapt the commands below slightly, in particular the commands for installing
|
||||
additional software.
|
||||
This guide assumes you develop under the latest version of Debian/Ubuntu.
|
||||
You can of course also use your favourite distribution. You just might have
|
||||
to adapt the commands below slightly, in particular the commands for
|
||||
installing additional software.
|
||||
|
||||
## Installing Nominatim
|
||||
|
||||
The first step is to install Nominatim itself. Please follow the installation
|
||||
instructions in the [Admin section](../admin/Installation.md). You don't need
|
||||
to set up a webserver for development, the webserver that is included with PHP
|
||||
is sufficient.
|
||||
to set up a webserver for development, the webserver that can be started
|
||||
via `nominatim serve` is sufficient.
|
||||
|
||||
If you want to run Nominatim in a VM via Vagrant, use the default `ubuntu` setup.
|
||||
If you want to run Nominatim in a VM via Vagrant, use the default `ubuntu24` setup.
|
||||
Vagrant's libvirt provider runs out-of-the-box under Ubuntu. You also need to
|
||||
install an NFS daemon to enable directory sharing between host and guest. The
|
||||
following packages should get you started:
|
||||
@@ -26,74 +26,99 @@ following packages should get you started:
|
||||
## Prerequisites for testing and documentation
|
||||
|
||||
The Nominatim test suite consists of behavioural tests (using behave) and
|
||||
unit tests (using PHPUnit for PHP code and pytest for Python code).
|
||||
It has the following additional requirements:
|
||||
unit tests (using pytest). It has the following additional requirements:
|
||||
|
||||
* [behave test framework](https://behave.readthedocs.io) >= 1.2.6
|
||||
* [phpunit](https://phpunit.de) (9.5 is known to work)
|
||||
* [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)
|
||||
* [Pylint](https://pylint.org/) (CI always runs the latest version from pip)
|
||||
* [flake8](https://flake8.pycqa.org/en/stable/) (CI always runs the latest version from pip)
|
||||
* [mypy](http://mypy-lang.org/) (plus typing information for external libs)
|
||||
* [Python Typing Extensions](https://github.com/python/typing_extensions) (for Python < 3.9)
|
||||
* [pytest](https://pytest.org)
|
||||
* [pytest-asyncio](https://pytest-asyncio.readthedocs.io)
|
||||
|
||||
For testing the Python search frontend, you need to install extra dependencies
|
||||
depending on your choice of webserver framework:
|
||||
|
||||
* [httpx](https://www.python-httpx.org/) (Starlette only)
|
||||
* [asgi-lifespan](https://github.com/florimondmanca/asgi-lifespan) (Starlette only)
|
||||
|
||||
The documentation is built with mkdocs:
|
||||
|
||||
* [mkdocs](https://www.mkdocs.org/) >= 1.1.2
|
||||
* [mkdocstrings](https://mkdocstrings.github.io/) >= 0.16
|
||||
* [mkdocstrings-python-legacy](https://mkdocstrings.github.io/python-legacy/)
|
||||
* [mkdocstrings](https://mkdocstrings.github.io/) >= 0.25
|
||||
* [mkdocs-material](https://squidfunk.github.io/mkdocs-material/)
|
||||
* [mkdocs-gen-files](https://oprypin.github.io/mkdocs-gen-files/)
|
||||
|
||||
Please be aware that tests always run against the globally installed
|
||||
osm2pgsql, so you need to have this set up. If you want to test against
|
||||
the vendored version of osm2pgsql, you need to set the PATH accordingly.
|
||||
|
||||
### Installing prerequisites on Ubuntu/Debian
|
||||
|
||||
Some of the Python packages require the newest version which is not yet
|
||||
available with the current distributions. Therefore it is recommended to
|
||||
install pip to get the newest versions.
|
||||
|
||||
To install all necessary packages run:
|
||||
The Python tools should always be run with the most recent version.
|
||||
The easiest way, to handle these Python dependencies is to run your
|
||||
development from within a virtual environment.
|
||||
|
||||
```sh
|
||||
sudo apt install php-cgi phpunit php-codesniffer \
|
||||
python3-pip python3-setuptools python3-dev
|
||||
|
||||
pip3 install --user behave mkdocs mkdocstrings pytest pylint \
|
||||
mypy types-PyYAML types-jinja2 types-psycopg2 types-psutil
|
||||
sudo apt install libsqlite3-mod-spatialite osm2pgsql \
|
||||
postgresql-postgis postgresql-postgis-scripts \
|
||||
pkg-config libicu-dev virtualenv
|
||||
```
|
||||
|
||||
The `mkdocs` executable will be located in `.local/bin`. You may have to add
|
||||
this directory to your path, for example by running:
|
||||
To set up the virtual environment with all necessary packages run:
|
||||
|
||||
```
|
||||
echo 'export PATH=~/.local/bin:$PATH' > ~/.profile
|
||||
```sh
|
||||
virtualenv ~/nominatim-dev-venv
|
||||
~/nominatim-dev-venv/bin/pip install\
|
||||
psutil psycopg[binary] PyICU SQLAlchemy \
|
||||
python-dotenv jinja2 pyYAML datrie behave \
|
||||
mkdocs mkdocstrings mkdocs-gen-files pytest pytest-asyncio flake8 \
|
||||
types-jinja2 types-markupsafe types-psutil types-psycopg2 \
|
||||
types-pygments types-pyyaml types-requests types-ujson \
|
||||
types-urllib3 typing-extensions unicorn falcon starlette \
|
||||
uvicorn mypy osmium aiosqlite
|
||||
```
|
||||
|
||||
If your distribution does not have PHPUnit 7.3+, you can install it (as well
|
||||
as CodeSniffer) via composer:
|
||||
Now enter the virtual environment whenever you want to develop:
|
||||
|
||||
```
|
||||
sudo apt-get install composer
|
||||
composer global require "squizlabs/php_codesniffer=*"
|
||||
composer global require "phpunit/phpunit=8.*"
|
||||
```sh
|
||||
. ~/nominatim-dev-venv/bin/activate
|
||||
```
|
||||
|
||||
The binaries are found in `.config/composer/vendor/bin`. You need to add this
|
||||
to your PATH as well:
|
||||
### Running Nominatim during development
|
||||
|
||||
The source code for Nominatim can be found in the `src` directory and can
|
||||
be run in-place. The source directory features a special script
|
||||
`nominatim-cli.py` which does the same as the installed 'nominatim' binary
|
||||
but executes against the code in the source tree. For example:
|
||||
|
||||
```
|
||||
echo 'export PATH=~/.config/composer/vendor/bin:$PATH' > ~/.profile
|
||||
me@machine:~$ cd Nominatim
|
||||
me@machine:~Nominatim$ ./nominatim-cli.py --version
|
||||
Nominatim version 4.4.99-1
|
||||
```
|
||||
|
||||
Make sure you have activated the virtual environment holding all
|
||||
necessary dependencies.
|
||||
|
||||
## Executing Tests
|
||||
|
||||
All tests are located in the `/test` directory.
|
||||
|
||||
To run all tests just go to the build directory and run make:
|
||||
To run all tests, run make from the source root:
|
||||
|
||||
```sh
|
||||
cd build
|
||||
make test
|
||||
make tests
|
||||
```
|
||||
|
||||
There are also make targets for executing only parts of the test suite.
|
||||
For example to run linting only use:
|
||||
|
||||
```sh
|
||||
make lint
|
||||
```
|
||||
|
||||
The possible testing targets are: mypy, lint, pytest, bdd.
|
||||
|
||||
For more information about the structure of the tests and how to change and
|
||||
extend the test suite, see the [Testing chapter](Testing.md).
|
||||
|
||||
@@ -104,18 +129,14 @@ built using the [MkDocs](https://www.mkdocs.org/) static site generation
|
||||
framework. The master branch is automatically deployed every night on
|
||||
[https://nominatim.org/release-docs/develop/](https://nominatim.org/release-docs/develop/)
|
||||
|
||||
To build the documentation, go to the build directory and run
|
||||
To build the documentation run
|
||||
|
||||
```
|
||||
make doc
|
||||
INFO - Cleaning site directory
|
||||
INFO - Building documentation to directory: /home/vagrant/build/site-html
|
||||
```
|
||||
|
||||
This runs `mkdocs build` plus extra transformation of some files and adds
|
||||
symlinks (see `CMakeLists.txt` for the exact steps).
|
||||
|
||||
Now you can start webserver for local testing
|
||||
For local testing, you can start webserver:
|
||||
|
||||
```
|
||||
build> make serve-doc
|
||||
@@ -127,7 +148,7 @@ If you develop inside a Vagrant virtual machine, use a port that is forwarded
|
||||
to your host:
|
||||
|
||||
```
|
||||
build> PYTHONPATH=$SRCDIR mkdocs serve --dev-addr 0.0.0.0:8088
|
||||
build> mkdocs serve --dev-addr 0.0.0.0:8088
|
||||
[server:296] Serving on http://0.0.0.0:8088
|
||||
[handlers:62] Start watching changes
|
||||
```
|
||||
|
||||
@@ -14,10 +14,11 @@ of sanitizers and token analysis.
|
||||
implemented, it is not guaranteed to be stable at the moment.
|
||||
|
||||
|
||||
## Using non-standard sanitizers and token analyzers
|
||||
## Using non-standard modules
|
||||
|
||||
Sanitizer names (in the `step` property) and token analysis names (in the
|
||||
`analyzer`) may refer to externally supplied modules. There are two ways
|
||||
Sanitizer names (in the `step` property), token analysis names (in the
|
||||
`analyzer`) and query preprocessor names (in the `step` property)
|
||||
may refer to externally supplied modules. There are two ways
|
||||
to include external modules: through a library or from the project directory.
|
||||
|
||||
To include a module from a library, use the absolute import path as name and
|
||||
@@ -27,6 +28,47 @@ To use a custom module without creating a library, you can put the module
|
||||
somewhere in your project directory and then use the relative path to the
|
||||
file. Include the whole name of the file including the `.py` ending.
|
||||
|
||||
## Custom query preprocessors
|
||||
|
||||
A query preprocessor must export a single factory function `create` with
|
||||
the following signature:
|
||||
|
||||
``` python
|
||||
create(self, config: QueryConfig) -> Callable[[list[Phrase]], list[Phrase]]
|
||||
```
|
||||
|
||||
The function receives the custom configuration for the preprocessor and
|
||||
returns a callable (function or class) with the actual preprocessing
|
||||
code. When a query comes in, then the callable gets a list of phrases
|
||||
and needs to return the transformed list of phrases. The list and phrases
|
||||
may be changed in place or a completely new list may be generated.
|
||||
|
||||
The `QueryConfig` is a simple dictionary which contains all configuration
|
||||
options given in the yaml configuration of the ICU tokenizer. It is up to
|
||||
the function to interpret the values.
|
||||
|
||||
A `nominatim_api.search.Phrase` describes a part of the query that contains one or more independent
|
||||
search terms. Breaking a query into phrases helps reducing the number of
|
||||
possible tokens Nominatim has to take into account. However a phrase break
|
||||
is definitive: a multi-term search word cannot go over a phrase break.
|
||||
A Phrase object has two fields:
|
||||
|
||||
* `ptype` further refines the type of phrase (see list below)
|
||||
* `text` contains the query text for the phrase
|
||||
|
||||
The order of phrases matters to Nominatim when doing further processing.
|
||||
Thus, while you may split or join phrases, you should not reorder them
|
||||
unless you really know what you are doing.
|
||||
|
||||
Phrase types (`nominatim_api.search.PhraseType`) can further help narrowing
|
||||
down how the tokens in the phrase are interpreted. The following phrase types
|
||||
are known:
|
||||
|
||||
::: nominatim_api.search.PhraseType
|
||||
options:
|
||||
heading_level: 6
|
||||
|
||||
|
||||
## Custom sanitizer modules
|
||||
|
||||
A sanitizer module must export a single factory function `create` with the
|
||||
@@ -52,9 +94,8 @@ the function.
|
||||
|
||||
### Sanitizer configuration
|
||||
|
||||
::: nominatim.tokenizer.sanitizers.config.SanitizerConfig
|
||||
rendering:
|
||||
show_source: no
|
||||
::: nominatim_db.tokenizer.sanitizers.config.SanitizerConfig
|
||||
options:
|
||||
heading_level: 6
|
||||
|
||||
### The main filter function of the sanitizer
|
||||
@@ -62,12 +103,10 @@ the function.
|
||||
The filter function receives a single object of type `ProcessInfo`
|
||||
which has with three members:
|
||||
|
||||
* `place`: read-only information about the place being processed.
|
||||
* `place: PlaceInfo`: read-only information about the place being processed.
|
||||
See PlaceInfo below.
|
||||
* `names`: The current list of names for the place. Each name is a
|
||||
PlaceName object.
|
||||
* `address`: The current list of address names for the place. Each name
|
||||
is a PlaceName object.
|
||||
* `names: List[PlaceName]`: The current list of names for the place.
|
||||
* `address: List[PlaceName]`: The current list of address names for the place.
|
||||
|
||||
While the `place` member is provided for information only, the `names` and
|
||||
`address` lists are meant to be manipulated by the sanitizer. It may add and
|
||||
@@ -76,17 +115,15 @@ adding extra attributes) or completely replace the list with a different one.
|
||||
|
||||
#### PlaceInfo - information about the place
|
||||
|
||||
::: nominatim.data.place_info.PlaceInfo
|
||||
rendering:
|
||||
show_source: no
|
||||
::: nominatim_db.data.place_info.PlaceInfo
|
||||
options:
|
||||
heading_level: 6
|
||||
|
||||
|
||||
#### PlaceName - extended naming information
|
||||
|
||||
::: nominatim.data.place_name.PlaceName
|
||||
rendering:
|
||||
show_source: no
|
||||
::: nominatim_db.data.place_name.PlaceName
|
||||
options:
|
||||
heading_level: 6
|
||||
|
||||
|
||||
@@ -95,21 +132,22 @@ adding extra attributes) or completely replace the list with a different one.
|
||||
The following sanitizer removes the directional prefixes from street names
|
||||
in the US:
|
||||
|
||||
``` python
|
||||
import re
|
||||
!!! example
|
||||
``` python
|
||||
import re
|
||||
|
||||
def _filter_function(obj):
|
||||
if obj.place.country_code == 'us' \
|
||||
and obj.place.rank_address >= 26 and obj.place.rank_address <= 27:
|
||||
for name in obj.names:
|
||||
name.name = re.sub(r'^(north|south|west|east) ',
|
||||
'',
|
||||
name.name,
|
||||
flags=re.IGNORECASE)
|
||||
def _filter_function(obj):
|
||||
if obj.place.country_code == 'us' \
|
||||
and obj.place.rank_address >= 26 and obj.place.rank_address <= 27:
|
||||
for name in obj.names:
|
||||
name.name = re.sub(r'^(north|south|west|east) ',
|
||||
'',
|
||||
name.name,
|
||||
flags=re.IGNORECASE)
|
||||
|
||||
def create(config):
|
||||
return _filter_function
|
||||
```
|
||||
def create(config):
|
||||
return _filter_function
|
||||
```
|
||||
|
||||
This is the most simple form of a sanitizer module. If defines a single
|
||||
filter function and implements the required `create()` function by returning
|
||||
@@ -133,26 +171,24 @@ sanitizers:
|
||||
|
||||
!!! warning
|
||||
This example is just a simplified show case on how to create a sanitizer.
|
||||
It is not really read for real-world use: while the sanitizer would
|
||||
correcly transform `West 5th Street` into `5th Street`. it would also
|
||||
It is not really meant for real-world use: while the sanitizer would
|
||||
correctly transform `West 5th Street` into `5th Street`. it would also
|
||||
shorten a simple `North Street` to `Street`.
|
||||
|
||||
For more sanitizer examples, have a look at the sanitizers provided by Nominatim.
|
||||
They can be found in the directory
|
||||
[`nominatim/tokenizer/sanitizers`](https://github.com/osm-search/Nominatim/tree/master/nominatim/tokenizer/sanitizers).
|
||||
[`src/nominatim_db/tokenizer/sanitizers`](https://github.com/osm-search/Nominatim/tree/master/src/nominatim_db/tokenizer/sanitizers).
|
||||
|
||||
|
||||
## Custom token analysis module
|
||||
|
||||
::: nominatim.tokenizer.token_analysis.base.AnalysisModule
|
||||
rendering:
|
||||
show_source: no
|
||||
::: nominatim_db.tokenizer.token_analysis.base.AnalysisModule
|
||||
options:
|
||||
heading_level: 6
|
||||
|
||||
|
||||
::: nominatim.tokenizer.token_analysis.base.Analyzer
|
||||
rendering:
|
||||
show_source: no
|
||||
::: nominatim_db.tokenizer.token_analysis.base.Analyzer
|
||||
options:
|
||||
heading_level: 6
|
||||
|
||||
### Example: Creating acronym variants for long names
|
||||
|
||||
@@ -8,9 +8,9 @@ the tests, see the [Development setup chapter](Development-Environment.md).
|
||||
|
||||
There are two kind of tests in this test suite. There are functional tests
|
||||
which test the API interface using a BDD test framework and there are unit
|
||||
tests for specific PHP functions.
|
||||
tests for the Python code.
|
||||
|
||||
This test directory is sturctured as follows:
|
||||
This test directory is structured as follows:
|
||||
|
||||
```
|
||||
-+- bdd Functional API tests
|
||||
@@ -20,28 +20,11 @@ This test directory is sturctured as follows:
|
||||
| +- db Tests for internal data processing on import and update
|
||||
| +- api Tests for API endpoints (search, reverse, etc.)
|
||||
|
|
||||
+- php PHP unit tests
|
||||
+- python Python unit tests
|
||||
+- testdb Base data for generating API test database
|
||||
+- testdata Additional test data used by unit tests
|
||||
```
|
||||
|
||||
## PHP Unit Tests (`test/php`)
|
||||
|
||||
Unit tests for PHP code can be found in the `php/` directory. They test selected
|
||||
PHP functions. Very low coverage.
|
||||
|
||||
To execute the test suite run
|
||||
|
||||
cd test/php
|
||||
UNIT_TEST_DSN='pgsql:dbname=nominatim_unit_tests' phpunit ../
|
||||
|
||||
It will read phpunit.xml which points to the library, test path, bootstrap
|
||||
strip and sets other parameters.
|
||||
|
||||
It will use (and destroy) a local database 'nominatim_unit_tests'. You can set
|
||||
a different connection string with e.g. UNIT_TEST_DSN='pgsql:dbname=foo_unit_tests'.
|
||||
|
||||
## Python Unit Tests (`test/python`)
|
||||
|
||||
Unit tests for Python code can be found in the `python/` directory. The goal is
|
||||
@@ -78,18 +61,17 @@ To run the functional tests, do
|
||||
|
||||
The tests can be configured with a set of environment variables (`behave -D key=val`):
|
||||
|
||||
* `BUILDDIR` - build directory of Nominatim installation to test
|
||||
* `TEMPLATE_DB` - name of template database used as a skeleton for
|
||||
the test databases (db tests)
|
||||
* `TEST_DB` - name of test database (db tests)
|
||||
* `API_TEST_DB` - name of the database containing the API test data (api tests)
|
||||
* `API_TEST_FILE` - OSM file to be imported into the API test database (api tests)
|
||||
* `API_ENGINE` - webframe to use for running search queries, same values as
|
||||
`nominatim serve --engine` parameter
|
||||
* `DB_HOST` - (optional) hostname of database host
|
||||
* `DB_PORT` - (optional) port of database on host
|
||||
* `DB_USER` - (optional) username of database login
|
||||
* `DB_PASS` - (optional) password for database login
|
||||
* `SERVER_MODULE_PATH` - (optional) path on the Postgres server to Nominatim
|
||||
module shared library file
|
||||
* `REMOVE_TEMPLATE` - if true, the template and API database will not be reused
|
||||
during the next run. Reusing the base templates speeds
|
||||
up tests considerably but might lead to outdated errors
|
||||
@@ -117,26 +99,9 @@ and compromises the following data:
|
||||
* extract of Autauga country, Alabama, US (for tests against Tiger data)
|
||||
* additional data from `test/testdb/additional_api_test.data.osm`
|
||||
|
||||
API tests should only be testing the functionality of the website PHP code.
|
||||
API tests should only be testing the functionality of the website frontend code.
|
||||
Most tests should be formulated as BDD DB creation tests (see below) instead.
|
||||
|
||||
#### Code Coverage
|
||||
|
||||
The API tests also support code coverage tests. You need to install
|
||||
[PHP_CodeCoverage](https://github.com/sebastianbergmann/php-code-coverage).
|
||||
On Debian/Ubuntu run:
|
||||
|
||||
apt-get install php-codecoverage php-xdebug
|
||||
|
||||
Then run the API tests as follows:
|
||||
|
||||
behave api -DPHPCOV=<coverage output dir>
|
||||
|
||||
The output directory must be an absolute path. To generate reports, you can use
|
||||
the [phpcov](https://github.com/sebastianbergmann/phpcov) tool:
|
||||
|
||||
phpcov merge --html=<report output dir> <coverage output dir>
|
||||
|
||||
### DB Creation Tests (`test/bdd/db`)
|
||||
|
||||
These tests check the import and update of the Nominatim database. They do not
|
||||
@@ -153,7 +118,3 @@ needs superuser rights for postgres.
|
||||
|
||||
These tests check that data is imported correctly into the place table. They
|
||||
use the same template database as the DB Creation tests, so the same remarks apply.
|
||||
|
||||
Note that most testing of the gazetteer output of osm2pgsql is done in the tests
|
||||
of osm2pgsql itself. The BDD tests are just there to ensure compatibility of
|
||||
the osm2pgsql and Nominatim code.
|
||||
|
||||
@@ -91,19 +91,19 @@ for a custom tokenizer implementation.
|
||||
|
||||
### Directory Structure
|
||||
|
||||
Nominatim expects two files for a tokenizer:
|
||||
Nominatim expects two files containing the Python part of the implementation:
|
||||
|
||||
* `nominatim/tokenizer/<NAME>_tokenizer.py` containing the Python part of the
|
||||
implementation
|
||||
* `lib-php/tokenizer/<NAME>_tokenizer.php` with the PHP part of the
|
||||
implementation
|
||||
* `src/nominatim_db/tokenizer/<NAME>_tokenizer.py` contains the tokenizer
|
||||
code used during import and
|
||||
* `src/nominatim_api/search/<NAME>_tokenizer.py` has the code used during
|
||||
query time.
|
||||
|
||||
where `<NAME>` is a unique name for the tokenizer consisting of only lower-case
|
||||
`<NAME>` is a unique name for the tokenizer consisting of only lower-case
|
||||
letters, digits and underscore. A tokenizer also needs to install some SQL
|
||||
functions. By convention, these should be placed in `lib-sql/tokenizer`.
|
||||
|
||||
If the tokenizer has a default configuration file, this should be saved in
|
||||
the `settings/<NAME>_tokenizer.<SUFFIX>`.
|
||||
`settings/<NAME>_tokenizer.<SUFFIX>`.
|
||||
|
||||
### Configuration and Persistence
|
||||
|
||||
@@ -115,9 +115,11 @@ are tied to a database installation and must only be read during installation
|
||||
time. If they are needed for the runtime then they must be saved into the
|
||||
`nominatim_properties` table and later loaded from there.
|
||||
|
||||
### The Python module
|
||||
### The Python modules
|
||||
|
||||
The Python module is expect to export a single factory function:
|
||||
#### `src/nominatim_db/tokenizer/`
|
||||
|
||||
The import Python module is expected to export a single factory function:
|
||||
|
||||
```python
|
||||
def create(dsn: str, data_dir: Path) -> AbstractTokenizer
|
||||
@@ -128,20 +130,41 @@ is a directory in the project directory that the tokenizer may use to save
|
||||
database-specific data. The function must return the instance of the tokenizer
|
||||
class as defined below.
|
||||
|
||||
#### `src/nominatim_api/search/`
|
||||
|
||||
The query-time Python module must also export a factory function:
|
||||
|
||||
``` python
|
||||
def create_query_analyzer(conn: SearchConnection) -> AbstractQueryAnalyzer
|
||||
```
|
||||
|
||||
The `conn` parameter contains the current search connection. See the
|
||||
[library documentation](../library/Low-Level-DB-Access.md#searchconnection-class)
|
||||
for details on the class. The function must return the instance of the tokenizer
|
||||
class as defined below.
|
||||
|
||||
|
||||
### Python Tokenizer Class
|
||||
|
||||
All tokenizers must inherit from `nominatim.tokenizer.base.AbstractTokenizer`
|
||||
All tokenizers must inherit from `nominatim_db.tokenizer.base.AbstractTokenizer`
|
||||
and implement the abstract functions defined there.
|
||||
|
||||
::: nominatim.tokenizer.base.AbstractTokenizer
|
||||
rendering:
|
||||
heading_level: 4
|
||||
::: nominatim_db.tokenizer.base.AbstractTokenizer
|
||||
options:
|
||||
heading_level: 6
|
||||
|
||||
### Python Analyzer Class
|
||||
|
||||
::: nominatim.tokenizer.base.AbstractAnalyzer
|
||||
rendering:
|
||||
heading_level: 4
|
||||
::: nominatim_db.tokenizer.base.AbstractAnalyzer
|
||||
options:
|
||||
heading_level: 6
|
||||
|
||||
|
||||
### Python Query Analyzer Class
|
||||
|
||||
::: nominatim_api.search.query_analyzer_factory.AbstractQueryAnalyzer
|
||||
options:
|
||||
heading_level: 6
|
||||
|
||||
### PL/pgSQL Functions
|
||||
|
||||
@@ -189,6 +212,28 @@ a house number token text. If a place has multiple house numbers they must
|
||||
be listed with a semicolon as delimiter. Must be NULL when the place has no
|
||||
house numbers.
|
||||
|
||||
```sql
|
||||
FUNCTION token_is_street_address(info JSONB) RETURNS BOOLEAN
|
||||
```
|
||||
|
||||
Return true if this is an object that should be parented against a street.
|
||||
Only relevant for objects with address rank 30.
|
||||
|
||||
```sql
|
||||
FUNCTION token_has_addr_street(info JSONB) RETURNS BOOLEAN
|
||||
```
|
||||
|
||||
Return true if there are street names to match against for finding the
|
||||
parent of the object.
|
||||
|
||||
|
||||
```sql
|
||||
FUNCTION token_has_addr_place(info JSONB) RETURNS BOOLEAN
|
||||
```
|
||||
|
||||
Return true if there are place names to match against for finding the
|
||||
parent of the object.
|
||||
|
||||
```sql
|
||||
FUNCTION token_matches_street(info JSONB, street_tokens INTEGER[]) RETURNS BOOLEAN
|
||||
```
|
||||
@@ -260,73 +305,3 @@ permanently. The indexer calls this function when all processing is done and
|
||||
replaces the content of the `token_info` column with the returned value before
|
||||
the trigger stores the information in the database. May return NULL if no
|
||||
information should be stored permanently.
|
||||
|
||||
### PHP Tokenizer class
|
||||
|
||||
The PHP tokenizer class is instantiated once per request and responsible for
|
||||
analyzing the incoming query. Multiple requests may be in flight in
|
||||
parallel.
|
||||
|
||||
The class is expected to be found under the
|
||||
name of `\Nominatim\Tokenizer`. To find the class the PHP code includes the file
|
||||
`tokenizer/tokenizer.php` in the project directory. This file must be created
|
||||
when the tokenizer is first set up on import. The file should initialize any
|
||||
configuration variables by setting PHP constants and then require the file
|
||||
with the actual implementation of the tokenizer.
|
||||
|
||||
The tokenizer class must implement the following functions:
|
||||
|
||||
```php
|
||||
public function __construct(object &$oDB)
|
||||
```
|
||||
|
||||
The constructor of the class receives a database connection that can be used
|
||||
to query persistent data in the database.
|
||||
|
||||
```php
|
||||
public function checkStatus()
|
||||
```
|
||||
|
||||
Check that the tokenizer can access its persistent data structures. If there
|
||||
is an issue, throw an `\Exception`.
|
||||
|
||||
```php
|
||||
public function normalizeString(string $sTerm) : string
|
||||
```
|
||||
|
||||
Normalize string to a form to be used for comparisons when reordering results.
|
||||
Nominatim reweighs results how well the final display string matches the actual
|
||||
query. Before comparing result and query, names and query are normalised against
|
||||
this function. The tokenizer can thus remove all properties that should not be
|
||||
taken into account for reweighing, e.g. special characters or case.
|
||||
|
||||
```php
|
||||
public function tokensForSpecialTerm(string $sTerm) : array
|
||||
```
|
||||
|
||||
Return the list of special term tokens that match the given term.
|
||||
|
||||
```php
|
||||
public function extractTokensFromPhrases(array &$aPhrases) : TokenList
|
||||
```
|
||||
|
||||
Parse the given phrases, splitting them into word lists and retrieve the
|
||||
matching tokens.
|
||||
|
||||
The phrase array may take on two forms. In unstructured searches (using `q=`
|
||||
parameter) the search query is split at the commas and the elements are
|
||||
put into a sorted list. For structured searches the phrase array is an
|
||||
associative array where the key designates the type of the term (street, city,
|
||||
county etc.) The tokenizer may ignore the phrase type at this stage in parsing.
|
||||
Matching phrase type and appropriate search token type will be done later
|
||||
when the SearchDescription is built.
|
||||
|
||||
For each phrase in the list of phrases, the function must analyse the phrase
|
||||
string and then call `setWordSets()` to communicate the result of the analysis.
|
||||
A word set is a list of strings, where each string refers to a search token.
|
||||
A phrase may have multiple interpretations. Therefore a list of word sets is
|
||||
usually attached to the phrase. The search tokens themselves are returned
|
||||
by the function in an associative array, where the key corresponds to the
|
||||
strings given in the word sets. The value is a list of search tokens. Thus
|
||||
a single string in the list of word sets may refer to multiple search tokens.
|
||||
|
||||
|
||||
@@ -20,5 +20,5 @@ and can be found in the files in the `sql/functions/` directory.
|
||||
|
||||
The __search frontend__ implements the actual API. It takes search
|
||||
and reverse geocoding queries from the user, looks up the data and
|
||||
returns the results in the requested format. This part is written in PHP
|
||||
and can be found in the `lib/` and `website/` directories.
|
||||
returns the results in the requested format. This part is located in the
|
||||
`nominatim-api` package. The source code can be found in `src/nominatim_api`.
|
||||
|
||||
@@ -18,7 +18,7 @@ elseif (has 'addr:place'?) then (yes)
|
||||
**with same name**;
|
||||
kill
|
||||
else (no)
|
||||
:add addr:place to adress;
|
||||
:add addr:place to address;
|
||||
:**Use closest place**\n**rank 16 to 25**;
|
||||
kill
|
||||
endif
|
||||
|
||||
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 9.8 KiB After Width: | Height: | Size: 9.8 KiB |
@@ -2,6 +2,10 @@
|
||||
display: none!important
|
||||
}
|
||||
|
||||
.md-content {
|
||||
max-width: 800px
|
||||
}
|
||||
|
||||
table {
|
||||
margin-bottom: 12pt
|
||||
}
|
||||
@@ -16,9 +20,22 @@ th {
|
||||
|
||||
.doc-object h6 {
|
||||
margin-bottom: 0.8em;
|
||||
font-size: 120%;
|
||||
font-size: 130%;
|
||||
}
|
||||
|
||||
.doc-object {
|
||||
margin-bottom: 1.3em;
|
||||
}
|
||||
|
||||
.doc-children .doc-contents {
|
||||
margin-left: 3em;
|
||||
}
|
||||
|
||||
.md-footer__inner {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.headerlink {
|
||||
filter: grayscale(100%);
|
||||
font-size: 80%;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
Nominatim (from the Latin, 'by name') is a tool to search OSM data by name and address and to generate synthetic addresses of OSM points (reverse geocoding).
|
||||
Nominatim (from the Latin, 'by name') is a tool to search OSM data by name and
|
||||
address and to generate synthetic addresses of OSM points (reverse geocoding).
|
||||
It has also limited capability to search features by their type
|
||||
(pubs, hotels, churches, etc).
|
||||
|
||||
This guide comes in four parts:
|
||||
This guide comes in five parts:
|
||||
|
||||
* __[API reference](api/Overview.md)__ for users of Nominatim
|
||||
* __[Administration Guide](admin/Installation.md)__ for those who want
|
||||
to install their own Nominatim server
|
||||
* __[Customization Guide](customize/Overview.md)__ for those who want to
|
||||
adapt their own installation to their special requirements
|
||||
* __[Library Guide](library/Getting-Started.md)__ for Python developers who
|
||||
want to use Nominatim as a library in their project
|
||||
* __[Developer's Guide](develop/overview.md)__ for developers of the software
|
||||
|
||||
33
docs/library/Configuration.md
Normal file
33
docs/library/Configuration.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# Configuration
|
||||
|
||||
When using Nominatim through the library, it can be configured in exactly
|
||||
the same way as when running as a service. You may instantiate the library
|
||||
against the [project directory](../admin/Import.md#creating-the-project-directory)
|
||||
of your Nominatim installation. It contains all files belonging to the
|
||||
Nominatim instance. This may include an `.env` file with configuration options.
|
||||
Setting configuration parameters via environment variables works as well.
|
||||
Alternatively to using the operating system's environment, a set of
|
||||
configuration parameters may also be passed to the Nomiantim API object.
|
||||
|
||||
Configuration options are resolved in the following order:
|
||||
|
||||
* from the OS environment (or the dictionary given in `environ`,
|
||||
(see NominatimAPI.md#nominatim.api.core.NominatimAPI.__init__)
|
||||
* from the .env file in the project directory of the installation
|
||||
* from the default installation in the configuration directory
|
||||
|
||||
For more information on configuration via dotenv and a list of possible
|
||||
configuration parameters, see the [Configuration page](../customize/Settings.md).
|
||||
|
||||
|
||||
## `Configuration` class
|
||||
|
||||
::: nominatim_api.Configuration
|
||||
options:
|
||||
members:
|
||||
- get_bool
|
||||
- get_int
|
||||
- get_str_list
|
||||
- get_path
|
||||
heading_level: 6
|
||||
show_signature_annotations: True
|
||||
289
docs/library/Getting-Started.md
Normal file
289
docs/library/Getting-Started.md
Normal file
@@ -0,0 +1,289 @@
|
||||
# Getting Started
|
||||
|
||||
The Nominatim search frontend is implemented as a Python library and can as
|
||||
such directly be used in Python scripts and applications. You don't need to
|
||||
set up a web frontend and access it through HTTP calls. The library gives
|
||||
direct access to the Nominatim database through similar search functions as
|
||||
offered by the web API. In addition, it will give you a more complete and
|
||||
detailed view on the search objects stored in the database.
|
||||
|
||||
!!! warning
|
||||
|
||||
The Nominatim library is used for accessing a local Nominatim database.
|
||||
It is not meant to be used against web services of Nominatim like the
|
||||
one on https://nominatim.openstreetmap.org. If you need a Python library
|
||||
to access these web services, have a look at
|
||||
[GeoPy](https://geopy.readthedocs.io). Don't forget to consult the
|
||||
usage policy of the service you want to use before accessing such
|
||||
a web service.
|
||||
|
||||
## Installation
|
||||
|
||||
To use the Nominatim library, you need access to a local Nominatim database.
|
||||
Follow the [installation](../admin/Installation.md) and
|
||||
[import](../admin/Import.md) instructions to set up your database.
|
||||
|
||||
The Nominatim frontend library is contained in the Python package `nominatim-api`.
|
||||
You can install the latest released version directly from pip:
|
||||
|
||||
pip install nominatim-api
|
||||
|
||||
To install the package from the source tree directly, run:
|
||||
|
||||
pip install packaging/nominatim-api
|
||||
|
||||
Usually you would want to run this in a virtual environment.
|
||||
|
||||
## A simple search example
|
||||
|
||||
To query the Nominatim database you need to first set up a connection. This
|
||||
is done by creating an Nominatim API object. This object exposes all the
|
||||
search functions of Nominatim that are also known from its web API.
|
||||
|
||||
This code snippet implements a simple search for the town of 'Brugge':
|
||||
|
||||
!!! example
|
||||
=== "NominatimAPIAsync"
|
||||
``` python
|
||||
import asyncio
|
||||
|
||||
import nominatim_api as napi
|
||||
|
||||
async def search(query):
|
||||
async with napi.NominatimAPIAsync() as api:
|
||||
return await api.search(query)
|
||||
|
||||
results = asyncio.run(search('Brugge'))
|
||||
if not results:
|
||||
print('Cannot find Brugge')
|
||||
else:
|
||||
print(f'Found a place at {results[0].centroid.x},{results[0].centroid.y}')
|
||||
```
|
||||
|
||||
=== "NominatimAPI"
|
||||
``` python
|
||||
import nominatim_api as napi
|
||||
|
||||
with napi.NominatimAPI() as api:
|
||||
results = api.search('Brugge')
|
||||
|
||||
if not results:
|
||||
print('Cannot find Brugge')
|
||||
else:
|
||||
print(f'Found a place at {results[0].centroid.x},{results[0].centroid.y}')
|
||||
```
|
||||
|
||||
The Nominatim library is designed around
|
||||
[asyncio](https://docs.python.org/3/library/asyncio.html). `NominatimAPIAsync`
|
||||
provides you with an interface of coroutines.
|
||||
If you have many requests to make, coroutines can speed up your applications
|
||||
significantly.
|
||||
|
||||
For smaller scripts there is also a synchronous wrapper around the API. By
|
||||
using `NominatimAPI`, you get exactly the same interface using classic functions.
|
||||
|
||||
The examples in this chapter will always show-case both
|
||||
implementations. The documentation itself will usually refer only to
|
||||
'Nominatim API class' when both flavours are meant. If a functionality is
|
||||
available only for the synchronous or asynchronous version, this will be
|
||||
explicitly mentioned.
|
||||
|
||||
## Defining which database to use
|
||||
|
||||
The [Configuration](../admin/Import.md#configuration-setup-in-env)
|
||||
section explains how Nominatim is configured using the
|
||||
[dotenv](https://github.com/theskumar/python-dotenv) library.
|
||||
The same configuration mechanism is used with the
|
||||
Nominatim API library. You should therefore be sure you are familiar with
|
||||
the section.
|
||||
|
||||
There are three different ways, how configuration options can be set for
|
||||
a 'Nominatim API class'. When you have set up your Nominatim database, you
|
||||
have normally created a [project directory](../admin/Import.md#creating-the-project-directory)
|
||||
which stores the various configuration and customization files that Nominatim
|
||||
needs. You may pass the location of the project directory to your
|
||||
'Nominatim API class' constructor and it will read the .env file in the
|
||||
directory and set the configuration accordingly. Here is the simple search
|
||||
example, using the configuration from a pre-defined project directory in
|
||||
`/srv/nominatim-project`:
|
||||
|
||||
!!! example
|
||||
=== "NominatimAPIAsync"
|
||||
``` python
|
||||
import asyncio
|
||||
|
||||
import nominatim_api as napi
|
||||
|
||||
async def search(query):
|
||||
async with napi.NominatimAPIAsync('/srv/nominatim-project') as api:
|
||||
return await api.search(query)
|
||||
|
||||
results = asyncio.run(search('Brugge'))
|
||||
if not results:
|
||||
print('Cannot find Brugge')
|
||||
else:
|
||||
print(f'Found a place at {results[0].centroid.x},{results[0].centroid.y}')
|
||||
```
|
||||
|
||||
=== "NominatimAPI"
|
||||
``` python
|
||||
import nominatim_api as napi
|
||||
|
||||
with napi.NominatimAPI('/srv/nominatim-project') as api:
|
||||
results = api.search('Brugge')
|
||||
|
||||
if not results:
|
||||
print('Cannot find Brugge')
|
||||
else:
|
||||
print(f'Found a place at {results[0].centroid.x},{results[0].centroid.y}')
|
||||
```
|
||||
|
||||
|
||||
You may also configure Nominatim by setting environment variables.
|
||||
Normally Nominatim will check the operating system environment. Lets
|
||||
say you want to look up 'Brugge' in the special database named 'belgium' instead of the
|
||||
standard 'nominatim' database. You can run the example script above like this:
|
||||
|
||||
```
|
||||
NOMINATIM_DATABASE_DSN=pgsql:dbname=belgium python3 example.py
|
||||
```
|
||||
|
||||
The third option to configure the library is to hand in the configuration
|
||||
parameters into the 'Nominatim API class'. Changing the database would look
|
||||
like this:
|
||||
|
||||
!!! example
|
||||
=== "NominatimAPIAsync"
|
||||
``` python
|
||||
import asyncio
|
||||
import nominatim_api as napi
|
||||
|
||||
config_params = {
|
||||
'NOMINATIM_DATABASE_DSN': 'pgsql:dbname=belgium'
|
||||
}
|
||||
|
||||
async def search(query):
|
||||
async with napi.NominatimAPIAsync(environ=config_params) as api:
|
||||
return await api.search(query)
|
||||
|
||||
results = asyncio.run(search('Brugge'))
|
||||
```
|
||||
|
||||
=== "NominatimAPI"
|
||||
``` python
|
||||
import nominatim_api as napi
|
||||
|
||||
config_params = {
|
||||
'NOMINATIM_DATABASE_DSN': 'pgsql:dbname=belgium'
|
||||
}
|
||||
|
||||
with napi.NominatimAPI(environ=config_params) as api:
|
||||
results = api.search('Brugge')
|
||||
```
|
||||
|
||||
When the `environ` parameter is given, then only configuration variables
|
||||
from this dictionary will be used. The operating system's environment
|
||||
variables will be ignored.
|
||||
|
||||
## Presenting results to humans
|
||||
|
||||
All search functions return full result objects from the database. Such a
|
||||
result object contains lots of details: names, address information, OSM tags etc.
|
||||
This gives you lots of flexibility what to do with the results.
|
||||
|
||||
One of the most common things to get is some kind of human-readable label
|
||||
that describes the result in a compact form. Usually this would be the name
|
||||
of the object and some parts of the address to explain where in the world
|
||||
it is. To create such a label, you need two things:
|
||||
|
||||
* the address details of the place
|
||||
* all names for the label adapted to the language you wish to use for display
|
||||
|
||||
Again searching for 'Brugge', this time with a nicely formatted result:
|
||||
|
||||
!!! example
|
||||
=== "NominatimAPIAsync"
|
||||
``` python
|
||||
import asyncio
|
||||
|
||||
import nominatim_api as napi
|
||||
|
||||
async def search(query):
|
||||
async with napi.NominatimAPIAsync() as api:
|
||||
return await api.search(query, address_details=True)
|
||||
|
||||
results = asyncio.run(search('Brugge'))
|
||||
|
||||
locale = napi.Locales(['fr', 'en'])
|
||||
for i, result in enumerate(results):
|
||||
address_parts = result.address_rows.localize(locale)
|
||||
print(f"{i + 1}. {', '.join(address_parts)}")
|
||||
```
|
||||
|
||||
=== "NominatimAPI"
|
||||
``` python
|
||||
import nominatim_api as napi
|
||||
|
||||
with napi.NominatimAPI() as api:
|
||||
results = api.search('Brugge', address_details=True)
|
||||
|
||||
locale = napi.Locales(['fr', 'en'])
|
||||
for i, result in enumerate(results):
|
||||
address_parts = result.address_rows.localize(locale)
|
||||
print(f"{i + 1}. {', '.join(address_parts)}")
|
||||
```
|
||||
|
||||
To request information about the address of a result, add the optional
|
||||
parameter 'address_details' to your search:
|
||||
|
||||
``` python
|
||||
>>> results = api.search('Brugge', address_details=True)
|
||||
```
|
||||
|
||||
An additional field `address_rows` will set in results that are returned.
|
||||
It contains a list of all places that make up the address of the place. For
|
||||
simplicity, this includes name and house number of the place itself. With
|
||||
the names in this list it is possible to create a human-readable description
|
||||
of the result. To do that, you first need to decide in which language the
|
||||
results should be presented. As with the names in the result itself, the
|
||||
places in `address_rows` contain all possible name translation for each row.
|
||||
|
||||
The library has a helper class `Locale` which helps extracting a name of a
|
||||
place in the preferred language. It takes a single parameter with a list
|
||||
of language codes in the order of preference. So
|
||||
|
||||
``` python
|
||||
locale = napi.Locale(['fr', 'en'])
|
||||
```
|
||||
|
||||
creates a helper class that returns the name preferably in French. If that is
|
||||
not possible, it tries English and eventually falls back to the default `name`
|
||||
or `ref`.
|
||||
|
||||
The `Locale` object can be applied to a name dictionary to return the best-matching
|
||||
name out of it:
|
||||
|
||||
``` python
|
||||
>>> print(locale.display_name(results[0].names))
|
||||
'Brugges'
|
||||
```
|
||||
|
||||
The `address_row` field has a helper function to apply the function to all
|
||||
its members and save the result in the `local_name` field. It also returns
|
||||
all the localized names as a convenient simple list. This list can be used
|
||||
to create a human-readable output:
|
||||
|
||||
``` python
|
||||
>>> address_parts = results[0].address_rows.localize(locale)
|
||||
>>> print(', '.join(address_parts))
|
||||
Bruges, Flandre-Occidentale, Flandre, Belgique
|
||||
```
|
||||
|
||||
This is a fairly simple way to create a human-readable description. The
|
||||
place information in `address_rows` contains further information about each
|
||||
place. For example, which OSM `admin_level` was used, what category the place
|
||||
belongs to or what rank Nominatim has assigned. Use this to adapt the output
|
||||
to local address formats.
|
||||
|
||||
For more information on address rows, see
|
||||
[detailed address description](Result-Handling.md#detailed-address-description).
|
||||
60
docs/library/Input-Parameter-Types.md
Normal file
60
docs/library/Input-Parameter-Types.md
Normal file
@@ -0,0 +1,60 @@
|
||||
# Input Parameter Types
|
||||
|
||||
This page describes in more detail some of the input parameter types used
|
||||
in the query functions of the API object.
|
||||
|
||||
## Place identification
|
||||
|
||||
The [details](NominatimAPI.md#nominatim_api.NominatimAPI.details) and
|
||||
[lookup](NominatimAPI.md#nominatim_api.NominatimAPI.lookup) functions
|
||||
require references to places in the database. Below the possible
|
||||
types for place identification are listed. All types are dataclasses.
|
||||
|
||||
### PlaceID
|
||||
|
||||
::: nominatim_api.PlaceID
|
||||
options:
|
||||
heading_level: 6
|
||||
|
||||
### OsmID
|
||||
|
||||
::: nominatim_api.OsmID
|
||||
options:
|
||||
heading_level: 6
|
||||
|
||||
## Geometry types
|
||||
|
||||
::: nominatim_api.GeometryFormat
|
||||
options:
|
||||
heading_level: 6
|
||||
members_order: source
|
||||
|
||||
## Geometry input
|
||||
|
||||
### Point
|
||||
|
||||
::: nominatim_api.Point
|
||||
options:
|
||||
heading_level: 6
|
||||
show_signature_annotations: True
|
||||
|
||||
### Bbox
|
||||
|
||||
::: nominatim_api.Bbox
|
||||
options:
|
||||
heading_level: 6
|
||||
show_signature_annotations: True
|
||||
members_order: source
|
||||
group_by_category: False
|
||||
|
||||
## Layers
|
||||
|
||||
Layers allow to restrict the search result to thematic groups. This is
|
||||
orthogonal to restriction by address ranks, which groups places by their
|
||||
geographic extent.
|
||||
|
||||
|
||||
::: nominatim_api.DataLayer
|
||||
options:
|
||||
heading_level: 6
|
||||
members_order: source
|
||||
55
docs/library/Low-Level-DB-Access.md
Normal file
55
docs/library/Low-Level-DB-Access.md
Normal file
@@ -0,0 +1,55 @@
|
||||
# Low-level connections
|
||||
|
||||
The `NominatimAPIAsync` class allows to directly access the underlying
|
||||
database connection to explore the raw data. Nominatim uses
|
||||
[SQLAlchemy](https://docs.sqlalchemy.org/) for building queries. Please
|
||||
refer to the documentation of the library to understand how to write SQL.
|
||||
|
||||
To get access to a search connection, use the `begin()` function of your
|
||||
API object. This returns a `SearchConnection` object described below
|
||||
wrapped in a context manager. Its
|
||||
`t` property has definitions for all Nominatim search tables. For an
|
||||
overview of available tables, refer to the
|
||||
[Development Layout](../develop/Database-Layout.md) in in the development
|
||||
chapter. Note that only tables that are needed for search are accessible
|
||||
as SQLAlchemy tables.
|
||||
|
||||
!!! warning
|
||||
The database layout is not part of the API definition and may change
|
||||
without notice. If you play with the low-level access functions, you
|
||||
need to be prepared for such changes.
|
||||
|
||||
Here is a simple example, which prints how many places are available in
|
||||
the placex table:
|
||||
|
||||
```
|
||||
import asyncio
|
||||
import sqlalchemy as sa
|
||||
from nominatim_api import NominatimAPIAsync
|
||||
|
||||
async def print_table_size():
|
||||
api = NominatimAPIAsync()
|
||||
|
||||
async with api.begin() as conn:
|
||||
cnt = await conn.scalar(sa.select(sa.func.count()).select_from(conn.t.placex))
|
||||
print(f'placex table has {cnt} rows.')
|
||||
|
||||
asyncio.run(print_table_size())
|
||||
```
|
||||
|
||||
!!! warning
|
||||
Low-level connections may only be used to read data from the database.
|
||||
Do not use it to add or modify data or you might break Nominatim's
|
||||
normal functions.
|
||||
|
||||
## SearchConnection class
|
||||
|
||||
::: nominatim_api.SearchConnection
|
||||
options:
|
||||
members:
|
||||
- scalar
|
||||
- execute
|
||||
- get_class_table
|
||||
- get_db_property
|
||||
- get_property
|
||||
heading_level: 6
|
||||
36
docs/library/NominatimAPI.md
Normal file
36
docs/library/NominatimAPI.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# The Nominatim API classes
|
||||
|
||||
The API classes are the core object of the search library. Always instantiate
|
||||
one of these classes first. The API classes are **not threadsafe**. You need
|
||||
to instantiate a separate instance for each thread.
|
||||
|
||||
### NominatimAPI
|
||||
|
||||
::: nominatim_api.NominatimAPI
|
||||
options:
|
||||
members:
|
||||
- __init__
|
||||
- config
|
||||
- close
|
||||
- status
|
||||
- details
|
||||
- lookup
|
||||
- reverse
|
||||
- search
|
||||
- search_address
|
||||
- search_category
|
||||
heading_level: 6
|
||||
group_by_category: False
|
||||
|
||||
|
||||
### NominatimAPIAsync
|
||||
|
||||
::: nominatim_api.NominatimAPIAsync
|
||||
options:
|
||||
members:
|
||||
- __init__
|
||||
- setup_database
|
||||
- close
|
||||
- begin
|
||||
heading_level: 6
|
||||
group_by_category: False
|
||||
58
docs/library/Result-Handling.md
Normal file
58
docs/library/Result-Handling.md
Normal file
@@ -0,0 +1,58 @@
|
||||
# Result handling
|
||||
|
||||
The search functions of the Nominatim API always return a result object
|
||||
with the raw information about the place that is available in the
|
||||
database. This section discusses data types used in the results and utility
|
||||
functions that allow further processing of the results.
|
||||
|
||||
## Result fields
|
||||
|
||||
### Sources
|
||||
|
||||
Nominatim takes the result data from multiple sources. The `source_table` field
|
||||
in the result describes, from which source the result was retrieved.
|
||||
|
||||
::: nominatim_api.SourceTable
|
||||
options:
|
||||
heading_level: 6
|
||||
members_order: source
|
||||
|
||||
### Detailed address description
|
||||
|
||||
When the `address_details` parameter is set, then functions return not
|
||||
only information about the result place but also about the place that
|
||||
make up the address. This information is almost always required when you
|
||||
want to present the user with a human-readable description of the result.
|
||||
See also [Localization](#localization) below.
|
||||
|
||||
The address details are available in the `address_rows` field as a ordered
|
||||
list of `AddressLine` objects with the country information last. The list also
|
||||
contains the result place itself and some artificial entries, for example,
|
||||
for the house number or the country code. This makes processing and creating
|
||||
a full address easier.
|
||||
|
||||
::: nominatim_api.AddressLine
|
||||
options:
|
||||
heading_level: 6
|
||||
members_order: source
|
||||
|
||||
### Detailed search terms
|
||||
|
||||
The `details` function can return detailed information about which search terms
|
||||
may be used to find a place, when the `keywords` parameter is set. Search
|
||||
terms are split into terms for the name of the place and search terms for
|
||||
its address.
|
||||
|
||||
::: nominatim_api.WordInfo
|
||||
options:
|
||||
heading_level: 6
|
||||
|
||||
## Localization
|
||||
|
||||
Results are always returned with the full list of available names.
|
||||
|
||||
### Locale
|
||||
|
||||
::: nominatim_api.Locales
|
||||
options:
|
||||
heading_level: 6
|
||||
32
docs/mk_install_instructions.py
Normal file
32
docs/mk_install_instructions.py
Normal file
@@ -0,0 +1,32 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#
|
||||
# This file is part of Nominatim. (https://nominatim.org)
|
||||
#
|
||||
# Copyright (C) 2024 by the Nominatim developer community.
|
||||
from pathlib import Path
|
||||
|
||||
import mkdocs_gen_files
|
||||
|
||||
VAGRANT_PATH = Path(__file__, '..', '..', 'vagrant').resolve()
|
||||
|
||||
for infile in VAGRANT_PATH.glob('Install-on-*.sh'):
|
||||
outfile = f"admin/{infile.stem}.md"
|
||||
title = infile.stem.replace('-', ' ')
|
||||
|
||||
with mkdocs_gen_files.open(outfile, "w") as outfd, infile.open() as infd:
|
||||
print("#", title, file=outfd)
|
||||
has_empty = False
|
||||
for line in infd:
|
||||
line = line.rstrip()
|
||||
docpos = line.find('#DOCS:')
|
||||
if docpos >= 0:
|
||||
line = line[docpos + 6:]
|
||||
elif line == '#' or line.startswith('#!'):
|
||||
line = ''
|
||||
elif line.startswith('# '):
|
||||
line = line[2:]
|
||||
if line or not has_empty:
|
||||
print(line, file=outfd)
|
||||
has_empty = not bool(line)
|
||||
|
||||
mkdocs_gen_files.set_edit_path(outfile, "docs/mk_install_instructions.py")
|
||||
14
lib-lua/flex-base.lua
Normal file
14
lib-lua/flex-base.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
-- This is just an alias for the Nominatim themepark theme module
|
||||
local flex = require('themes/nominatim/init')
|
||||
|
||||
function flex.load_topic(name, cfg)
|
||||
local topic_file = debug.getinfo(1, "S").source:sub(2):match("(.*/)") .. 'themes/nominatim/topics/'.. name .. '.lua'
|
||||
|
||||
if topic_file == nil then
|
||||
error('Cannot find topic: ' .. name)
|
||||
end
|
||||
|
||||
loadfile(topic_file)(nil, flex, cfg or {})
|
||||
end
|
||||
|
||||
return flex
|
||||
6
lib-lua/import-address.lua
Normal file
6
lib-lua/import-address.lua
Normal file
@@ -0,0 +1,6 @@
|
||||
-- This is just an alias for the Nominatim themepark address topic
|
||||
local flex = require('flex-base')
|
||||
|
||||
flex.load_topic('address')
|
||||
|
||||
return flex
|
||||
6
lib-lua/import-admin.lua
Normal file
6
lib-lua/import-admin.lua
Normal file
@@ -0,0 +1,6 @@
|
||||
-- This is just an alias for the Nominatim themepark admin topic
|
||||
local flex = require('flex-base')
|
||||
|
||||
flex.load_topic('admin')
|
||||
|
||||
return flex
|
||||
6
lib-lua/import-extratags.lua
Normal file
6
lib-lua/import-extratags.lua
Normal file
@@ -0,0 +1,6 @@
|
||||
-- This is just an alias for the Nominatim themepark full topic
|
||||
local flex = require('flex-base')
|
||||
|
||||
flex.load_topic('full', {with_extratags = true})
|
||||
|
||||
return flex
|
||||
6
lib-lua/import-full.lua
Normal file
6
lib-lua/import-full.lua
Normal file
@@ -0,0 +1,6 @@
|
||||
-- This is just an alias for the Nominatim themepark full topic
|
||||
local flex = require('flex-base')
|
||||
|
||||
flex.load_topic('full')
|
||||
|
||||
return flex
|
||||
6
lib-lua/import-street.lua
Normal file
6
lib-lua/import-street.lua
Normal file
@@ -0,0 +1,6 @@
|
||||
-- This is just an alias for the Nominatim themepark street topic
|
||||
local flex = require('flex-base')
|
||||
|
||||
flex.load_topic('street')
|
||||
|
||||
return flex
|
||||
118
lib-lua/taginfo.lua
Normal file
118
lib-lua/taginfo.lua
Normal file
@@ -0,0 +1,118 @@
|
||||
-- Prints taginfo project description in the standard output
|
||||
--
|
||||
|
||||
-- create fake "osm2pgsql" table for flex-base, originally created by the main C++ program
|
||||
osm2pgsql = {}
|
||||
function osm2pgsql.define_table(...) end
|
||||
|
||||
-- provide path to flex-style lua file
|
||||
package.path = arg[0]:match("(.*/)") .. "?.lua;" .. package.path
|
||||
local flex = require('import-' .. (arg[1] or 'extratags'))
|
||||
local json = require ('dkjson')
|
||||
|
||||
local NAME_DESCRIPTIONS = {
|
||||
'Searchable auxiliary name of the place',
|
||||
main = 'Searchable primary name of the place',
|
||||
house = 'House name part of an address, searchable'
|
||||
}
|
||||
local ADDRESS_DESCRIPTIONS = {
|
||||
'Used to determine the address of a place',
|
||||
main = 'Primary key for an address point',
|
||||
postcode = 'Used to determine the postcode of a place',
|
||||
country = 'Used to determine country of a place (only if written as two-letter code)',
|
||||
interpolation = 'Primary key for an address interpolation line'
|
||||
}
|
||||
|
||||
------------ helper functions ---------------------
|
||||
-- Sets the key order for the resulting JSON table
|
||||
local function set_keyorder(table, order)
|
||||
setmetatable(table, {
|
||||
__jsonorder = order
|
||||
})
|
||||
end
|
||||
|
||||
local function get_key_description(key, description)
|
||||
local desc = {}
|
||||
desc.key = key
|
||||
desc.description = description
|
||||
set_keyorder(desc, {'key', 'description'})
|
||||
return desc
|
||||
end
|
||||
|
||||
local function get_key_value_description(key, value, description)
|
||||
local desc = {key = key, value = value, description = description}
|
||||
set_keyorder(desc, {'key', 'value', 'description'})
|
||||
return desc
|
||||
end
|
||||
|
||||
local function group_table_to_keys(tags, data, descriptions)
|
||||
for group, values in pairs(data) do
|
||||
local desc = descriptions[group] or descriptions[1]
|
||||
for _, key in pairs(values) do
|
||||
if key:sub(1, 1) ~= '*' and key:sub(#key, #key) ~= '*' then
|
||||
table.insert(tags, get_key_description(key, desc))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Prints the collected tags in the required format in JSON
|
||||
local function print_taginfo()
|
||||
local taginfo = flex.get_taginfo()
|
||||
local tags = {}
|
||||
|
||||
for k, values in pairs(taginfo.main) do
|
||||
if values[1] == nil or values[1] == 'delete' or values[1] == 'extra' then
|
||||
for v, group in pairs(values) do
|
||||
if type(v) == 'string' and group ~= 'delete' and group ~= 'extra' then
|
||||
local text = 'POI/feature in the search database'
|
||||
if type(group) ~= 'function' then
|
||||
text = 'Fallback ' .. text
|
||||
end
|
||||
table.insert(tags, get_key_value_description(k, v, text))
|
||||
end
|
||||
end
|
||||
elseif type(values[1]) == 'function' or values[1] == 'fallback' then
|
||||
local desc = 'POI/feature in the search database'
|
||||
if values[1] == 'fallback' then
|
||||
desc = 'Fallback ' .. desc
|
||||
end
|
||||
local excp = {}
|
||||
for v, group in pairs(values) do
|
||||
if group == 'delete' or group == 'extra' then
|
||||
table.insert(excp, v)
|
||||
end
|
||||
end
|
||||
if next(excp) ~= nil then
|
||||
desc = desc .. string.format(' (except for values: %s)',
|
||||
table.concat(excp, ', '))
|
||||
end
|
||||
table.insert(tags, get_key_description(k, desc))
|
||||
end
|
||||
end
|
||||
|
||||
group_table_to_keys(tags, taginfo.name, NAME_DESCRIPTIONS)
|
||||
group_table_to_keys(tags, taginfo.address, ADDRESS_DESCRIPTIONS)
|
||||
|
||||
local format = {
|
||||
data_format = 1,
|
||||
data_url = 'https://nominatim.openstreetmap.org/taginfo.json',
|
||||
project = {
|
||||
name = 'Nominatim',
|
||||
description = 'OSM search engine.',
|
||||
project_url = 'https://nominatim.openstreetmap.org',
|
||||
doc_url = 'https://nominatim.org/release-docs/develop/',
|
||||
contact_name = 'Sarah Hoffmann',
|
||||
contact_email = 'lonvia@denofr.de'
|
||||
}
|
||||
}
|
||||
format.tags = tags
|
||||
|
||||
set_keyorder(format, {'data_format', 'data_url', 'project', 'tags'})
|
||||
set_keyorder(format.project, {'name', 'description', 'project_url', 'doc_url',
|
||||
'contact_name', 'contact_email'})
|
||||
|
||||
print(json.encode(format))
|
||||
end
|
||||
|
||||
print_taginfo()
|
||||
925
lib-lua/themes/nominatim/init.lua
Normal file
925
lib-lua/themes/nominatim/init.lua
Normal file
@@ -0,0 +1,925 @@
|
||||
-- Nominatim themepark theme.
|
||||
--
|
||||
-- The Nominatim theme creates a fixed set of import tables for use with
|
||||
-- Nominatim. Creation and object processing are directly controlled by
|
||||
-- the theme. Topics provide preset configurations. You should add exactly
|
||||
-- one topic to your project.
|
||||
--
|
||||
-- The theme also exports a number of functions that can be used to configure
|
||||
-- its behaviour. These may be directly called in the style file after
|
||||
-- importing the theme:
|
||||
--
|
||||
-- local nominatim = themepark:init_theme('nominatim')
|
||||
-- nominatim.set_main_tags{boundary = 'always'}
|
||||
--
|
||||
-- This allows to write your own configuration from scratch. You can also
|
||||
-- use it to customize topics. In that case, first add the topic, then
|
||||
-- change the configuration:
|
||||
--
|
||||
-- themepark:add_topic('nominatim/full')
|
||||
-- local nominatim = themepark:init_theme('nominatim')
|
||||
-- nominatim.ignore_tags{'amenity'}
|
||||
|
||||
local module = {}
|
||||
|
||||
local MAIN_KEYS = {admin_level = {'delete'}}
|
||||
local PRE_FILTER = {prefix = {}, suffix = {}}
|
||||
local NAMES = {}
|
||||
local NAME_FILTER = nil
|
||||
local ADDRESS_TAGS = {}
|
||||
local ADDRESS_FILTER = nil
|
||||
local EXTRATAGS_FILTER
|
||||
local POSTCODE_FALLBACK = true
|
||||
|
||||
-- This file can also be directly require'd instead of running it under
|
||||
-- the themepark framework. In that case the first parameter is usually
|
||||
-- the module name. Lets check for that, so that further down we can call
|
||||
-- the low-level osm2pgsql functions instead of themepark functions.
|
||||
local themepark = ...
|
||||
if type(themepark) ~= 'table' then
|
||||
themepark = nil
|
||||
end
|
||||
|
||||
-- The single place table.
|
||||
local place_table_definition = {
|
||||
name = "place",
|
||||
ids = { type = 'any', id_column = 'osm_id', type_column = 'osm_type' },
|
||||
columns = {
|
||||
{ column = 'class', type = 'text', not_null = true },
|
||||
{ column = 'type', type = 'text', not_null = true },
|
||||
{ column = 'admin_level', type = 'smallint' },
|
||||
{ column = 'name', type = 'hstore' },
|
||||
{ column = 'address', type = 'hstore' },
|
||||
{ column = 'extratags', type = 'hstore' },
|
||||
{ column = 'geometry', type = 'geometry', projection = 'WGS84', not_null = true },
|
||||
},
|
||||
data_tablespace = os.getenv("NOMINATIM_TABLESPACE_PLACE_DATA"),
|
||||
index_tablespace = os.getenv("NOMINATIM_TABLESPACE_PLACE_INDEX"),
|
||||
indexes = {}
|
||||
}
|
||||
|
||||
local insert_row
|
||||
local script_path = debug.getinfo(1, "S").source:match("@?(.*/)")
|
||||
local PRESETS = loadfile(script_path .. 'presets.lua')()
|
||||
|
||||
if themepark then
|
||||
themepark:add_table(place_table_definition)
|
||||
insert_row = function(columns)
|
||||
themepark:insert('place', columns, {}, {})
|
||||
end
|
||||
else
|
||||
local place_table = osm2pgsql.define_table(place_table_definition)
|
||||
insert_row = function(columns)
|
||||
place_table:insert(columns)
|
||||
end
|
||||
end
|
||||
|
||||
------------ Geometry functions for relations ---------------------
|
||||
|
||||
function module.relation_as_multipolygon(o)
|
||||
return o:as_multipolygon()
|
||||
end
|
||||
|
||||
function module.relation_as_multiline(o)
|
||||
return o:as_multilinestring():line_merge()
|
||||
end
|
||||
|
||||
|
||||
module.RELATION_TYPES = {
|
||||
multipolygon = module.relation_as_multipolygon,
|
||||
boundary = module.relation_as_multipolygon,
|
||||
waterway = module.relation_as_multiline
|
||||
}
|
||||
|
||||
--------- Built-in place transformation functions --------------------------
|
||||
|
||||
local PlaceTransform = {}
|
||||
|
||||
-- Special transform meanings which are interpreted elsewhere
|
||||
PlaceTransform.fallback = 'fallback'
|
||||
PlaceTransform.delete = 'delete'
|
||||
PlaceTransform.extra = 'extra'
|
||||
|
||||
-- always: unconditionally use that place
|
||||
function PlaceTransform.always(place)
|
||||
return place
|
||||
end
|
||||
|
||||
-- never: unconditionally drop the place
|
||||
function PlaceTransform.never()
|
||||
return nil
|
||||
end
|
||||
|
||||
-- named: use the place if it has a fully-qualified name
|
||||
function PlaceTransform.named(place)
|
||||
if place.has_name then
|
||||
return place
|
||||
end
|
||||
end
|
||||
|
||||
-- named_with_key: use place if there is a name with the main key prefix
|
||||
function PlaceTransform.named_with_key(place, k)
|
||||
local names = {}
|
||||
local prefix = k .. ':name'
|
||||
for namek, namev in pairs(place.intags) do
|
||||
if namek:sub(1, #prefix) == prefix
|
||||
and (#namek == #prefix
|
||||
or namek:sub(#prefix + 1, #prefix + 1) == ':') then
|
||||
names[namek:sub(#k + 2)] = namev
|
||||
end
|
||||
end
|
||||
|
||||
if next(names) ~= nil then
|
||||
return place:clone{names=names}
|
||||
end
|
||||
end
|
||||
|
||||
-- Special transform used with address fallbacks: ignore all names
|
||||
-- except for those marked as being part of the address.
|
||||
local function address_fallback(place)
|
||||
if next(place.names) == nil or NAMES.house == nil then
|
||||
return place
|
||||
end
|
||||
|
||||
local names = {}
|
||||
for k, v in pairs(place.names) do
|
||||
if NAME_FILTER(k, v) == 'house' then
|
||||
names[k] = v
|
||||
end
|
||||
end
|
||||
return place:clone{names=names}
|
||||
end
|
||||
|
||||
--------- Built-in extratags transformation functions ---------------
|
||||
|
||||
local function default_extratags_filter(p, k)
|
||||
-- Default handling is to copy over place tag for boundaries.
|
||||
-- Nominatim needs this.
|
||||
if k ~= 'boundary' or p.intags.place == nil then
|
||||
return p.extratags
|
||||
end
|
||||
|
||||
local extra = { place = p.intags.place }
|
||||
for kin, vin in pairs(p.extratags) do
|
||||
extra[kin] = vin
|
||||
end
|
||||
|
||||
return extra
|
||||
end
|
||||
EXTRATAGS_FILTER = default_extratags_filter
|
||||
|
||||
----------------- other helper functions -----------------------------
|
||||
|
||||
local function lookup_prefilter_classification(k, v)
|
||||
-- full matches
|
||||
local desc = MAIN_KEYS[k]
|
||||
local fullmatch = desc and (desc[v] or desc[1])
|
||||
if fullmatch ~= nil then
|
||||
return fullmatch
|
||||
end
|
||||
-- suffixes
|
||||
for slen, slist in pairs(PRE_FILTER.suffix) do
|
||||
if #k >= slen then
|
||||
local group = slist[k:sub(-slen)]
|
||||
if group ~= nil then
|
||||
return group
|
||||
end
|
||||
end
|
||||
end
|
||||
-- prefixes
|
||||
for slen, slist in pairs(PRE_FILTER.prefix) do
|
||||
if #k >= slen then
|
||||
local group = slist[k:sub(1, slen)]
|
||||
if group ~= nil then
|
||||
return group
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function merge_filters_into_main(group, keys, tags)
|
||||
if keys ~= nil then
|
||||
for _, key in pairs(keys) do
|
||||
-- ignore suffix and prefix matches
|
||||
if key:sub(1, 1) ~= '*' and key:sub(#key, #key) ~= '*' then
|
||||
if MAIN_KEYS[key] == nil then
|
||||
MAIN_KEYS[key] = {}
|
||||
end
|
||||
MAIN_KEYS[key][1] = group
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if tags ~= nil then
|
||||
for key, values in pairs(tags) do
|
||||
if MAIN_KEYS[key] == nil then
|
||||
MAIN_KEYS[key] = {}
|
||||
end
|
||||
for _, v in pairs(values) do
|
||||
MAIN_KEYS[key][v] = group
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function remove_group_from_main(group)
|
||||
for key, values in pairs(MAIN_KEYS) do
|
||||
for _, ttype in pairs(values) do
|
||||
if ttype == group then
|
||||
values[ttype] = nil
|
||||
end
|
||||
end
|
||||
if next(values) == nil then
|
||||
MAIN_KEYS[key] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function add_pre_filter(data)
|
||||
for group, keys in pairs(data) do
|
||||
for _, key in pairs(keys) do
|
||||
local klen = #key - 1
|
||||
if key:sub(1, 1) == '*' then
|
||||
if klen > 0 then
|
||||
if PRE_FILTER.suffix[klen] == nil then
|
||||
PRE_FILTER.suffix[klen] = {}
|
||||
end
|
||||
PRE_FILTER.suffix[klen][key:sub(2)] = group
|
||||
end
|
||||
elseif key:sub(#key, #key) == '*' then
|
||||
if PRE_FILTER.prefix[klen] == nil then
|
||||
PRE_FILTER.prefix[klen] = {}
|
||||
end
|
||||
PRE_FILTER.prefix[klen][key:sub(1, klen)] = group
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
------------- Place class ------------------------------------------
|
||||
|
||||
local Place = {}
|
||||
Place.__index = Place
|
||||
|
||||
function Place.new(object, geom_func)
|
||||
local self = setmetatable({}, Place)
|
||||
self.object = object
|
||||
self.geom_func = geom_func
|
||||
|
||||
self.admin_level = tonumber(self.object.tags.admin_level or 15) or 15
|
||||
if self.admin_level == nil
|
||||
or self.admin_level <= 0 or self.admin_level > 15
|
||||
or math.floor(self.admin_level) ~= self.admin_level then
|
||||
self.admin_level = 15
|
||||
end
|
||||
|
||||
self.num_entries = 0
|
||||
self.has_name = false
|
||||
self.names = {}
|
||||
self.address = {}
|
||||
self.extratags = {}
|
||||
|
||||
self.intags = {}
|
||||
|
||||
local has_main_tags = false
|
||||
for k, v in pairs(self.object.tags) do
|
||||
local group = lookup_prefilter_classification(k, v)
|
||||
if group == 'extra' then
|
||||
self.extratags[k] = v
|
||||
elseif group ~= 'delete' then
|
||||
self.intags[k] = v
|
||||
if group ~= nil then
|
||||
has_main_tags = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not has_main_tags then
|
||||
-- no interesting tags, don't bother processing
|
||||
self.intags = {}
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function Place:clean(data)
|
||||
for k, v in pairs(self.intags) do
|
||||
if data.delete ~= nil and data.delete(k, v) then
|
||||
self.intags[k] = nil
|
||||
elseif data.extra ~= nil and data.extra(k, v) then
|
||||
self.extratags[k] = v
|
||||
self.intags[k] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Place:delete(data)
|
||||
if data.match ~= nil then
|
||||
for k, v in pairs(self.intags) do
|
||||
if data.match(k, v) then
|
||||
self.intags[k] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Place:grab_extratags(data)
|
||||
local count = 0
|
||||
|
||||
if data.match ~= nil then
|
||||
for k, v in pairs(self.intags) do
|
||||
if data.match(k, v) then
|
||||
self.intags[k] = nil
|
||||
self.extratags[k] = v
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return count
|
||||
end
|
||||
|
||||
local function strip_address_prefix(k)
|
||||
if k:sub(1, 5) == 'addr:' then
|
||||
return k:sub(6)
|
||||
end
|
||||
|
||||
if k:sub(1, 6) == 'is_in:' then
|
||||
return k:sub(7)
|
||||
end
|
||||
|
||||
return k
|
||||
end
|
||||
|
||||
|
||||
function Place:grab_address_parts(data)
|
||||
local count = 0
|
||||
|
||||
if data.groups ~= nil then
|
||||
for k, v in pairs(self.intags) do
|
||||
local atype = data.groups(k, v)
|
||||
|
||||
if atype ~= nil then
|
||||
if atype == 'main' then
|
||||
self.has_name = true
|
||||
self.address[strip_address_prefix(k)] = v
|
||||
count = count + 1
|
||||
elseif atype == 'extra' then
|
||||
self.address[strip_address_prefix(k)] = v
|
||||
else
|
||||
self.address[atype] = v
|
||||
end
|
||||
self.intags[k] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return count
|
||||
end
|
||||
|
||||
|
||||
function Place:grab_name_parts(data)
|
||||
local fallback = nil
|
||||
|
||||
if data.groups ~= nil then
|
||||
for k, v in pairs(self.intags) do
|
||||
local atype = data.groups(k, v)
|
||||
|
||||
if atype ~= nil then
|
||||
self.names[k] = v
|
||||
self.intags[k] = nil
|
||||
if atype == 'main' then
|
||||
self.has_name = true
|
||||
elseif atype == 'house' then
|
||||
self.has_name = true
|
||||
fallback = {'place', 'house', address_fallback}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return fallback
|
||||
end
|
||||
|
||||
|
||||
function Place:write_place(k, v, mfunc)
|
||||
v = v or self.intags[k]
|
||||
if v == nil then
|
||||
return 0
|
||||
end
|
||||
|
||||
local place = mfunc(self, k, v)
|
||||
if place then
|
||||
local res = place:write_row(k, v)
|
||||
self.num_entries = self.num_entries + res
|
||||
return res
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
function Place:write_row(k, v)
|
||||
if self.geometry == nil then
|
||||
self.geometry = self.geom_func(self.object)
|
||||
end
|
||||
if self.geometry == nil or self.geometry:is_null() then
|
||||
return 0
|
||||
end
|
||||
|
||||
local extratags = EXTRATAGS_FILTER(self, k, v)
|
||||
if not (extratags and next(extratags)) then
|
||||
extratags = nil
|
||||
end
|
||||
|
||||
insert_row{
|
||||
class = k,
|
||||
type = v,
|
||||
admin_level = self.admin_level,
|
||||
name = next(self.names) and self.names,
|
||||
address = next(self.address) and self.address,
|
||||
extratags = extratags,
|
||||
geometry = self.geometry
|
||||
}
|
||||
|
||||
return 1
|
||||
end
|
||||
|
||||
|
||||
function Place:clone(data)
|
||||
local cp = setmetatable({}, Place)
|
||||
cp.object = self.object
|
||||
cp.geometry = data.geometry or self.geometry
|
||||
cp.geom_func = self.geom_func
|
||||
cp.intags = data.intags or self.intags
|
||||
cp.admin_level = data.admin_level or self.admin_level
|
||||
cp.names = data.names or self.names
|
||||
cp.address = data.address or self.address
|
||||
cp.extratags = data.extratags or self.extratags
|
||||
|
||||
return cp
|
||||
end
|
||||
|
||||
|
||||
function module.tag_match(data)
|
||||
if data == nil or next(data) == nil then
|
||||
return nil
|
||||
end
|
||||
|
||||
local fullmatches = {}
|
||||
local key_prefixes = {}
|
||||
local key_suffixes = {}
|
||||
|
||||
if data.keys ~= nil then
|
||||
for _, key in pairs(data.keys) do
|
||||
if key:sub(1, 1) == '*' then
|
||||
if #key > 1 then
|
||||
if key_suffixes[#key - 1] == nil then
|
||||
key_suffixes[#key - 1] = {}
|
||||
end
|
||||
key_suffixes[#key - 1][key:sub(2)] = true
|
||||
end
|
||||
elseif key:sub(#key, #key) == '*' then
|
||||
if key_prefixes[#key - 1] == nil then
|
||||
key_prefixes[#key - 1] = {}
|
||||
end
|
||||
key_prefixes[#key - 1][key:sub(1, #key - 1)] = true
|
||||
else
|
||||
fullmatches[key] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if data.tags ~= nil then
|
||||
for k, vlist in pairs(data.tags) do
|
||||
if fullmatches[k] == nil then
|
||||
fullmatches[k] = {}
|
||||
for _, v in pairs(vlist) do
|
||||
fullmatches[k][v] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return function (k, v)
|
||||
if fullmatches[k] ~= nil and (fullmatches[k] == true or fullmatches[k][v] ~= nil) then
|
||||
return true
|
||||
end
|
||||
|
||||
for slen, slist in pairs(key_suffixes) do
|
||||
if #k >= slen and slist[k:sub(-slen)] ~= nil then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
for slen, slist in pairs(key_prefixes) do
|
||||
if #k >= slen and slist[k:sub(1, slen)] ~= nil then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function module.tag_group(data)
|
||||
if data == nil or next(data) == nil then
|
||||
return nil
|
||||
end
|
||||
|
||||
local fullmatches = {}
|
||||
local key_prefixes = {}
|
||||
local key_suffixes = {}
|
||||
|
||||
for group, tags in pairs(data) do
|
||||
for _, key in pairs(tags) do
|
||||
if key:sub(1, 1) == '*' then
|
||||
if #key > 1 then
|
||||
if key_suffixes[#key - 1] == nil then
|
||||
key_suffixes[#key - 1] = {}
|
||||
end
|
||||
key_suffixes[#key - 1][key:sub(2)] = group
|
||||
end
|
||||
elseif key:sub(#key, #key) == '*' then
|
||||
if key_prefixes[#key - 1] == nil then
|
||||
key_prefixes[#key - 1] = {}
|
||||
end
|
||||
key_prefixes[#key - 1][key:sub(1, #key - 1)] = group
|
||||
else
|
||||
fullmatches[key] = group
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return function (k)
|
||||
local val = fullmatches[k]
|
||||
if val ~= nil then
|
||||
return val
|
||||
end
|
||||
|
||||
for slen, slist in pairs(key_suffixes) do
|
||||
if #k >= slen then
|
||||
val = slist[k:sub(-slen)]
|
||||
if val ~= nil then
|
||||
return val
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for slen, slist in pairs(key_prefixes) do
|
||||
if #k >= slen then
|
||||
val = slist[k:sub(1, slen)]
|
||||
if val ~= nil then
|
||||
return val
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Returns prefix part of the keys, and reject suffix matching keys
|
||||
local function process_key(key)
|
||||
if key:sub(1, 1) == '*' then
|
||||
return nil
|
||||
end
|
||||
if key:sub(#key, #key) == '*' then
|
||||
return key:sub(1, #key - 2)
|
||||
end
|
||||
return key
|
||||
end
|
||||
|
||||
-- Process functions for all data types
|
||||
function module.process_node(object)
|
||||
|
||||
local function geom_func(o)
|
||||
return o:as_point()
|
||||
end
|
||||
|
||||
module.process_tags(Place.new(object, geom_func))
|
||||
end
|
||||
|
||||
function module.process_way(object)
|
||||
|
||||
local function geom_func(o)
|
||||
local geom = o:as_polygon()
|
||||
|
||||
if geom:is_null() then
|
||||
geom = o:as_linestring()
|
||||
if geom:is_null() or geom:length() > 30 then
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
return geom
|
||||
end
|
||||
|
||||
module.process_tags(Place.new(object, geom_func))
|
||||
end
|
||||
|
||||
function module.process_relation(object)
|
||||
local geom_func = module.RELATION_TYPES[object.tags.type]
|
||||
|
||||
if geom_func ~= nil then
|
||||
module.process_tags(Place.new(object, geom_func))
|
||||
end
|
||||
end
|
||||
|
||||
-- The process functions are used by default by osm2pgsql.
|
||||
if themepark then
|
||||
themepark:add_proc('node', module.process_node)
|
||||
themepark:add_proc('way', module.process_way)
|
||||
themepark:add_proc('relation', module.process_relation)
|
||||
else
|
||||
osm2pgsql.process_node = module.process_node
|
||||
osm2pgsql.process_way = module.process_way
|
||||
osm2pgsql.process_relation = module.process_relation
|
||||
end
|
||||
|
||||
function module.process_tags(o)
|
||||
if next(o.intags) == nil then
|
||||
return -- shortcut when pre-filtering has removed all tags
|
||||
end
|
||||
|
||||
-- Exception for boundary/place double tagging
|
||||
if o.intags.boundary == 'administrative' then
|
||||
o:grab_extratags{match = function (k, v)
|
||||
return k == 'place' and v:sub(1,3) ~= 'isl'
|
||||
end}
|
||||
end
|
||||
|
||||
-- name keys
|
||||
local fallback = o:grab_name_parts{groups=NAME_FILTER}
|
||||
|
||||
-- address keys
|
||||
if o:grab_address_parts{groups=ADDRESS_FILTER} > 0 and fallback == nil then
|
||||
fallback = {'place', 'house', address_fallback}
|
||||
end
|
||||
if o.address.country ~= nil and #o.address.country ~= 2 then
|
||||
o.address['country'] = nil
|
||||
end
|
||||
if POSTCODE_FALLBACK and fallback == nil and o.address.postcode ~= nil then
|
||||
fallback = {'place', 'postcode', PlaceTransform.always}
|
||||
end
|
||||
|
||||
if o.address.interpolation ~= nil then
|
||||
o:write_place('place', 'houses', PlaceTransform.always)
|
||||
return
|
||||
end
|
||||
|
||||
-- collect main keys
|
||||
for k, v in pairs(o.intags) do
|
||||
local ktable = MAIN_KEYS[k]
|
||||
if ktable then
|
||||
local ktype = ktable[v] or ktable[1]
|
||||
if type(ktype) == 'function' then
|
||||
o:write_place(k, v, ktype)
|
||||
elseif ktype == 'fallback' and o.has_name then
|
||||
fallback = {k, v, PlaceTransform.named}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if fallback ~= nil and o.num_entries == 0 then
|
||||
o:write_place(fallback[1], fallback[2], fallback[3])
|
||||
end
|
||||
end
|
||||
|
||||
--------- Convenience functions for simple style configuration -----------------
|
||||
|
||||
function module.set_prefilters(data)
|
||||
remove_group_from_main('delete')
|
||||
merge_filters_into_main('delete', data.delete_keys, data.delete_tags)
|
||||
|
||||
remove_group_from_main('extra')
|
||||
merge_filters_into_main('extra', data.extra_keys, data.extra_tags)
|
||||
|
||||
PRE_FILTER = {prefix = {}, suffix = {}}
|
||||
add_pre_filter{delete = data.delete_keys, extra = data.extra_keys}
|
||||
end
|
||||
|
||||
|
||||
function module.ignore_keys(data)
|
||||
if type(data) == 'string' then
|
||||
local preset = data
|
||||
data = PRESETS.IGNORE_KEYS[data]
|
||||
if data == nil then
|
||||
error('Unknown preset for ignored keys: ' .. preset)
|
||||
end
|
||||
end
|
||||
merge_filters_into_main('delete', data)
|
||||
add_pre_filter{delete = data}
|
||||
end
|
||||
|
||||
|
||||
function module.add_for_extratags(data)
|
||||
if type(data) == 'string' then
|
||||
local preset = data
|
||||
data = PRESETS.EXTRATAGS[data] or PRESETS.IGNORE_KEYS[data]
|
||||
if data == nil then
|
||||
error('Unknown preset for extratags: ' .. preset)
|
||||
end
|
||||
end
|
||||
merge_filters_into_main('extra', data)
|
||||
add_pre_filter{extra = data}
|
||||
end
|
||||
|
||||
|
||||
function module.set_main_tags(data)
|
||||
for key, values in pairs(MAIN_KEYS) do
|
||||
for _, ttype in pairs(values) do
|
||||
if ttype == 'fallback' or type(ttype) == 'function' then
|
||||
values[ttype] = nil
|
||||
end
|
||||
end
|
||||
if next(values) == nil then
|
||||
MAIN_KEYS[key] = nil
|
||||
end
|
||||
end
|
||||
module.modify_main_tags(data)
|
||||
end
|
||||
|
||||
|
||||
function module.modify_main_tags(data)
|
||||
if type(data) == 'string' then
|
||||
local preset = data
|
||||
if data:sub(1, 7) == 'street/' then
|
||||
data = PRESETS.MAIN_TAGS_STREETS[data:sub(8)]
|
||||
elseif data:sub(1, 4) == 'poi/' then
|
||||
data = PRESETS.MAIN_TAGS_POIS(data:sub(5))
|
||||
else
|
||||
data = PRESETS.MAIN_TAGS[data]
|
||||
end
|
||||
if data == nil then
|
||||
error('Unknown preset for main tags: ' .. preset)
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in pairs(data) do
|
||||
if MAIN_KEYS[k] == nil then
|
||||
MAIN_KEYS[k] = {}
|
||||
end
|
||||
if type(v) == 'function' then
|
||||
MAIN_KEYS[k][1] = v
|
||||
elseif type(v) == 'string' then
|
||||
MAIN_KEYS[k][1] = PlaceTransform[v]
|
||||
elseif type(v) == 'table' then
|
||||
for subk, subv in pairs(v) do
|
||||
if type(subv) == 'function' then
|
||||
MAIN_KEYS[k][subk] = subv
|
||||
else
|
||||
MAIN_KEYS[k][subk] = PlaceTransform[subv]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function module.modify_name_tags(data)
|
||||
if type(data) == 'string' then
|
||||
local preset = data
|
||||
data = PRESETS.NAME_TAGS[data]
|
||||
if data == nil then
|
||||
error('Unknown preset for name keys: ' .. preset)
|
||||
end
|
||||
end
|
||||
|
||||
for k,v in pairs(data) do
|
||||
if next(v) then
|
||||
NAMES[k] = v
|
||||
else
|
||||
NAMES[k] = nil
|
||||
end
|
||||
end
|
||||
NAME_FILTER = module.tag_group(NAMES)
|
||||
remove_group_from_main('fallback:name')
|
||||
if data.house ~= nil then
|
||||
merge_filters_into_main('fallback:name', data.house)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function module.set_name_tags(data)
|
||||
NAMES = {}
|
||||
module.modify_name_tags(data)
|
||||
end
|
||||
|
||||
|
||||
function module.set_address_tags(data)
|
||||
ADDRESS_TAGS = {}
|
||||
module.modify_address_tags(data)
|
||||
end
|
||||
|
||||
|
||||
function module.modify_address_tags(data)
|
||||
if type(data) == 'string' then
|
||||
local preset = data
|
||||
data = PRESETS.ADDRESS_TAGS[data]
|
||||
if data == nil then
|
||||
error('Unknown preset for address keys: ' .. preset)
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in pairs(data) do
|
||||
if k == 'postcode_fallback' then
|
||||
POSTCODE_FALLBACK = v
|
||||
elseif next(v) == nil then
|
||||
ADDRESS_TAGS[k] = nil
|
||||
else
|
||||
ADDRESS_TAGS[k] = v
|
||||
end
|
||||
end
|
||||
|
||||
ADDRESS_FILTER = module.tag_group(ADDRESS_TAGS)
|
||||
|
||||
remove_group_from_main('fallback:address')
|
||||
merge_filters_into_main('fallback:address', data.main)
|
||||
merge_filters_into_main('fallback:address', data.interpolation)
|
||||
remove_group_from_main('fallback:postcode')
|
||||
if POSTCODE_FALLBACK then
|
||||
merge_filters_into_main('fallback:postcode', data.postcode)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function module.set_address_tags(data)
|
||||
ADDRESS_TAGS_SOURCE = {}
|
||||
module.modify_address_tags(data)
|
||||
end
|
||||
|
||||
|
||||
function module.set_postcode_fallback(enable)
|
||||
if POSTCODE_FALLBACK ~= enable then
|
||||
remove_group_from_main('fallback:postcode')
|
||||
if enable then
|
||||
merge_filters_into_main('fallback:postcode', ADDRESS_TAGS.postcode)
|
||||
end
|
||||
end
|
||||
POSTCODE_FALLBACK = enable
|
||||
end
|
||||
|
||||
|
||||
function module.set_unused_handling(data)
|
||||
if type(data) == 'function' then
|
||||
EXTRATAGS_FILTER = data
|
||||
elseif data == nil then
|
||||
EXTRATAGS_FILTER = default_extratags_filter
|
||||
elseif data.extra_keys == nil and data.extra_tags == nil then
|
||||
local delfilter = module.tag_match{keys = data.delete_keys, tags = data.delete_tags}
|
||||
EXTRATAGS_FILTER = function (p, k)
|
||||
local extra = {}
|
||||
for kin, vin in pairs(p.intags) do
|
||||
if kin ~= k and not delfilter(kin, vin) then
|
||||
extra[kin] = vin
|
||||
end
|
||||
end
|
||||
if next(extra) == nil then
|
||||
return p.extratags
|
||||
end
|
||||
for kextra, vextra in pairs(p.extratags) do
|
||||
extra[kextra] = vextra
|
||||
end
|
||||
return extra
|
||||
end
|
||||
elseif data.delete_keys == nil and data.delete_tags == nil then
|
||||
local incfilter = module.tag_match{keys = data.extra_keys, tags = data.extra_tags}
|
||||
EXTRATAGS_FILTER = function (p, k)
|
||||
local extra = {}
|
||||
for kin, vin in pairs(p.intags) do
|
||||
if kin ~= k and incfilter(kin, vin) then
|
||||
extra[kin] = vin
|
||||
end
|
||||
end
|
||||
if next(extra) == nil then
|
||||
return p.extratags
|
||||
end
|
||||
for kextra, vextra in pairs(p.extratags) do
|
||||
extra[kextra] = vextra
|
||||
end
|
||||
return extra
|
||||
end
|
||||
else
|
||||
error("unused handler can have only 'extra_keys' or 'delete_keys' set.")
|
||||
end
|
||||
end
|
||||
|
||||
function module.set_relation_types(data)
|
||||
module.RELATION_TYPES = {}
|
||||
for k, v in data do
|
||||
if v == 'multipolygon' then
|
||||
module.RELATION_TYPES[k] = module.relation_as_multipolygon
|
||||
elseif v == 'multiline' then
|
||||
module.RELATION_TYPES[k] = module.relation_as_multiline
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function module.get_taginfo()
|
||||
return {main = MAIN_KEYS, name = NAMES, address = ADDRESS_TAGS}
|
||||
end
|
||||
|
||||
return module
|
||||
380
lib-lua/themes/nominatim/presets.lua
Normal file
380
lib-lua/themes/nominatim/presets.lua
Normal file
@@ -0,0 +1,380 @@
|
||||
-- Defines defaults used in the topic definitions.
|
||||
|
||||
local module = {}
|
||||
|
||||
-- Helper functions
|
||||
|
||||
local function group_merge(group1, group2)
|
||||
for name, values in pairs(group2) do
|
||||
if group1[name] == nil then
|
||||
group1[name] = values
|
||||
else
|
||||
for _, v in pairs(values) do
|
||||
table.insert(group1[name], v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return group1
|
||||
end
|
||||
|
||||
-- Customized main tag filter functions
|
||||
|
||||
local EXCLUDED_FOOTWAYS = { sidewalk = 1, crossing = 1, link = 1, traffic_aisle }
|
||||
|
||||
local function filter_footways(place)
|
||||
if place.has_name then
|
||||
local footway = place.object.tags.footway
|
||||
if footway == nil or EXCLUDED_FOOTWAYS[footway] ~= 1 then
|
||||
return place
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function include_when_tag_present(key, value, named)
|
||||
if named then
|
||||
return function(place)
|
||||
if place.has_name and place.intags[key] == value then
|
||||
return place
|
||||
end
|
||||
return false
|
||||
end
|
||||
else
|
||||
return function(place)
|
||||
if place.intags[key] == value then
|
||||
return place
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function exclude_when_key_present(key, named)
|
||||
if named then
|
||||
return function(place)
|
||||
if place.has_name and place.intags[key] == nil then
|
||||
return place
|
||||
end
|
||||
return false
|
||||
end
|
||||
else
|
||||
return function(place)
|
||||
if place.intags[key] == nil then
|
||||
return place
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
local function lock_transform(place)
|
||||
if place.object.tags.waterway ~= nil then
|
||||
local name = place.object.tags.lock_name
|
||||
if name ~= nil then
|
||||
return place:clone{names={name=name, ref=place.object.tags.lock_ref}}
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
-- Main tag definition
|
||||
|
||||
module.MAIN_TAGS = {}
|
||||
|
||||
module.MAIN_TAGS.admin = {
|
||||
boundary = {administrative = 'named'},
|
||||
landuse = {residential = 'fallback',
|
||||
farm = 'fallback',
|
||||
farmyard = 'fallback',
|
||||
industrial = 'fallback',
|
||||
commercial = 'fallback',
|
||||
allotments = 'fallback',
|
||||
retail = 'fallback'},
|
||||
place = {county = 'always',
|
||||
district = 'always',
|
||||
municipality = 'always',
|
||||
city = 'always',
|
||||
town = 'always',
|
||||
borough = 'always',
|
||||
village = 'always',
|
||||
suburb = 'always',
|
||||
hamlet = 'always',
|
||||
croft = 'always',
|
||||
subdivision = 'always',
|
||||
allotments = 'always',
|
||||
neighbourhood = 'always',
|
||||
quarter = 'always',
|
||||
isolated_dwelling = 'always',
|
||||
farm = 'always',
|
||||
city_block = 'always',
|
||||
locality = 'always'}
|
||||
}
|
||||
|
||||
module.MAIN_TAGS.all_boundaries = {
|
||||
boundary = {'named',
|
||||
place = 'delete',
|
||||
land_area = 'delete',
|
||||
postal_code = 'always'},
|
||||
landuse = 'fallback',
|
||||
place = 'always'
|
||||
}
|
||||
|
||||
module.MAIN_TAGS.natural = {
|
||||
waterway = {'named',
|
||||
riverbank = 'delete'},
|
||||
natural = {'named',
|
||||
yes = 'delete',
|
||||
no = 'delete',
|
||||
coastline = 'delete',
|
||||
saddle = 'fallback',
|
||||
water = exclude_when_key_present('water', true)},
|
||||
mountain_pass = {'always',
|
||||
no = 'delete'},
|
||||
water = {include_when_tag_present('natural', 'water', true),
|
||||
river = 'never',
|
||||
stream = 'never',
|
||||
canal = 'never',
|
||||
ditch = 'never',
|
||||
drain = 'never',
|
||||
fish_pass = 'never',
|
||||
yes = 'delete',
|
||||
intermittent = 'delete',
|
||||
tidal = 'delete'
|
||||
}
|
||||
}
|
||||
|
||||
module.MAIN_TAGS_POIS = function (group)
|
||||
group = group or 'delete'
|
||||
return {
|
||||
aerialway = {'always',
|
||||
no = group,
|
||||
pylon = group},
|
||||
aeroway = {'always',
|
||||
no = group},
|
||||
amenity = {'always',
|
||||
no = group,
|
||||
parking_space = group,
|
||||
parking_entrance = group,
|
||||
waste_disposal = group,
|
||||
hunting_stand = group},
|
||||
building = {'fallback',
|
||||
no = group},
|
||||
bridge = {'named_with_key',
|
||||
no = group},
|
||||
club = {'always',
|
||||
no = group},
|
||||
craft = {'always',
|
||||
no = group},
|
||||
emergency = {'always',
|
||||
no = group,
|
||||
yes = group,
|
||||
fire_hydrant = group},
|
||||
healthcare = {'fallback',
|
||||
yes = group,
|
||||
no = group},
|
||||
highway = {'always',
|
||||
no = group,
|
||||
turning_circle = group,
|
||||
mini_roundabout = group,
|
||||
noexit = group,
|
||||
crossing = group,
|
||||
give_way = group,
|
||||
stop = group,
|
||||
turning_loop = group,
|
||||
passing_place = group,
|
||||
street_lamp = 'named',
|
||||
traffic_signals = 'named'},
|
||||
historic = {'always',
|
||||
yes = group,
|
||||
no = group},
|
||||
information = {include_when_tag_present('tourism', 'information'),
|
||||
yes = 'delete',
|
||||
route_marker = 'never',
|
||||
trail_blaze = 'never'},
|
||||
junction = {'fallback',
|
||||
no = group},
|
||||
leisure = {'always',
|
||||
nature_reserve = 'fallback',
|
||||
swimming_pool = 'named',
|
||||
no = group},
|
||||
lock = {yes = lock_transform},
|
||||
man_made = {pier = 'always',
|
||||
tower = 'always',
|
||||
bridge = 'always',
|
||||
works = 'named',
|
||||
water_tower = 'always',
|
||||
dyke = 'named',
|
||||
adit = 'named',
|
||||
lighthouse = 'always',
|
||||
watermill = 'always',
|
||||
tunnel = 'always'},
|
||||
military = {'always',
|
||||
yes = group,
|
||||
no = group},
|
||||
office = {'always',
|
||||
no = group},
|
||||
railway = {'named',
|
||||
rail = group,
|
||||
no = group,
|
||||
abandoned = group,
|
||||
disused = group,
|
||||
razed = group,
|
||||
level_crossing = group,
|
||||
switch = group,
|
||||
signal = group,
|
||||
buffer_stop = group},
|
||||
shop = {'always',
|
||||
no = group},
|
||||
tourism = {'always',
|
||||
no = group,
|
||||
yes = group,
|
||||
information = exclude_when_key_present('information')},
|
||||
tunnel = {'named_with_key',
|
||||
no = group}
|
||||
} end
|
||||
|
||||
module.MAIN_TAGS_STREETS = {}
|
||||
|
||||
module.MAIN_TAGS_STREETS.default = {
|
||||
place = {square = 'always'},
|
||||
highway = {motorway = 'always',
|
||||
trunk = 'always',
|
||||
primary = 'always',
|
||||
secondary = 'always',
|
||||
tertiary = 'always',
|
||||
unclassified = 'always',
|
||||
residential = 'always',
|
||||
road = 'always',
|
||||
living_street = 'always',
|
||||
pedestrian = 'always',
|
||||
service = 'named',
|
||||
cycleway = 'named',
|
||||
path = 'named',
|
||||
footway = filter_footways,
|
||||
steps = 'named',
|
||||
bridleway = 'named',
|
||||
track = 'named',
|
||||
motorway_link = 'named',
|
||||
trunk_link = 'named',
|
||||
primary_link = 'named',
|
||||
secondary_link = 'named',
|
||||
tertiary_link = 'named'}
|
||||
}
|
||||
|
||||
module.MAIN_TAGS_STREETS.car = {
|
||||
place = {square = 'always'},
|
||||
highway = {motorway = 'always',
|
||||
trunk = 'always',
|
||||
primary = 'always',
|
||||
secondary = 'always',
|
||||
tertiary = 'always',
|
||||
unclassified = 'always',
|
||||
residential = 'always',
|
||||
road = 'always',
|
||||
living_street = 'always',
|
||||
service = 'always',
|
||||
track = 'always',
|
||||
motorway_link = 'always',
|
||||
trunk_link = 'always',
|
||||
primary_link = 'always',
|
||||
secondary_link = 'always',
|
||||
tertiary_link = 'always'}
|
||||
}
|
||||
|
||||
module.MAIN_TAGS_STREETS.all = {
|
||||
place = {square = 'always'},
|
||||
highway = {motorway = 'always',
|
||||
trunk = 'always',
|
||||
primary = 'always',
|
||||
secondary = 'always',
|
||||
tertiary = 'always',
|
||||
unclassified = 'always',
|
||||
residential = 'always',
|
||||
road = 'always',
|
||||
living_street = 'always',
|
||||
pedestrian = 'always',
|
||||
service = 'always',
|
||||
cycleway = 'always',
|
||||
path = 'always',
|
||||
footway = 'always',
|
||||
steps = 'always',
|
||||
bridleway = 'always',
|
||||
track = 'always',
|
||||
motorway_link = 'always',
|
||||
trunk_link = 'always',
|
||||
primary_link = 'always',
|
||||
secondary_link = 'always',
|
||||
tertiary_link = 'always'}
|
||||
}
|
||||
|
||||
|
||||
-- name tags
|
||||
|
||||
module.NAME_TAGS = {}
|
||||
|
||||
module.NAME_TAGS.core = {main = {'name', 'name:*',
|
||||
'int_name', 'int_name:*',
|
||||
'nat_name', 'nat_name:*',
|
||||
'reg_name', 'reg_name:*',
|
||||
'loc_name', 'loc_name:*',
|
||||
'old_name', 'old_name:*',
|
||||
'alt_name', 'alt_name:*', 'alt_name_*',
|
||||
'official_name', 'official_name:*',
|
||||
'place_name', 'place_name:*',
|
||||
'short_name', 'short_name:*'},
|
||||
extra = {'ref', 'int_ref', 'nat_ref', 'reg_ref',
|
||||
'loc_ref', 'old_ref', 'ISO3166-2'}
|
||||
}
|
||||
module.NAME_TAGS.address = {house = {'addr:housename'}}
|
||||
module.NAME_TAGS.poi = group_merge({main = {'brand'},
|
||||
extra = {'iata', 'icao'}},
|
||||
module.NAME_TAGS.core)
|
||||
|
||||
-- Address tagging
|
||||
|
||||
module.ADDRESS_TAGS = {}
|
||||
|
||||
module.ADDRESS_TAGS.core = { extra = {'addr:*', 'is_in:*', 'tiger:county'},
|
||||
postcode = {'postal_code', 'postcode', 'addr:postcode',
|
||||
'tiger:zip_left', 'tiger:zip_right'},
|
||||
country = {'country_code', 'ISO3166-1',
|
||||
'addr:country_code', 'is_in:country_code',
|
||||
'addr:country', 'is_in:country'}
|
||||
}
|
||||
|
||||
module.ADDRESS_TAGS.houses = { main = {'addr:housenumber',
|
||||
'addr:conscriptionnumber',
|
||||
'addr:streetnumber'},
|
||||
interpolation = {'addr:interpolation'}
|
||||
}
|
||||
|
||||
-- Ignored tags (prefiltered away)
|
||||
|
||||
module.IGNORE_KEYS = {}
|
||||
|
||||
module.IGNORE_KEYS.metatags = {'note', 'note:*', 'source', 'source:*', '*source',
|
||||
'attribution', 'comment', 'fixme', 'created_by',
|
||||
'tiger:cfcc', 'tiger:reviewed', 'nysgissam:*',
|
||||
'NHD:*', 'nhd:*', 'gnis:*', 'geobase:*', 'yh:*',
|
||||
'osak:*', 'naptan:*', 'CLC:*', 'import', 'it:fvg:*',
|
||||
'lacounty:*', 'ref:linz:*',
|
||||
'ref:bygningsnr', 'ref:ruian:*', 'building:ruian:type',
|
||||
'type',
|
||||
'is_in:postcode'}
|
||||
module.IGNORE_KEYS.name = {'*:prefix', '*:suffix', 'name:prefix:*', 'name:suffix:*',
|
||||
'name:etymology', 'name:etymology:*',
|
||||
'name:signed', 'name:botanical'}
|
||||
module.IGNORE_KEYS.address = {'addr:street:*', 'addr:city:*', 'addr:district:*',
|
||||
'addr:province:*', 'addr:subdistrict:*', 'addr:place:*',
|
||||
'addr:TW:dataset'}
|
||||
|
||||
-- Extra tags (prefiltered away)
|
||||
|
||||
module.EXTRATAGS = {}
|
||||
|
||||
module.EXTRATAGS.required = {'wikipedia', 'wikipedia:*', 'wikidata', 'capital'}
|
||||
|
||||
return module
|
||||
23
lib-lua/themes/nominatim/topics/address.lua
Normal file
23
lib-lua/themes/nominatim/topics/address.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
local _, flex, cfg = ...
|
||||
|
||||
flex.set_main_tags('admin')
|
||||
flex.modify_main_tags('street/' .. (cfg.street_theme or 'default'))
|
||||
flex.modify_main_tags{boundary = {postal_code = 'always'}}
|
||||
|
||||
flex.set_name_tags('core')
|
||||
flex.modify_name_tags('address')
|
||||
|
||||
flex.set_address_tags('core')
|
||||
flex.modify_address_tags('houses')
|
||||
|
||||
flex.ignore_keys('metatags')
|
||||
flex.add_for_extratags('required')
|
||||
|
||||
if cfg.with_extratags then
|
||||
flex.set_unused_handling{delete_keys = {'tiger:*'}}
|
||||
flex.add_for_extratags('name')
|
||||
flex.add_for_extratags('address')
|
||||
else
|
||||
flex.ignore_keys('name')
|
||||
flex.ignore_keys('address')
|
||||
end
|
||||
20
lib-lua/themes/nominatim/topics/admin.lua
Normal file
20
lib-lua/themes/nominatim/topics/admin.lua
Normal file
@@ -0,0 +1,20 @@
|
||||
local _, flex, cfg = ...
|
||||
|
||||
flex.set_main_tags('admin')
|
||||
|
||||
flex.set_name_tags('core')
|
||||
|
||||
flex.set_address_tags('core')
|
||||
flex.set_postcode_fallback(false)
|
||||
|
||||
flex.ignore_keys('metatags')
|
||||
flex.add_for_extratags('required')
|
||||
|
||||
if cfg.with_extratags then
|
||||
flex.set_unused_handling{delete_keys = {'tiger:*'}}
|
||||
flex.add_for_extratags('name')
|
||||
flex.add_for_extratags('address')
|
||||
else
|
||||
flex.ignore_keys('name')
|
||||
flex.ignore_keys('address')
|
||||
end
|
||||
32
lib-lua/themes/nominatim/topics/full.lua
Normal file
32
lib-lua/themes/nominatim/topics/full.lua
Normal file
@@ -0,0 +1,32 @@
|
||||
local _, flex, cfg = ...
|
||||
|
||||
local group
|
||||
if cfg.with_extratags then
|
||||
group = 'extra'
|
||||
else
|
||||
group = 'delete'
|
||||
end
|
||||
|
||||
flex.set_main_tags('all_boundaries')
|
||||
flex.modify_main_tags('natural')
|
||||
flex.modify_main_tags('street/' .. (cfg.street_theme or 'default'))
|
||||
flex.modify_main_tags('poi/' .. group)
|
||||
|
||||
flex.set_name_tags('core')
|
||||
flex.modify_name_tags('address')
|
||||
flex.modify_name_tags('poi')
|
||||
|
||||
flex.set_address_tags('core')
|
||||
flex.modify_address_tags('houses')
|
||||
|
||||
flex.ignore_keys('metatags')
|
||||
flex.add_for_extratags('required')
|
||||
|
||||
if cfg.with_extratags then
|
||||
flex.set_unused_handling{delete_keys = {'tiger:*'}}
|
||||
flex.add_for_extratags('name')
|
||||
flex.add_for_extratags('address')
|
||||
else
|
||||
flex.ignore_keys('name')
|
||||
flex.ignore_keys('address')
|
||||
end
|
||||
22
lib-lua/themes/nominatim/topics/street.lua
Normal file
22
lib-lua/themes/nominatim/topics/street.lua
Normal file
@@ -0,0 +1,22 @@
|
||||
local _, flex, cfg = ...
|
||||
|
||||
flex.set_main_tags('admin')
|
||||
flex.modify_main_tags('street/' .. (cfg.street_theme or 'default'))
|
||||
flex.modify_main_tags{boundary = {postal_code = 'always'}}
|
||||
|
||||
flex.set_name_tags('core')
|
||||
|
||||
flex.set_address_tags('core')
|
||||
flex.set_postcode_fallback(false)
|
||||
|
||||
flex.ignore_keys('metatags')
|
||||
flex.add_for_extratags('required')
|
||||
|
||||
if cfg.with_extratags then
|
||||
flex.set_unused_handling{delete_keys = {'tiger:*'}}
|
||||
flex.add_for_extratags('name')
|
||||
flex.add_for_extratags('address')
|
||||
else
|
||||
flex.ignore_keys('name')
|
||||
flex.ignore_keys('address')
|
||||
end
|
||||
@@ -1,191 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* This file is part of Nominatim. (https://nominatim.org)
|
||||
*
|
||||
* Copyright (C) 2022 by the Nominatim developer community.
|
||||
* For a full list of authors see the git log.
|
||||
*/
|
||||
|
||||
namespace Nominatim;
|
||||
|
||||
require_once(CONST_LibDir.'/ClassTypes.php');
|
||||
|
||||
/**
|
||||
* Detailed list of address parts for a single result
|
||||
*/
|
||||
class AddressDetails
|
||||
{
|
||||
private $iPlaceID;
|
||||
private $aAddressLines;
|
||||
|
||||
public function __construct(&$oDB, $iPlaceID, $sHousenumber, $mLangPref)
|
||||
{
|
||||
$this->iPlaceID = $iPlaceID;
|
||||
|
||||
if (is_array($mLangPref)) {
|
||||
$mLangPref = $oDB->getArraySQL($oDB->getDBQuotedList($mLangPref));
|
||||
}
|
||||
|
||||
if (!isset($sHousenumber)) {
|
||||
$sHousenumber = -1;
|
||||
}
|
||||
|
||||
$sSQL = 'SELECT *,';
|
||||
$sSQL .= ' get_name_by_language(name,'.$mLangPref.') as localname';
|
||||
$sSQL .= ' FROM get_addressdata('.$iPlaceID.','.$sHousenumber.')';
|
||||
$sSQL .= ' ORDER BY rank_address DESC, isaddress DESC';
|
||||
|
||||
$this->aAddressLines = $oDB->getAll($sSQL);
|
||||
}
|
||||
|
||||
private static function isAddress($aLine)
|
||||
{
|
||||
return $aLine['isaddress'] || $aLine['type'] == 'country_code';
|
||||
}
|
||||
|
||||
public function getAddressDetails($bAll = false)
|
||||
{
|
||||
if ($bAll) {
|
||||
return $this->aAddressLines;
|
||||
}
|
||||
|
||||
return array_filter($this->aAddressLines, array(__CLASS__, 'isAddress'));
|
||||
}
|
||||
|
||||
public function getLocaleAddress()
|
||||
{
|
||||
$aParts = array();
|
||||
$sPrevResult = '';
|
||||
|
||||
foreach ($this->aAddressLines as $aLine) {
|
||||
if ($aLine['isaddress'] && $sPrevResult != $aLine['localname']) {
|
||||
$sPrevResult = $aLine['localname'];
|
||||
$aParts[] = $sPrevResult;
|
||||
}
|
||||
}
|
||||
|
||||
return join(', ', $aParts);
|
||||
}
|
||||
|
||||
public function getAddressNames()
|
||||
{
|
||||
$aAddress = array();
|
||||
|
||||
foreach ($this->aAddressLines as $aLine) {
|
||||
if (!self::isAddress($aLine)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$sTypeLabel = ClassTypes\getLabelTag($aLine);
|
||||
|
||||
$sName = null;
|
||||
if (isset($aLine['localname']) && $aLine['localname']!=='') {
|
||||
$sName = $aLine['localname'];
|
||||
} elseif (isset($aLine['housenumber']) && $aLine['housenumber']!=='') {
|
||||
$sName = $aLine['housenumber'];
|
||||
}
|
||||
|
||||
if (isset($sName)
|
||||
&& (!isset($aAddress[$sTypeLabel])
|
||||
|| $aLine['class'] == 'place')
|
||||
) {
|
||||
$aAddress[$sTypeLabel] = $sName;
|
||||
|
||||
if (!empty($aLine['name'])) {
|
||||
$this->addSubdivisionCode($aAddress, $aLine['admin_level'], $aLine['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $aAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotates the given json with geocodejson address information fields.
|
||||
*
|
||||
* @param array $aJson Json hash to add the fields to.
|
||||
*
|
||||
* Geocodejson has the following fields:
|
||||
* street, locality, postcode, city, district,
|
||||
* county, state, country
|
||||
*
|
||||
* Postcode and housenumber are added by type, district is not used.
|
||||
* All other fields are set according to address rank.
|
||||
*/
|
||||
public function addGeocodeJsonAddressParts(&$aJson)
|
||||
{
|
||||
foreach (array_reverse($this->aAddressLines) as $aLine) {
|
||||
if (!$aLine['isaddress']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($aLine['localname']) || $aLine['localname'] == '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($aLine['type'] == 'postcode' || $aLine['type'] == 'postal_code') {
|
||||
$aJson['postcode'] = $aLine['localname'];
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($aLine['type'] == 'house_number') {
|
||||
$aJson['housenumber'] = $aLine['localname'];
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->iPlaceID == $aLine['place_id']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$iRank = (int)$aLine['rank_address'];
|
||||
|
||||
if ($iRank > 25 && $iRank < 28) {
|
||||
$aJson['street'] = $aLine['localname'];
|
||||
} elseif ($iRank >= 22 && $iRank <= 25) {
|
||||
$aJson['locality'] = $aLine['localname'];
|
||||
} elseif ($iRank >= 17 && $iRank <= 21) {
|
||||
$aJson['district'] = $aLine['localname'];
|
||||
} elseif ($iRank >= 13 && $iRank <= 16) {
|
||||
$aJson['city'] = $aLine['localname'];
|
||||
} elseif ($iRank >= 10 && $iRank <= 12) {
|
||||
$aJson['county'] = $aLine['localname'];
|
||||
} elseif ($iRank >= 5 && $iRank <= 9) {
|
||||
$aJson['state'] = $aLine['localname'];
|
||||
} elseif ($iRank == 4) {
|
||||
$aJson['country'] = $aLine['localname'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getAdminLevels()
|
||||
{
|
||||
$aAddress = array();
|
||||
foreach (array_reverse($this->aAddressLines) as $aLine) {
|
||||
if (self::isAddress($aLine)
|
||||
&& isset($aLine['admin_level'])
|
||||
&& $aLine['admin_level'] < 15
|
||||
&& !isset($aAddress['level'.$aLine['admin_level']])
|
||||
) {
|
||||
$aAddress['level'.$aLine['admin_level']] = $aLine['localname'];
|
||||
}
|
||||
}
|
||||
return $aAddress;
|
||||
}
|
||||
|
||||
public function debugInfo()
|
||||
{
|
||||
return $this->aAddressLines;
|
||||
}
|
||||
|
||||
private function addSubdivisionCode(&$aAddress, $iAdminLevel, $nameDetails)
|
||||
{
|
||||
if (is_string($nameDetails)) {
|
||||
$nameDetails = json_decode('{' . str_replace('"=>"', '":"', $nameDetails) . '}', true);
|
||||
}
|
||||
if (!empty($nameDetails['ISO3166-2'])) {
|
||||
$aAddress["ISO3166-2-lvl$iAdminLevel"] = $nameDetails['ISO3166-2'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,576 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* This file is part of Nominatim. (https://nominatim.org)
|
||||
*
|
||||
* Copyright (C) 2022 by the Nominatim developer community.
|
||||
* For a full list of authors see the git log.
|
||||
*/
|
||||
|
||||
namespace Nominatim\ClassTypes;
|
||||
|
||||
/**
|
||||
* Create a label tag for the given place that can be used as an XML name.
|
||||
*
|
||||
* @param array[] $aPlace Information about the place to label.
|
||||
*
|
||||
* A label tag groups various object types together under a common
|
||||
* label. The returned value is lower case and has no spaces
|
||||
*/
|
||||
function getLabelTag($aPlace, $sCountry = null)
|
||||
{
|
||||
$iRank = (int) ($aPlace['rank_address'] ?? 30);
|
||||
$sLabel;
|
||||
if (isset($aPlace['place_type'])) {
|
||||
$sLabel = $aPlace['place_type'];
|
||||
} elseif ($aPlace['class'] == 'boundary' && $aPlace['type'] == 'administrative') {
|
||||
$sLabel = getBoundaryLabel($iRank/2, $sCountry);
|
||||
} elseif ($aPlace['type'] == 'postal_code') {
|
||||
$sLabel = 'postcode';
|
||||
} elseif ($iRank < 26) {
|
||||
$sLabel = $aPlace['type'];
|
||||
} elseif ($iRank < 28) {
|
||||
$sLabel = 'road';
|
||||
} elseif ($aPlace['class'] == 'place'
|
||||
&& ($aPlace['type'] == 'house_number' ||
|
||||
$aPlace['type'] == 'house_name' ||
|
||||
$aPlace['type'] == 'country_code')
|
||||
) {
|
||||
$sLabel = $aPlace['type'];
|
||||
} else {
|
||||
$sLabel = $aPlace['class'];
|
||||
}
|
||||
|
||||
return strtolower(str_replace(' ', '_', $sLabel));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a label for the given place.
|
||||
*
|
||||
* @param array[] $aPlace Information about the place to label.
|
||||
*/
|
||||
function getLabel($aPlace, $sCountry = null)
|
||||
{
|
||||
if (isset($aPlace['place_type'])) {
|
||||
return ucwords(str_replace('_', ' ', $aPlace['place_type']));
|
||||
}
|
||||
|
||||
if ($aPlace['class'] == 'boundary' && $aPlace['type'] == 'administrative') {
|
||||
return getBoundaryLabel(($aPlace['rank_address'] ?? 30)/2, $sCountry ?? null);
|
||||
}
|
||||
|
||||
// Return a label only for 'important' class/type combinations
|
||||
if (getImportance($aPlace) !== null) {
|
||||
return ucwords(str_replace('_', ' ', $aPlace['type']));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a simple label for an administrative boundary for the given country.
|
||||
*
|
||||
* @param int $iAdminLevel Content of admin_level tag.
|
||||
* @param string $sCountry Country code of the country where the object is
|
||||
* in. May be null, in which case a world-wide
|
||||
* fallback is used.
|
||||
* @param string $sFallback String to return if no explicit string is listed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getBoundaryLabel($iAdminLevel, $sCountry, $sFallback = 'Administrative')
|
||||
{
|
||||
static $aBoundaryList = array (
|
||||
'default' => array (
|
||||
1 => 'Continent',
|
||||
2 => 'Country',
|
||||
3 => 'Region',
|
||||
4 => 'State',
|
||||
5 => 'State District',
|
||||
6 => 'County',
|
||||
7 => 'Municipality',
|
||||
8 => 'City',
|
||||
9 => 'City District',
|
||||
10 => 'Suburb',
|
||||
11 => 'Neighbourhood',
|
||||
12 => 'City Block'
|
||||
),
|
||||
'no' => array (
|
||||
3 => 'State',
|
||||
4 => 'County'
|
||||
),
|
||||
'se' => array (
|
||||
3 => 'State',
|
||||
4 => 'County'
|
||||
)
|
||||
);
|
||||
|
||||
if (isset($aBoundaryList[$sCountry])
|
||||
&& isset($aBoundaryList[$sCountry][$iAdminLevel])
|
||||
) {
|
||||
return $aBoundaryList[$sCountry][$iAdminLevel];
|
||||
}
|
||||
|
||||
return $aBoundaryList['default'][$iAdminLevel] ?? $sFallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an estimated radius of how far the object node extends.
|
||||
*
|
||||
* @param array[] $aPlace Information about the place. This must be a node
|
||||
* feature.
|
||||
*
|
||||
* @return float The radius around the feature in degrees.
|
||||
*/
|
||||
function getDefRadius($aPlace)
|
||||
{
|
||||
$aSpecialRadius = array(
|
||||
'place:continent' => 25,
|
||||
'place:country' => 7,
|
||||
'place:state' => 2.6,
|
||||
'place:province' => 2.6,
|
||||
'place:region' => 1.0,
|
||||
'place:county' => 0.7,
|
||||
'place:city' => 0.16,
|
||||
'place:municipality' => 0.16,
|
||||
'place:island' => 0.32,
|
||||
'place:postcode' => 0.16,
|
||||
'place:town' => 0.04,
|
||||
'place:village' => 0.02,
|
||||
'place:hamlet' => 0.02,
|
||||
'place:district' => 0.02,
|
||||
'place:borough' => 0.02,
|
||||
'place:suburb' => 0.02,
|
||||
'place:locality' => 0.01,
|
||||
'place:neighbourhood'=> 0.01,
|
||||
'place:quarter' => 0.01,
|
||||
'place:city_block' => 0.01,
|
||||
'landuse:farm' => 0.01,
|
||||
'place:farm' => 0.01,
|
||||
'place:airport' => 0.015,
|
||||
'aeroway:aerodrome' => 0.015,
|
||||
'railway:station' => 0.005
|
||||
);
|
||||
|
||||
$sClassPlace = $aPlace['class'].':'.$aPlace['type'];
|
||||
|
||||
return $aSpecialRadius[$sClassPlace] ?? 0.00005;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the icon to use with the given object.
|
||||
*/
|
||||
function getIcon($aPlace)
|
||||
{
|
||||
$aIcons = array(
|
||||
'boundary:administrative' => 'poi_boundary_administrative',
|
||||
'place:city' => 'poi_place_city',
|
||||
'place:town' => 'poi_place_town',
|
||||
'place:village' => 'poi_place_village',
|
||||
'place:hamlet' => 'poi_place_village',
|
||||
'place:suburb' => 'poi_place_village',
|
||||
'place:locality' => 'poi_place_village',
|
||||
'place:airport' => 'transport_airport2',
|
||||
'aeroway:aerodrome' => 'transport_airport2',
|
||||
'railway:station' => 'transport_train_station2',
|
||||
'amenity:place_of_worship' => 'place_of_worship_unknown3',
|
||||
'amenity:pub' => 'food_pub',
|
||||
'amenity:bar' => 'food_bar',
|
||||
'amenity:university' => 'education_university',
|
||||
'tourism:museum' => 'tourist_museum',
|
||||
'amenity:arts_centre' => 'tourist_art_gallery2',
|
||||
'tourism:zoo' => 'tourist_zoo',
|
||||
'tourism:theme_park' => 'poi_point_of_interest',
|
||||
'tourism:attraction' => 'poi_point_of_interest',
|
||||
'leisure:golf_course' => 'sport_golf',
|
||||
'historic:castle' => 'tourist_castle',
|
||||
'amenity:hospital' => 'health_hospital',
|
||||
'amenity:school' => 'education_school',
|
||||
'amenity:theatre' => 'tourist_theatre',
|
||||
'amenity:library' => 'amenity_library',
|
||||
'amenity:fire_station' => 'amenity_firestation3',
|
||||
'amenity:police' => 'amenity_police2',
|
||||
'amenity:bank' => 'money_bank2',
|
||||
'amenity:post_office' => 'amenity_post_office',
|
||||
'tourism:hotel' => 'accommodation_hotel2',
|
||||
'amenity:cinema' => 'tourist_cinema',
|
||||
'tourism:artwork' => 'tourist_art_gallery2',
|
||||
'historic:archaeological_site' => 'tourist_archaeological2',
|
||||
'amenity:doctors' => 'health_doctors',
|
||||
'leisure:sports_centre' => 'sport_leisure_centre',
|
||||
'leisure:swimming_pool' => 'sport_swimming_outdoor',
|
||||
'shop:supermarket' => 'shopping_supermarket',
|
||||
'shop:convenience' => 'shopping_convenience',
|
||||
'amenity:restaurant' => 'food_restaurant',
|
||||
'amenity:fast_food' => 'food_fastfood',
|
||||
'amenity:cafe' => 'food_cafe',
|
||||
'tourism:guest_house' => 'accommodation_bed_and_breakfast',
|
||||
'amenity:pharmacy' => 'health_pharmacy_dispensing',
|
||||
'amenity:fuel' => 'transport_fuel',
|
||||
'natural:peak' => 'poi_peak',
|
||||
'natural:wood' => 'landuse_coniferous_and_deciduous',
|
||||
'shop:bicycle' => 'shopping_bicycle',
|
||||
'shop:clothes' => 'shopping_clothes',
|
||||
'shop:hairdresser' => 'shopping_hairdresser',
|
||||
'shop:doityourself' => 'shopping_diy',
|
||||
'shop:estate_agent' => 'shopping_estateagent2',
|
||||
'shop:car' => 'shopping_car',
|
||||
'shop:garden_centre' => 'shopping_garden_centre',
|
||||
'shop:car_repair' => 'shopping_car_repair',
|
||||
'shop:bakery' => 'shopping_bakery',
|
||||
'shop:butcher' => 'shopping_butcher',
|
||||
'shop:apparel' => 'shopping_clothes',
|
||||
'shop:laundry' => 'shopping_laundrette',
|
||||
'shop:beverages' => 'shopping_alcohol',
|
||||
'shop:alcohol' => 'shopping_alcohol',
|
||||
'shop:optician' => 'health_opticians',
|
||||
'shop:chemist' => 'health_pharmacy',
|
||||
'shop:gallery' => 'tourist_art_gallery2',
|
||||
'shop:jewelry' => 'shopping_jewelry',
|
||||
'tourism:information' => 'amenity_information',
|
||||
'historic:ruins' => 'tourist_ruin',
|
||||
'amenity:college' => 'education_school',
|
||||
'historic:monument' => 'tourist_monument',
|
||||
'historic:memorial' => 'tourist_monument',
|
||||
'historic:mine' => 'poi_mine',
|
||||
'tourism:caravan_site' => 'accommodation_caravan_park',
|
||||
'amenity:bus_station' => 'transport_bus_station',
|
||||
'amenity:atm' => 'money_atm2',
|
||||
'tourism:viewpoint' => 'tourist_view_point',
|
||||
'tourism:guesthouse' => 'accommodation_bed_and_breakfast',
|
||||
'railway:tram' => 'transport_tram_stop',
|
||||
'amenity:courthouse' => 'amenity_court',
|
||||
'amenity:recycling' => 'amenity_recycling',
|
||||
'amenity:dentist' => 'health_dentist',
|
||||
'natural:beach' => 'tourist_beach',
|
||||
'railway:tram_stop' => 'transport_tram_stop',
|
||||
'amenity:prison' => 'amenity_prison',
|
||||
'highway:bus_stop' => 'transport_bus_stop2'
|
||||
);
|
||||
|
||||
$sClassPlace = $aPlace['class'].':'.$aPlace['type'];
|
||||
|
||||
return $aIcons[$sClassPlace] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an icon for the given object with its full URL.
|
||||
*/
|
||||
function getIconFile($aPlace)
|
||||
{
|
||||
if (CONST_MapIcon_URL === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$sIcon = getIcon($aPlace);
|
||||
|
||||
if (!isset($sIcon)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return CONST_MapIcon_URL.'/'.$sIcon.'.p.20.png';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a class importance value for the given place.
|
||||
*
|
||||
* @param array[] $aPlace Information about the place.
|
||||
*
|
||||
* @return int An importance value. The lower the value, the more
|
||||
* important the class.
|
||||
*/
|
||||
function getImportance($aPlace)
|
||||
{
|
||||
static $aWithImportance = null;
|
||||
|
||||
if ($aWithImportance === null) {
|
||||
$aWithImportance = array_flip(array(
|
||||
'boundary:administrative',
|
||||
'place:country',
|
||||
'place:state',
|
||||
'place:province',
|
||||
'place:county',
|
||||
'place:city',
|
||||
'place:region',
|
||||
'place:island',
|
||||
'place:town',
|
||||
'place:village',
|
||||
'place:hamlet',
|
||||
'place:suburb',
|
||||
'place:locality',
|
||||
'landuse:farm',
|
||||
'place:farm',
|
||||
'highway:motorway_junction',
|
||||
'highway:motorway',
|
||||
'highway:trunk',
|
||||
'highway:primary',
|
||||
'highway:secondary',
|
||||
'highway:tertiary',
|
||||
'highway:residential',
|
||||
'highway:unclassified',
|
||||
'highway:living_street',
|
||||
'highway:service',
|
||||
'highway:track',
|
||||
'highway:road',
|
||||
'highway:byway',
|
||||
'highway:bridleway',
|
||||
'highway:cycleway',
|
||||
'highway:pedestrian',
|
||||
'highway:footway',
|
||||
'highway:steps',
|
||||
'highway:motorway_link',
|
||||
'highway:trunk_link',
|
||||
'highway:primary_link',
|
||||
'landuse:industrial',
|
||||
'landuse:residential',
|
||||
'landuse:retail',
|
||||
'landuse:commercial',
|
||||
'place:airport',
|
||||
'aeroway:aerodrome',
|
||||
'railway:station',
|
||||
'amenity:place_of_worship',
|
||||
'amenity:pub',
|
||||
'amenity:bar',
|
||||
'amenity:university',
|
||||
'tourism:museum',
|
||||
'amenity:arts_centre',
|
||||
'tourism:zoo',
|
||||
'tourism:theme_park',
|
||||
'tourism:attraction',
|
||||
'leisure:golf_course',
|
||||
'historic:castle',
|
||||
'amenity:hospital',
|
||||
'amenity:school',
|
||||
'amenity:theatre',
|
||||
'amenity:public_building',
|
||||
'amenity:library',
|
||||
'amenity:townhall',
|
||||
'amenity:community_centre',
|
||||
'amenity:fire_station',
|
||||
'amenity:police',
|
||||
'amenity:bank',
|
||||
'amenity:post_office',
|
||||
'leisure:park',
|
||||
'amenity:park',
|
||||
'landuse:park',
|
||||
'landuse:recreation_ground',
|
||||
'tourism:hotel',
|
||||
'tourism:motel',
|
||||
'amenity:cinema',
|
||||
'tourism:artwork',
|
||||
'historic:archaeological_site',
|
||||
'amenity:doctors',
|
||||
'leisure:sports_centre',
|
||||
'leisure:swimming_pool',
|
||||
'shop:supermarket',
|
||||
'shop:convenience',
|
||||
'amenity:restaurant',
|
||||
'amenity:fast_food',
|
||||
'amenity:cafe',
|
||||
'tourism:guest_house',
|
||||
'amenity:pharmacy',
|
||||
'amenity:fuel',
|
||||
'natural:peak',
|
||||
'waterway:waterfall',
|
||||
'natural:wood',
|
||||
'natural:water',
|
||||
'landuse:forest',
|
||||
'landuse:cemetery',
|
||||
'landuse:allotments',
|
||||
'landuse:farmyard',
|
||||
'railway:rail',
|
||||
'waterway:canal',
|
||||
'waterway:river',
|
||||
'waterway:stream',
|
||||
'shop:bicycle',
|
||||
'shop:clothes',
|
||||
'shop:hairdresser',
|
||||
'shop:doityourself',
|
||||
'shop:estate_agent',
|
||||
'shop:car',
|
||||
'shop:garden_centre',
|
||||
'shop:car_repair',
|
||||
'shop:newsagent',
|
||||
'shop:bakery',
|
||||
'shop:furniture',
|
||||
'shop:butcher',
|
||||
'shop:apparel',
|
||||
'shop:electronics',
|
||||
'shop:department_store',
|
||||
'shop:books',
|
||||
'shop:yes',
|
||||
'shop:outdoor',
|
||||
'shop:mall',
|
||||
'shop:florist',
|
||||
'shop:charity',
|
||||
'shop:hardware',
|
||||
'shop:laundry',
|
||||
'shop:shoes',
|
||||
'shop:beverages',
|
||||
'shop:dry_cleaning',
|
||||
'shop:carpet',
|
||||
'shop:computer',
|
||||
'shop:alcohol',
|
||||
'shop:optician',
|
||||
'shop:chemist',
|
||||
'shop:gallery',
|
||||
'shop:mobile_phone',
|
||||
'shop:sports',
|
||||
'shop:jewelry',
|
||||
'shop:pet',
|
||||
'shop:beauty',
|
||||
'shop:stationery',
|
||||
'shop:shopping_centre',
|
||||
'shop:general',
|
||||
'shop:electrical',
|
||||
'shop:toys',
|
||||
'shop:jeweller',
|
||||
'shop:betting',
|
||||
'shop:household',
|
||||
'shop:travel_agency',
|
||||
'shop:hifi',
|
||||
'amenity:shop',
|
||||
'tourism:information',
|
||||
'place:house',
|
||||
'place:house_name',
|
||||
'place:house_number',
|
||||
'place:country_code',
|
||||
'leisure:pitch',
|
||||
'highway:unsurfaced',
|
||||
'historic:ruins',
|
||||
'amenity:college',
|
||||
'historic:monument',
|
||||
'railway:subway',
|
||||
'historic:memorial',
|
||||
'leisure:nature_reserve',
|
||||
'leisure:common',
|
||||
'waterway:lock_gate',
|
||||
'natural:fell',
|
||||
'amenity:nightclub',
|
||||
'highway:path',
|
||||
'leisure:garden',
|
||||
'landuse:reservoir',
|
||||
'leisure:playground',
|
||||
'leisure:stadium',
|
||||
'historic:mine',
|
||||
'natural:cliff',
|
||||
'tourism:caravan_site',
|
||||
'amenity:bus_station',
|
||||
'amenity:kindergarten',
|
||||
'highway:construction',
|
||||
'amenity:atm',
|
||||
'amenity:emergency_phone',
|
||||
'waterway:lock',
|
||||
'waterway:riverbank',
|
||||
'natural:coastline',
|
||||
'tourism:viewpoint',
|
||||
'tourism:hostel',
|
||||
'tourism:bed_and_breakfast',
|
||||
'railway:halt',
|
||||
'railway:platform',
|
||||
'railway:tram',
|
||||
'amenity:courthouse',
|
||||
'amenity:recycling',
|
||||
'amenity:dentist',
|
||||
'natural:beach',
|
||||
'place:moor',
|
||||
'amenity:grave_yard',
|
||||
'waterway:drain',
|
||||
'landuse:grass',
|
||||
'landuse:village_green',
|
||||
'natural:bay',
|
||||
'railway:tram_stop',
|
||||
'leisure:marina',
|
||||
'highway:stile',
|
||||
'natural:moor',
|
||||
'railway:light_rail',
|
||||
'railway:narrow_gauge',
|
||||
'natural:land',
|
||||
'amenity:village_hall',
|
||||
'waterway:dock',
|
||||
'amenity:veterinary',
|
||||
'landuse:brownfield',
|
||||
'leisure:track',
|
||||
'railway:historic_station',
|
||||
'landuse:construction',
|
||||
'amenity:prison',
|
||||
'landuse:quarry',
|
||||
'amenity:telephone',
|
||||
'highway:traffic_signals',
|
||||
'natural:heath',
|
||||
'historic:house',
|
||||
'amenity:social_club',
|
||||
'landuse:military',
|
||||
'amenity:health_centre',
|
||||
'historic:building',
|
||||
'amenity:clinic',
|
||||
'highway:services',
|
||||
'amenity:ferry_terminal',
|
||||
'natural:marsh',
|
||||
'natural:hill',
|
||||
'highway:raceway',
|
||||
'amenity:taxi',
|
||||
'amenity:take_away',
|
||||
'amenity:car_rental',
|
||||
'place:islet',
|
||||
'amenity:nursery',
|
||||
'amenity:nursing_home',
|
||||
'amenity:toilets',
|
||||
'amenity:hall',
|
||||
'waterway:boatyard',
|
||||
'highway:mini_roundabout',
|
||||
'historic:manor',
|
||||
'tourism:chalet',
|
||||
'amenity:bicycle_parking',
|
||||
'amenity:hotel',
|
||||
'waterway:weir',
|
||||
'natural:wetland',
|
||||
'natural:cave_entrance',
|
||||
'amenity:crematorium',
|
||||
'tourism:picnic_site',
|
||||
'landuse:wood',
|
||||
'landuse:basin',
|
||||
'natural:tree',
|
||||
'leisure:slipway',
|
||||
'landuse:meadow',
|
||||
'landuse:piste',
|
||||
'amenity:care_home',
|
||||
'amenity:club',
|
||||
'amenity:medical_centre',
|
||||
'historic:roman_road',
|
||||
'historic:fort',
|
||||
'railway:subway_entrance',
|
||||
'historic:yes',
|
||||
'highway:gate',
|
||||
'leisure:fishing',
|
||||
'historic:museum',
|
||||
'amenity:car_wash',
|
||||
'railway:level_crossing',
|
||||
'leisure:bird_hide',
|
||||
'natural:headland',
|
||||
'tourism:apartments',
|
||||
'amenity:shopping',
|
||||
'natural:scrub',
|
||||
'natural:fen',
|
||||
'building:yes',
|
||||
'mountain_pass:yes',
|
||||
'amenity:parking',
|
||||
'highway:bus_stop',
|
||||
'place:postcode',
|
||||
'amenity:post_box',
|
||||
'place:houses',
|
||||
'railway:preserved',
|
||||
'waterway:derelict_canal',
|
||||
'amenity:dead_pub',
|
||||
'railway:disused_station',
|
||||
'railway:abandoned',
|
||||
'railway:disused'
|
||||
));
|
||||
}
|
||||
|
||||
$sClassPlace = $aPlace['class'].':'.$aPlace['type'];
|
||||
|
||||
return $aWithImportance[$sClassPlace] ?? null;
|
||||
}
|
||||
360
lib-php/DB.php
360
lib-php/DB.php
@@ -1,360 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* This file is part of Nominatim. (https://nominatim.org)
|
||||
*
|
||||
* Copyright (C) 2022 by the Nominatim developer community.
|
||||
* For a full list of authors see the git log.
|
||||
*/
|
||||
|
||||
namespace Nominatim;
|
||||
|
||||
require_once(CONST_LibDir.'/DatabaseError.php');
|
||||
|
||||
/**
|
||||
* Uses PDO to access the database specified in the CONST_Database_DSN
|
||||
* setting.
|
||||
*/
|
||||
class DB
|
||||
{
|
||||
protected $connection;
|
||||
|
||||
public function __construct($sDSN = null)
|
||||
{
|
||||
$this->sDSN = $sDSN ?? getSetting('DATABASE_DSN');
|
||||
}
|
||||
|
||||
public function connect($bNew = false, $bPersistent = true)
|
||||
{
|
||||
if (isset($this->connection) && !$bNew) {
|
||||
return true;
|
||||
}
|
||||
$aConnOptions = array(
|
||||
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
|
||||
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
|
||||
\PDO::ATTR_PERSISTENT => $bPersistent
|
||||
);
|
||||
|
||||
// https://secure.php.net/manual/en/ref.pdo-pgsql.connection.php
|
||||
try {
|
||||
$conn = new \PDO($this->sDSN, null, null, $aConnOptions);
|
||||
} catch (\PDOException $e) {
|
||||
$sMsg = 'Failed to establish database connection:' . $e->getMessage();
|
||||
throw new \Nominatim\DatabaseError($sMsg, 500, null, $e->getMessage());
|
||||
}
|
||||
|
||||
$conn->exec("SET DateStyle TO 'sql,european'");
|
||||
$conn->exec("SET client_encoding TO 'utf-8'");
|
||||
// Disable JIT and parallel workers. They interfere badly with search SQL.
|
||||
$conn->exec("UPDATE pg_settings SET setting = -1 WHERE name = 'jit_above_cost'");
|
||||
$conn->exec("UPDATE pg_settings SET setting = 0 WHERE name = 'max_parallel_workers_per_gather'");
|
||||
$iMaxExecution = ini_get('max_execution_time');
|
||||
if ($iMaxExecution > 0) {
|
||||
$conn->setAttribute(\PDO::ATTR_TIMEOUT, $iMaxExecution); // seconds
|
||||
}
|
||||
|
||||
$this->connection = $conn;
|
||||
return true;
|
||||
}
|
||||
|
||||
// returns the number of rows that were modified or deleted by the SQL
|
||||
// statement. If no rows were affected returns 0.
|
||||
public function exec($sSQL, $aInputVars = null, $sErrMessage = 'Database query failed')
|
||||
{
|
||||
$val = null;
|
||||
try {
|
||||
if (isset($aInputVars)) {
|
||||
$stmt = $this->connection->prepare($sSQL);
|
||||
$stmt->execute($aInputVars);
|
||||
} else {
|
||||
$val = $this->connection->exec($sSQL);
|
||||
}
|
||||
} catch (\PDOException $e) {
|
||||
throw new \Nominatim\DatabaseError($sErrMessage, 500, null, $e, $sSQL);
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes query. Returns first row as array.
|
||||
* Returns false if no result found.
|
||||
*
|
||||
* @param string $sSQL
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function getRow($sSQL, $aInputVars = null, $sErrMessage = 'Database query failed')
|
||||
{
|
||||
try {
|
||||
$stmt = $this->getQueryStatement($sSQL, $aInputVars, $sErrMessage);
|
||||
$row = $stmt->fetch();
|
||||
} catch (\PDOException $e) {
|
||||
throw new \Nominatim\DatabaseError($sErrMessage, 500, null, $e, $sSQL);
|
||||
}
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes query. Returns first value of first result.
|
||||
* Returns false if no results found.
|
||||
*
|
||||
* @param string $sSQL
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function getOne($sSQL, $aInputVars = null, $sErrMessage = 'Database query failed')
|
||||
{
|
||||
try {
|
||||
$stmt = $this->getQueryStatement($sSQL, $aInputVars, $sErrMessage);
|
||||
$row = $stmt->fetch(\PDO::FETCH_NUM);
|
||||
if ($row === false) {
|
||||
return false;
|
||||
}
|
||||
} catch (\PDOException $e) {
|
||||
throw new \Nominatim\DatabaseError($sErrMessage, 500, null, $e, $sSQL);
|
||||
}
|
||||
return $row[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes query. Returns array of results (arrays).
|
||||
* Returns empty array if no results found.
|
||||
*
|
||||
* @param string $sSQL
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function getAll($sSQL, $aInputVars = null, $sErrMessage = 'Database query failed')
|
||||
{
|
||||
try {
|
||||
$stmt = $this->getQueryStatement($sSQL, $aInputVars, $sErrMessage);
|
||||
$rows = $stmt->fetchAll();
|
||||
} catch (\PDOException $e) {
|
||||
throw new \Nominatim\DatabaseError($sErrMessage, 500, null, $e, $sSQL);
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes query. Returns array of the first value of each result.
|
||||
* Returns empty array if no results found.
|
||||
*
|
||||
* @param string $sSQL
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function getCol($sSQL, $aInputVars = null, $sErrMessage = 'Database query failed')
|
||||
{
|
||||
$aVals = array();
|
||||
try {
|
||||
$stmt = $this->getQueryStatement($sSQL, $aInputVars, $sErrMessage);
|
||||
|
||||
while (($val = $stmt->fetchColumn(0)) !== false) { // returns first column or false
|
||||
$aVals[] = $val;
|
||||
}
|
||||
} catch (\PDOException $e) {
|
||||
throw new \Nominatim\DatabaseError($sErrMessage, 500, null, $e, $sSQL);
|
||||
}
|
||||
return $aVals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes query. Returns associate array mapping first value to second value of each result.
|
||||
* Returns empty array if no results found.
|
||||
*
|
||||
* @param string $sSQL
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function getAssoc($sSQL, $aInputVars = null, $sErrMessage = 'Database query failed')
|
||||
{
|
||||
try {
|
||||
$stmt = $this->getQueryStatement($sSQL, $aInputVars, $sErrMessage);
|
||||
|
||||
$aList = array();
|
||||
while ($aRow = $stmt->fetch(\PDO::FETCH_NUM)) {
|
||||
$aList[$aRow[0]] = $aRow[1];
|
||||
}
|
||||
} catch (\PDOException $e) {
|
||||
throw new \Nominatim\DatabaseError($sErrMessage, 500, null, $e, $sSQL);
|
||||
}
|
||||
return $aList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes query. Returns a PDO statement to iterate over.
|
||||
*
|
||||
* @param string $sSQL
|
||||
*
|
||||
* @return PDOStatement
|
||||
*/
|
||||
public function getQueryStatement($sSQL, $aInputVars = null, $sErrMessage = 'Database query failed')
|
||||
{
|
||||
try {
|
||||
if (isset($aInputVars)) {
|
||||
$stmt = $this->connection->prepare($sSQL);
|
||||
$stmt->execute($aInputVars);
|
||||
} else {
|
||||
$stmt = $this->connection->query($sSQL);
|
||||
}
|
||||
} catch (\PDOException $e) {
|
||||
throw new \Nominatim\DatabaseError($sErrMessage, 500, null, $e, $sSQL);
|
||||
}
|
||||
return $stmt;
|
||||
}
|
||||
|
||||
/**
|
||||
* St. John's Way => 'St. John\'s Way'
|
||||
*
|
||||
* @param string $sVal Text to be quoted.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDBQuoted($sVal)
|
||||
{
|
||||
return $this->connection->quote($sVal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Like getDBQuoted, but takes an array.
|
||||
*
|
||||
* @param array $aVals List of text to be quoted.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function getDBQuotedList($aVals)
|
||||
{
|
||||
return array_map(function ($sVal) {
|
||||
return $this->getDBQuoted($sVal);
|
||||
}, $aVals);
|
||||
}
|
||||
|
||||
/**
|
||||
* [1,2,'b'] => 'ARRAY[1,2,'b']''
|
||||
*
|
||||
* @param array $aVals List of text to be quoted.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getArraySQL($a)
|
||||
{
|
||||
return 'ARRAY['.join(',', $a).']';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a table exists in the database. Returns true if it does.
|
||||
*
|
||||
* @param string $sTableName
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function tableExists($sTableName)
|
||||
{
|
||||
$sSQL = 'SELECT count(*) FROM pg_tables WHERE tablename = :tablename';
|
||||
return ($this->getOne($sSQL, array(':tablename' => $sTableName)) == 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a table. Returns true if deleted or didn't exist.
|
||||
*
|
||||
* @param string $sTableName
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function deleteTable($sTableName)
|
||||
{
|
||||
return $this->exec('DROP TABLE IF EXISTS '.$sTableName.' CASCADE') == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to connect to the database but on failure doesn't throw an exception.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function checkConnection()
|
||||
{
|
||||
$bExists = true;
|
||||
try {
|
||||
$this->connect(true);
|
||||
} catch (\Nominatim\DatabaseError $e) {
|
||||
$bExists = false;
|
||||
}
|
||||
return $bExists;
|
||||
}
|
||||
|
||||
/**
|
||||
* e.g. 9.6, 10, 11.2
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getPostgresVersion()
|
||||
{
|
||||
$sVersionString = $this->getOne('SHOW server_version_num');
|
||||
preg_match('#([0-9]?[0-9])([0-9][0-9])[0-9][0-9]#', $sVersionString, $aMatches);
|
||||
return (float) ($aMatches[1].'.'.$aMatches[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* e.g. 2, 2.2
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getPostgisVersion()
|
||||
{
|
||||
$sVersionString = $this->getOne('select postgis_lib_version()');
|
||||
preg_match('#^([0-9]+)[.]([0-9]+)[.]#', $sVersionString, $aMatches);
|
||||
return (float) ($aMatches[1].'.'.$aMatches[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an associate array of postgresql database connection settings. Keys can
|
||||
* be 'database', 'hostspec', 'port', 'username', 'password'.
|
||||
* Returns empty array on failure, thus check if at least 'database' is set.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public static function parseDSN($sDSN)
|
||||
{
|
||||
// https://secure.php.net/manual/en/ref.pdo-pgsql.connection.php
|
||||
$aInfo = array();
|
||||
if (preg_match('/^pgsql:(.+)$/', $sDSN, $aMatches)) {
|
||||
foreach (explode(';', $aMatches[1]) as $sKeyVal) {
|
||||
list($sKey, $sVal) = explode('=', $sKeyVal, 2);
|
||||
if ($sKey == 'host') {
|
||||
$sKey = 'hostspec';
|
||||
} elseif ($sKey == 'dbname') {
|
||||
$sKey = 'database';
|
||||
} elseif ($sKey == 'user') {
|
||||
$sKey = 'username';
|
||||
}
|
||||
$aInfo[$sKey] = $sVal;
|
||||
}
|
||||
}
|
||||
return $aInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes an array of settings and return the DNS string. Key names can be
|
||||
* 'database', 'hostspec', 'port', 'username', 'password' but aliases
|
||||
* 'dbname', 'host' and 'user' are also supported.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
public static function generateDSN($aInfo)
|
||||
{
|
||||
$sDSN = sprintf(
|
||||
'pgsql:host=%s;port=%s;dbname=%s;user=%s;password=%s;',
|
||||
$aInfo['host'] ?? $aInfo['hostspec'] ?? '',
|
||||
$aInfo['port'] ?? '',
|
||||
$aInfo['dbname'] ?? $aInfo['database'] ?? '',
|
||||
$aInfo['user'] ?? '',
|
||||
$aInfo['password'] ?? ''
|
||||
);
|
||||
$sDSN = preg_replace('/\b\w+=;/', '', $sDSN);
|
||||
$sDSN = preg_replace('/;\Z/', '', $sDSN);
|
||||
|
||||
return $sDSN;
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* This file is part of Nominatim. (https://nominatim.org)
|
||||
*
|
||||
* Copyright (C) 2022 by the Nominatim developer community.
|
||||
* For a full list of authors see the git log.
|
||||
*/
|
||||
|
||||
namespace Nominatim;
|
||||
|
||||
class DatabaseError extends \Exception
|
||||
{
|
||||
|
||||
public function __construct($message, $code, $previous, $oPDOErr, $sSql = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
// https://secure.php.net/manual/en/class.pdoexception.php
|
||||
$this->oPDOErr = $oPDOErr;
|
||||
$this->sSql = $sSql;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
|
||||
}
|
||||
|
||||
public function getSqlError()
|
||||
{
|
||||
return $this->oPDOErr->getMessage();
|
||||
}
|
||||
|
||||
public function getSqlDebugDump()
|
||||
{
|
||||
if (CONST_Debug) {
|
||||
return var_export($this->oPDOErr, true);
|
||||
} else {
|
||||
return $this->sSql;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* This file is part of Nominatim. (https://nominatim.org)
|
||||
*
|
||||
* Copyright (C) 2022 by the Nominatim developer community.
|
||||
* For a full list of authors see the git log.
|
||||
*/
|
||||
|
||||
namespace Nominatim;
|
||||
|
||||
class Debug
|
||||
{
|
||||
public static function newFunction($sHeading)
|
||||
{
|
||||
echo "<pre><h2>Debug output for $sHeading</h2></pre>\n";
|
||||
}
|
||||
|
||||
public static function newSection($sHeading)
|
||||
{
|
||||
echo "<hr><pre><h3>$sHeading</h3></pre>\n";
|
||||
}
|
||||
|
||||
public static function printVar($sHeading, $mVar)
|
||||
{
|
||||
echo '<pre><b>'.$sHeading. ':</b> ';
|
||||
Debug::outputVar($mVar, str_repeat(' ', strlen($sHeading) + 3));
|
||||
echo "</pre>\n";
|
||||
}
|
||||
|
||||
public static function fmtArrayVals($aArr)
|
||||
{
|
||||
return array('__debug_format' => 'array_vals', 'data' => $aArr);
|
||||
}
|
||||
|
||||
public static function printDebugArray($sHeading, $oVar)
|
||||
{
|
||||
|
||||
if ($oVar === null) {
|
||||
Debug::printVar($sHeading, 'null');
|
||||
} else {
|
||||
Debug::printVar($sHeading, $oVar->debugInfo());
|
||||
}
|
||||
}
|
||||
|
||||
public static function printDebugTable($sHeading, $aVar)
|
||||
{
|
||||
echo '<b>'.$sHeading.":</b>\n";
|
||||
echo "<table border='1'>\n";
|
||||
if (!empty($aVar)) {
|
||||
echo " <tr>\n";
|
||||
$aKeys = array();
|
||||
$aInfo = reset($aVar);
|
||||
if (!is_array($aInfo)) {
|
||||
$aInfo = $aInfo->debugInfo();
|
||||
}
|
||||
foreach ($aInfo as $sKey => $mVal) {
|
||||
echo ' <th><small>'.$sKey.'</small></th>'."\n";
|
||||
$aKeys[] = $sKey;
|
||||
}
|
||||
echo " </tr>\n";
|
||||
foreach ($aVar as $oRow) {
|
||||
$aInfo = $oRow;
|
||||
if (!is_array($oRow)) {
|
||||
$aInfo = $oRow->debugInfo();
|
||||
}
|
||||
echo " <tr>\n";
|
||||
foreach ($aKeys as $sKey) {
|
||||
echo ' <td><pre>';
|
||||
if (isset($aInfo[$sKey])) {
|
||||
Debug::outputVar($aInfo[$sKey], '');
|
||||
}
|
||||
echo '</pre></td>'."\n";
|
||||
}
|
||||
echo " </tr>\n";
|
||||
}
|
||||
}
|
||||
echo "</table>\n";
|
||||
}
|
||||
|
||||
public static function printGroupedSearch($aSearches, $aWordsIDs)
|
||||
{
|
||||
echo '<table border="1">';
|
||||
echo '<tr><th>rank</th><th>Name Tokens</th><th>Name Not</th>';
|
||||
echo '<th>Address Tokens</th><th>Address Not</th>';
|
||||
echo '<th>country</th><th>operator</th>';
|
||||
echo '<th>class</th><th>type</th><th>postcode</th><th>housenumber</th></tr>';
|
||||
foreach ($aSearches as $aRankedSet) {
|
||||
foreach ($aRankedSet as $aRow) {
|
||||
$aRow->dumpAsHtmlTableRow($aWordsIDs);
|
||||
}
|
||||
}
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
public static function printGroupTable($sHeading, $aVar)
|
||||
{
|
||||
echo '<b>'.$sHeading.":</b>\n";
|
||||
echo "<table border='1'>\n";
|
||||
if (!empty($aVar)) {
|
||||
echo " <tr>\n";
|
||||
echo ' <th><small>Group</small></th>'."\n";
|
||||
$aKeys = array();
|
||||
$aInfo = reset($aVar)[0];
|
||||
if (!is_array($aInfo)) {
|
||||
$aInfo = $aInfo->debugInfo();
|
||||
}
|
||||
foreach ($aInfo as $sKey => $mVal) {
|
||||
echo ' <th><small>'.$sKey.'</small></th>'."\n";
|
||||
$aKeys[] = $sKey;
|
||||
}
|
||||
echo " </tr>\n";
|
||||
foreach ($aVar as $sGrpKey => $aGroup) {
|
||||
foreach ($aGroup as $oRow) {
|
||||
$aInfo = $oRow;
|
||||
if (!is_array($oRow)) {
|
||||
$aInfo = $oRow->debugInfo();
|
||||
}
|
||||
echo " <tr>\n";
|
||||
echo ' <td><pre>'.$sGrpKey.'</pre></td>'."\n";
|
||||
foreach ($aKeys as $sKey) {
|
||||
echo ' <td><pre>';
|
||||
if (!empty($aInfo[$sKey])) {
|
||||
Debug::outputVar($aInfo[$sKey], '');
|
||||
}
|
||||
echo '</pre></td>'."\n";
|
||||
}
|
||||
echo " </tr>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
echo "</table>\n";
|
||||
}
|
||||
|
||||
public static function printSQL($sSQL)
|
||||
{
|
||||
echo '<p><tt><font color="#aaa">'.htmlspecialchars($sSQL, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401).'</font></tt></p>'."\n";
|
||||
}
|
||||
|
||||
private static function outputVar($mVar, $sPreNL)
|
||||
{
|
||||
if (is_array($mVar) && !isset($mVar['__debug_format'])) {
|
||||
$sPre = '';
|
||||
foreach ($mVar as $mKey => $aValue) {
|
||||
echo $sPre;
|
||||
$iKeyLen = Debug::outputSimpleVar($mKey);
|
||||
echo ' => ';
|
||||
Debug::outputVar(
|
||||
$aValue,
|
||||
$sPreNL.str_repeat(' ', $iKeyLen + 4)
|
||||
);
|
||||
$sPre = "\n".$sPreNL;
|
||||
}
|
||||
} elseif (is_array($mVar) && isset($mVar['__debug_format'])) {
|
||||
if (!empty($mVar['data'])) {
|
||||
$sPre = '';
|
||||
foreach ($mVar['data'] as $mValue) {
|
||||
echo $sPre;
|
||||
Debug::outputSimpleVar($mValue);
|
||||
$sPre = ', ';
|
||||
}
|
||||
}
|
||||
} elseif (is_object($mVar) && method_exists($mVar, 'debugInfo')) {
|
||||
Debug::outputVar($mVar->debugInfo(), $sPreNL);
|
||||
} elseif (is_a($mVar, 'stdClass')) {
|
||||
Debug::outputVar(json_decode(json_encode($mVar), true), $sPreNL);
|
||||
} else {
|
||||
Debug::outputSimpleVar($mVar);
|
||||
}
|
||||
}
|
||||
|
||||
private static function outputSimpleVar($mVar)
|
||||
{
|
||||
if (is_bool($mVar)) {
|
||||
echo '<i>'.($mVar ? 'True' : 'False').'</i>';
|
||||
return $mVar ? 4 : 5;
|
||||
}
|
||||
|
||||
if (is_string($mVar)) {
|
||||
$sOut = "'$mVar'";
|
||||
} else {
|
||||
$sOut = (string)$mVar;
|
||||
}
|
||||
|
||||
echo htmlspecialchars($sOut, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401);
|
||||
return strlen($sOut);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* This file is part of Nominatim. (https://nominatim.org)
|
||||
*
|
||||
* Copyright (C) 2022 by the Nominatim developer community.
|
||||
* For a full list of authors see the git log.
|
||||
*/
|
||||
|
||||
namespace Nominatim;
|
||||
|
||||
class Debug
|
||||
{
|
||||
public static function __callStatic($name, $arguments)
|
||||
{
|
||||
// nothing
|
||||
}
|
||||
}
|
||||
@@ -1,938 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* This file is part of Nominatim. (https://nominatim.org)
|
||||
*
|
||||
* Copyright (C) 2022 by the Nominatim developer community.
|
||||
* For a full list of authors see the git log.
|
||||
*/
|
||||
|
||||
namespace Nominatim;
|
||||
|
||||
require_once(CONST_LibDir.'/PlaceLookup.php');
|
||||
require_once(CONST_LibDir.'/Phrase.php');
|
||||
require_once(CONST_LibDir.'/ReverseGeocode.php');
|
||||
require_once(CONST_LibDir.'/SearchDescription.php');
|
||||
require_once(CONST_LibDir.'/SearchContext.php');
|
||||
require_once(CONST_LibDir.'/SearchPosition.php');
|
||||
require_once(CONST_LibDir.'/TokenList.php');
|
||||
require_once(CONST_TokenizerDir.'/tokenizer.php');
|
||||
|
||||
class Geocode
|
||||
{
|
||||
protected $oDB;
|
||||
|
||||
protected $oPlaceLookup;
|
||||
protected $oTokenizer;
|
||||
|
||||
protected $aLangPrefOrder = array();
|
||||
|
||||
protected $aExcludePlaceIDs = array();
|
||||
|
||||
protected $iLimit = 20;
|
||||
protected $iFinalLimit = 10;
|
||||
protected $iOffset = 0;
|
||||
protected $bFallback = false;
|
||||
|
||||
protected $aCountryCodes = false;
|
||||
|
||||
protected $bBoundedSearch = false;
|
||||
protected $aViewBox = false;
|
||||
protected $aRoutePoints = false;
|
||||
protected $aRouteWidth = false;
|
||||
|
||||
protected $iMaxRank = 20;
|
||||
protected $iMinAddressRank = 0;
|
||||
protected $iMaxAddressRank = 30;
|
||||
protected $aAddressRankList = array();
|
||||
|
||||
protected $sAllowedTypesSQLList = false;
|
||||
|
||||
protected $sQuery = false;
|
||||
protected $aStructuredQuery = false;
|
||||
|
||||
|
||||
public function __construct(&$oDB)
|
||||
{
|
||||
$this->oDB =& $oDB;
|
||||
$this->oPlaceLookup = new PlaceLookup($this->oDB);
|
||||
$this->oTokenizer = new \Nominatim\Tokenizer($this->oDB);
|
||||
}
|
||||
|
||||
public function setLanguagePreference($aLangPref)
|
||||
{
|
||||
$this->aLangPrefOrder = $aLangPref;
|
||||
}
|
||||
|
||||
public function getMoreUrlParams()
|
||||
{
|
||||
if ($this->aStructuredQuery) {
|
||||
$aParams = $this->aStructuredQuery;
|
||||
} else {
|
||||
$aParams = array('q' => $this->sQuery);
|
||||
}
|
||||
|
||||
$aParams = array_merge($aParams, $this->oPlaceLookup->getMoreUrlParams());
|
||||
|
||||
if ($this->aExcludePlaceIDs) {
|
||||
$aParams['exclude_place_ids'] = implode(',', $this->aExcludePlaceIDs);
|
||||
}
|
||||
|
||||
if ($this->bBoundedSearch) {
|
||||
$aParams['bounded'] = '1';
|
||||
}
|
||||
|
||||
if ($this->aCountryCodes) {
|
||||
$aParams['countrycodes'] = implode(',', $this->aCountryCodes);
|
||||
}
|
||||
|
||||
if ($this->aViewBox) {
|
||||
$aParams['viewbox'] = join(',', $this->aViewBox);
|
||||
}
|
||||
|
||||
return $aParams;
|
||||
}
|
||||
|
||||
public function setLimit($iLimit = 10)
|
||||
{
|
||||
if ($iLimit > 50) {
|
||||
$iLimit = 50;
|
||||
} elseif ($iLimit < 1) {
|
||||
$iLimit = 1;
|
||||
}
|
||||
|
||||
$this->iFinalLimit = $iLimit;
|
||||
$this->iLimit = $iLimit + max($iLimit, 10);
|
||||
}
|
||||
|
||||
public function setFeatureType($sFeatureType)
|
||||
{
|
||||
switch ($sFeatureType) {
|
||||
case 'country':
|
||||
$this->setRankRange(4, 4);
|
||||
break;
|
||||
case 'state':
|
||||
$this->setRankRange(8, 8);
|
||||
break;
|
||||
case 'city':
|
||||
$this->setRankRange(14, 16);
|
||||
break;
|
||||
case 'settlement':
|
||||
$this->setRankRange(8, 20);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function setRankRange($iMin, $iMax)
|
||||
{
|
||||
$this->iMinAddressRank = $iMin;
|
||||
$this->iMaxAddressRank = $iMax;
|
||||
}
|
||||
|
||||
public function setViewbox($aViewbox)
|
||||
{
|
||||
$aBox = array_map('floatval', $aViewbox);
|
||||
|
||||
$this->aViewBox[0] = max(-180.0, min($aBox[0], $aBox[2]));
|
||||
$this->aViewBox[1] = max(-90.0, min($aBox[1], $aBox[3]));
|
||||
$this->aViewBox[2] = min(180.0, max($aBox[0], $aBox[2]));
|
||||
$this->aViewBox[3] = min(90.0, max($aBox[1], $aBox[3]));
|
||||
|
||||
if ($this->aViewBox[2] - $this->aViewBox[0] < 0.000000001
|
||||
|| $this->aViewBox[3] - $this->aViewBox[1] < 0.000000001
|
||||
) {
|
||||
userError("Bad parameter 'viewbox'. Not a box.");
|
||||
}
|
||||
}
|
||||
|
||||
private function viewboxImportanceFactor($fX, $fY)
|
||||
{
|
||||
if (!$this->aViewBox) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
$fWidth = ($this->aViewBox[2] - $this->aViewBox[0])/2;
|
||||
$fHeight = ($this->aViewBox[3] - $this->aViewBox[1])/2;
|
||||
|
||||
$fXDist = abs($fX - ($this->aViewBox[0] + $this->aViewBox[2])/2);
|
||||
$fYDist = abs($fY - ($this->aViewBox[1] + $this->aViewBox[3])/2);
|
||||
|
||||
if ($fXDist <= $fWidth && $fYDist <= $fHeight) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($fXDist <= $fWidth * 3 && $fYDist <= 3 * $fHeight) {
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
return 0.25;
|
||||
}
|
||||
|
||||
public function setQuery($sQueryString)
|
||||
{
|
||||
$this->sQuery = $sQueryString;
|
||||
$this->aStructuredQuery = false;
|
||||
}
|
||||
|
||||
public function getQueryString()
|
||||
{
|
||||
return $this->sQuery;
|
||||
}
|
||||
|
||||
|
||||
public function loadParamArray($oParams, $sForceGeometryType = null)
|
||||
{
|
||||
$this->bBoundedSearch = $oParams->getBool('bounded', $this->bBoundedSearch);
|
||||
|
||||
$this->setLimit($oParams->getInt('limit', $this->iFinalLimit));
|
||||
$this->iOffset = $oParams->getInt('offset', $this->iOffset);
|
||||
|
||||
$this->bFallback = $oParams->getBool('fallback', $this->bFallback);
|
||||
|
||||
// List of excluded Place IDs - used for more accurate pageing
|
||||
$sExcluded = $oParams->getStringList('exclude_place_ids');
|
||||
if ($sExcluded) {
|
||||
foreach ($sExcluded as $iExcludedPlaceID) {
|
||||
$iExcludedPlaceID = (int)$iExcludedPlaceID;
|
||||
if ($iExcludedPlaceID) {
|
||||
$aExcludePlaceIDs[$iExcludedPlaceID] = $iExcludedPlaceID;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($aExcludePlaceIDs)) {
|
||||
$this->aExcludePlaceIDs = $aExcludePlaceIDs;
|
||||
}
|
||||
}
|
||||
|
||||
// Only certain ranks of feature
|
||||
$sFeatureType = $oParams->getString('featureType');
|
||||
if (!$sFeatureType) {
|
||||
$sFeatureType = $oParams->getString('featuretype');
|
||||
}
|
||||
if ($sFeatureType) {
|
||||
$this->setFeatureType($sFeatureType);
|
||||
}
|
||||
|
||||
// Country code list
|
||||
$sCountries = $oParams->getStringList('countrycodes');
|
||||
if ($sCountries) {
|
||||
foreach ($sCountries as $sCountryCode) {
|
||||
if (preg_match('/^[a-zA-Z][a-zA-Z]$/', $sCountryCode)) {
|
||||
$aCountries[] = strtolower($sCountryCode);
|
||||
}
|
||||
}
|
||||
if (isset($aCountries)) {
|
||||
$this->aCountryCodes = $aCountries;
|
||||
}
|
||||
}
|
||||
|
||||
$aViewbox = $oParams->getStringList('viewboxlbrt');
|
||||
if ($aViewbox) {
|
||||
if (count($aViewbox) != 4) {
|
||||
userError("Bad parameter 'viewboxlbrt'. Expected 4 coordinates.");
|
||||
}
|
||||
$this->setViewbox($aViewbox);
|
||||
} else {
|
||||
$aViewbox = $oParams->getStringList('viewbox');
|
||||
if ($aViewbox) {
|
||||
if (count($aViewbox) != 4) {
|
||||
userError("Bad parameter 'viewbox'. Expected 4 coordinates.");
|
||||
}
|
||||
$this->setViewBox($aViewbox);
|
||||
} else {
|
||||
$aRoute = $oParams->getStringList('route');
|
||||
$fRouteWidth = $oParams->getFloat('routewidth');
|
||||
if ($aRoute && $fRouteWidth) {
|
||||
$this->aRoutePoints = $aRoute;
|
||||
$this->aRouteWidth = $fRouteWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->oPlaceLookup->loadParamArray($oParams, $sForceGeometryType);
|
||||
$this->oPlaceLookup->setIncludeAddressDetails($oParams->getBool('addressdetails', false));
|
||||
}
|
||||
|
||||
public function setQueryFromParams($oParams)
|
||||
{
|
||||
// Search query
|
||||
$sQuery = $oParams->getString('q');
|
||||
if (!$sQuery) {
|
||||
$this->setStructuredQuery(
|
||||
$oParams->getString('amenity'),
|
||||
$oParams->getString('street'),
|
||||
$oParams->getString('city'),
|
||||
$oParams->getString('county'),
|
||||
$oParams->getString('state'),
|
||||
$oParams->getString('country'),
|
||||
$oParams->getString('postalcode')
|
||||
);
|
||||
} else {
|
||||
$this->setQuery($sQuery);
|
||||
}
|
||||
}
|
||||
|
||||
public function loadStructuredAddressElement($sValue, $sKey, $iNewMinAddressRank, $iNewMaxAddressRank, $aItemListValues)
|
||||
{
|
||||
$sValue = trim($sValue);
|
||||
if (!$sValue) {
|
||||
return false;
|
||||
}
|
||||
$this->aStructuredQuery[$sKey] = $sValue;
|
||||
if ($this->iMinAddressRank == 0 && $this->iMaxAddressRank == 30) {
|
||||
$this->iMinAddressRank = $iNewMinAddressRank;
|
||||
$this->iMaxAddressRank = $iNewMaxAddressRank;
|
||||
}
|
||||
if ($aItemListValues) {
|
||||
$this->aAddressRankList = array_merge($this->aAddressRankList, $aItemListValues);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function setStructuredQuery($sAmenity = false, $sStreet = false, $sCity = false, $sCounty = false, $sState = false, $sCountry = false, $sPostalCode = false)
|
||||
{
|
||||
$this->sQuery = false;
|
||||
|
||||
// Reset
|
||||
$this->iMinAddressRank = 0;
|
||||
$this->iMaxAddressRank = 30;
|
||||
$this->aAddressRankList = array();
|
||||
|
||||
$this->aStructuredQuery = array();
|
||||
$this->sAllowedTypesSQLList = false;
|
||||
|
||||
$this->loadStructuredAddressElement($sAmenity, 'amenity', 26, 30, false);
|
||||
$this->loadStructuredAddressElement($sStreet, 'street', 26, 30, false);
|
||||
$this->loadStructuredAddressElement($sCity, 'city', 14, 24, false);
|
||||
$this->loadStructuredAddressElement($sCounty, 'county', 9, 13, false);
|
||||
$this->loadStructuredAddressElement($sState, 'state', 8, 8, false);
|
||||
$this->loadStructuredAddressElement($sPostalCode, 'postalcode', 5, 11, array(5, 11));
|
||||
$this->loadStructuredAddressElement($sCountry, 'country', 4, 4, false);
|
||||
|
||||
if (!empty($this->aStructuredQuery)) {
|
||||
$this->sQuery = join(', ', $this->aStructuredQuery);
|
||||
if ($this->iMaxAddressRank < 30) {
|
||||
$this->sAllowedTypesSQLList = '(\'place\',\'boundary\')';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function fallbackStructuredQuery()
|
||||
{
|
||||
$aParams = $this->aStructuredQuery;
|
||||
|
||||
if (!$aParams || count($aParams) == 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$aOrderToFallback = array('postalcode', 'street', 'city', 'county', 'state');
|
||||
|
||||
foreach ($aOrderToFallback as $sType) {
|
||||
if (isset($aParams[$sType])) {
|
||||
unset($aParams[$sType]);
|
||||
$this->setStructuredQuery(@$aParams['amenity'], @$aParams['street'], @$aParams['city'], @$aParams['county'], @$aParams['state'], @$aParams['country'], @$aParams['postalcode']);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getGroupedSearches($aSearches, $aPhrases, $oValidTokens)
|
||||
{
|
||||
/*
|
||||
Calculate all searches using oValidTokens i.e.
|
||||
'Wodsworth Road, Sheffield' =>
|
||||
|
||||
Phrase Wordset
|
||||
0 0 (wodsworth road)
|
||||
0 1 (wodsworth)(road)
|
||||
1 0 (sheffield)
|
||||
|
||||
Score how good the search is so they can be ordered
|
||||
*/
|
||||
foreach ($aPhrases as $iPhrase => $oPhrase) {
|
||||
$aNewPhraseSearches = array();
|
||||
$oPosition = new SearchPosition(
|
||||
$oPhrase->getPhraseType(),
|
||||
$iPhrase,
|
||||
count($aPhrases)
|
||||
);
|
||||
|
||||
foreach ($oPhrase->getWordSets() as $aWordset) {
|
||||
$aWordsetSearches = $aSearches;
|
||||
|
||||
// Add all words from this wordset
|
||||
foreach ($aWordset as $iToken => $sToken) {
|
||||
$aNewWordsetSearches = array();
|
||||
$oPosition->setTokenPosition($iToken, count($aWordset));
|
||||
|
||||
foreach ($aWordsetSearches as $oCurrentSearch) {
|
||||
foreach ($oValidTokens->get($sToken) as $oSearchTerm) {
|
||||
if ($oSearchTerm->isExtendable($oCurrentSearch, $oPosition)) {
|
||||
$aNewSearches = $oSearchTerm->extendSearch(
|
||||
$oCurrentSearch,
|
||||
$oPosition
|
||||
);
|
||||
|
||||
foreach ($aNewSearches as $oSearch) {
|
||||
if ($oSearch->getRank() < $this->iMaxRank) {
|
||||
$aNewWordsetSearches[] = $oSearch;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Sort and cut
|
||||
usort($aNewWordsetSearches, array('Nominatim\SearchDescription', 'bySearchRank'));
|
||||
$aWordsetSearches = array_slice($aNewWordsetSearches, 0, 50);
|
||||
}
|
||||
|
||||
$aNewPhraseSearches = array_merge($aNewPhraseSearches, $aNewWordsetSearches);
|
||||
usort($aNewPhraseSearches, array('Nominatim\SearchDescription', 'bySearchRank'));
|
||||
|
||||
$aSearchHash = array();
|
||||
foreach ($aNewPhraseSearches as $iSearch => $aSearch) {
|
||||
$sHash = serialize($aSearch);
|
||||
if (isset($aSearchHash[$sHash])) {
|
||||
unset($aNewPhraseSearches[$iSearch]);
|
||||
} else {
|
||||
$aSearchHash[$sHash] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
$aNewPhraseSearches = array_slice($aNewPhraseSearches, 0, 50);
|
||||
}
|
||||
|
||||
// Re-group the searches by their score, junk anything over 20 as just not worth trying
|
||||
$aGroupedSearches = array();
|
||||
foreach ($aNewPhraseSearches as $aSearch) {
|
||||
$iRank = $aSearch->getRank();
|
||||
if ($iRank < $this->iMaxRank) {
|
||||
if (!isset($aGroupedSearches[$iRank])) {
|
||||
$aGroupedSearches[$iRank] = array();
|
||||
}
|
||||
$aGroupedSearches[$iRank][] = $aSearch;
|
||||
}
|
||||
}
|
||||
ksort($aGroupedSearches);
|
||||
|
||||
$iSearchCount = 0;
|
||||
$aSearches = array();
|
||||
foreach ($aGroupedSearches as $aNewSearches) {
|
||||
$iSearchCount += count($aNewSearches);
|
||||
$aSearches = array_merge($aSearches, $aNewSearches);
|
||||
if ($iSearchCount > 50) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Revisit searches, drop bad searches and give penalty to unlikely combinations.
|
||||
$aGroupedSearches = array();
|
||||
foreach ($aSearches as $oSearch) {
|
||||
if (!$oSearch->isValidSearch()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$iRank = $oSearch->getRank();
|
||||
if (!isset($aGroupedSearches[$iRank])) {
|
||||
$aGroupedSearches[$iRank] = array();
|
||||
}
|
||||
$aGroupedSearches[$iRank][] = $oSearch;
|
||||
}
|
||||
ksort($aGroupedSearches);
|
||||
|
||||
return $aGroupedSearches;
|
||||
}
|
||||
|
||||
/* Perform the actual query lookup.
|
||||
|
||||
Returns an ordered list of results, each with the following fields:
|
||||
osm_type: type of corresponding OSM object
|
||||
N - node
|
||||
W - way
|
||||
R - relation
|
||||
P - postcode (internally computed)
|
||||
osm_id: id of corresponding OSM object
|
||||
class: general object class (corresponds to tag key of primary OSM tag)
|
||||
type: subclass of object (corresponds to tag value of primary OSM tag)
|
||||
admin_level: see https://wiki.openstreetmap.org/wiki/Admin_level
|
||||
rank_search: rank in search hierarchy
|
||||
(see also https://wiki.openstreetmap.org/wiki/Nominatim/Development_overview#Country_to_street_level)
|
||||
rank_address: rank in address hierarchy (determines orer in address)
|
||||
place_id: internal key (may differ between different instances)
|
||||
country_code: ISO country code
|
||||
langaddress: localized full address
|
||||
placename: localized name of object
|
||||
ref: content of ref tag (if available)
|
||||
lon: longitude
|
||||
lat: latitude
|
||||
importance: importance of place based on Wikipedia link count
|
||||
addressimportance: cumulated importance of address elements
|
||||
extra_place: type of place (for admin boundaries, if there is a place tag)
|
||||
aBoundingBox: bounding Box
|
||||
label: short description of the object class/type (English only)
|
||||
name: full name (currently the same as langaddress)
|
||||
foundorder: secondary ordering for places with same importance
|
||||
*/
|
||||
|
||||
|
||||
public function lookup()
|
||||
{
|
||||
Debug::newFunction('Geocode::lookup');
|
||||
if (!$this->sQuery && !$this->aStructuredQuery) {
|
||||
return array();
|
||||
}
|
||||
|
||||
Debug::printDebugArray('Geocode', $this);
|
||||
|
||||
$oCtx = new SearchContext();
|
||||
|
||||
if ($this->aRoutePoints) {
|
||||
$oCtx->setViewboxFromRoute(
|
||||
$this->oDB,
|
||||
$this->aRoutePoints,
|
||||
$this->aRouteWidth,
|
||||
$this->bBoundedSearch
|
||||
);
|
||||
} elseif ($this->aViewBox) {
|
||||
$oCtx->setViewboxFromBox($this->aViewBox, $this->bBoundedSearch);
|
||||
}
|
||||
if ($this->aExcludePlaceIDs) {
|
||||
$oCtx->setExcludeList($this->aExcludePlaceIDs);
|
||||
}
|
||||
if ($this->aCountryCodes) {
|
||||
$oCtx->setCountryList($this->aCountryCodes);
|
||||
}
|
||||
|
||||
Debug::newSection('Query Preprocessing');
|
||||
|
||||
$sQuery = $this->sQuery;
|
||||
if (!preg_match('//u', $sQuery)) {
|
||||
userError('Query string is not UTF-8 encoded.');
|
||||
}
|
||||
|
||||
// Do we have anything that looks like a lat/lon pair?
|
||||
$sQuery = $oCtx->setNearPointFromQuery($sQuery);
|
||||
|
||||
if ($sQuery || $this->aStructuredQuery) {
|
||||
// Start with a single blank search
|
||||
$aSearches = array(new SearchDescription($oCtx));
|
||||
|
||||
if ($sQuery) {
|
||||
$sQuery = $aSearches[0]->extractKeyValuePairs($sQuery);
|
||||
}
|
||||
|
||||
$sSpecialTerm = '';
|
||||
if ($sQuery) {
|
||||
preg_match_all(
|
||||
'/\\[([\\w ]*)\\]/u',
|
||||
$sQuery,
|
||||
$aSpecialTermsRaw,
|
||||
PREG_SET_ORDER
|
||||
);
|
||||
if (!empty($aSpecialTermsRaw)) {
|
||||
Debug::printVar('Special terms', $aSpecialTermsRaw);
|
||||
}
|
||||
|
||||
foreach ($aSpecialTermsRaw as $aSpecialTerm) {
|
||||
$sQuery = str_replace($aSpecialTerm[0], ' ', $sQuery);
|
||||
if (!$sSpecialTerm) {
|
||||
$sSpecialTerm = $aSpecialTerm[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$sSpecialTerm && $this->aStructuredQuery
|
||||
&& isset($this->aStructuredQuery['amenity'])) {
|
||||
$sSpecialTerm = $this->aStructuredQuery['amenity'];
|
||||
unset($this->aStructuredQuery['amenity']);
|
||||
}
|
||||
|
||||
if ($sSpecialTerm && !$aSearches[0]->hasOperator()) {
|
||||
$aTokens = $this->oTokenizer->tokensForSpecialTerm($sSpecialTerm);
|
||||
|
||||
if (!empty($aTokens)) {
|
||||
$aNewSearches = array();
|
||||
$oPosition = new SearchPosition('', 0, 1);
|
||||
$oPosition->setTokenPosition(0, 1);
|
||||
|
||||
foreach ($aSearches as $oSearch) {
|
||||
foreach ($aTokens as $oToken) {
|
||||
$aNewSearches = array_merge(
|
||||
$aNewSearches,
|
||||
$oToken->extendSearch($oSearch, $oPosition)
|
||||
);
|
||||
}
|
||||
}
|
||||
$aSearches = $aNewSearches;
|
||||
}
|
||||
}
|
||||
|
||||
// Split query into phrases
|
||||
// Commas are used to reduce the search space by indicating where phrases split
|
||||
$aPhrases = array();
|
||||
if ($this->aStructuredQuery) {
|
||||
foreach ($this->aStructuredQuery as $iPhrase => $sPhrase) {
|
||||
$aPhrases[] = new Phrase($sPhrase, $iPhrase);
|
||||
}
|
||||
} else {
|
||||
foreach (explode(',', $sQuery) as $sPhrase) {
|
||||
$aPhrases[] = new Phrase($sPhrase, '');
|
||||
}
|
||||
}
|
||||
|
||||
Debug::printDebugArray('Search context', $oCtx);
|
||||
Debug::printDebugArray('Base search', empty($aSearches) ? null : $aSearches[0]);
|
||||
|
||||
Debug::newSection('Tokenization');
|
||||
$oValidTokens = $this->oTokenizer->extractTokensFromPhrases($aPhrases);
|
||||
|
||||
if ($oValidTokens->count() > 0) {
|
||||
$oCtx->setFullNameWords($oValidTokens->getFullWordIDs());
|
||||
|
||||
$aPhrases = array_filter($aPhrases, function ($oPhrase) {
|
||||
return $oPhrase->getWordSets() !== null;
|
||||
});
|
||||
|
||||
// Any words that have failed completely?
|
||||
// TODO: suggestions
|
||||
|
||||
Debug::printGroupTable('Valid Tokens', $oValidTokens->debugInfo());
|
||||
Debug::printDebugTable('Phrases', $aPhrases);
|
||||
|
||||
Debug::newSection('Search candidates');
|
||||
|
||||
$aGroupedSearches = $this->getGroupedSearches($aSearches, $aPhrases, $oValidTokens);
|
||||
|
||||
if (!$this->aStructuredQuery) {
|
||||
// Reverse phrase array and also reverse the order of the wordsets in
|
||||
// the first and final phrase. Don't bother about phrases in the middle
|
||||
// because order in the address doesn't matter.
|
||||
$aPhrases = array_reverse($aPhrases);
|
||||
$aPhrases[0]->invertWordSets();
|
||||
if (count($aPhrases) > 1) {
|
||||
$aPhrases[count($aPhrases)-1]->invertWordSets();
|
||||
}
|
||||
$aReverseGroupedSearches = $this->getGroupedSearches($aSearches, $aPhrases, $oValidTokens);
|
||||
|
||||
foreach ($aReverseGroupedSearches as $aSearches) {
|
||||
foreach ($aSearches as $aSearch) {
|
||||
if (!isset($aGroupedSearches[$aSearch->getRank()])) {
|
||||
$aGroupedSearches[$aSearch->getRank()] = array();
|
||||
}
|
||||
$aGroupedSearches[$aSearch->getRank()][] = $aSearch;
|
||||
}
|
||||
}
|
||||
|
||||
ksort($aGroupedSearches);
|
||||
}
|
||||
} else {
|
||||
// Re-group the searches by their score, junk anything over 20 as just not worth trying
|
||||
$aGroupedSearches = array();
|
||||
foreach ($aSearches as $aSearch) {
|
||||
if ($aSearch->getRank() < $this->iMaxRank) {
|
||||
if (!isset($aGroupedSearches[$aSearch->getRank()])) {
|
||||
$aGroupedSearches[$aSearch->getRank()] = array();
|
||||
}
|
||||
$aGroupedSearches[$aSearch->getRank()][] = $aSearch;
|
||||
}
|
||||
}
|
||||
ksort($aGroupedSearches);
|
||||
}
|
||||
|
||||
// Filter out duplicate searches
|
||||
$aSearchHash = array();
|
||||
foreach ($aGroupedSearches as $iGroup => $aSearches) {
|
||||
foreach ($aSearches as $iSearch => $aSearch) {
|
||||
$sHash = serialize($aSearch);
|
||||
if (isset($aSearchHash[$sHash])) {
|
||||
unset($aGroupedSearches[$iGroup][$iSearch]);
|
||||
if (empty($aGroupedSearches[$iGroup])) {
|
||||
unset($aGroupedSearches[$iGroup]);
|
||||
}
|
||||
} else {
|
||||
$aSearchHash[$sHash] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Debug::printGroupedSearch(
|
||||
$aGroupedSearches,
|
||||
$oValidTokens->debugTokenByWordIdList()
|
||||
);
|
||||
|
||||
// Start the search process
|
||||
$iGroupLoop = 0;
|
||||
$iQueryLoop = 0;
|
||||
$aNextResults = array();
|
||||
foreach ($aGroupedSearches as $iGroupedRank => $aSearches) {
|
||||
$iGroupLoop++;
|
||||
$aResults = $aNextResults;
|
||||
foreach ($aSearches as $oSearch) {
|
||||
$iQueryLoop++;
|
||||
|
||||
Debug::newSection("Search Loop, group $iGroupLoop, loop $iQueryLoop");
|
||||
Debug::printGroupedSearch(
|
||||
array($iGroupedRank => array($oSearch)),
|
||||
$oValidTokens->debugTokenByWordIdList()
|
||||
);
|
||||
|
||||
$aNewResults = $oSearch->query(
|
||||
$this->oDB,
|
||||
$this->iMinAddressRank,
|
||||
$this->iMaxAddressRank,
|
||||
$this->iLimit
|
||||
);
|
||||
|
||||
// The same result may appear in different rounds, only
|
||||
// use the one with minimal rank.
|
||||
foreach ($aNewResults as $iPlace => $oRes) {
|
||||
if (!isset($aResults[$iPlace])
|
||||
|| $aResults[$iPlace]->iResultRank > $oRes->iResultRank) {
|
||||
$aResults[$iPlace] = $oRes;
|
||||
}
|
||||
}
|
||||
|
||||
if ($iQueryLoop > 20) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($aResults)) {
|
||||
$aSplitResults = Result::splitResults($aResults);
|
||||
Debug::printVar('Split results', $aSplitResults);
|
||||
if ($iGroupLoop <= 4
|
||||
&& reset($aSplitResults['head'])->iResultRank > 0
|
||||
&& $iGroupedRank !== array_key_last($aGroupedSearches)) {
|
||||
// Haven't found an exact match for the query yet.
|
||||
// Therefore add result from the next group level.
|
||||
$aNextResults = $aSplitResults['head'];
|
||||
foreach ($aNextResults as $oRes) {
|
||||
$oRes->iResultRank--;
|
||||
}
|
||||
foreach ($aSplitResults['tail'] as $oRes) {
|
||||
$oRes->iResultRank--;
|
||||
$aNextResults[$oRes->iId] = $oRes;
|
||||
}
|
||||
$aResults = array();
|
||||
} else {
|
||||
$aResults = $aSplitResults['head'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($aResults) && ($this->iMinAddressRank != 0 || $this->iMaxAddressRank != 30)) {
|
||||
// Need to verify passes rank limits before dropping out of the loop (yuk!)
|
||||
// reduces the number of place ids, like a filter
|
||||
// rank_address is 30 for interpolated housenumbers
|
||||
$aFilterSql = array();
|
||||
$sPlaceIds = Result::joinIdsByTable($aResults, Result::TABLE_PLACEX);
|
||||
if ($sPlaceIds) {
|
||||
$sSQL = 'SELECT place_id FROM placex ';
|
||||
$sSQL .= 'WHERE place_id in ('.$sPlaceIds.') ';
|
||||
$sSQL .= ' AND (';
|
||||
$sSQL .= " placex.rank_address between $this->iMinAddressRank and $this->iMaxAddressRank ";
|
||||
$sSQL .= " OR placex.rank_search between $this->iMinAddressRank and $this->iMaxAddressRank ";
|
||||
if ($this->aAddressRankList) {
|
||||
$sSQL .= ' OR placex.rank_address in ('.join(',', $this->aAddressRankList).')';
|
||||
}
|
||||
$sSQL .= ')';
|
||||
$aFilterSql[] = $sSQL;
|
||||
}
|
||||
$sPlaceIds = Result::joinIdsByTable($aResults, Result::TABLE_POSTCODE);
|
||||
if ($sPlaceIds) {
|
||||
$sSQL = ' SELECT place_id FROM location_postcode lp ';
|
||||
$sSQL .= 'WHERE place_id in ('.$sPlaceIds.') ';
|
||||
$sSQL .= " AND (lp.rank_address between $this->iMinAddressRank and $this->iMaxAddressRank ";
|
||||
if ($this->aAddressRankList) {
|
||||
$sSQL .= ' OR lp.rank_address in ('.join(',', $this->aAddressRankList).')';
|
||||
}
|
||||
$sSQL .= ') ';
|
||||
$aFilterSql[] = $sSQL;
|
||||
}
|
||||
|
||||
$aFilteredIDs = array();
|
||||
if ($aFilterSql) {
|
||||
$sSQL = join(' UNION ', $aFilterSql);
|
||||
Debug::printSQL($sSQL);
|
||||
$aFilteredIDs = $this->oDB->getCol($sSQL);
|
||||
}
|
||||
|
||||
$tempIDs = array();
|
||||
foreach ($aResults as $oResult) {
|
||||
if (($this->iMaxAddressRank == 30 &&
|
||||
($oResult->iTable == Result::TABLE_OSMLINE
|
||||
|| $oResult->iTable == Result::TABLE_TIGER))
|
||||
|| in_array($oResult->iId, $aFilteredIDs)
|
||||
) {
|
||||
$tempIDs[$oResult->iId] = $oResult;
|
||||
}
|
||||
}
|
||||
$aResults = $tempIDs;
|
||||
}
|
||||
|
||||
if (!empty($aResults) || $iGroupLoop > 4 || $iQueryLoop > 30) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Just interpret as a reverse geocode
|
||||
$oReverse = new ReverseGeocode($this->oDB);
|
||||
$oReverse->setZoom(18);
|
||||
|
||||
$oLookup = $oReverse->lookupPoint($oCtx->sqlNear, false);
|
||||
|
||||
Debug::printVar('Reverse search', $oLookup);
|
||||
|
||||
if ($oLookup) {
|
||||
$aResults = array($oLookup->iId => $oLookup);
|
||||
}
|
||||
}
|
||||
|
||||
// No results? Done
|
||||
if (empty($aResults)) {
|
||||
if ($this->bFallback && $this->fallbackStructuredQuery()) {
|
||||
return $this->lookup();
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
if ($this->aAddressRankList) {
|
||||
$this->oPlaceLookup->setAddressRankList($this->aAddressRankList);
|
||||
}
|
||||
$this->oPlaceLookup->setAllowedTypesSQLList($this->sAllowedTypesSQLList);
|
||||
$this->oPlaceLookup->setLanguagePreference($this->aLangPrefOrder);
|
||||
if ($oCtx->hasNearPoint()) {
|
||||
$this->oPlaceLookup->setAnchorSql($oCtx->sqlNear);
|
||||
}
|
||||
|
||||
$aSearchResults = $this->oPlaceLookup->lookup($aResults);
|
||||
|
||||
$aRecheckWords = preg_split('/\b[\s,\\-]*/u', $sQuery);
|
||||
foreach ($aRecheckWords as $i => $sWord) {
|
||||
if (!preg_match('/[\pL\pN]/', $sWord)) {
|
||||
unset($aRecheckWords[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
Debug::printVar('Recheck words', $aRecheckWords);
|
||||
|
||||
foreach ($aSearchResults as $iIdx => $aResult) {
|
||||
$fRadius = ClassTypes\getDefRadius($aResult);
|
||||
|
||||
$aOutlineResult = $this->oPlaceLookup->getOutlines($aResult['place_id'], $aResult['lon'], $aResult['lat'], $fRadius);
|
||||
if ($aOutlineResult) {
|
||||
$aResult = array_merge($aResult, $aOutlineResult);
|
||||
}
|
||||
|
||||
// Is there an icon set for this type of result?
|
||||
$sIcon = ClassTypes\getIconFile($aResult);
|
||||
if (isset($sIcon)) {
|
||||
$aResult['icon'] = $sIcon;
|
||||
}
|
||||
|
||||
$sLabel = ClassTypes\getLabel($aResult);
|
||||
if (isset($sLabel)) {
|
||||
$aResult['label'] = $sLabel;
|
||||
}
|
||||
$aResult['name'] = $aResult['langaddress'];
|
||||
|
||||
if ($oCtx->hasNearPoint()) {
|
||||
$aResult['importance'] = 0.001;
|
||||
$aResult['foundorder'] = $aResult['addressimportance'];
|
||||
} else {
|
||||
if ($aResult['importance'] == 0) {
|
||||
$aResult['importance'] = 0.0001;
|
||||
}
|
||||
$aResult['importance'] *= $this->viewboxImportanceFactor(
|
||||
$aResult['lon'],
|
||||
$aResult['lat']
|
||||
);
|
||||
|
||||
// secondary ordering (for results with same importance (the smaller the better):
|
||||
// - approximate importance of address parts
|
||||
if (isset($aResult['addressimportance']) && $aResult['addressimportance']) {
|
||||
$aResult['foundorder'] = -$aResult['addressimportance']/10;
|
||||
} else {
|
||||
$aResult['foundorder'] = -$aResult['importance'];
|
||||
}
|
||||
// - number of exact matches from the query
|
||||
$aResult['foundorder'] -= $aResults[$aResult['place_id']]->iExactMatches;
|
||||
// - importance of the class/type
|
||||
$iClassImportance = ClassTypes\getImportance($aResult);
|
||||
if (isset($iClassImportance)) {
|
||||
$aResult['foundorder'] += 0.0001 * $iClassImportance;
|
||||
} else {
|
||||
$aResult['foundorder'] += 0.01;
|
||||
}
|
||||
// - rank
|
||||
$aResult['foundorder'] -= 0.00001 * (30 - $aResult['rank_search']);
|
||||
|
||||
// Adjust importance for the number of exact string matches in the result
|
||||
$iCountWords = 0;
|
||||
$sAddress = $aResult['langaddress'];
|
||||
foreach ($aRecheckWords as $i => $sWord) {
|
||||
if (grapheme_stripos($sAddress, $sWord)!==false) {
|
||||
$iCountWords++;
|
||||
if (preg_match('/(^|,)\s*'.preg_quote($sWord, '/').'\s*(,|$)/', $sAddress)) {
|
||||
$iCountWords += 0.1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 0.1 is a completely arbitrary number but something in the range 0.1 to 0.5 would seem right
|
||||
$aResult['importance'] = $aResult['importance'] + ($iCountWords*0.1);
|
||||
}
|
||||
$aSearchResults[$iIdx] = $aResult;
|
||||
}
|
||||
uasort($aSearchResults, 'byImportance');
|
||||
Debug::printVar('Pre-filter results', $aSearchResults);
|
||||
|
||||
$aOSMIDDone = array();
|
||||
$aClassTypeNameDone = array();
|
||||
$aToFilter = $aSearchResults;
|
||||
$aSearchResults = array();
|
||||
|
||||
foreach ($aToFilter as $aResult) {
|
||||
$this->aExcludePlaceIDs[$aResult['place_id']] = $aResult['place_id'];
|
||||
if (!$this->oPlaceLookup->doDeDupe() || (!isset($aOSMIDDone[$aResult['osm_type'].$aResult['osm_id']])
|
||||
&& !isset($aClassTypeNameDone[$aResult['osm_type'].$aResult['class'].$aResult['type'].$aResult['name'].$aResult['admin_level']]))
|
||||
) {
|
||||
$aOSMIDDone[$aResult['osm_type'].$aResult['osm_id']] = true;
|
||||
$aClassTypeNameDone[$aResult['osm_type'].$aResult['class'].$aResult['type'].$aResult['name'].$aResult['admin_level']] = true;
|
||||
$aSearchResults[] = $aResult;
|
||||
}
|
||||
|
||||
// Absolute limit on number of results
|
||||
if (count($aSearchResults) >= $this->iFinalLimit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Debug::printVar('Post-filter results', $aSearchResults);
|
||||
return $aSearchResults;
|
||||
} // end lookup()
|
||||
|
||||
public function debugInfo()
|
||||
{
|
||||
return array(
|
||||
'Query' => $this->sQuery,
|
||||
'Structured query' => $this->aStructuredQuery,
|
||||
'Name keys' => Debug::fmtArrayVals($this->aLangPrefOrder),
|
||||
'Excluded place IDs' => Debug::fmtArrayVals($this->aExcludePlaceIDs),
|
||||
'Limit (for searches)' => $this->iLimit,
|
||||
'Limit (for results)'=> $this->iFinalLimit,
|
||||
'Country codes' => Debug::fmtArrayVals($this->aCountryCodes),
|
||||
'Bounded search' => $this->bBoundedSearch,
|
||||
'Viewbox' => Debug::fmtArrayVals($this->aViewBox),
|
||||
'Route points' => Debug::fmtArrayVals($this->aRoutePoints),
|
||||
'Route width' => $this->aRouteWidth,
|
||||
'Max rank' => $this->iMaxRank,
|
||||
'Min address rank' => $this->iMinAddressRank,
|
||||
'Max address rank' => $this->iMaxAddressRank,
|
||||
'Address rank list' => Debug::fmtArrayVals($this->aAddressRankList)
|
||||
);
|
||||
}
|
||||
} // end class
|
||||
@@ -1,157 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* This file is part of Nominatim. (https://nominatim.org)
|
||||
*
|
||||
* Copyright (C) 2022 by the Nominatim developer community.
|
||||
* For a full list of authors see the git log.
|
||||
*/
|
||||
|
||||
namespace Nominatim;
|
||||
|
||||
class ParameterParser
|
||||
{
|
||||
private $aParams;
|
||||
|
||||
|
||||
public function __construct($aParams = null)
|
||||
{
|
||||
$this->aParams = ($aParams === null) ? $_GET : $aParams;
|
||||
}
|
||||
|
||||
public function getBool($sName, $bDefault = false)
|
||||
{
|
||||
if (!isset($this->aParams[$sName])
|
||||
|| !is_string($this->aParams[$sName])
|
||||
|| strlen($this->aParams[$sName]) == 0
|
||||
) {
|
||||
return $bDefault;
|
||||
}
|
||||
|
||||
return (bool) $this->aParams[$sName];
|
||||
}
|
||||
|
||||
public function getInt($sName, $bDefault = false)
|
||||
{
|
||||
if (!isset($this->aParams[$sName]) || is_array($this->aParams[$sName])) {
|
||||
return $bDefault;
|
||||
}
|
||||
|
||||
if (!preg_match('/^[+-]?[0-9]+$/', $this->aParams[$sName])) {
|
||||
userError("Integer number expected for parameter '$sName'");
|
||||
}
|
||||
|
||||
return (int) $this->aParams[$sName];
|
||||
}
|
||||
|
||||
public function getFloat($sName, $bDefault = false)
|
||||
{
|
||||
if (!isset($this->aParams[$sName]) || is_array($this->aParams[$sName])) {
|
||||
return $bDefault;
|
||||
}
|
||||
|
||||
if (!preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $this->aParams[$sName])) {
|
||||
userError("Floating-point number expected for parameter '$sName'");
|
||||
}
|
||||
|
||||
return (float) $this->aParams[$sName];
|
||||
}
|
||||
|
||||
public function getString($sName, $bDefault = false)
|
||||
{
|
||||
if (!isset($this->aParams[$sName])
|
||||
|| !is_string($this->aParams[$sName])
|
||||
|| strlen($this->aParams[$sName]) == 0
|
||||
) {
|
||||
return $bDefault;
|
||||
}
|
||||
|
||||
return $this->aParams[$sName];
|
||||
}
|
||||
|
||||
public function getSet($sName, $aValues, $sDefault = false)
|
||||
{
|
||||
if (!isset($this->aParams[$sName])
|
||||
|| !is_string($this->aParams[$sName])
|
||||
|| strlen($this->aParams[$sName]) == 0
|
||||
) {
|
||||
return $sDefault;
|
||||
}
|
||||
|
||||
if (!in_array($this->aParams[$sName], $aValues, true)) {
|
||||
userError("Parameter '$sName' must be one of: ".join(', ', $aValues));
|
||||
}
|
||||
|
||||
return $this->aParams[$sName];
|
||||
}
|
||||
|
||||
public function getStringList($sName, $aDefault = false)
|
||||
{
|
||||
$sValue = $this->getString($sName);
|
||||
|
||||
if ($sValue) {
|
||||
// removes all NULL, FALSE and Empty Strings but leaves 0 (zero) values
|
||||
return array_values(array_filter(explode(',', $sValue), 'strlen'));
|
||||
}
|
||||
|
||||
return $aDefault;
|
||||
}
|
||||
|
||||
public function getPreferredLanguages($sFallback = null)
|
||||
{
|
||||
if ($sFallback === null && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
||||
$sFallback = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
|
||||
}
|
||||
|
||||
$aLanguages = array();
|
||||
$sLangString = $this->getString('accept-language', $sFallback);
|
||||
|
||||
if ($sLangString
|
||||
&& preg_match_all('/(([a-z]{1,8})([-_][a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $sLangString, $aLanguagesParse, PREG_SET_ORDER)
|
||||
) {
|
||||
foreach ($aLanguagesParse as $iLang => $aLanguage) {
|
||||
$aLanguages[$aLanguage[1]] = isset($aLanguage[5])?(float)$aLanguage[5]:1 - ($iLang/100);
|
||||
if (!isset($aLanguages[$aLanguage[2]])) {
|
||||
$aLanguages[$aLanguage[2]] = $aLanguages[$aLanguage[1]]/10;
|
||||
}
|
||||
}
|
||||
arsort($aLanguages);
|
||||
}
|
||||
if (empty($aLanguages) && CONST_Default_Language) {
|
||||
$aLanguages[CONST_Default_Language] = 1;
|
||||
}
|
||||
|
||||
foreach ($aLanguages as $sLanguage => $fLanguagePref) {
|
||||
$this->addNameTag($aLangPrefOrder, 'name:'.$sLanguage);
|
||||
}
|
||||
$this->addNameTag($aLangPrefOrder, 'name');
|
||||
$this->addNameTag($aLangPrefOrder, 'brand');
|
||||
foreach ($aLanguages as $sLanguage => $fLanguagePref) {
|
||||
$this->addNameTag($aLangPrefOrder, 'official_name:'.$sLanguage);
|
||||
$this->addNameTag($aLangPrefOrder, 'short_name:'.$sLanguage);
|
||||
}
|
||||
$this->addNameTag($aLangPrefOrder, 'official_name');
|
||||
$this->addNameTag($aLangPrefOrder, 'short_name');
|
||||
$this->addNameTag($aLangPrefOrder, 'ref');
|
||||
$this->addNameTag($aLangPrefOrder, 'type');
|
||||
return $aLangPrefOrder;
|
||||
}
|
||||
|
||||
private function addNameTag(&$aLangPrefOrder, $sTag)
|
||||
{
|
||||
$aLangPrefOrder[$sTag] = $sTag;
|
||||
$aLangPrefOrder['_place_'.$sTag] = '_place_'.$sTag;
|
||||
}
|
||||
|
||||
public function hasSetAny($aParamNames)
|
||||
{
|
||||
foreach ($aParamNames as $sName) {
|
||||
if ($this->getBool($sName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* This file is part of Nominatim. (https://nominatim.org)
|
||||
*
|
||||
* Copyright (C) 2022 by the Nominatim developer community.
|
||||
* For a full list of authors see the git log.
|
||||
*/
|
||||
|
||||
namespace Nominatim;
|
||||
|
||||
/**
|
||||
* Segment of a query string.
|
||||
*
|
||||
* The parts of a query strings are usually separated by commas.
|
||||
*/
|
||||
class Phrase
|
||||
{
|
||||
// Complete phrase as a string (guaranteed to have no leading or trailing
|
||||
// spaces).
|
||||
private $sPhrase;
|
||||
// Element type for structured searches.
|
||||
private $sPhraseType;
|
||||
// Possible segmentations of the phrase.
|
||||
private $aWordSets;
|
||||
|
||||
public function __construct($sPhrase, $sPhraseType)
|
||||
{
|
||||
$this->sPhrase = trim($sPhrase);
|
||||
$this->sPhraseType = $sPhraseType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the original phrase of the string.
|
||||
*/
|
||||
public function getPhrase()
|
||||
{
|
||||
return $this->sPhrase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the element type of the phrase.
|
||||
*
|
||||
* @return string Pharse type if the phrase comes from a structured query
|
||||
* or empty string otherwise.
|
||||
*/
|
||||
public function getPhraseType()
|
||||
{
|
||||
return $this->sPhraseType;
|
||||
}
|
||||
|
||||
public function setWordSets($aWordSets)
|
||||
{
|
||||
$this->aWordSets = $aWordSets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the array of possible segmentations of the phrase.
|
||||
*
|
||||
* @return string[][] Array of segmentations, each consisting of an
|
||||
* array of terms.
|
||||
*/
|
||||
public function getWordSets()
|
||||
{
|
||||
return $this->aWordSets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invert the set of possible segmentations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function invertWordSets()
|
||||
{
|
||||
foreach ($this->aWordSets as $i => $aSet) {
|
||||
$this->aWordSets[$i] = array_reverse($aSet);
|
||||
}
|
||||
}
|
||||
|
||||
public function debugInfo()
|
||||
{
|
||||
return array(
|
||||
'Type' => $this->sPhraseType,
|
||||
'Phrase' => $this->sPhrase,
|
||||
'WordSets' => $this->aWordSets
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,615 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* This file is part of Nominatim. (https://nominatim.org)
|
||||
*
|
||||
* Copyright (C) 2022 by the Nominatim developer community.
|
||||
* For a full list of authors see the git log.
|
||||
*/
|
||||
|
||||
namespace Nominatim;
|
||||
|
||||
require_once(CONST_LibDir.'/AddressDetails.php');
|
||||
require_once(CONST_LibDir.'/Result.php');
|
||||
|
||||
class PlaceLookup
|
||||
{
|
||||
protected $oDB;
|
||||
|
||||
protected $aLangPrefOrderSql = "''";
|
||||
|
||||
protected $bAddressDetails = false;
|
||||
protected $bExtraTags = false;
|
||||
protected $bNameDetails = false;
|
||||
|
||||
protected $bIncludePolygonAsText = false;
|
||||
protected $bIncludePolygonAsGeoJSON = false;
|
||||
protected $bIncludePolygonAsKML = false;
|
||||
protected $bIncludePolygonAsSVG = false;
|
||||
protected $fPolygonSimplificationThreshold = 0.0;
|
||||
|
||||
protected $sAnchorSql = null;
|
||||
protected $sAddressRankListSql = null;
|
||||
protected $sAllowedTypesSQLList = null;
|
||||
protected $bDeDupe = true;
|
||||
|
||||
|
||||
public function __construct(&$oDB)
|
||||
{
|
||||
$this->oDB =& $oDB;
|
||||
}
|
||||
|
||||
public function doDeDupe()
|
||||
{
|
||||
return $this->bDeDupe;
|
||||
}
|
||||
|
||||
public function setIncludeAddressDetails($b)
|
||||
{
|
||||
$this->bAddressDetails = $b;
|
||||
}
|
||||
|
||||
public function loadParamArray($oParams, $sGeomType = null)
|
||||
{
|
||||
$aLangs = $oParams->getPreferredLanguages();
|
||||
$this->aLangPrefOrderSql =
|
||||
'ARRAY['.join(',', $this->oDB->getDBQuotedList($aLangs)).']';
|
||||
|
||||
$this->bExtraTags = $oParams->getBool('extratags', false);
|
||||
$this->bNameDetails = $oParams->getBool('namedetails', false);
|
||||
|
||||
$this->bDeDupe = $oParams->getBool('dedupe', $this->bDeDupe);
|
||||
|
||||
if ($sGeomType === null || $sGeomType == 'geojson') {
|
||||
$this->bIncludePolygonAsGeoJSON = $oParams->getBool('polygon_geojson');
|
||||
}
|
||||
|
||||
if ($oParams->getString('format', '') !== 'geojson') {
|
||||
if ($sGeomType === null || $sGeomType == 'text') {
|
||||
$this->bIncludePolygonAsText = $oParams->getBool('polygon_text');
|
||||
}
|
||||
if ($sGeomType === null || $sGeomType == 'kml') {
|
||||
$this->bIncludePolygonAsKML = $oParams->getBool('polygon_kml');
|
||||
}
|
||||
if ($sGeomType === null || $sGeomType == 'svg') {
|
||||
$this->bIncludePolygonAsSVG = $oParams->getBool('polygon_svg');
|
||||
}
|
||||
}
|
||||
$this->fPolygonSimplificationThreshold
|
||||
= $oParams->getFloat('polygon_threshold', 0.0);
|
||||
|
||||
$iWantedTypes =
|
||||
($this->bIncludePolygonAsText ? 1 : 0) +
|
||||
($this->bIncludePolygonAsGeoJSON ? 1 : 0) +
|
||||
($this->bIncludePolygonAsKML ? 1 : 0) +
|
||||
($this->bIncludePolygonAsSVG ? 1 : 0);
|
||||
if ($iWantedTypes > CONST_PolygonOutput_MaximumTypes) {
|
||||
if (CONST_PolygonOutput_MaximumTypes) {
|
||||
userError('Select only '.CONST_PolygonOutput_MaximumTypes.' polgyon output option');
|
||||
} else {
|
||||
userError('Polygon output is disabled');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getMoreUrlParams()
|
||||
{
|
||||
$aParams = array();
|
||||
|
||||
if ($this->bAddressDetails) {
|
||||
$aParams['addressdetails'] = '1';
|
||||
}
|
||||
if ($this->bExtraTags) {
|
||||
$aParams['extratags'] = '1';
|
||||
}
|
||||
if ($this->bNameDetails) {
|
||||
$aParams['namedetails'] = '1';
|
||||
}
|
||||
|
||||
if ($this->bIncludePolygonAsText) {
|
||||
$aParams['polygon_text'] = '1';
|
||||
}
|
||||
if ($this->bIncludePolygonAsGeoJSON) {
|
||||
$aParams['polygon_geojson'] = '1';
|
||||
}
|
||||
if ($this->bIncludePolygonAsKML) {
|
||||
$aParams['polygon_kml'] = '1';
|
||||
}
|
||||
if ($this->bIncludePolygonAsSVG) {
|
||||
$aParams['polygon_svg'] = '1';
|
||||
}
|
||||
|
||||
if ($this->fPolygonSimplificationThreshold > 0.0) {
|
||||
$aParams['polygon_threshold'] = $this->fPolygonSimplificationThreshold;
|
||||
}
|
||||
|
||||
if (!$this->bDeDupe) {
|
||||
$aParams['dedupe'] = '0';
|
||||
}
|
||||
|
||||
return $aParams;
|
||||
}
|
||||
|
||||
public function setAnchorSql($sPoint)
|
||||
{
|
||||
$this->sAnchorSql = $sPoint;
|
||||
}
|
||||
|
||||
public function setAddressRankList($aList)
|
||||
{
|
||||
$this->sAddressRankListSql = '('.join(',', $aList).')';
|
||||
}
|
||||
|
||||
public function setAllowedTypesSQLList($sSql)
|
||||
{
|
||||
$this->sAllowedTypesSQLList = $sSql;
|
||||
}
|
||||
|
||||
public function setLanguagePreference($aLangPrefOrder)
|
||||
{
|
||||
$this->aLangPrefOrderSql = $this->oDB->getArraySQL(
|
||||
$this->oDB->getDBQuotedList($aLangPrefOrder)
|
||||
);
|
||||
}
|
||||
|
||||
private function addressImportanceSql($sGeometry, $sPlaceId)
|
||||
{
|
||||
if ($this->sAnchorSql) {
|
||||
$sSQL = 'ST_Distance('.$this->sAnchorSql.','.$sGeometry.')';
|
||||
} else {
|
||||
$sSQL = '(SELECT max(ai_p.importance * (ai_p.rank_address + 2))';
|
||||
$sSQL .= ' FROM place_addressline ai_s, placex ai_p';
|
||||
$sSQL .= ' WHERE ai_s.place_id = '.$sPlaceId;
|
||||
$sSQL .= ' AND ai_p.place_id = ai_s.address_place_id ';
|
||||
$sSQL .= ' AND ai_s.isaddress ';
|
||||
$sSQL .= ' AND ai_p.importance is not null)';
|
||||
}
|
||||
|
||||
return $sSQL.' AS addressimportance,';
|
||||
}
|
||||
|
||||
private function langAddressSql($sHousenumber)
|
||||
{
|
||||
if ($this->bAddressDetails) {
|
||||
return ''; // langaddress will be computed from address details
|
||||
}
|
||||
|
||||
return 'get_address_by_language(place_id,'.$sHousenumber.','.$this->aLangPrefOrderSql.') AS langaddress,';
|
||||
}
|
||||
|
||||
public function lookupOSMID($sType, $iID)
|
||||
{
|
||||
$sSQL = 'select place_id from placex where osm_type = :type and osm_id = :id';
|
||||
$iPlaceID = $this->oDB->getOne($sSQL, array(':type' => $sType, ':id' => $iID));
|
||||
|
||||
if (!$iPlaceID) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$aResults = $this->lookup(array($iPlaceID => new Result($iPlaceID)), 0, 30, true);
|
||||
|
||||
return empty($aResults) ? null : reset($aResults);
|
||||
}
|
||||
|
||||
public function lookup($aResults, $iMinRank = 0, $iMaxRank = 30, $bAllowLinked = false)
|
||||
{
|
||||
Debug::newFunction('Place lookup');
|
||||
|
||||
if (empty($aResults)) {
|
||||
return array();
|
||||
}
|
||||
$aSubSelects = array();
|
||||
|
||||
$sPlaceIDs = Result::joinIdsByTable($aResults, Result::TABLE_PLACEX);
|
||||
if ($sPlaceIDs) {
|
||||
Debug::printVar('Ids from placex', $sPlaceIDs);
|
||||
$sSQL = 'SELECT ';
|
||||
$sSQL .= ' osm_type,';
|
||||
$sSQL .= ' osm_id,';
|
||||
$sSQL .= ' class,';
|
||||
$sSQL .= ' type,';
|
||||
$sSQL .= ' admin_level,';
|
||||
$sSQL .= ' rank_search,';
|
||||
$sSQL .= ' rank_address,';
|
||||
$sSQL .= ' min(place_id) AS place_id,';
|
||||
$sSQL .= ' min(parent_place_id) AS parent_place_id,';
|
||||
$sSQL .= ' -1 as housenumber,';
|
||||
$sSQL .= ' country_code,';
|
||||
$sSQL .= $this->langAddressSql('-1');
|
||||
$sSQL .= ' get_name_by_language(name,'.$this->aLangPrefOrderSql.') AS placename,';
|
||||
$sSQL .= " get_name_by_language(name, ARRAY['ref']) AS ref,";
|
||||
if ($this->bExtraTags) {
|
||||
$sSQL .= 'hstore_to_json(extratags)::text AS extra,';
|
||||
}
|
||||
if ($this->bNameDetails) {
|
||||
$sSQL .= 'hstore_to_json(name)::text AS names,';
|
||||
}
|
||||
$sSQL .= ' avg(ST_X(centroid)) AS lon, ';
|
||||
$sSQL .= ' avg(ST_Y(centroid)) AS lat, ';
|
||||
$sSQL .= ' COALESCE(importance,0.75-(rank_search::float/40)) AS importance, ';
|
||||
$sSQL .= $this->addressImportanceSql(
|
||||
'ST_Collect(centroid)',
|
||||
'min(CASE WHEN placex.rank_search < 28 THEN placex.place_id ELSE placex.parent_place_id END)'
|
||||
);
|
||||
$sSQL .= " COALESCE(extratags->'place', extratags->'linked_place') AS extra_place ";
|
||||
$sSQL .= ' FROM placex';
|
||||
$sSQL .= " WHERE place_id in ($sPlaceIDs) ";
|
||||
$sSQL .= ' AND (';
|
||||
$sSQL .= " placex.rank_address between $iMinRank and $iMaxRank ";
|
||||
if (14 >= $iMinRank && 14 <= $iMaxRank) {
|
||||
$sSQL .= " OR (extratags->'place') = 'city'";
|
||||
}
|
||||
if ($this->sAddressRankListSql) {
|
||||
$sSQL .= ' OR placex.rank_address in '.$this->sAddressRankListSql;
|
||||
}
|
||||
$sSQL .= ' ) ';
|
||||
if ($this->sAllowedTypesSQLList) {
|
||||
$sSQL .= 'AND placex.class in '.$this->sAllowedTypesSQLList;
|
||||
}
|
||||
if (!$bAllowLinked) {
|
||||
$sSQL .= ' AND linked_place_id is null ';
|
||||
}
|
||||
$sSQL .= ' GROUP BY ';
|
||||
$sSQL .= ' osm_type, ';
|
||||
$sSQL .= ' osm_id, ';
|
||||
$sSQL .= ' class, ';
|
||||
$sSQL .= ' type, ';
|
||||
$sSQL .= ' admin_level, ';
|
||||
$sSQL .= ' rank_search, ';
|
||||
$sSQL .= ' rank_address, ';
|
||||
$sSQL .= ' housenumber,';
|
||||
$sSQL .= ' country_code, ';
|
||||
$sSQL .= ' importance, ';
|
||||
if (!$this->bDeDupe) {
|
||||
$sSQL .= 'place_id,';
|
||||
}
|
||||
if (!$this->bAddressDetails) {
|
||||
$sSQL .= 'langaddress, ';
|
||||
}
|
||||
$sSQL .= ' placename, ';
|
||||
$sSQL .= ' ref, ';
|
||||
if ($this->bExtraTags) {
|
||||
$sSQL .= 'extratags, ';
|
||||
}
|
||||
if ($this->bNameDetails) {
|
||||
$sSQL .= 'name, ';
|
||||
}
|
||||
$sSQL .= ' extra_place ';
|
||||
|
||||
$aSubSelects[] = $sSQL;
|
||||
}
|
||||
|
||||
// postcode table
|
||||
$sPlaceIDs = Result::joinIdsByTable($aResults, Result::TABLE_POSTCODE);
|
||||
if ($sPlaceIDs) {
|
||||
Debug::printVar('Ids from location_postcode', $sPlaceIDs);
|
||||
$sSQL = 'SELECT';
|
||||
$sSQL .= " 'P' as osm_type,";
|
||||
$sSQL .= ' (SELECT osm_id from placex p WHERE p.place_id = lp.parent_place_id) as osm_id,';
|
||||
$sSQL .= " 'place' as class, 'postcode' as type,";
|
||||
$sSQL .= ' null::smallint as admin_level, rank_search, rank_address,';
|
||||
$sSQL .= ' place_id, parent_place_id,';
|
||||
$sSQL .= ' -1 as housenumber,';
|
||||
$sSQL .= ' country_code,';
|
||||
$sSQL .= $this->langAddressSql('-1');
|
||||
$sSQL .= ' postcode as placename,';
|
||||
$sSQL .= ' postcode as ref,';
|
||||
if ($this->bExtraTags) {
|
||||
$sSQL .= 'null::text AS extra,';
|
||||
}
|
||||
if ($this->bNameDetails) {
|
||||
$sSQL .= 'null::text AS names,';
|
||||
}
|
||||
$sSQL .= ' ST_x(geometry) AS lon, ST_y(geometry) AS lat,';
|
||||
$sSQL .= ' (0.75-(rank_search::float/40)) AS importance, ';
|
||||
$sSQL .= $this->addressImportanceSql('geometry', 'lp.parent_place_id');
|
||||
$sSQL .= ' null::text AS extra_place ';
|
||||
$sSQL .= 'FROM location_postcode lp';
|
||||
$sSQL .= " WHERE place_id in ($sPlaceIDs) ";
|
||||
$sSQL .= " AND lp.rank_address between $iMinRank and $iMaxRank";
|
||||
|
||||
$aSubSelects[] = $sSQL;
|
||||
}
|
||||
|
||||
// All other tables are rank 30 only.
|
||||
if ($iMaxRank == 30) {
|
||||
// TIGER table
|
||||
if (CONST_Use_US_Tiger_Data) {
|
||||
$sPlaceIDs = Result::joinIdsByTable($aResults, Result::TABLE_TIGER);
|
||||
if ($sPlaceIDs) {
|
||||
Debug::printVar('Ids from Tiger table', $sPlaceIDs);
|
||||
$sHousenumbers = Result::sqlHouseNumberTable($aResults, Result::TABLE_TIGER);
|
||||
// Tiger search only if a housenumber was searched and if it was found
|
||||
// (realized through a join)
|
||||
$sSQL = ' SELECT ';
|
||||
$sSQL .= " 'T' AS osm_type, ";
|
||||
$sSQL .= ' (SELECT osm_id from placex p WHERE p.place_id=blub.parent_place_id) as osm_id, ';
|
||||
$sSQL .= " 'place' AS class, ";
|
||||
$sSQL .= " 'house' AS type, ";
|
||||
$sSQL .= ' null::smallint AS admin_level, ';
|
||||
$sSQL .= ' 30 AS rank_search, ';
|
||||
$sSQL .= ' 30 AS rank_address, ';
|
||||
$sSQL .= ' place_id, ';
|
||||
$sSQL .= ' parent_place_id, ';
|
||||
$sSQL .= ' housenumber_for_place as housenumber,';
|
||||
$sSQL .= " 'us' AS country_code, ";
|
||||
$sSQL .= $this->langAddressSql('housenumber_for_place');
|
||||
$sSQL .= ' null::text AS placename, ';
|
||||
$sSQL .= ' null::text AS ref, ';
|
||||
if ($this->bExtraTags) {
|
||||
$sSQL .= 'null::text AS extra,';
|
||||
}
|
||||
if ($this->bNameDetails) {
|
||||
$sSQL .= 'null::text AS names,';
|
||||
}
|
||||
$sSQL .= ' st_x(centroid) AS lon, ';
|
||||
$sSQL .= ' st_y(centroid) AS lat,';
|
||||
$sSQL .= ' -1.15 AS importance, ';
|
||||
$sSQL .= $this->addressImportanceSql('centroid', 'blub.parent_place_id');
|
||||
$sSQL .= ' null::text AS extra_place ';
|
||||
$sSQL .= ' FROM (';
|
||||
$sSQL .= ' SELECT place_id, '; // interpolate the Tiger housenumbers here
|
||||
$sSQL .= ' CASE WHEN startnumber != endnumber';
|
||||
$sSQL .= ' THEN ST_LineInterpolatePoint(linegeo, (housenumber_for_place-startnumber::float)/(endnumber-startnumber)::float)';
|
||||
$sSQL .= ' ELSE ST_LineInterpolatePoint(linegeo, 0.5) END AS centroid, ';
|
||||
$sSQL .= ' parent_place_id, ';
|
||||
$sSQL .= ' housenumber_for_place';
|
||||
$sSQL .= ' FROM (';
|
||||
$sSQL .= ' location_property_tiger ';
|
||||
$sSQL .= ' JOIN (values '.$sHousenumbers.') AS housenumbers(place_id, housenumber_for_place) USING(place_id)) ';
|
||||
$sSQL .= ' WHERE ';
|
||||
$sSQL .= ' housenumber_for_place >= startnumber';
|
||||
$sSQL .= ' AND housenumber_for_place <= endnumber';
|
||||
$sSQL .= ' ) AS blub'; //postgres wants an alias here
|
||||
|
||||
$aSubSelects[] = $sSQL;
|
||||
}
|
||||
}
|
||||
|
||||
// osmline - interpolated housenumbers
|
||||
$sPlaceIDs = Result::joinIdsByTable($aResults, Result::TABLE_OSMLINE);
|
||||
if ($sPlaceIDs) {
|
||||
Debug::printVar('Ids from interpolation', $sPlaceIDs);
|
||||
$sHousenumbers = Result::sqlHouseNumberTable($aResults, Result::TABLE_OSMLINE);
|
||||
// interpolation line search only if a housenumber was searched
|
||||
// (realized through a join)
|
||||
$sSQL = 'SELECT ';
|
||||
$sSQL .= " 'W' AS osm_type, ";
|
||||
$sSQL .= ' osm_id, ';
|
||||
$sSQL .= " 'place' AS class, ";
|
||||
$sSQL .= " 'house' AS type, ";
|
||||
$sSQL .= ' null::smallint AS admin_level, ';
|
||||
$sSQL .= ' 30 AS rank_search, ';
|
||||
$sSQL .= ' 30 AS rank_address, ';
|
||||
$sSQL .= ' place_id, ';
|
||||
$sSQL .= ' parent_place_id, ';
|
||||
$sSQL .= ' housenumber_for_place as housenumber,';
|
||||
$sSQL .= ' country_code, ';
|
||||
$sSQL .= $this->langAddressSql('housenumber_for_place');
|
||||
$sSQL .= ' null::text AS placename, ';
|
||||
$sSQL .= ' null::text AS ref, ';
|
||||
if ($this->bExtraTags) {
|
||||
$sSQL .= 'null::text AS extra, ';
|
||||
}
|
||||
if ($this->bNameDetails) {
|
||||
$sSQL .= 'null::text AS names, ';
|
||||
}
|
||||
$sSQL .= ' st_x(centroid) AS lon, ';
|
||||
$sSQL .= ' st_y(centroid) AS lat, ';
|
||||
// slightly smaller than the importance for normal houses
|
||||
$sSQL .= ' -0.1 AS importance, ';
|
||||
$sSQL .= $this->addressImportanceSql('centroid', 'blub.parent_place_id');
|
||||
$sSQL .= ' null::text AS extra_place ';
|
||||
$sSQL .= ' FROM (';
|
||||
$sSQL .= ' SELECT ';
|
||||
$sSQL .= ' osm_id, ';
|
||||
$sSQL .= ' place_id, ';
|
||||
$sSQL .= ' country_code, ';
|
||||
$sSQL .= ' CASE '; // interpolate the housenumbers here
|
||||
$sSQL .= ' WHEN startnumber != endnumber ';
|
||||
$sSQL .= ' THEN ST_LineInterpolatePoint(linegeo, (housenumber_for_place-startnumber::float)/(endnumber-startnumber)::float) ';
|
||||
$sSQL .= ' ELSE linegeo ';
|
||||
$sSQL .= ' END as centroid, ';
|
||||
$sSQL .= ' parent_place_id, ';
|
||||
$sSQL .= ' housenumber_for_place ';
|
||||
$sSQL .= ' FROM (';
|
||||
$sSQL .= ' location_property_osmline ';
|
||||
$sSQL .= ' JOIN (values '.$sHousenumbers.') AS housenumbers(place_id, housenumber_for_place) USING(place_id)';
|
||||
$sSQL .= ' ) ';
|
||||
$sSQL .= ' WHERE housenumber_for_place >= 0 ';
|
||||
$sSQL .= ' ) as blub'; //postgres wants an alias here
|
||||
|
||||
$aSubSelects[] = $sSQL;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($aSubSelects)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$sSQL = join(' UNION ', $aSubSelects);
|
||||
Debug::printSQL($sSQL);
|
||||
$aPlaces = $this->oDB->getAll($sSQL, null, 'Could not lookup place');
|
||||
|
||||
foreach ($aPlaces as &$aPlace) {
|
||||
$aPlace['importance'] = (float) $aPlace['importance'];
|
||||
if ($this->bAddressDetails) {
|
||||
// to get addressdetails for tiger data, the housenumber is needed
|
||||
$aPlace['address'] = new AddressDetails(
|
||||
$this->oDB,
|
||||
$aPlace['place_id'],
|
||||
$aPlace['housenumber'],
|
||||
$this->aLangPrefOrderSql
|
||||
);
|
||||
$aPlace['langaddress'] = $aPlace['address']->getLocaleAddress();
|
||||
}
|
||||
|
||||
if ($this->bExtraTags) {
|
||||
if ($aPlace['extra']) {
|
||||
$aPlace['sExtraTags'] = json_decode($aPlace['extra'], true);
|
||||
} else {
|
||||
$aPlace['sExtraTags'] = (object) array();
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->bNameDetails) {
|
||||
$aPlace['sNameDetails'] = $this->extractNames($aPlace['names']);
|
||||
}
|
||||
|
||||
$aPlace['addresstype'] = ClassTypes\getLabelTag(
|
||||
$aPlace,
|
||||
$aPlace['country_code']
|
||||
);
|
||||
|
||||
$aResults[$aPlace['place_id']] = $aPlace;
|
||||
}
|
||||
|
||||
$aResults = array_filter(
|
||||
$aResults,
|
||||
function ($v) {
|
||||
return !($v instanceof Result);
|
||||
}
|
||||
);
|
||||
|
||||
Debug::printVar('Places', $aResults);
|
||||
|
||||
return $aResults;
|
||||
}
|
||||
|
||||
|
||||
private function extractNames($sNames)
|
||||
{
|
||||
if (!$sNames) {
|
||||
return (object) array();
|
||||
}
|
||||
|
||||
$aFullNames = json_decode($sNames, true);
|
||||
$aNames = array();
|
||||
|
||||
foreach ($aFullNames as $sKey => $sValue) {
|
||||
if (strpos($sKey, '_place_') === 0) {
|
||||
$sSubKey = substr($sKey, 7);
|
||||
if (array_key_exists($sSubKey, $aFullNames)) {
|
||||
$aNames[$sKey] = $sValue;
|
||||
} else {
|
||||
$aNames[$sSubKey] = $sValue;
|
||||
}
|
||||
} else {
|
||||
$aNames[$sKey] = $sValue;
|
||||
}
|
||||
}
|
||||
|
||||
return $aNames;
|
||||
}
|
||||
|
||||
|
||||
/* returns an array which will contain the keys
|
||||
* aBoundingBox
|
||||
* and may also contain one or more of the keys
|
||||
* asgeojson
|
||||
* askml
|
||||
* assvg
|
||||
* astext
|
||||
* lat
|
||||
* lon
|
||||
*/
|
||||
public function getOutlines($iPlaceID, $fLon = null, $fLat = null, $fRadius = null, $fLonReverse = null, $fLatReverse = null)
|
||||
{
|
||||
|
||||
$aOutlineResult = array();
|
||||
if (!$iPlaceID) {
|
||||
return $aOutlineResult;
|
||||
}
|
||||
|
||||
// Get the bounding box and outline polygon
|
||||
$sSQL = 'select place_id,0 as numfeatures,st_area(geometry) as area,';
|
||||
$sSQL .= ' ST_Y(centroid) as centrelat, ST_X(centroid) as centrelon,';
|
||||
$sSQL .= ' ST_YMin(geometry) as minlat,ST_YMax(geometry) as maxlat,';
|
||||
$sSQL .= ' ST_XMin(geometry) as minlon,ST_XMax(geometry) as maxlon';
|
||||
if ($this->bIncludePolygonAsGeoJSON) {
|
||||
$sSQL .= ',ST_AsGeoJSON(geometry) as asgeojson';
|
||||
}
|
||||
if ($this->bIncludePolygonAsKML) {
|
||||
$sSQL .= ',ST_AsKML(geometry) as askml';
|
||||
}
|
||||
if ($this->bIncludePolygonAsSVG) {
|
||||
$sSQL .= ',ST_AsSVG(geometry) as assvg';
|
||||
}
|
||||
if ($this->bIncludePolygonAsText) {
|
||||
$sSQL .= ',ST_AsText(geometry) as astext';
|
||||
}
|
||||
|
||||
$sSQL .= ' FROM (SELECT place_id';
|
||||
if ($fLonReverse != null && $fLatReverse != null) {
|
||||
$sSQL .= ',CASE WHEN (class = \'highway\') AND (ST_GeometryType(geometry) = \'ST_LineString\') THEN ';
|
||||
$sSQL .=' ST_ClosestPoint(geometry, ST_SetSRID(ST_Point('.$fLatReverse.','.$fLonReverse.'),4326))';
|
||||
$sSQL .=' ELSE centroid END AS centroid';
|
||||
} else {
|
||||
$sSQL .= ',centroid';
|
||||
}
|
||||
if ($this->fPolygonSimplificationThreshold > 0) {
|
||||
$sSQL .= ',ST_SimplifyPreserveTopology(geometry,'.$this->fPolygonSimplificationThreshold.') as geometry';
|
||||
} else {
|
||||
$sSQL .= ',geometry';
|
||||
}
|
||||
$sSQL .= ' FROM placex where place_id = '.$iPlaceID.') as plx';
|
||||
|
||||
$aPointPolygon = $this->oDB->getRow($sSQL, null, 'Could not get outline');
|
||||
|
||||
if ($aPointPolygon && $aPointPolygon['place_id']) {
|
||||
if ($aPointPolygon['centrelon'] !== null && $aPointPolygon['centrelat'] !== null) {
|
||||
$aOutlineResult['lat'] = $aPointPolygon['centrelat'];
|
||||
$aOutlineResult['lon'] = $aPointPolygon['centrelon'];
|
||||
}
|
||||
|
||||
if ($this->bIncludePolygonAsGeoJSON) {
|
||||
$aOutlineResult['asgeojson'] = $aPointPolygon['asgeojson'];
|
||||
}
|
||||
if ($this->bIncludePolygonAsKML) {
|
||||
$aOutlineResult['askml'] = $aPointPolygon['askml'];
|
||||
}
|
||||
if ($this->bIncludePolygonAsSVG) {
|
||||
$aOutlineResult['assvg'] = $aPointPolygon['assvg'];
|
||||
}
|
||||
if ($this->bIncludePolygonAsText) {
|
||||
$aOutlineResult['astext'] = $aPointPolygon['astext'];
|
||||
}
|
||||
|
||||
if (abs($aPointPolygon['minlat'] - $aPointPolygon['maxlat']) < 0.0000001) {
|
||||
$aPointPolygon['minlat'] = $aPointPolygon['minlat'] - $fRadius;
|
||||
$aPointPolygon['maxlat'] = $aPointPolygon['maxlat'] + $fRadius;
|
||||
}
|
||||
|
||||
if (abs($aPointPolygon['minlon'] - $aPointPolygon['maxlon']) < 0.0000001) {
|
||||
$aPointPolygon['minlon'] = $aPointPolygon['minlon'] - $fRadius;
|
||||
$aPointPolygon['maxlon'] = $aPointPolygon['maxlon'] + $fRadius;
|
||||
}
|
||||
|
||||
$aOutlineResult['aBoundingBox'] = array(
|
||||
(string)$aPointPolygon['minlat'],
|
||||
(string)$aPointPolygon['maxlat'],
|
||||
(string)$aPointPolygon['minlon'],
|
||||
(string)$aPointPolygon['maxlon']
|
||||
);
|
||||
}
|
||||
|
||||
// as a fallback we generate a bounding box without knowing the size of the geometry
|
||||
if ((!isset($aOutlineResult['aBoundingBox'])) && isset($fLon)) {
|
||||
$aBounds = array(
|
||||
'minlat' => $fLat - $fRadius,
|
||||
'maxlat' => $fLat + $fRadius,
|
||||
'minlon' => $fLon - $fRadius,
|
||||
'maxlon' => $fLon + $fRadius
|
||||
);
|
||||
|
||||
$aOutlineResult['aBoundingBox'] = array(
|
||||
(string)$aBounds['minlat'],
|
||||
(string)$aBounds['maxlat'],
|
||||
(string)$aBounds['minlon'],
|
||||
(string)$aBounds['maxlon']
|
||||
);
|
||||
}
|
||||
return $aOutlineResult;
|
||||
}
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* This file is part of Nominatim. (https://nominatim.org)
|
||||
*
|
||||
* Copyright (C) 2022 by the Nominatim developer community.
|
||||
* For a full list of authors see the git log.
|
||||
*/
|
||||
|
||||
namespace Nominatim;
|
||||
|
||||
/**
|
||||
* A single result of a search operation or a reverse lookup.
|
||||
*
|
||||
* This object only contains the id of the result. It does not yet
|
||||
* have any details needed to format the output document.
|
||||
*/
|
||||
class Result
|
||||
{
|
||||
const TABLE_PLACEX = 0;
|
||||
const TABLE_POSTCODE = 1;
|
||||
const TABLE_OSMLINE = 2;
|
||||
const TABLE_TIGER = 3;
|
||||
|
||||
/// Database table that contains the result.
|
||||
public $iTable;
|
||||
/// Id of the result.
|
||||
public $iId;
|
||||
/// House number (only for interpolation results).
|
||||
public $iHouseNumber = -1;
|
||||
/// Number of exact matches in address (address searches only).
|
||||
public $iExactMatches = 0;
|
||||
/// Subranking within the results (the higher the worse).
|
||||
public $iResultRank = 0;
|
||||
/// Address rank of the result.
|
||||
public $iAddressRank;
|
||||
|
||||
public function debugInfo()
|
||||
{
|
||||
return array(
|
||||
'Table' => $this->iTable,
|
||||
'ID' => $this->iId,
|
||||
'House number' => $this->iHouseNumber,
|
||||
'Exact Matches' => $this->iExactMatches,
|
||||
'Result rank' => $this->iResultRank
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function __construct($sId, $iTable = Result::TABLE_PLACEX)
|
||||
{
|
||||
$this->iTable = $iTable;
|
||||
$this->iId = (int) $sId;
|
||||
}
|
||||
|
||||
public static function joinIdsByTable($aResults, $iTable)
|
||||
{
|
||||
return join(',', array_keys(array_filter(
|
||||
$aResults,
|
||||
function ($aValue) use ($iTable) {
|
||||
return $aValue->iTable == $iTable;
|
||||
}
|
||||
)));
|
||||
}
|
||||
|
||||
public static function joinIdsByTableMinRank($aResults, $iTable, $iMinAddressRank)
|
||||
{
|
||||
return join(',', array_keys(array_filter(
|
||||
$aResults,
|
||||
function ($aValue) use ($iTable, $iMinAddressRank) {
|
||||
return $aValue->iTable == $iTable && $aValue->iAddressRank >= $iMinAddressRank;
|
||||
}
|
||||
)));
|
||||
}
|
||||
|
||||
public static function joinIdsByTableMaxRank($aResults, $iTable, $iMaxAddressRank)
|
||||
{
|
||||
return join(',', array_keys(array_filter(
|
||||
$aResults,
|
||||
function ($aValue) use ($iTable, $iMaxAddressRank) {
|
||||
return $aValue->iTable == $iTable && $aValue->iAddressRank <= $iMaxAddressRank;
|
||||
}
|
||||
)));
|
||||
}
|
||||
|
||||
public static function sqlHouseNumberTable($aResults, $iTable)
|
||||
{
|
||||
$sHousenumbers = '';
|
||||
$sSep = '';
|
||||
foreach ($aResults as $oResult) {
|
||||
if ($oResult->iTable == $iTable) {
|
||||
$sHousenumbers .= $sSep.'('.$oResult->iId.',';
|
||||
$sHousenumbers .= $oResult->iHouseNumber.')';
|
||||
$sSep = ',';
|
||||
}
|
||||
}
|
||||
|
||||
return $sHousenumbers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Split a result array into highest ranked result and the rest
|
||||
*
|
||||
* @param object[] $aResults List of results to split.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public static function splitResults($aResults)
|
||||
{
|
||||
$aHead = array();
|
||||
$aTail = array();
|
||||
$iMinRank = 10000;
|
||||
|
||||
foreach ($aResults as $oRes) {
|
||||
if ($oRes->iResultRank < $iMinRank) {
|
||||
$aTail += $aHead;
|
||||
$aHead = array($oRes->iId => $oRes);
|
||||
$iMinRank = $oRes->iResultRank;
|
||||
} elseif ($oRes->iResultRank == $iMinRank) {
|
||||
$aHead[$oRes->iId] = $oRes;
|
||||
} else {
|
||||
$aTail[$oRes->iId] = $oRes;
|
||||
}
|
||||
}
|
||||
|
||||
return array('head' => $aHead, 'tail' => $aTail);
|
||||
}
|
||||
}
|
||||
@@ -1,396 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* This file is part of Nominatim. (https://nominatim.org)
|
||||
*
|
||||
* Copyright (C) 2022 by the Nominatim developer community.
|
||||
* For a full list of authors see the git log.
|
||||
*/
|
||||
|
||||
namespace Nominatim;
|
||||
|
||||
require_once(CONST_LibDir.'/Result.php');
|
||||
|
||||
class ReverseGeocode
|
||||
{
|
||||
protected $oDB;
|
||||
protected $iMaxRank = 28;
|
||||
|
||||
|
||||
public function __construct(&$oDB)
|
||||
{
|
||||
$this->oDB =& $oDB;
|
||||
}
|
||||
|
||||
|
||||
public function setZoom($iZoom)
|
||||
{
|
||||
// Zoom to rank, this could probably be calculated but a lookup gives fine control
|
||||
$aZoomRank = array(
|
||||
0 => 2, // Continent / Sea
|
||||
1 => 2,
|
||||
2 => 2,
|
||||
3 => 4, // Country
|
||||
4 => 4,
|
||||
5 => 8, // State
|
||||
6 => 10, // Region
|
||||
7 => 10,
|
||||
8 => 12, // County
|
||||
9 => 12,
|
||||
10 => 17, // City
|
||||
11 => 17,
|
||||
12 => 18, // Town / Village
|
||||
13 => 18,
|
||||
14 => 22, // Suburb
|
||||
15 => 22,
|
||||
16 => 26, // major street
|
||||
17 => 27, // minor street
|
||||
18 => 30, // or >, Building
|
||||
19 => 30, // or >, Building
|
||||
);
|
||||
$this->iMaxRank = (isset($iZoom) && isset($aZoomRank[$iZoom]))?$aZoomRank[$iZoom]:28;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the closest interpolation with the given search diameter.
|
||||
*
|
||||
* @param string $sPointSQL Reverse geocoding point as SQL
|
||||
* @param float $fSearchDiam Search diameter
|
||||
*
|
||||
* @return Record of the interpolation or null.
|
||||
*/
|
||||
protected function lookupInterpolation($sPointSQL, $fSearchDiam)
|
||||
{
|
||||
Debug::newFunction('lookupInterpolation');
|
||||
$sSQL = 'SELECT place_id, parent_place_id, 30 as rank_search,';
|
||||
$sSQL .= ' (CASE WHEN endnumber != startnumber';
|
||||
$sSQL .= ' THEN (endnumber - startnumber) * ST_LineLocatePoint(linegeo,'.$sPointSQL.')';
|
||||
$sSQL .= ' ELSE startnumber END) as fhnr,';
|
||||
$sSQL .= ' startnumber, endnumber, step,';
|
||||
$sSQL .= ' ST_Distance(linegeo,'.$sPointSQL.') as distance';
|
||||
$sSQL .= ' FROM location_property_osmline';
|
||||
$sSQL .= ' WHERE ST_DWithin('.$sPointSQL.', linegeo, '.$fSearchDiam.')';
|
||||
$sSQL .= ' and indexed_status = 0 and startnumber is not NULL ';
|
||||
$sSQL .= ' and parent_place_id != 0';
|
||||
$sSQL .= ' ORDER BY distance ASC limit 1';
|
||||
Debug::printSQL($sSQL);
|
||||
|
||||
return $this->oDB->getRow(
|
||||
$sSQL,
|
||||
null,
|
||||
'Could not determine closest housenumber on an osm interpolation line.'
|
||||
);
|
||||
}
|
||||
|
||||
protected function lookupLargeArea($sPointSQL, $iMaxRank)
|
||||
{
|
||||
if ($iMaxRank > 4) {
|
||||
$aPlace = $this->lookupPolygon($sPointSQL, $iMaxRank);
|
||||
if ($aPlace) {
|
||||
return new Result($aPlace['place_id']);
|
||||
}
|
||||
}
|
||||
|
||||
// If no polygon which contains the searchpoint is found,
|
||||
// searches in the country_osm_grid table for a polygon.
|
||||
return $this->lookupInCountry($sPointSQL, $iMaxRank);
|
||||
}
|
||||
|
||||
protected function lookupInCountry($sPointSQL, $iMaxRank)
|
||||
{
|
||||
Debug::newFunction('lookupInCountry');
|
||||
// searches for polygon in table country_osm_grid which contains the searchpoint
|
||||
// and searches for the nearest place node to the searchpoint in this polygon
|
||||
$sSQL = 'SELECT country_code FROM country_osm_grid';
|
||||
$sSQL .= ' WHERE ST_CONTAINS(geometry, '.$sPointSQL.') LIMIT 1';
|
||||
Debug::printSQL($sSQL);
|
||||
|
||||
$sCountryCode = $this->oDB->getOne(
|
||||
$sSQL,
|
||||
null,
|
||||
'Could not determine country polygon containing the point.'
|
||||
);
|
||||
Debug::printVar('Country code', $sCountryCode);
|
||||
|
||||
if ($sCountryCode) {
|
||||
if ($iMaxRank > 4) {
|
||||
// look for place nodes with the given country code
|
||||
$sSQL = 'SELECT place_id FROM';
|
||||
$sSQL .= ' (SELECT place_id, rank_search,';
|
||||
$sSQL .= ' ST_distance('.$sPointSQL.', geometry) as distance';
|
||||
$sSQL .= ' FROM placex';
|
||||
$sSQL .= ' WHERE osm_type = \'N\'';
|
||||
$sSQL .= ' AND country_code = \''.$sCountryCode.'\'';
|
||||
$sSQL .= ' AND rank_search < 26 '; // needed to select right index
|
||||
$sSQL .= ' AND rank_search between 5 and ' .min(25, $iMaxRank);
|
||||
$sSQL .= ' AND class = \'place\' AND type != \'postcode\'';
|
||||
$sSQL .= ' AND name IS NOT NULL ';
|
||||
$sSQL .= ' and indexed_status = 0 and linked_place_id is null';
|
||||
$sSQL .= ' AND ST_DWithin('.$sPointSQL.', geometry, 1.8)) p ';
|
||||
$sSQL .= 'WHERE distance <= reverse_place_diameter(rank_search)';
|
||||
$sSQL .= ' ORDER BY rank_search DESC, distance ASC';
|
||||
$sSQL .= ' LIMIT 1';
|
||||
Debug::printSQL($sSQL);
|
||||
|
||||
$aPlace = $this->oDB->getRow($sSQL, null, 'Could not determine place node.');
|
||||
Debug::printVar('Country node', $aPlace);
|
||||
|
||||
if ($aPlace) {
|
||||
return new Result($aPlace['place_id']);
|
||||
}
|
||||
}
|
||||
|
||||
// still nothing, then return the country object
|
||||
$sSQL = 'SELECT place_id, ST_distance('.$sPointSQL.', centroid) as distance';
|
||||
$sSQL .= ' FROM placex';
|
||||
$sSQL .= ' WHERE country_code = \''.$sCountryCode.'\'';
|
||||
$sSQL .= ' AND rank_search = 4 AND rank_address = 4';
|
||||
$sSQL .= ' AND class in (\'boundary\', \'place\')';
|
||||
$sSQL .= ' AND linked_place_id is null';
|
||||
$sSQL .= ' ORDER BY distance ASC';
|
||||
Debug::printSQL($sSQL);
|
||||
|
||||
$aPlace = $this->oDB->getRow($sSQL, null, 'Could not determine place node.');
|
||||
Debug::printVar('Country place', $aPlace);
|
||||
if ($aPlace) {
|
||||
return new Result($aPlace['place_id']);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for areas or nodes for areas or nodes between state and suburb level.
|
||||
*
|
||||
* @param string $sPointSQL Search point as SQL string.
|
||||
* @param int $iMaxRank Maximum address rank of the feature.
|
||||
*
|
||||
* @return Record of the found feature or null.
|
||||
*
|
||||
* Searches first for polygon that contains the search point.
|
||||
* If such a polygon is found, place nodes with a higher rank are
|
||||
* searched inside the polygon.
|
||||
*/
|
||||
protected function lookupPolygon($sPointSQL, $iMaxRank)
|
||||
{
|
||||
Debug::newFunction('lookupPolygon');
|
||||
// polygon search begins at suburb-level
|
||||
if ($iMaxRank > 25) {
|
||||
$iMaxRank = 25;
|
||||
}
|
||||
// no polygon search over country-level
|
||||
if ($iMaxRank < 5) {
|
||||
$iMaxRank = 5;
|
||||
}
|
||||
// search for polygon
|
||||
$sSQL = 'SELECT place_id, parent_place_id, rank_address, rank_search FROM';
|
||||
$sSQL .= '(select place_id, parent_place_id, rank_address, rank_search, country_code, geometry';
|
||||
$sSQL .= ' FROM placex';
|
||||
$sSQL .= ' WHERE ST_GeometryType(geometry) in (\'ST_Polygon\', \'ST_MultiPolygon\')';
|
||||
// Ensure that query planner doesn't use the index on rank_search.
|
||||
$sSQL .= ' AND coalesce(rank_search, 0) between 5 and ' .$iMaxRank;
|
||||
$sSQL .= ' AND rank_address between 4 and 25'; // needed for index selection
|
||||
$sSQL .= ' AND geometry && '.$sPointSQL;
|
||||
$sSQL .= ' AND type != \'postcode\' ';
|
||||
$sSQL .= ' AND name is not null';
|
||||
$sSQL .= ' AND indexed_status = 0 and linked_place_id is null';
|
||||
$sSQL .= ' ORDER BY rank_search DESC LIMIT 50 ) as a';
|
||||
$sSQL .= ' WHERE ST_Contains(geometry, '.$sPointSQL.' )';
|
||||
$sSQL .= ' ORDER BY rank_search DESC LIMIT 1';
|
||||
Debug::printSQL($sSQL);
|
||||
|
||||
$aPoly = $this->oDB->getRow($sSQL, null, 'Could not determine polygon containing the point.');
|
||||
Debug::printVar('Polygon result', $aPoly);
|
||||
|
||||
if ($aPoly) {
|
||||
// if a polygon is found, search for placenodes begins ...
|
||||
$iRankAddress = $aPoly['rank_address'];
|
||||
$iRankSearch = $aPoly['rank_search'];
|
||||
$iPlaceID = $aPoly['place_id'];
|
||||
|
||||
if ($iRankSearch != $iMaxRank) {
|
||||
$sSQL = 'SELECT place_id FROM ';
|
||||
$sSQL .= '(SELECT place_id, rank_search, country_code, geometry,';
|
||||
$sSQL .= ' ST_distance('.$sPointSQL.', geometry) as distance';
|
||||
$sSQL .= ' FROM placex';
|
||||
$sSQL .= ' WHERE osm_type = \'N\'';
|
||||
// using rank_search because of a better differentiation
|
||||
// for place nodes at rank_address 16
|
||||
$sSQL .= ' AND rank_search > '.$iRankSearch;
|
||||
$sSQL .= ' AND rank_search <= '.$iMaxRank;
|
||||
$sSQL .= ' AND rank_search < 26 '; // needed to select right index
|
||||
$sSQL .= ' AND rank_address > 0';
|
||||
$sSQL .= ' AND class = \'place\'';
|
||||
$sSQL .= ' AND type != \'postcode\'';
|
||||
$sSQL .= ' AND name IS NOT NULL ';
|
||||
$sSQL .= ' AND indexed_status = 0 AND linked_place_id is null';
|
||||
$sSQL .= ' AND ST_DWithin('.$sPointSQL.', geometry, reverse_place_diameter('.$iRankSearch.'::smallint))';
|
||||
$sSQL .= ' ORDER BY distance ASC,';
|
||||
$sSQL .= ' rank_address DESC';
|
||||
$sSQL .= ' limit 500) as a';
|
||||
$sSQL .= ' WHERE ST_CONTAINS((SELECT geometry FROM placex WHERE place_id = '.$iPlaceID.'), geometry )';
|
||||
$sSQL .= ' AND distance <= reverse_place_diameter(rank_search)';
|
||||
$sSQL .= ' ORDER BY distance ASC, rank_search DESC';
|
||||
$sSQL .= ' LIMIT 1';
|
||||
Debug::printSQL($sSQL);
|
||||
|
||||
$aPlaceNode = $this->oDB->getRow($sSQL, null, 'Could not determine place node.');
|
||||
Debug::printVar('Nearest place node', $aPlaceNode);
|
||||
if ($aPlaceNode) {
|
||||
return $aPlaceNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $aPoly;
|
||||
}
|
||||
|
||||
|
||||
public function lookup($fLat, $fLon, $bDoInterpolation = true)
|
||||
{
|
||||
return $this->lookupPoint(
|
||||
'ST_SetSRID(ST_Point('.$fLon.','.$fLat.'),4326)',
|
||||
$bDoInterpolation
|
||||
);
|
||||
}
|
||||
|
||||
public function lookupPoint($sPointSQL, $bDoInterpolation = true)
|
||||
{
|
||||
Debug::newFunction('lookupPoint');
|
||||
// Find the nearest point
|
||||
$fSearchDiam = 0.006;
|
||||
$oResult = null;
|
||||
$aPlace = null;
|
||||
|
||||
// for POI or street level
|
||||
if ($this->iMaxRank >= 26) {
|
||||
// starts if the search is on POI or street level,
|
||||
// searches for the nearest POI or street,
|
||||
// if a street is found and a POI is searched for,
|
||||
// the nearest POI which the found street is a parent of is chosen.
|
||||
$sSQL = 'select place_id,parent_place_id,rank_address,country_code,';
|
||||
$sSQL .= ' ST_distance('.$sPointSQL.', geometry) as distance';
|
||||
$sSQL .= ' FROM ';
|
||||
$sSQL .= ' placex';
|
||||
$sSQL .= ' WHERE ST_DWithin('.$sPointSQL.', geometry, '.$fSearchDiam.')';
|
||||
$sSQL .= ' AND';
|
||||
$sSQL .= ' rank_address between 26 and '.$this->iMaxRank;
|
||||
$sSQL .= ' and (name is not null or housenumber is not null';
|
||||
$sSQL .= ' or rank_address between 26 and 27)';
|
||||
$sSQL .= ' and (rank_address between 26 and 27';
|
||||
$sSQL .= ' or ST_GeometryType(geometry) != \'ST_LineString\')';
|
||||
$sSQL .= ' and class not in (\'boundary\')';
|
||||
$sSQL .= ' and indexed_status = 0 and linked_place_id is null';
|
||||
$sSQL .= ' and (ST_GeometryType(geometry) not in (\'ST_Polygon\',\'ST_MultiPolygon\') ';
|
||||
$sSQL .= ' OR ST_DWithin('.$sPointSQL.', centroid, '.$fSearchDiam.'))';
|
||||
$sSQL .= ' ORDER BY distance ASC limit 1';
|
||||
Debug::printSQL($sSQL);
|
||||
|
||||
$aPlace = $this->oDB->getRow($sSQL, null, 'Could not determine closest place.');
|
||||
|
||||
Debug::printVar('POI/street level result', $aPlace);
|
||||
if ($aPlace) {
|
||||
$iPlaceID = $aPlace['place_id'];
|
||||
$oResult = new Result($iPlaceID);
|
||||
$iRankAddress = $aPlace['rank_address'];
|
||||
}
|
||||
|
||||
if ($aPlace) {
|
||||
// if street and maxrank > streetlevel
|
||||
if ($iRankAddress <= 27 && $this->iMaxRank > 27) {
|
||||
// find the closest object (up to a certain radius) of which the street is a parent of
|
||||
$sSQL = ' select place_id,';
|
||||
$sSQL .= ' ST_distance('.$sPointSQL.', geometry) as distance';
|
||||
$sSQL .= ' FROM ';
|
||||
$sSQL .= ' placex';
|
||||
// radius ?
|
||||
$sSQL .= ' WHERE ST_DWithin('.$sPointSQL.', geometry, 0.001)';
|
||||
$sSQL .= ' AND parent_place_id = '.$iPlaceID;
|
||||
$sSQL .= ' and rank_address > 28';
|
||||
$sSQL .= ' and ST_GeometryType(geometry) != \'ST_LineString\'';
|
||||
$sSQL .= ' and (name is not null or housenumber is not null)';
|
||||
$sSQL .= ' and class not in (\'boundary\')';
|
||||
$sSQL .= ' and indexed_status = 0 and linked_place_id is null';
|
||||
$sSQL .= ' ORDER BY distance ASC limit 1';
|
||||
Debug::printSQL($sSQL);
|
||||
|
||||
$aStreet = $this->oDB->getRow($sSQL, null, 'Could not determine closest place.');
|
||||
Debug::printVar('Closest POI result', $aStreet);
|
||||
|
||||
if ($aStreet) {
|
||||
$aPlace = $aStreet;
|
||||
$oResult = new Result($aStreet['place_id']);
|
||||
$iRankAddress = 30;
|
||||
}
|
||||
}
|
||||
|
||||
// In the US we can check TIGER data for nearest housenumber
|
||||
if (CONST_Use_US_Tiger_Data
|
||||
&& $iRankAddress <= 27
|
||||
&& $aPlace['country_code'] == 'us'
|
||||
&& $this->iMaxRank >= 28
|
||||
) {
|
||||
$sSQL = 'SELECT place_id,parent_place_id,30 as rank_search,';
|
||||
$sSQL .= ' (endnumber - startnumber) * ST_LineLocatePoint(linegeo,'.$sPointSQL.') as fhnr,';
|
||||
$sSQL .= ' startnumber, endnumber, step,';
|
||||
$sSQL .= ' ST_Distance('.$sPointSQL.', linegeo) as distance';
|
||||
$sSQL .= ' FROM location_property_tiger WHERE parent_place_id = '.$oResult->iId;
|
||||
$sSQL .= ' AND ST_DWithin('.$sPointSQL.', linegeo, 0.001)';
|
||||
$sSQL .= ' ORDER BY distance ASC limit 1';
|
||||
Debug::printSQL($sSQL);
|
||||
|
||||
$aPlaceTiger = $this->oDB->getRow($sSQL, null, 'Could not determine closest Tiger place.');
|
||||
Debug::printVar('Tiger house number result', $aPlaceTiger);
|
||||
|
||||
if ($aPlaceTiger) {
|
||||
$aPlace = $aPlaceTiger;
|
||||
$oResult = new Result($aPlaceTiger['place_id'], Result::TABLE_TIGER);
|
||||
$iRndNum = max(0, round($aPlaceTiger['fhnr'] / $aPlaceTiger['step']) * $aPlaceTiger['step']);
|
||||
$oResult->iHouseNumber = $aPlaceTiger['startnumber'] + $iRndNum;
|
||||
if ($oResult->iHouseNumber > $aPlaceTiger['endnumber']) {
|
||||
$oResult->iHouseNumber = $aPlaceTiger['endnumber'];
|
||||
}
|
||||
$iRankAddress = 30;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($bDoInterpolation && $this->iMaxRank >= 30) {
|
||||
$fDistance = $fSearchDiam;
|
||||
if ($aPlace) {
|
||||
// We can't reliably go from the closest street to an
|
||||
// interpolation line because the closest interpolation
|
||||
// may have a different street segments as a parent.
|
||||
// Therefore allow an interpolation line to take precedence
|
||||
// even when the street is closer.
|
||||
$fDistance = $iRankAddress < 28 ? 0.001 : $aPlace['distance'];
|
||||
}
|
||||
|
||||
$aHouse = $this->lookupInterpolation($sPointSQL, $fDistance);
|
||||
Debug::printVar('Interpolation result', $aPlace);
|
||||
|
||||
if ($aHouse) {
|
||||
$oResult = new Result($aHouse['place_id'], Result::TABLE_OSMLINE);
|
||||
$iRndNum = max(0, round($aHouse['fhnr'] / $aHouse['step']) * $aHouse['step']);
|
||||
$oResult->iHouseNumber = $aHouse['startnumber'] + $iRndNum;
|
||||
if ($oResult->iHouseNumber > $aHouse['endnumber']) {
|
||||
$oResult->iHouseNumber = $aHouse['endnumber'];
|
||||
}
|
||||
$aPlace = $aHouse;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$aPlace) {
|
||||
// if no POI or street is found ...
|
||||
$oResult = $this->lookupLargeArea($sPointSQL, 25);
|
||||
}
|
||||
} else {
|
||||
// lower than street level ($iMaxRank < 26 )
|
||||
$oResult = $this->lookupLargeArea($sPointSQL, $this->iMaxRank);
|
||||
}
|
||||
|
||||
Debug::printVar('Final result', $oResult);
|
||||
return $oResult;
|
||||
}
|
||||
}
|
||||
@@ -1,319 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* This file is part of Nominatim. (https://nominatim.org)
|
||||
*
|
||||
* Copyright (C) 2022 by the Nominatim developer community.
|
||||
* For a full list of authors see the git log.
|
||||
*/
|
||||
|
||||
namespace Nominatim;
|
||||
|
||||
require_once(CONST_LibDir.'/lib.php');
|
||||
|
||||
|
||||
/**
|
||||
* Collection of search constraints that are independent of the
|
||||
* actual interpretation of the search query.
|
||||
*
|
||||
* The search context is shared between all SearchDescriptions. This
|
||||
* object mainly serves as context provider for the database queries.
|
||||
* Therefore most data is directly cached as SQL statements.
|
||||
*/
|
||||
class SearchContext
|
||||
{
|
||||
/// Search radius around a given Near reference point.
|
||||
private $fNearRadius = false;
|
||||
/// True if search must be restricted to viewbox only.
|
||||
public $bViewboxBounded = false;
|
||||
|
||||
/// Reference point for search (as SQL).
|
||||
public $sqlNear = '';
|
||||
/// Viewbox selected for search (as SQL).
|
||||
public $sqlViewboxSmall = '';
|
||||
/// Viewbox with a larger buffer around (as SQL).
|
||||
public $sqlViewboxLarge = '';
|
||||
/// Reference along a route (as SQL).
|
||||
public $sqlViewboxCentre = '';
|
||||
/// List of countries to restrict search to (as array).
|
||||
public $aCountryList = null;
|
||||
/// List of countries to restrict search to (as SQL).
|
||||
public $sqlCountryList = '';
|
||||
/// List of place IDs to exclude (as SQL).
|
||||
private $sqlExcludeList = '';
|
||||
/// Subset of word ids of full words in the query.
|
||||
private $aFullNameWords = array();
|
||||
|
||||
public function setFullNameWords($aWordList)
|
||||
{
|
||||
$this->aFullNameWords = $aWordList;
|
||||
}
|
||||
|
||||
public function getFullNameTerms()
|
||||
{
|
||||
return $this->aFullNameWords;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a reference point is defined.
|
||||
*
|
||||
* @return bool True if a reference point is defined.
|
||||
*/
|
||||
public function hasNearPoint()
|
||||
{
|
||||
return $this->fNearRadius !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get radius around reference point.
|
||||
*
|
||||
* @return float Search radius around reference point.
|
||||
*/
|
||||
public function nearRadius()
|
||||
{
|
||||
return $this->fNearRadius;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set search reference point in WGS84.
|
||||
*
|
||||
* If set, then only places around this point will be taken into account.
|
||||
*
|
||||
* @param float $fLat Latitude of point.
|
||||
* @param float $fLon Longitude of point.
|
||||
* @param float $fRadius Search radius around point.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setNearPoint($fLat, $fLon, $fRadius = 0.1)
|
||||
{
|
||||
$this->fNearRadius = $fRadius;
|
||||
$this->sqlNear = 'ST_SetSRID(ST_Point('.$fLon.','.$fLat.'),4326)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the search is geographically restricted.
|
||||
*
|
||||
* Searches are restricted if a reference point is given or if
|
||||
* a bounded viewbox is set.
|
||||
*
|
||||
* @return bool True, if the search is geographically bounded.
|
||||
*/
|
||||
public function isBoundedSearch()
|
||||
{
|
||||
return $this->hasNearPoint() || ($this->sqlViewboxSmall && $this->bViewboxBounded);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set rectangular viewbox.
|
||||
*
|
||||
* The viewbox may be bounded which means that no search results
|
||||
* must be outside the viewbox.
|
||||
*
|
||||
* @param float[4] $aViewBox Coordinates of the viewbox.
|
||||
* @param bool $bBounded True if the viewbox is bounded.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setViewboxFromBox(&$aViewBox, $bBounded)
|
||||
{
|
||||
$this->bViewboxBounded = $bBounded;
|
||||
$this->sqlViewboxCentre = '';
|
||||
|
||||
$this->sqlViewboxSmall = sprintf(
|
||||
'ST_SetSRID(ST_MakeBox2D(ST_Point(%F,%F),ST_Point(%F,%F)),4326)',
|
||||
$aViewBox[0],
|
||||
$aViewBox[1],
|
||||
$aViewBox[2],
|
||||
$aViewBox[3]
|
||||
);
|
||||
|
||||
$fHeight = abs($aViewBox[0] - $aViewBox[2]);
|
||||
$fWidth = abs($aViewBox[1] - $aViewBox[3]);
|
||||
|
||||
$this->sqlViewboxLarge = sprintf(
|
||||
'ST_SetSRID(ST_MakeBox2D(ST_Point(%F,%F),ST_Point(%F,%F)),4326)',
|
||||
max($aViewBox[0], $aViewBox[2]) + $fHeight,
|
||||
max($aViewBox[1], $aViewBox[3]) + $fWidth,
|
||||
min($aViewBox[0], $aViewBox[2]) - $fHeight,
|
||||
min($aViewBox[1], $aViewBox[3]) - $fWidth
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set viewbox along a route.
|
||||
*
|
||||
* The viewbox may be bounded which means that no search results
|
||||
* must be outside the viewbox.
|
||||
*
|
||||
* @param object $oDB Nominatim::DB instance to use for computing the box.
|
||||
* @param string[] $aRoutePoints List of x,y coordinates along a route.
|
||||
* @param float $fRouteWidth Buffer around the route to use.
|
||||
* @param bool $bBounded True if the viewbox bounded.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setViewboxFromRoute(&$oDB, $aRoutePoints, $fRouteWidth, $bBounded)
|
||||
{
|
||||
$this->bViewboxBounded = $bBounded;
|
||||
$this->sqlViewboxCentre = "ST_SetSRID('LINESTRING(";
|
||||
$sSep = '';
|
||||
foreach ($aRoutePoints as $aPoint) {
|
||||
$fPoint = (float)$aPoint;
|
||||
$this->sqlViewboxCentre .= $sSep.$fPoint;
|
||||
$sSep = ($sSep == ' ') ? ',' : ' ';
|
||||
}
|
||||
$this->sqlViewboxCentre .= ")'::geometry,4326)";
|
||||
|
||||
$sSQL = 'ST_BUFFER('.$this->sqlViewboxCentre.','.($fRouteWidth/69).')';
|
||||
$sGeom = $oDB->getOne('select '.$sSQL, null, 'Could not get small viewbox');
|
||||
$this->sqlViewboxSmall = "'".$sGeom."'::geometry";
|
||||
|
||||
$sSQL = 'ST_BUFFER('.$this->sqlViewboxCentre.','.($fRouteWidth/30).')';
|
||||
$sGeom = $oDB->getOne('select '.$sSQL, null, 'Could not get large viewbox');
|
||||
$this->sqlViewboxLarge = "'".$sGeom."'::geometry";
|
||||
}
|
||||
|
||||
/**
|
||||
* Set list of excluded place IDs.
|
||||
*
|
||||
* @param integer[] $aExcluded List of IDs.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setExcludeList($aExcluded)
|
||||
{
|
||||
$this->sqlExcludeList = ' not in ('.join(',', $aExcluded).')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set list of countries to restrict search to.
|
||||
*
|
||||
* @param string[] $aCountries List of two-letter lower-case country codes.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setCountryList($aCountries)
|
||||
{
|
||||
$this->sqlCountryList = '('.join(',', array_map('addQuotes', $aCountries)).')';
|
||||
$this->aCountryList = $aCountries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract a reference point from a query string.
|
||||
*
|
||||
* @param string $sQuery Query to scan.
|
||||
*
|
||||
* @return string The remaining query string.
|
||||
*/
|
||||
public function setNearPointFromQuery($sQuery)
|
||||
{
|
||||
$aResult = parseLatLon($sQuery);
|
||||
|
||||
if ($aResult !== false
|
||||
&& $aResult[1] <= 90.1
|
||||
&& $aResult[1] >= -90.1
|
||||
&& $aResult[2] <= 180.1
|
||||
&& $aResult[2] >= -180.1
|
||||
) {
|
||||
$this->setNearPoint($aResult[1], $aResult[2]);
|
||||
$sQuery = trim(str_replace($aResult[0], ' ', $sQuery));
|
||||
}
|
||||
|
||||
return $sQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an SQL snippet for computing the distance from the reference point.
|
||||
*
|
||||
* @param string $sObj SQL variable name to compute the distance from.
|
||||
*
|
||||
* @return string An SQL string.
|
||||
*/
|
||||
public function distanceSQL($sObj)
|
||||
{
|
||||
return 'ST_Distance('.$this->sqlNear.", $sObj)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an SQL snippet for checking if something is within range of the
|
||||
* reference point.
|
||||
*
|
||||
* @param string $sObj SQL variable name to compute if it is within range.
|
||||
*
|
||||
* @return string An SQL string.
|
||||
*/
|
||||
public function withinSQL($sObj)
|
||||
{
|
||||
return sprintf('ST_DWithin(%s, %s, %F)', $sObj, $this->sqlNear, $this->fNearRadius);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an SQL snippet of the importance factor of the viewbox.
|
||||
*
|
||||
* The importance factor is computed by checking if an object is within
|
||||
* the viewbox and/or the extended version of the viewbox.
|
||||
*
|
||||
* @param string $sObj SQL variable name of object to weight the importance
|
||||
*
|
||||
* @return string SQL snippet of the factor with a leading multiply sign.
|
||||
*/
|
||||
public function viewboxImportanceSQL($sObj)
|
||||
{
|
||||
$sSQL = '';
|
||||
|
||||
if ($this->sqlViewboxSmall) {
|
||||
$sSQL = " * CASE WHEN ST_Contains($this->sqlViewboxSmall, $sObj) THEN 1 ELSE 0.5 END";
|
||||
}
|
||||
if ($this->sqlViewboxLarge) {
|
||||
$sSQL = " * CASE WHEN ST_Contains($this->sqlViewboxLarge, $sObj) THEN 1 ELSE 0.5 END";
|
||||
}
|
||||
|
||||
return $sSQL;
|
||||
}
|
||||
|
||||
/**
|
||||
* SQL snippet checking if a place ID should be excluded.
|
||||
*
|
||||
* @param string $sVariable SQL variable name of place ID to check,
|
||||
* potentially prefixed with more SQL.
|
||||
*
|
||||
* @return string SQL snippet.
|
||||
*/
|
||||
public function excludeSQL($sVariable)
|
||||
{
|
||||
if ($this->sqlExcludeList) {
|
||||
return $sVariable.$this->sqlExcludeList;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given country is covered by the search context.
|
||||
*
|
||||
* @param string $sCountryCode Country code of the country to check.
|
||||
*
|
||||
* @return True, if no country code restrictions are set or the
|
||||
* country is included in the country list.
|
||||
*/
|
||||
public function isCountryApplicable($sCountryCode)
|
||||
{
|
||||
return $this->aCountryList === null || in_array($sCountryCode, $this->aCountryList);
|
||||
}
|
||||
|
||||
public function debugInfo()
|
||||
{
|
||||
return array(
|
||||
'Near radius' => $this->fNearRadius,
|
||||
'Near point (SQL)' => $this->sqlNear,
|
||||
'Bounded viewbox' => $this->bViewboxBounded,
|
||||
'Viewbox (SQL, small)' => $this->sqlViewboxSmall,
|
||||
'Viewbox (SQL, large)' => $this->sqlViewboxLarge,
|
||||
'Viewbox (SQL, centre)' => $this->sqlViewboxCentre,
|
||||
'Countries (SQL)' => $this->sqlCountryList,
|
||||
'Excluded IDs (SQL)' => $this->sqlExcludeList
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,985 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* This file is part of Nominatim. (https://nominatim.org)
|
||||
*
|
||||
* Copyright (C) 2022 by the Nominatim developer community.
|
||||
* For a full list of authors see the git log.
|
||||
*/
|
||||
|
||||
namespace Nominatim;
|
||||
|
||||
require_once(CONST_LibDir.'/SpecialSearchOperator.php');
|
||||
require_once(CONST_LibDir.'/SearchContext.php');
|
||||
require_once(CONST_LibDir.'/Result.php');
|
||||
|
||||
/**
|
||||
* Description of a single interpretation of a search query.
|
||||
*/
|
||||
class SearchDescription
|
||||
{
|
||||
/// Ranking how well the description fits the query.
|
||||
private $iSearchRank = 0;
|
||||
/// Country code of country the result must belong to.
|
||||
private $sCountryCode = '';
|
||||
/// List of word ids making up the name of the object.
|
||||
private $aName = array();
|
||||
/// True if the name is rare enough to force index use on name.
|
||||
private $bRareName = false;
|
||||
/// True if the name requires to be accompanied by address terms.
|
||||
private $bNameNeedsAddress = false;
|
||||
/// List of word ids making up the address of the object.
|
||||
private $aAddress = array();
|
||||
/// List of word ids that appear in the name but should be ignored.
|
||||
private $aNameNonSearch = array();
|
||||
/// List of word ids that appear in the address but should be ignored.
|
||||
private $aAddressNonSearch = array();
|
||||
/// Kind of search for special searches, see Nominatim::Operator.
|
||||
private $iOperator = Operator::NONE;
|
||||
/// Class of special feature to search for.
|
||||
private $sClass = '';
|
||||
/// Type of special feature to search for.
|
||||
private $sType = '';
|
||||
/// Housenumber of the object.
|
||||
private $sHouseNumber = '';
|
||||
/// Postcode for the object.
|
||||
private $sPostcode = '';
|
||||
/// Global search constraints.
|
||||
private $oContext;
|
||||
|
||||
// Temporary values used while creating the search description.
|
||||
|
||||
/// Index of phrase currently processed.
|
||||
private $iNamePhrase = -1;
|
||||
|
||||
/**
|
||||
* Create an empty search description.
|
||||
*
|
||||
* @param object $oContext Global context to use. Will be inherited by
|
||||
* all derived search objects.
|
||||
*/
|
||||
public function __construct($oContext)
|
||||
{
|
||||
$this->oContext = $oContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current search rank.
|
||||
*
|
||||
* The higher the search rank the lower the likelihood that the
|
||||
* search is a correct interpretation of the search query.
|
||||
*
|
||||
* @return integer Search rank.
|
||||
*/
|
||||
public function getRank()
|
||||
{
|
||||
return $this->iSearchRank;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract key/value pairs from a query.
|
||||
*
|
||||
* Key/value pairs are recognised if they are of the form [<key>=<value>].
|
||||
* If multiple terms of this kind are found then all terms are removed
|
||||
* but only the first is used for search.
|
||||
*
|
||||
* @param string $sQuery Original query string.
|
||||
*
|
||||
* @return string The query string with the special search patterns removed.
|
||||
*/
|
||||
public function extractKeyValuePairs($sQuery)
|
||||
{
|
||||
// Search for terms of kind [<key>=<value>].
|
||||
preg_match_all(
|
||||
'/\\[([\\w_]*)=([\\w_]*)\\]/',
|
||||
$sQuery,
|
||||
$aSpecialTermsRaw,
|
||||
PREG_SET_ORDER
|
||||
);
|
||||
|
||||
foreach ($aSpecialTermsRaw as $aTerm) {
|
||||
$sQuery = str_replace($aTerm[0], ' ', $sQuery);
|
||||
if (!$this->hasOperator()) {
|
||||
$this->setPoiSearch(Operator::TYPE, $aTerm[1], $aTerm[2]);
|
||||
}
|
||||
}
|
||||
|
||||
return $sQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the combination of parameters is sensible.
|
||||
*
|
||||
* @return bool True, if the search looks valid.
|
||||
*/
|
||||
public function isValidSearch()
|
||||
{
|
||||
if (empty($this->aName)) {
|
||||
if ($this->sHouseNumber) {
|
||||
return false;
|
||||
}
|
||||
if (!$this->sClass && !$this->sCountryCode) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ($this->bNameNeedsAddress && empty($this->aAddress)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////// Search building functions
|
||||
|
||||
/**
|
||||
* Create a copy of this search description adding to search rank.
|
||||
*
|
||||
* @param integer $iTermCost Cost to add to the current search rank.
|
||||
*
|
||||
* @return object Cloned search description.
|
||||
*/
|
||||
public function clone($iTermCost)
|
||||
{
|
||||
$oSearch = clone $this;
|
||||
$oSearch->iSearchRank += $iTermCost;
|
||||
|
||||
return $oSearch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the search currently includes a name.
|
||||
*
|
||||
* @param bool bIncludeNonNames If true stop-word tokens are taken into
|
||||
* account, too.
|
||||
*
|
||||
* @return bool True, if search has a name.
|
||||
*/
|
||||
public function hasName($bIncludeNonNames = false)
|
||||
{
|
||||
return !empty($this->aName)
|
||||
|| (!empty($this->aNameNonSearch) && $bIncludeNonNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the search currently includes an address term.
|
||||
*
|
||||
* @return bool True, if any address term is included, including stop-word
|
||||
* terms.
|
||||
*/
|
||||
public function hasAddress()
|
||||
{
|
||||
return !empty($this->aAddress) || !empty($this->aAddressNonSearch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a country restriction is currently included in the search.
|
||||
*
|
||||
* @return bool True, if a country restriction is set.
|
||||
*/
|
||||
public function hasCountry()
|
||||
{
|
||||
return $this->sCountryCode !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a postcode is currently included in the search.
|
||||
*
|
||||
* @return bool True, if a postcode is set.
|
||||
*/
|
||||
public function hasPostcode()
|
||||
{
|
||||
return $this->sPostcode !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a house number is set for the search.
|
||||
*
|
||||
* @return bool True, if a house number is set.
|
||||
*/
|
||||
public function hasHousenumber()
|
||||
{
|
||||
return $this->sHouseNumber !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a special type of place is requested.
|
||||
*
|
||||
* param integer iOperator When set, check for the particular
|
||||
* operator used for the special type.
|
||||
*
|
||||
* @return bool True, if speial type is requested or, if requested,
|
||||
* a special type with the given operator.
|
||||
*/
|
||||
public function hasOperator($iOperator = null)
|
||||
{
|
||||
return $iOperator === null ? $this->iOperator != Operator::NONE : $this->iOperator == $iOperator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given token to the list of terms to search for in the address.
|
||||
*
|
||||
* @param integer iID ID of term to add.
|
||||
* @param bool bSearchable Term should be used to search for result
|
||||
* (i.e. term is not a stop word).
|
||||
*/
|
||||
public function addAddressToken($iId, $bSearchable = true)
|
||||
{
|
||||
if ($bSearchable) {
|
||||
$this->aAddress[$iId] = $iId;
|
||||
} else {
|
||||
$this->aAddressNonSearch[$iId] = $iId;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given full-word token to the list of terms to search for in the
|
||||
* name.
|
||||
*
|
||||
* @param integer iId ID of term to add.
|
||||
* @param bool bRareName True if the term is infrequent enough to not
|
||||
* require other constraints for efficient search.
|
||||
*/
|
||||
public function addNameToken($iId, $bRareName)
|
||||
{
|
||||
$this->aName[$iId] = $iId;
|
||||
$this->bRareName = $bRareName;
|
||||
$this->bNameNeedsAddress = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given partial token to the list of terms to search for in
|
||||
* the name.
|
||||
*
|
||||
* @param integer iID ID of term to add.
|
||||
* @param bool bSearchable Term should be used to search for result
|
||||
* (i.e. term is not a stop word).
|
||||
* @param bool bNeedsAddress True if the term is too unspecific to be used
|
||||
* in a stand-alone search without an address
|
||||
* to narrow down the search.
|
||||
* @param integer iPhraseNumber Index of phrase, where the partial term
|
||||
* appears.
|
||||
*/
|
||||
public function addPartialNameToken($iId, $bSearchable, $bNeedsAddress, $iPhraseNumber)
|
||||
{
|
||||
if (empty($this->aName)) {
|
||||
$this->bNameNeedsAddress = $bNeedsAddress;
|
||||
} elseif ($bSearchable && count($this->aName) >= 2) {
|
||||
$this->bNameNeedsAddress = false;
|
||||
} else {
|
||||
$this->bNameNeedsAddress &= $bNeedsAddress;
|
||||
}
|
||||
if ($bSearchable) {
|
||||
$this->aName[$iId] = $iId;
|
||||
} else {
|
||||
$this->aNameNonSearch[$iId] = $iId;
|
||||
}
|
||||
$this->iNamePhrase = $iPhraseNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set country restriction for the search.
|
||||
*
|
||||
* @param string sCountryCode Country code of country to restrict search to.
|
||||
*/
|
||||
public function setCountry($sCountryCode)
|
||||
{
|
||||
$this->sCountryCode = $sCountryCode;
|
||||
$this->iNamePhrase = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set postcode search constraint.
|
||||
*
|
||||
* @param string sPostcode Postcode the result should have.
|
||||
*/
|
||||
public function setPostcode($sPostcode)
|
||||
{
|
||||
$this->sPostcode = $sPostcode;
|
||||
$this->iNamePhrase = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this search a search for a postcode object.
|
||||
*
|
||||
* @param integer iId Token Id for the postcode.
|
||||
* @param string sPostcode Postcode to look for.
|
||||
*/
|
||||
public function setPostcodeAsName($iId, $sPostcode)
|
||||
{
|
||||
$this->iOperator = Operator::POSTCODE;
|
||||
$this->aAddress = array_merge($this->aAddress, $this->aName);
|
||||
$this->aName = array($iId => $sPostcode);
|
||||
$this->bRareName = true;
|
||||
$this->iNamePhrase = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set house number search cnstraint.
|
||||
*
|
||||
* @param string sNumber House number the result should have.
|
||||
*/
|
||||
public function setHousenumber($sNumber)
|
||||
{
|
||||
$this->sHouseNumber = $sNumber;
|
||||
$this->iNamePhrase = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this search a search for a house number.
|
||||
*
|
||||
* @param integer iId Token Id for the house number.
|
||||
*/
|
||||
public function setHousenumberAsName($iId)
|
||||
{
|
||||
$this->aAddress = array_merge($this->aAddress, $this->aName);
|
||||
$this->bRareName = false;
|
||||
$this->bNameNeedsAddress = true;
|
||||
$this->aName = array($iId => $iId);
|
||||
$this->iNamePhrase = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this search a POI search.
|
||||
*
|
||||
* In a POI search, objects are not (only) searched by their name
|
||||
* but also by the primary OSM key/value pair (class and type in Nominatim).
|
||||
*
|
||||
* @param integer $iOperator Type of POI search
|
||||
* @param string $sClass Class (or OSM tag key) of POI.
|
||||
* @param string $sType Type (or OSM tag value) of POI.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setPoiSearch($iOperator, $sClass, $sType)
|
||||
{
|
||||
$this->iOperator = $iOperator;
|
||||
$this->sClass = $sClass;
|
||||
$this->sType = $sType;
|
||||
$this->iNamePhrase = -1;
|
||||
}
|
||||
|
||||
public function getNamePhrase()
|
||||
{
|
||||
return $this->iNamePhrase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the global search context.
|
||||
*
|
||||
* @return object Objects of global search constraints.
|
||||
*/
|
||||
public function getContext()
|
||||
{
|
||||
return $this->oContext;
|
||||
}
|
||||
|
||||
/////////// Query functions
|
||||
|
||||
|
||||
/**
|
||||
* Query database for places that match this search.
|
||||
*
|
||||
* @param object $oDB Nominatim::DB instance to use.
|
||||
* @param integer $iMinRank Minimum address rank to restrict search to.
|
||||
* @param integer $iMaxRank Maximum address rank to restrict search to.
|
||||
* @param integer $iLimit Maximum number of results.
|
||||
*
|
||||
* @return mixed[] An array with two fields: IDs contains the list of
|
||||
* matching place IDs and houseNumber the houseNumber
|
||||
* if applicable or -1 if not.
|
||||
*/
|
||||
public function query(&$oDB, $iMinRank, $iMaxRank, $iLimit)
|
||||
{
|
||||
$aResults = array();
|
||||
|
||||
if ($this->sCountryCode
|
||||
&& empty($this->aName)
|
||||
&& !$this->iOperator
|
||||
&& !$this->sClass
|
||||
&& !$this->oContext->hasNearPoint()
|
||||
) {
|
||||
// Just looking for a country - look it up
|
||||
if (4 >= $iMinRank && 4 <= $iMaxRank) {
|
||||
$aResults = $this->queryCountry($oDB);
|
||||
}
|
||||
} elseif (empty($this->aName) && empty($this->aAddress)) {
|
||||
// Neither name nor address? Then we must be
|
||||
// looking for a POI in a geographic area.
|
||||
if ($this->oContext->isBoundedSearch()) {
|
||||
$aResults = $this->queryNearbyPoi($oDB, $iLimit);
|
||||
}
|
||||
} elseif ($this->iOperator == Operator::POSTCODE) {
|
||||
// looking for postcode
|
||||
$aResults = $this->queryPostcode($oDB, $iLimit);
|
||||
} else {
|
||||
// Ordinary search:
|
||||
// First search for places according to name and address.
|
||||
$aResults = $this->queryNamedPlace(
|
||||
$oDB,
|
||||
$iMinRank,
|
||||
$iMaxRank,
|
||||
$iLimit
|
||||
);
|
||||
|
||||
// finally get POIs if requested
|
||||
if ($this->sClass && !empty($aResults)) {
|
||||
$aResults = $this->queryPoiByOperator($oDB, $aResults, $iLimit);
|
||||
}
|
||||
}
|
||||
|
||||
Debug::printDebugTable('Place IDs', $aResults);
|
||||
|
||||
if (!empty($aResults) && $this->sPostcode) {
|
||||
$sPlaceIds = Result::joinIdsByTable($aResults, Result::TABLE_PLACEX);
|
||||
if ($sPlaceIds) {
|
||||
$sSQL = 'SELECT place_id FROM placex';
|
||||
$sSQL .= ' WHERE place_id in ('.$sPlaceIds.')';
|
||||
$sSQL .= " AND postcode != '".$this->sPostcode."'";
|
||||
Debug::printSQL($sSQL);
|
||||
$aFilteredPlaceIDs = $oDB->getCol($sSQL);
|
||||
if ($aFilteredPlaceIDs) {
|
||||
foreach ($aFilteredPlaceIDs as $iPlaceId) {
|
||||
$aResults[$iPlaceId]->iResultRank++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $aResults;
|
||||
}
|
||||
|
||||
|
||||
private function queryCountry(&$oDB)
|
||||
{
|
||||
$sSQL = 'SELECT place_id FROM placex ';
|
||||
$sSQL .= "WHERE country_code='".$this->sCountryCode."'";
|
||||
$sSQL .= ' AND rank_search = 4';
|
||||
if ($this->oContext->bViewboxBounded) {
|
||||
$sSQL .= ' AND ST_Intersects('.$this->oContext->sqlViewboxSmall.', geometry)';
|
||||
}
|
||||
$sSQL .= ' ORDER BY st_area(geometry) DESC LIMIT 1';
|
||||
|
||||
Debug::printSQL($sSQL);
|
||||
|
||||
$iPlaceId = $oDB->getOne($sSQL);
|
||||
|
||||
$aResults = array();
|
||||
if ($iPlaceId) {
|
||||
$aResults[$iPlaceId] = new Result($iPlaceId);
|
||||
}
|
||||
|
||||
return $aResults;
|
||||
}
|
||||
|
||||
private function queryNearbyPoi(&$oDB, $iLimit)
|
||||
{
|
||||
if (!$this->sClass) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$aDBResults = array();
|
||||
$sPoiTable = $this->poiTable();
|
||||
|
||||
if ($oDB->tableExists($sPoiTable)) {
|
||||
$sSQL = 'SELECT place_id FROM '.$sPoiTable.' ct';
|
||||
if ($this->oContext->sqlCountryList) {
|
||||
$sSQL .= ' JOIN placex USING (place_id)';
|
||||
}
|
||||
if ($this->oContext->hasNearPoint()) {
|
||||
$sSQL .= ' WHERE '.$this->oContext->withinSQL('ct.centroid');
|
||||
} elseif ($this->oContext->bViewboxBounded) {
|
||||
$sSQL .= ' WHERE ST_Contains('.$this->oContext->sqlViewboxSmall.', ct.centroid)';
|
||||
}
|
||||
if ($this->oContext->sqlCountryList) {
|
||||
$sSQL .= ' AND country_code in '.$this->oContext->sqlCountryList;
|
||||
}
|
||||
$sSQL .= $this->oContext->excludeSQL(' AND place_id');
|
||||
if ($this->oContext->sqlViewboxCentre) {
|
||||
$sSQL .= ' ORDER BY ST_Distance(';
|
||||
$sSQL .= $this->oContext->sqlViewboxCentre.', ct.centroid) ASC';
|
||||
} elseif ($this->oContext->hasNearPoint()) {
|
||||
$sSQL .= ' ORDER BY '.$this->oContext->distanceSQL('ct.centroid').' ASC';
|
||||
}
|
||||
$sSQL .= " LIMIT $iLimit";
|
||||
Debug::printSQL($sSQL);
|
||||
$aDBResults = $oDB->getCol($sSQL);
|
||||
}
|
||||
|
||||
if ($this->oContext->hasNearPoint()) {
|
||||
$sSQL = 'SELECT place_id FROM placex WHERE ';
|
||||
$sSQL .= 'class = :class and type = :type';
|
||||
$sSQL .= ' AND '.$this->oContext->withinSQL('geometry');
|
||||
$sSQL .= ' AND linked_place_id is null';
|
||||
if ($this->oContext->sqlCountryList) {
|
||||
$sSQL .= ' AND country_code in '.$this->oContext->sqlCountryList;
|
||||
}
|
||||
$sSQL .= ' ORDER BY '.$this->oContext->distanceSQL('centroid').' ASC';
|
||||
$sSQL .= " LIMIT $iLimit";
|
||||
Debug::printSQL($sSQL);
|
||||
$aDBResults = $oDB->getCol(
|
||||
$sSQL,
|
||||
array(':class' => $this->sClass, ':type' => $this->sType)
|
||||
);
|
||||
}
|
||||
|
||||
$aResults = array();
|
||||
foreach ($aDBResults as $iPlaceId) {
|
||||
$aResults[$iPlaceId] = new Result($iPlaceId);
|
||||
}
|
||||
|
||||
return $aResults;
|
||||
}
|
||||
|
||||
private function queryPostcode(&$oDB, $iLimit)
|
||||
{
|
||||
$sSQL = 'SELECT p.place_id FROM location_postcode p ';
|
||||
|
||||
if (!empty($this->aAddress)) {
|
||||
$sSQL .= ', search_name s ';
|
||||
$sSQL .= 'WHERE s.place_id = p.parent_place_id ';
|
||||
$sSQL .= 'AND array_cat(s.nameaddress_vector, s.name_vector)';
|
||||
$sSQL .= ' @> '.$oDB->getArraySQL($this->aAddress).' AND ';
|
||||
} else {
|
||||
$sSQL .= 'WHERE ';
|
||||
}
|
||||
|
||||
$sSQL .= "p.postcode = '".reset($this->aName)."'";
|
||||
$sSQL .= $this->countryCodeSQL(' AND p.country_code');
|
||||
if ($this->oContext->bViewboxBounded) {
|
||||
$sSQL .= ' AND ST_Intersects('.$this->oContext->sqlViewboxSmall.', geometry)';
|
||||
}
|
||||
$sSQL .= $this->oContext->excludeSQL(' AND p.place_id');
|
||||
$sSQL .= " LIMIT $iLimit";
|
||||
|
||||
Debug::printSQL($sSQL);
|
||||
|
||||
$aResults = array();
|
||||
foreach ($oDB->getCol($sSQL) as $iPlaceId) {
|
||||
$aResults[$iPlaceId] = new Result($iPlaceId, Result::TABLE_POSTCODE);
|
||||
}
|
||||
|
||||
return $aResults;
|
||||
}
|
||||
|
||||
private function queryNamedPlace(&$oDB, $iMinAddressRank, $iMaxAddressRank, $iLimit)
|
||||
{
|
||||
$aTerms = array();
|
||||
$aOrder = array();
|
||||
|
||||
if (!empty($this->aName)) {
|
||||
$aTerms[] = 'name_vector @> '.$oDB->getArraySQL($this->aName);
|
||||
}
|
||||
if (!empty($this->aAddress)) {
|
||||
// For infrequent name terms disable index usage for address
|
||||
if ($this->bRareName) {
|
||||
$aTerms[] = 'array_cat(nameaddress_vector,ARRAY[]::integer[]) @> '.$oDB->getArraySQL($this->aAddress);
|
||||
} else {
|
||||
$aTerms[] = 'nameaddress_vector @> '.$oDB->getArraySQL($this->aAddress);
|
||||
}
|
||||
}
|
||||
|
||||
$sCountryTerm = $this->countryCodeSQL('country_code');
|
||||
if ($sCountryTerm) {
|
||||
$aTerms[] = $sCountryTerm;
|
||||
}
|
||||
|
||||
if ($this->sHouseNumber) {
|
||||
$aTerms[] = 'address_rank between 16 and 30';
|
||||
} elseif (!$this->sClass || $this->iOperator == Operator::NAME) {
|
||||
if ($iMinAddressRank > 0) {
|
||||
$aTerms[] = "((address_rank between $iMinAddressRank and $iMaxAddressRank) or (search_rank between $iMinAddressRank and $iMaxAddressRank))";
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->oContext->hasNearPoint()) {
|
||||
$aTerms[] = $this->oContext->withinSQL('centroid');
|
||||
$aOrder[] = $this->oContext->distanceSQL('centroid');
|
||||
} elseif ($this->sPostcode) {
|
||||
if (empty($this->aAddress)) {
|
||||
$aTerms[] = "EXISTS(SELECT place_id FROM location_postcode p WHERE p.postcode = '".$this->sPostcode."' AND ST_DWithin(search_name.centroid, p.geometry, 0.12))";
|
||||
} else {
|
||||
$aOrder[] = "(SELECT min(ST_Distance(search_name.centroid, p.geometry)) FROM location_postcode p WHERE p.postcode = '".$this->sPostcode."')";
|
||||
}
|
||||
}
|
||||
|
||||
$sExcludeSQL = $this->oContext->excludeSQL('place_id');
|
||||
if ($sExcludeSQL) {
|
||||
$aTerms[] = $sExcludeSQL;
|
||||
}
|
||||
|
||||
if ($this->oContext->bViewboxBounded) {
|
||||
$aTerms[] = 'centroid && '.$this->oContext->sqlViewboxSmall;
|
||||
}
|
||||
|
||||
if ($this->sHouseNumber) {
|
||||
$sImportanceSQL = '- abs(26 - address_rank) + 3';
|
||||
} else {
|
||||
$sImportanceSQL = '(CASE WHEN importance = 0 OR importance IS NULL THEN 0.75001-(search_rank::float/40) ELSE importance END)';
|
||||
}
|
||||
$sImportanceSQL .= $this->oContext->viewboxImportanceSQL('centroid');
|
||||
$aOrder[] = "$sImportanceSQL DESC";
|
||||
|
||||
$aFullNameAddress = $this->oContext->getFullNameTerms();
|
||||
if (!empty($aFullNameAddress)) {
|
||||
$sExactMatchSQL = ' ( ';
|
||||
$sExactMatchSQL .= ' SELECT count(*) FROM ( ';
|
||||
$sExactMatchSQL .= ' SELECT unnest('.$oDB->getArraySQL($aFullNameAddress).')';
|
||||
$sExactMatchSQL .= ' INTERSECT ';
|
||||
$sExactMatchSQL .= ' SELECT unnest(nameaddress_vector)';
|
||||
$sExactMatchSQL .= ' ) s';
|
||||
$sExactMatchSQL .= ') as exactmatch';
|
||||
$aOrder[] = 'exactmatch DESC';
|
||||
} else {
|
||||
$sExactMatchSQL = '0::int as exactmatch';
|
||||
}
|
||||
|
||||
if (empty($aTerms)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
if ($this->hasHousenumber()) {
|
||||
$sHouseNumberRegex = $oDB->getDBQuoted('\\\\m'.$this->sHouseNumber.'\\\\M');
|
||||
|
||||
// Housenumbers on streets and places.
|
||||
$sPlacexSql = 'SELECT array_agg(place_id) FROM placex';
|
||||
$sPlacexSql .= ' WHERE parent_place_id = sin.place_id AND sin.address_rank < 30';
|
||||
$sPlacexSql .= $this->oContext->excludeSQL(' AND place_id');
|
||||
$sPlacexSql .= ' and housenumber ~* E'.$sHouseNumberRegex;
|
||||
|
||||
// Interpolations on streets and places.
|
||||
$sInterpolSql = 'null';
|
||||
$sTigerSql = 'null';
|
||||
if (preg_match('/^[0-9]+$/', $this->sHouseNumber)) {
|
||||
$sIpolHnr = 'WHERE parent_place_id = sin.place_id ';
|
||||
$sIpolHnr .= ' AND startnumber is not NULL AND sin.address_rank < 30';
|
||||
$sIpolHnr .= ' AND '.$this->sHouseNumber.' between startnumber and endnumber';
|
||||
$sIpolHnr .= ' AND ('.$this->sHouseNumber.' - startnumber) % step = 0';
|
||||
|
||||
$sInterpolSql = 'SELECT array_agg(place_id) FROM location_property_osmline '.$sIpolHnr;
|
||||
if (CONST_Use_US_Tiger_Data) {
|
||||
$sTigerSql = 'SELECT array_agg(place_id) FROM location_property_tiger '.$sIpolHnr;
|
||||
$sTigerSql .= " and sin.country_code = 'us'";
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->sClass) {
|
||||
$iLimit = 40;
|
||||
}
|
||||
|
||||
$sSelfHnr = 'SELECT * FROM placex WHERE place_id = search_name.place_id';
|
||||
$sSelfHnr .= ' AND housenumber ~* E'.$sHouseNumberRegex;
|
||||
|
||||
$aTerms[] = '(address_rank < 30 or exists('.$sSelfHnr.'))';
|
||||
|
||||
|
||||
$sSQL = 'SELECT sin.*, ';
|
||||
$sSQL .= '('.$sPlacexSql.') as placex_hnr, ';
|
||||
$sSQL .= '('.$sInterpolSql.') as interpol_hnr, ';
|
||||
$sSQL .= '('.$sTigerSql.') as tiger_hnr ';
|
||||
$sSQL .= ' FROM (';
|
||||
$sSQL .= ' SELECT place_id, address_rank, country_code,'.$sExactMatchSQL.',';
|
||||
$sSQL .= ' CASE WHEN importance = 0 OR importance IS NULL';
|
||||
$sSQL .= ' THEN 0.75001-(search_rank::float/40) ELSE importance END as importance';
|
||||
$sSQL .= ' FROM search_name';
|
||||
$sSQL .= ' WHERE '.join(' and ', $aTerms);
|
||||
$sSQL .= ' ORDER BY '.join(', ', $aOrder);
|
||||
$sSQL .= ' LIMIT 40000';
|
||||
$sSQL .= ') as sin';
|
||||
$sSQL .= ' ORDER BY address_rank = 30 desc, placex_hnr, interpol_hnr, tiger_hnr,';
|
||||
$sSQL .= ' importance';
|
||||
$sSQL .= ' LIMIT '.$iLimit;
|
||||
} else {
|
||||
if ($this->sClass) {
|
||||
$iLimit = 40;
|
||||
}
|
||||
|
||||
$sSQL = 'SELECT place_id, address_rank, '.$sExactMatchSQL;
|
||||
$sSQL .= ' FROM search_name';
|
||||
$sSQL .= ' WHERE '.join(' and ', $aTerms);
|
||||
$sSQL .= ' ORDER BY '.join(', ', $aOrder);
|
||||
$sSQL .= ' LIMIT '.$iLimit;
|
||||
}
|
||||
|
||||
Debug::printSQL($sSQL);
|
||||
|
||||
$aDBResults = $oDB->getAll($sSQL, null, 'Could not get places for search terms.');
|
||||
|
||||
$aResults = array();
|
||||
|
||||
foreach ($aDBResults as $aResult) {
|
||||
$oResult = new Result($aResult['place_id']);
|
||||
$oResult->iExactMatches = $aResult['exactmatch'];
|
||||
$oResult->iAddressRank = $aResult['address_rank'];
|
||||
|
||||
$bNeedResult = true;
|
||||
if ($this->hasHousenumber() && $aResult['address_rank'] < 30) {
|
||||
if ($aResult['placex_hnr']) {
|
||||
foreach (explode(',', substr($aResult['placex_hnr'], 1, -1)) as $sPlaceID) {
|
||||
$iPlaceID = intval($sPlaceID);
|
||||
$oHnrResult = new Result($iPlaceID);
|
||||
$oHnrResult->iExactMatches = $aResult['exactmatch'];
|
||||
$oHnrResult->iAddressRank = 30;
|
||||
$aResults[$iPlaceID] = $oHnrResult;
|
||||
$bNeedResult = false;
|
||||
}
|
||||
}
|
||||
if ($aResult['interpol_hnr']) {
|
||||
foreach (explode(',', substr($aResult['interpol_hnr'], 1, -1)) as $sPlaceID) {
|
||||
$iPlaceID = intval($sPlaceID);
|
||||
$oHnrResult = new Result($iPlaceID, Result::TABLE_OSMLINE);
|
||||
$oHnrResult->iExactMatches = $aResult['exactmatch'];
|
||||
$oHnrResult->iAddressRank = 30;
|
||||
$oHnrResult->iHouseNumber = intval($this->sHouseNumber);
|
||||
$aResults[$iPlaceID] = $oHnrResult;
|
||||
$bNeedResult = false;
|
||||
}
|
||||
}
|
||||
if ($aResult['tiger_hnr']) {
|
||||
foreach (explode(',', substr($aResult['tiger_hnr'], 1, -1)) as $sPlaceID) {
|
||||
$iPlaceID = intval($sPlaceID);
|
||||
$oHnrResult = new Result($iPlaceID, Result::TABLE_TIGER);
|
||||
$oHnrResult->iExactMatches = $aResult['exactmatch'];
|
||||
$oHnrResult->iAddressRank = 30;
|
||||
$oHnrResult->iHouseNumber = intval($this->sHouseNumber);
|
||||
$aResults[$iPlaceID] = $oHnrResult;
|
||||
$bNeedResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($aResult['address_rank'] < 26) {
|
||||
$oResult->iResultRank += 2;
|
||||
} else {
|
||||
$oResult->iResultRank++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($bNeedResult) {
|
||||
$aResults[$aResult['place_id']] = $oResult;
|
||||
}
|
||||
}
|
||||
|
||||
return $aResults;
|
||||
}
|
||||
|
||||
|
||||
private function queryPoiByOperator(&$oDB, $aParentIDs, $iLimit)
|
||||
{
|
||||
$aResults = array();
|
||||
$sPlaceIDs = Result::joinIdsByTable($aParentIDs, Result::TABLE_PLACEX);
|
||||
|
||||
if (!$sPlaceIDs) {
|
||||
return $aResults;
|
||||
}
|
||||
|
||||
if ($this->iOperator == Operator::TYPE || $this->iOperator == Operator::NAME) {
|
||||
// If they were searching for a named class (i.e. 'Kings Head pub')
|
||||
// then we might have an extra match
|
||||
$sSQL = 'SELECT place_id FROM placex ';
|
||||
$sSQL .= " WHERE place_id in ($sPlaceIDs)";
|
||||
$sSQL .= " AND class='".$this->sClass."' ";
|
||||
$sSQL .= " AND type='".$this->sType."'";
|
||||
$sSQL .= ' AND linked_place_id is null';
|
||||
$sSQL .= $this->oContext->excludeSQL(' AND place_id');
|
||||
$sSQL .= ' ORDER BY rank_search ASC ';
|
||||
$sSQL .= " LIMIT $iLimit";
|
||||
|
||||
Debug::printSQL($sSQL);
|
||||
|
||||
foreach ($oDB->getCol($sSQL) as $iPlaceId) {
|
||||
$aResults[$iPlaceId] = new Result($iPlaceId);
|
||||
}
|
||||
}
|
||||
|
||||
// NEAR and IN are handled the same
|
||||
if ($this->iOperator == Operator::TYPE || $this->iOperator == Operator::NEAR) {
|
||||
$sClassTable = $this->poiTable();
|
||||
$bCacheTable = $oDB->tableExists($sClassTable);
|
||||
|
||||
$sSQL = "SELECT min(rank_search) FROM placex WHERE place_id in ($sPlaceIDs)";
|
||||
Debug::printSQL($sSQL);
|
||||
$iMaxRank = (int) $oDB->getOne($sSQL);
|
||||
|
||||
// For state / country level searches the normal radius search doesn't work very well
|
||||
$sPlaceGeom = false;
|
||||
if ($iMaxRank < 9 && $bCacheTable) {
|
||||
// Try and get a polygon to search in instead
|
||||
$sSQL = 'SELECT geometry FROM placex';
|
||||
$sSQL .= " WHERE place_id in ($sPlaceIDs)";
|
||||
$sSQL .= " AND rank_search < $iMaxRank + 5";
|
||||
$sSQL .= ' AND ST_Area(Box2d(geometry)) < 20';
|
||||
$sSQL .= " AND ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon')";
|
||||
$sSQL .= ' ORDER BY rank_search ASC ';
|
||||
$sSQL .= ' LIMIT 1';
|
||||
Debug::printSQL($sSQL);
|
||||
$sPlaceGeom = $oDB->getOne($sSQL);
|
||||
}
|
||||
|
||||
if ($sPlaceGeom) {
|
||||
$sPlaceIDs = false;
|
||||
} else {
|
||||
$iMaxRank += 5;
|
||||
$sSQL = 'SELECT place_id FROM placex';
|
||||
$sSQL .= " WHERE place_id in ($sPlaceIDs) and rank_search < $iMaxRank";
|
||||
Debug::printSQL($sSQL);
|
||||
$aPlaceIDs = $oDB->getCol($sSQL);
|
||||
$sPlaceIDs = join(',', $aPlaceIDs);
|
||||
}
|
||||
|
||||
if ($sPlaceIDs || $sPlaceGeom) {
|
||||
$fRange = 0.01;
|
||||
if ($bCacheTable) {
|
||||
// More efficient - can make the range bigger
|
||||
$fRange = 0.05;
|
||||
|
||||
$sOrderBySQL = '';
|
||||
if ($this->oContext->hasNearPoint()) {
|
||||
$sOrderBySQL = $this->oContext->distanceSQL('l.centroid');
|
||||
} elseif ($sPlaceIDs) {
|
||||
$sOrderBySQL = 'ST_Distance(l.centroid, f.geometry)';
|
||||
} elseif ($sPlaceGeom) {
|
||||
$sOrderBySQL = "ST_Distance(st_centroid('".$sPlaceGeom."'), l.centroid)";
|
||||
}
|
||||
|
||||
$sSQL = 'SELECT distinct i.place_id';
|
||||
if ($sOrderBySQL) {
|
||||
$sSQL .= ', i.order_term';
|
||||
}
|
||||
$sSQL .= ' from (SELECT l.place_id';
|
||||
if ($sOrderBySQL) {
|
||||
$sSQL .= ','.$sOrderBySQL.' as order_term';
|
||||
}
|
||||
$sSQL .= ' from '.$sClassTable.' as l';
|
||||
|
||||
if ($sPlaceIDs) {
|
||||
$sSQL .= ',placex as f WHERE ';
|
||||
$sSQL .= "f.place_id in ($sPlaceIDs) ";
|
||||
$sSQL .= " AND ST_DWithin(l.centroid, f.centroid, $fRange)";
|
||||
} elseif ($sPlaceGeom) {
|
||||
$sSQL .= " WHERE ST_Contains('$sPlaceGeom', l.centroid)";
|
||||
}
|
||||
|
||||
$sSQL .= $this->oContext->excludeSQL(' AND l.place_id');
|
||||
$sSQL .= 'limit 300) i ';
|
||||
if ($sOrderBySQL) {
|
||||
$sSQL .= 'order by order_term asc';
|
||||
}
|
||||
$sSQL .= " limit $iLimit";
|
||||
|
||||
Debug::printSQL($sSQL);
|
||||
|
||||
foreach ($oDB->getCol($sSQL) as $iPlaceId) {
|
||||
$aResults[$iPlaceId] = new Result($iPlaceId);
|
||||
}
|
||||
} else {
|
||||
if ($this->oContext->hasNearPoint()) {
|
||||
$fRange = $this->oContext->nearRadius();
|
||||
}
|
||||
|
||||
$sOrderBySQL = '';
|
||||
if ($this->oContext->hasNearPoint()) {
|
||||
$sOrderBySQL = $this->oContext->distanceSQL('l.geometry');
|
||||
} else {
|
||||
$sOrderBySQL = 'ST_Distance(l.geometry, f.geometry)';
|
||||
}
|
||||
|
||||
$sSQL = 'SELECT distinct l.place_id';
|
||||
if ($sOrderBySQL) {
|
||||
$sSQL .= ','.$sOrderBySQL.' as orderterm';
|
||||
}
|
||||
$sSQL .= ' FROM placex as l, placex as f';
|
||||
$sSQL .= " WHERE f.place_id in ($sPlaceIDs)";
|
||||
$sSQL .= " AND ST_DWithin(l.geometry, f.centroid, $fRange)";
|
||||
$sSQL .= " AND l.class='".$this->sClass."'";
|
||||
$sSQL .= " AND l.type='".$this->sType."'";
|
||||
$sSQL .= $this->oContext->excludeSQL(' AND l.place_id');
|
||||
if ($sOrderBySQL) {
|
||||
$sSQL .= 'ORDER BY orderterm ASC';
|
||||
}
|
||||
$sSQL .= " limit $iLimit";
|
||||
|
||||
Debug::printSQL($sSQL);
|
||||
|
||||
foreach ($oDB->getCol($sSQL) as $iPlaceId) {
|
||||
$aResults[$iPlaceId] = new Result($iPlaceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $aResults;
|
||||
}
|
||||
|
||||
private function poiTable()
|
||||
{
|
||||
return 'place_classtype_'.$this->sClass.'_'.$this->sType;
|
||||
}
|
||||
|
||||
private function countryCodeSQL($sVar)
|
||||
{
|
||||
if ($this->sCountryCode) {
|
||||
return $sVar.' = \''.$this->sCountryCode."'";
|
||||
}
|
||||
if ($this->oContext->sqlCountryList) {
|
||||
return $sVar.' in '.$this->oContext->sqlCountryList;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/////////// Sort functions
|
||||
|
||||
|
||||
public static function bySearchRank($a, $b)
|
||||
{
|
||||
if ($a->iSearchRank == $b->iSearchRank) {
|
||||
return $a->iOperator + strlen($a->sHouseNumber)
|
||||
- $b->iOperator - strlen($b->sHouseNumber);
|
||||
}
|
||||
|
||||
return $a->iSearchRank < $b->iSearchRank ? -1 : 1;
|
||||
}
|
||||
|
||||
//////////// Debugging functions
|
||||
|
||||
|
||||
public function debugInfo()
|
||||
{
|
||||
return array(
|
||||
'Search rank' => $this->iSearchRank,
|
||||
'Country code' => $this->sCountryCode,
|
||||
'Name terms' => $this->aName,
|
||||
'Name terms (stop words)' => $this->aNameNonSearch,
|
||||
'Address terms' => $this->aAddress,
|
||||
'Address terms (stop words)' => $this->aAddressNonSearch,
|
||||
'Address terms (full words)' => $this->aFullNameAddress ?? '',
|
||||
'Special search' => $this->iOperator,
|
||||
'Class' => $this->sClass,
|
||||
'Type' => $this->sType,
|
||||
'House number' => $this->sHouseNumber,
|
||||
'Postcode' => $this->sPostcode
|
||||
);
|
||||
}
|
||||
|
||||
public function dumpAsHtmlTableRow(&$aWordIDs)
|
||||
{
|
||||
$kf = function ($k) use (&$aWordIDs) {
|
||||
return $aWordIDs[$k] ?? '['.$k.']';
|
||||
};
|
||||
|
||||
echo '<tr>';
|
||||
echo "<td>$this->iSearchRank</td>";
|
||||
echo '<td>'.join(', ', array_map($kf, $this->aName)).'</td>';
|
||||
echo '<td>'.join(', ', array_map($kf, $this->aNameNonSearch)).'</td>';
|
||||
echo '<td>'.join(', ', array_map($kf, $this->aAddress)).'</td>';
|
||||
echo '<td>'.join(', ', array_map($kf, $this->aAddressNonSearch)).'</td>';
|
||||
echo '<td>'.$this->sCountryCode.'</td>';
|
||||
echo '<td>'.Operator::toString($this->iOperator).'</td>';
|
||||
echo '<td>'.$this->sClass.'</td>';
|
||||
echo '<td>'.$this->sType.'</td>';
|
||||
echo '<td>'.$this->sPostcode.'</td>';
|
||||
echo '<td>'.$this->sHouseNumber.'</td>';
|
||||
|
||||
echo '</tr>';
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* This file is part of Nominatim. (https://nominatim.org)
|
||||
*
|
||||
* Copyright (C) 2022 by the Nominatim developer community.
|
||||
* For a full list of authors see the git log.
|
||||
*/
|
||||
|
||||
namespace Nominatim;
|
||||
|
||||
/**
|
||||
* Description of the position of a token within a query.
|
||||
*/
|
||||
class SearchPosition
|
||||
{
|
||||
private $sPhraseType;
|
||||
|
||||
private $iPhrase;
|
||||
private $iNumPhrases;
|
||||
|
||||
private $iToken;
|
||||
private $iNumTokens;
|
||||
|
||||
|
||||
public function __construct($sPhraseType, $iPhrase, $iNumPhrases)
|
||||
{
|
||||
$this->sPhraseType = $sPhraseType;
|
||||
$this->iPhrase = $iPhrase;
|
||||
$this->iNumPhrases = $iNumPhrases;
|
||||
}
|
||||
|
||||
public function setTokenPosition($iToken, $iNumTokens)
|
||||
{
|
||||
$this->iToken = $iToken;
|
||||
$this->iNumTokens = $iNumTokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the phrase can be of the given type.
|
||||
*
|
||||
* @param string $sType Type of phrse requested.
|
||||
*
|
||||
* @return True if the phrase is untyped or of the given type.
|
||||
*/
|
||||
public function maybePhrase($sType)
|
||||
{
|
||||
return $this->sPhraseType == '' || $this->sPhraseType == $sType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the phrase is exactly of the given type.
|
||||
*
|
||||
* @param string $sType Type of phrse requested.
|
||||
*
|
||||
* @return True if the phrase of the given type.
|
||||
*/
|
||||
public function isPhrase($sType)
|
||||
{
|
||||
return $this->sPhraseType == $sType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the token is the very first in the query.
|
||||
*/
|
||||
public function isFirstToken()
|
||||
{
|
||||
return $this->iPhrase == 0 && $this->iToken == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the token is the final one in the query.
|
||||
*/
|
||||
public function isLastToken()
|
||||
{
|
||||
return $this->iToken + 1 == $this->iNumTokens && $this->iPhrase + 1 == $this->iNumPhrases;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current token is part of the first phrase in the query.
|
||||
*/
|
||||
public function isFirstPhrase()
|
||||
{
|
||||
return $this->iPhrase == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the phrase position in the query.
|
||||
*/
|
||||
public function getPhrase()
|
||||
{
|
||||
return $this->iPhrase;
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* This file is part of Nominatim. (https://nominatim.org)
|
||||
*
|
||||
* Copyright (C) 2022 by the Nominatim developer community.
|
||||
* For a full list of authors see the git log.
|
||||
*/
|
||||
|
||||
namespace Nominatim;
|
||||
|
||||
class Shell
|
||||
{
|
||||
public function __construct($sBaseCmd, ...$aParams)
|
||||
{
|
||||
if (!$sBaseCmd) {
|
||||
throw new \Exception('Command missing in new() call');
|
||||
}
|
||||
$this->baseCmd = $sBaseCmd;
|
||||
$this->aParams = array();
|
||||
$this->aEnv = null; // null = use the same environment as the current PHP process
|
||||
|
||||
$this->stdoutString = null;
|
||||
|
||||
foreach ($aParams as $sParam) {
|
||||
$this->addParams($sParam);
|
||||
}
|
||||
}
|
||||
|
||||
public function addParams(...$aParams)
|
||||
{
|
||||
foreach ($aParams as $sParam) {
|
||||
if (isset($sParam) && $sParam !== null && $sParam !== '') {
|
||||
array_push($this->aParams, $sParam);
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addEnvPair($sKey, $sVal)
|
||||
{
|
||||
if (isset($sKey) && $sKey && isset($sVal)) {
|
||||
if (!isset($this->aEnv)) {
|
||||
$this->aEnv = $_ENV;
|
||||
}
|
||||
$this->aEnv = array_merge($this->aEnv, array($sKey => $sVal), $_ENV);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function escapedCmd()
|
||||
{
|
||||
$aEscaped = array_map(function ($sParam) {
|
||||
return $this->escapeParam($sParam);
|
||||
}, array_merge(array($this->baseCmd), $this->aParams));
|
||||
|
||||
return join(' ', $aEscaped);
|
||||
}
|
||||
|
||||
public function run($bExitOnFail = false)
|
||||
{
|
||||
$sCmd = $this->escapedCmd();
|
||||
// $aEnv does not need escaping, proc_open seems to handle it fine
|
||||
|
||||
$aFDs = array(
|
||||
0 => array('pipe', 'r'),
|
||||
1 => STDOUT,
|
||||
2 => STDERR
|
||||
);
|
||||
$aPipes = null;
|
||||
$hProc = @proc_open($sCmd, $aFDs, $aPipes, null, $this->aEnv);
|
||||
if (!is_resource($hProc)) {
|
||||
throw new \Exception('Unable to run command: ' . $sCmd);
|
||||
}
|
||||
|
||||
fclose($aPipes[0]); // no stdin
|
||||
|
||||
$iStat = proc_close($hProc);
|
||||
|
||||
if ($iStat != 0 && $bExitOnFail) {
|
||||
exit($iStat);
|
||||
}
|
||||
|
||||
return $iStat;
|
||||
}
|
||||
|
||||
private function escapeParam($sParam)
|
||||
{
|
||||
return (preg_match('/^-*\w+$/', $sParam)) ? $sParam : escapeshellarg($sParam);
|
||||
}
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* This file is part of Nominatim. (https://nominatim.org)
|
||||
*
|
||||
* Copyright (C) 2022 by the Nominatim developer community.
|
||||
* For a full list of authors see the git log.
|
||||
*/
|
||||
|
||||
namespace Nominatim;
|
||||
|
||||
/**
|
||||
* A word list creator based on simple splitting by space.
|
||||
*
|
||||
* Creates possible permutations of split phrases by finding all combination
|
||||
* of splitting the phrase on space boundaries.
|
||||
*/
|
||||
class SimpleWordList
|
||||
{
|
||||
const MAX_WORDSET_LEN = 20;
|
||||
const MAX_WORDSETS = 100;
|
||||
|
||||
// The phrase as a list of simple terms (without spaces).
|
||||
private $aWords;
|
||||
|
||||
/**
|
||||
* Create a new word list
|
||||
*
|
||||
* @param string sPhrase Phrase to create the word list from. The phrase is
|
||||
* expected to be normalised, so that there are no
|
||||
* subsequent spaces.
|
||||
*/
|
||||
public function __construct($sPhrase)
|
||||
{
|
||||
if (strlen($sPhrase) > 0) {
|
||||
$this->aWords = explode(' ', $sPhrase);
|
||||
} else {
|
||||
$this->aWords = array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all possible tokens that are present in this word list.
|
||||
*
|
||||
* @return array The list of string tokens in the word list.
|
||||
*/
|
||||
public function getTokens()
|
||||
{
|
||||
$aTokens = array();
|
||||
$iNumWords = count($this->aWords);
|
||||
|
||||
for ($i = 0; $i < $iNumWords; $i++) {
|
||||
$sPhrase = $this->aWords[$i];
|
||||
$aTokens[$sPhrase] = $sPhrase;
|
||||
|
||||
for ($j = $i + 1; $j < $iNumWords; $j++) {
|
||||
$sPhrase .= ' '.$this->aWords[$j];
|
||||
$aTokens[$sPhrase] = $sPhrase;
|
||||
}
|
||||
}
|
||||
|
||||
return $aTokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute all possible permutations of phrase splits that result in
|
||||
* words which are in the token list.
|
||||
*/
|
||||
public function getWordSets($oTokens)
|
||||
{
|
||||
$iNumWords = count($this->aWords);
|
||||
|
||||
if ($iNumWords == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Caches the word set for the partial phrase up to word i.
|
||||
$aSetCache = array_fill(0, $iNumWords, array());
|
||||
|
||||
// Initialise first element of cache. There can only be the word.
|
||||
if ($oTokens->containsAny($this->aWords[0])) {
|
||||
$aSetCache[0][] = array($this->aWords[0]);
|
||||
}
|
||||
|
||||
// Now do the next elements using what we already have.
|
||||
for ($i = 1; $i < $iNumWords; $i++) {
|
||||
for ($j = $i; $j > 0; $j--) {
|
||||
$sPartial = $j == $i ? $this->aWords[$j] : $this->aWords[$j].' '.$sPartial;
|
||||
if (!empty($aSetCache[$j - 1]) && $oTokens->containsAny($sPartial)) {
|
||||
$aPartial = array($sPartial);
|
||||
foreach ($aSetCache[$j - 1] as $aSet) {
|
||||
if (count($aSet) < SimpleWordList::MAX_WORDSET_LEN) {
|
||||
$aSetCache[$i][] = array_merge($aSet, $aPartial);
|
||||
}
|
||||
}
|
||||
if (count($aSetCache[$i]) > 2 * SimpleWordList::MAX_WORDSETS) {
|
||||
usort(
|
||||
$aSetCache[$i],
|
||||
array('\Nominatim\SimpleWordList', 'cmpByArraylen')
|
||||
);
|
||||
$aSetCache[$i] = array_slice(
|
||||
$aSetCache[$i],
|
||||
0,
|
||||
SimpleWordList::MAX_WORDSETS
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// finally the current full phrase
|
||||
$sPartial = $this->aWords[0].' '.$sPartial;
|
||||
if ($oTokens->containsAny($sPartial)) {
|
||||
$aSetCache[$i][] = array($sPartial);
|
||||
}
|
||||
}
|
||||
|
||||
$aWordSets = $aSetCache[$iNumWords - 1];
|
||||
usort($aWordSets, array('\Nominatim\SimpleWordList', 'cmpByArraylen'));
|
||||
return array_slice($aWordSets, 0, SimpleWordList::MAX_WORDSETS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom search routine which takes two arrays. The array with the fewest
|
||||
* items wins. If same number of items then the one with the longest first
|
||||
* element wins.
|
||||
*/
|
||||
public static function cmpByArraylen($aA, $aB)
|
||||
{
|
||||
$iALen = count($aA);
|
||||
$iBLen = count($aB);
|
||||
|
||||
if ($iALen == $iBLen) {
|
||||
return strlen($aB[0]) <=> strlen($aA[0]);
|
||||
}
|
||||
|
||||
return ($iALen < $iBLen) ? -1 : 1;
|
||||
}
|
||||
|
||||
public function debugInfo()
|
||||
{
|
||||
return $this->aWords;
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* This file is part of Nominatim. (https://nominatim.org)
|
||||
*
|
||||
* Copyright (C) 2022 by the Nominatim developer community.
|
||||
* For a full list of authors see the git log.
|
||||
*/
|
||||
|
||||
namespace Nominatim;
|
||||
|
||||
/**
|
||||
* Operators describing special searches.
|
||||
*/
|
||||
abstract class Operator
|
||||
{
|
||||
/// No operator selected.
|
||||
const NONE = 0;
|
||||
/// Search for POI of the given type.
|
||||
const TYPE = 1;
|
||||
/// Search for POIs near the given place.
|
||||
const NEAR = 2;
|
||||
/// Search for POIS in the given place.
|
||||
const IN = 3;
|
||||
/// Search for POIS named as given.
|
||||
const NAME = 4;
|
||||
/// Search for postcodes.
|
||||
const POSTCODE = 5;
|
||||
|
||||
private static $aConstantNames = null;
|
||||
|
||||
|
||||
public static function toString($iOperator)
|
||||
{
|
||||
if ($iOperator == Operator::NONE) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (Operator::$aConstantNames === null) {
|
||||
$oReflector = new \ReflectionClass('Nominatim\Operator');
|
||||
$aConstants = $oReflector->getConstants();
|
||||
|
||||
Operator::$aConstantNames = array();
|
||||
foreach ($aConstants as $sName => $iValue) {
|
||||
Operator::$aConstantNames[$iValue] = $sName;
|
||||
}
|
||||
}
|
||||
|
||||
return Operator::$aConstantNames[$iOperator];
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* This file is part of Nominatim. (https://nominatim.org)
|
||||
*
|
||||
* Copyright (C) 2022 by the Nominatim developer community.
|
||||
* For a full list of authors see the git log.
|
||||
*/
|
||||
|
||||
namespace Nominatim;
|
||||
|
||||
require_once(CONST_TokenizerDir.'/tokenizer.php');
|
||||
|
||||
use Exception;
|
||||
|
||||
class Status
|
||||
{
|
||||
protected $oDB;
|
||||
|
||||
public function __construct(&$oDB)
|
||||
{
|
||||
$this->oDB =& $oDB;
|
||||
}
|
||||
|
||||
public function status()
|
||||
{
|
||||
if (!$this->oDB) {
|
||||
throw new Exception('No database', 700);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->oDB->connect();
|
||||
} catch (\Nominatim\DatabaseError $e) {
|
||||
throw new Exception('Database connection failed', 700);
|
||||
}
|
||||
|
||||
$oTokenizer = new \Nominatim\Tokenizer($this->oDB);
|
||||
$oTokenizer->checkStatus();
|
||||
}
|
||||
|
||||
public function dataDate()
|
||||
{
|
||||
$sSQL = 'SELECT EXTRACT(EPOCH FROM lastimportdate) FROM import_status LIMIT 1';
|
||||
$iDataDateEpoch = $this->oDB->getOne($sSQL);
|
||||
|
||||
if ($iDataDateEpoch === false) {
|
||||
throw new Exception('Import date is not available', 705);
|
||||
}
|
||||
|
||||
return $iDataDateEpoch;
|
||||
}
|
||||
|
||||
public function databaseVersion()
|
||||
{
|
||||
$sSQL = 'SELECT value FROM nominatim_properties WHERE property = \'database_version\'';
|
||||
return $this->oDB->getOne($sSQL);
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* This file is part of Nominatim. (https://nominatim.org)
|
||||
*
|
||||
* Copyright (C) 2022 by the Nominatim developer community.
|
||||
* For a full list of authors see the git log.
|
||||
*/
|
||||
|
||||
namespace Nominatim\Token;
|
||||
|
||||
/**
|
||||
* A country token.
|
||||
*/
|
||||
class Country
|
||||
{
|
||||
/// Database word id, if available.
|
||||
private $iId;
|
||||
/// Two-letter country code (lower-cased).
|
||||
private $sCountryCode;
|
||||
|
||||
public function __construct($iId, $sCountryCode)
|
||||
{
|
||||
$this->iId = $iId;
|
||||
$this->sCountryCode = $sCountryCode;
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->iId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the token can be added to the given search.
|
||||
* Derive new searches by adding this token to an existing search.
|
||||
*
|
||||
* @param object $oSearch Partial search description derived so far.
|
||||
* @param object $oPosition Description of the token position within
|
||||
the query.
|
||||
*
|
||||
* @return True if the token is compatible with the search configuration
|
||||
* given the position.
|
||||
*/
|
||||
public function isExtendable($oSearch, $oPosition)
|
||||
{
|
||||
return !$oSearch->hasCountry()
|
||||
&& $oPosition->maybePhrase('country')
|
||||
&& $oSearch->getContext()->isCountryApplicable($this->sCountryCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Derive new searches by adding this token to an existing search.
|
||||
*
|
||||
* @param object $oSearch Partial search description derived so far.
|
||||
* @param object $oPosition Description of the token position within
|
||||
the query.
|
||||
*
|
||||
* @return SearchDescription[] List of derived search descriptions.
|
||||
*/
|
||||
public function extendSearch($oSearch, $oPosition)
|
||||
{
|
||||
$oNewSearch = $oSearch->clone($oPosition->isLastToken() ? 1 : 6);
|
||||
$oNewSearch->setCountry($this->sCountryCode);
|
||||
|
||||
return array($oNewSearch);
|
||||
}
|
||||
|
||||
public function debugInfo()
|
||||
{
|
||||
return array(
|
||||
'ID' => $this->iId,
|
||||
'Type' => 'country',
|
||||
'Info' => $this->sCountryCode
|
||||
);
|
||||
}
|
||||
|
||||
public function debugCode()
|
||||
{
|
||||
return 'C';
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user