Compare commits

...

180 Commits

Author SHA1 Message Date
Sarah Hoffmann
3734f1d0b8 prepare 4.5.0 release 2024-09-11 17:51:38 +02:00
Sarah Hoffmann
a66c063314 Merge pull request #3532 from lonvia/refresh-docs
Update library documentation
2024-09-11 10:27:09 +02:00
Sarah Hoffmann
fe0ade81f5 docs: improve contents listing 2024-09-10 20:41:35 +02:00
Sarah Hoffmann
f52212abbd docs: rework library getting started 2024-09-10 20:41:35 +02:00
Sarah Hoffmann
8f30a32466 docs: avoid loading external fonts 2024-09-10 20:41:35 +02:00
Sarah Hoffmann
157c3cccd1 fix permalink character 2024-09-10 20:41:35 +02:00
Sarah Hoffmann
3e6be0b0be Merge pull request #3530 from lonvia/clean-use-of-os-environ
Don't use OS environment variables when an explicit environment was set
2024-09-02 09:49:10 +02:00
Sarah Hoffmann
882fb16881 restrict use of os.environ in Configuration
Only use the OS environment, when the environ parameter is set
to None. Currently it would use the OS env on an empty dict.
2024-09-01 16:17:30 +02:00
Sarah Hoffmann
72be143cef Merge pull request #3523 from mtmail/import-styles-country-code
Import-Styles.md - clarify country_code key
2024-08-26 14:03:47 +02:00
Sarah Hoffmann
086116b3a1 Merge pull request #3525 from lonvia/project-dir-less-library
Simplify handling of project directory for Nominatim library
2024-08-26 13:54:35 +02:00
marc tobias
ed7f0d9e46 Import-Styles.md - clarify country_code key 2024-08-23 13:50:25 +02:00
mtmail
b5a6d7a4a6 fix typo in Import-Styles.md 2024-08-23 00:40:13 +02:00
Sarah Hoffmann
7f11de0db9 allow None and str for project_dir in NominatimAPI init 2024-08-22 22:49:12 +02:00
Sarah Hoffmann
f535340d5a Merge pull request #3520 from lonvia/restrict-interpolation-range
Restrict interpolation housenumbers to 0-999999
2024-08-20 09:03:52 +02:00
Sarah Hoffmann
c7d80a2cc8 Merge pull request #3521 from lonvia/make-requests-optional
Fix error around missing requests library
2024-08-20 09:03:39 +02:00
Sarah Hoffmann
0efdd1b9a6 restrict interpolation housenumbers to 0-999999
Ensures that the numbers fit into integers.
2024-08-19 20:40:25 +02:00
Sarah Hoffmann
fd9437277e import requests library later than osmium
requests will usually be pulled in by osmium and is therefore not
a direct dependency of nominatim. Make sure it is only used, when
osmium is present.
2024-08-19 16:36:09 +02:00
Sarah Hoffmann
968f1cd453 Merge pull request #3519 from lonvia/api-error-handling
Improve error handling around CLI api commands
2024-08-19 16:26:18 +02:00
Sarah Hoffmann
adce7261ac translate UsageError in CLI API commands
UsageErrors are handled specially and don't show backtraces
unless explicitly requested. We want the same behaviour for
errors coming from the API functions.
2024-08-19 12:02:33 +02:00
Sarah Hoffmann
b01a836d1e use NominatimAPI in with context in CLI tool 2024-08-19 11:42:22 +02:00
Sarah Hoffmann
c2594aca40 make NominatimAPI[Async] a context manager
If close() isn't properly called, it can lead to odd error messages
about uncaught exceptions.
2024-08-19 11:31:38 +02:00
Sarah Hoffmann
8b41b80bff Merge pull request #3517 from lonvia/improve-custom-formatter
Extend use of custom result formatters to CLI tool
2024-08-18 10:20:53 +02:00
Sarah Hoffmann
feb8cc29a5 improve error message on missing modules from nominatim_api 2024-08-17 10:03:36 +02:00
Sarah Hoffmann
1cd8ffad0b improve docs on custom result formatters
Adds section on formatting errors and using CLI. Improves wording
in others.
2024-08-16 22:11:41 +02:00
Sarah Hoffmann
d648561a87 CLI: more useful error messages on JSON formatting errors 2024-08-16 19:47:48 +02:00
Sarah Hoffmann
8e8f7a641b use custom result formatters in CLI commands 2024-08-16 19:30:57 +02:00
Sarah Hoffmann
69369c08c8 add missing includes in result fomatting example 2024-08-16 11:32:38 +02:00
Sarah Hoffmann
fdb3fc2f7b Merge pull request #3516 from lonvia/fixed-country-order
Ensure consistent country assignments
2024-08-15 16:54:38 +02:00
Sarah Hoffmann
054efc8311 ensure consistent country assignments
When OSM data has areas with overlapping countries, use the country
assignments from the pre-defined country grid for tie-breaking.
If that fails, fall back to the country with the smaller partition
number.
2024-08-15 14:26:09 +02:00
Sarah Hoffmann
d7cf81c047 Merge pull request #3515 from lonvia/custom-result-formatting
Add the capability to define custom formatting functions for API output
2024-08-15 09:26:27 +02:00
Sarah Hoffmann
19eb4d91a0 add documentation for custom formatters 2024-08-14 18:24:40 +02:00
Sarah Hoffmann
5a61d3d5f6 configurable error formatting and content type in result formatter 2024-08-14 12:00:08 +02:00
Sarah Hoffmann
52ee5dc73c make API formatter loadable from project directory 2024-08-13 23:21:38 +02:00
Sarah Hoffmann
0c25e80be0 make formatting module non-static 2024-08-13 22:39:43 +02:00
Sarah Hoffmann
4e0602919c move ASGIAdoptor out of v1 module 2024-08-13 21:32:11 +02:00
Sarah Hoffmann
d22ca186e4 remove v1-specific functions from ASGIAdaptor 2024-08-13 19:38:14 +02:00
Sarah Hoffmann
4f4a288757 Merge pull request #3514 from lonvia/remove-pythonpath
Vagrant install: remove custom python path
2024-08-13 15:18:48 +02:00
Sarah Hoffmann
14cc047cf4 vagrant install: remove custom python path 2024-08-13 09:31:36 +02:00
Sarah Hoffmann
043d52821c Merge pull request #3510 from lonvia/indexing-precompute-count
Indexing: precompute counts of affected rows
2024-08-12 23:55:19 +02:00
Sarah Hoffmann
3905dd68dd indexing: precompute row counts
Doing this once for the whole batch of ranks saves about
half a second for small imports. Speeds up BDD tests.
2024-08-12 14:57:26 +02:00
Sarah Hoffmann
bd0316b5c3 Merge pull request #3509 from lonvia/deprecations
Add deprecation warnings and check for osm2pgsql version
2024-08-12 11:27:56 +02:00
Sarah Hoffmann
fd33ef92dc add deprecation warnings in the code 2024-08-09 19:25:15 +02:00
Sarah Hoffmann
6527b7cdcd fail if osm2pgsql is not recent enough 2024-08-09 19:25:15 +02:00
Sarah Hoffmann
3cc20581ae osm2pgsq: do not use deprecated tablespace options 2024-08-09 19:25:15 +02:00
Sarah Hoffmann
a2a44b875a add deprecation warnings throughout docs 2024-08-09 19:25:15 +02:00
Sarah Hoffmann
a14ab1c08c Merge pull request #3506 from mtmail/development-environment-more-dependencies
Development environment: add missing dependencies
2024-08-09 19:24:56 +02:00
marc tobias
0ba3d01982 Development environment: add missing dependencies 2024-08-09 17:57:18 +02:00
Sarah Hoffmann
f6e792f31b Merge pull request #3502 from mtmail/check-database-check-another-index
check-database: check for another required db index
2024-08-08 15:21:38 +02:00
Sarah Hoffmann
882f182374 Merge pull request #3503 from lonvia/mkdocs-without-cmake
Build documentation without CMake
2024-08-07 19:21:00 +02:00
Sarah Hoffmann
d1e7b85cc5 fix dangling links in documentation 2024-08-07 16:58:45 +02:00
Sarah Hoffmann
6b1c32893b move generated docs to site-html 2024-08-07 16:48:22 +02:00
Sarah Hoffmann
474a22cb3b build man page without CMake 2024-08-07 16:38:56 +02:00
Sarah Hoffmann
8e46458d9e remove CMake-based build of docs 2024-08-07 16:31:15 +02:00
Sarah Hoffmann
7282d816c8 build vagrant instructions dynamically with mkdocs-gen-files 2024-08-07 16:28:44 +02:00
marc tobias
7cf21f8caf check-database: check for another required db index 2024-08-07 15:19:40 +02:00
Sarah Hoffmann
738e99ce71 Merge pull request #3499 from mtmail/add-data-warn-if-frozen
Add data warn if frozen
2024-08-07 11:11:58 +02:00
Sarah Hoffmann
e104115134 switch instruction to use wikimedia CSV file 2024-08-07 10:43:45 +02:00
marc tobias
f0390cfe85 add-data: warn and exit if database is frozen 2024-08-05 16:14:19 +02:00
Sarah Hoffmann
a4d7cdd2ad Merge pull request #3493 from lonvia/clean-up-bdd-tests
Various cleanups of BDD tests
2024-07-31 17:02:39 +02:00
Sarah Hoffmann
2914284a83 adapt BDD tests for legacy tokenizer + Python frontend
Mostly disables the tests, the cases are not worth fixing anymore.
Others just avoid using terms that trigger abbreviations.
2024-07-31 14:55:16 +02:00
Sarah Hoffmann
a97bfaf26c fix postcode lookup with legacy tokenizer 2024-07-31 14:54:55 +02:00
Sarah Hoffmann
cfe5284f64 make housenumber search work with non-indexed partials 2024-07-31 14:09:35 +02:00
Sarah Hoffmann
2048009600 disable ZIP5+ test for Python frontend
Currently not working.
2024-07-31 14:08:57 +02:00
Sarah Hoffmann
d47acbc18a add forgotten BDD test 2024-07-31 11:16:49 +02:00
Sarah Hoffmann
f5fd2f0e7a switch CI to new handling of legacy BDD tests 2024-07-31 11:16:49 +02:00
Sarah Hoffmann
c8d45972bb remove support for PHP code coverage in BDD tests 2024-07-31 11:16:49 +02:00
Sarah Hoffmann
474aea61da bdd tests: get rid of dependency on build path
BDD tests will now use whatever osm2pgsql they find in the PATH.
For testing against legacy tokenizer, use -DSERVER_MODULE_PATH
to point to the module. This will no longer work out of the box.
2024-07-31 11:16:49 +02:00
Sarah Hoffmann
67462e0953 Merge pull request #3492 from lonvia/drop-waste-disposal
Remove waste disposals and hunting stands from index
2024-07-30 17:03:08 +02:00
Sarah Hoffmann
804fb5f93e Merge pull request #3490 from mtmail/which-url-after-webserver-install
After install point user to '/status' not '/' path
2024-07-30 15:39:22 +02:00
marc tobias
f52097c064 After install point user to /status not / path 2024-07-30 13:10:24 +02:00
Sarah Hoffmann
d336b81293 drop amenity=waste_prposal and amenity=hunting_stand 2024-07-30 10:41:13 +02:00
Sarah Hoffmann
507c0286da Merge pull request #3491 from mtmail/faq-unicode-encoding
Admin FAQ entry for UnicodeEncodeError
2024-07-29 22:01:46 +02:00
marc tobias
04a3f39371 Admin FAQ entry for UnicodeEncodeError 2024-07-29 18:26:11 +02:00
Sarah Hoffmann
bc75e5626e Merge pull request #3466 from mtmail/apple-silicon-parallels
Vagrant: add config for Apple Silicon
2024-07-29 16:52:54 +02:00
Sarah Hoffmann
0add25e335 Merge pull request #3487 from lonvia/port-to-psycopg3
Move importer code to psycopg3
2024-07-29 16:52:07 +02:00
Sarah Hoffmann
253dc7d7cd Ubuntu 22 doesn't have psycopg yet 2024-07-29 08:54:18 +02:00
Sarah Hoffmann
221b5cd8a2 fix dependencies and adapt documentation for psycopg3 2024-07-29 08:54:09 +02:00
Sarah Hoffmann
9659afbade port code to psycopg3 2024-07-29 08:50:19 +02:00
Sarah Hoffmann
3742fa2929 make DB helper functions free functions
Also changes the drop function so that it can drop multiple tables
at once.
2024-07-29 08:49:30 +02:00
Sarah Hoffmann
71249bd94a remove extension existence helper
This is only used in one place.
2024-07-29 08:49:02 +02:00
Sarah Hoffmann
e3353deee0 Merge pull request #3480 from mtmail/import-style-adits
full,extra import style: add adits
2024-07-24 22:59:29 +02:00
marc tobias
00563a1fa2 full,extra import style: add adits 2024-07-17 10:57:29 +02:00
Shumail Mohyuddin
b8686c19a0 fix docs link in update interval error message (#3479) 2024-07-17 10:37:07 +02:00
Sarah Hoffmann
b89144dcb2 Merge pull request #3468 from mtmail/setup-python-v5
Github Actions: now use setup-python v4->v5
2024-07-08 18:45:06 +02:00
Sarah Hoffmann
8e5a19b392 Merge pull request #3467 from mtmail/docs-datrie
Documentation: typo in python package name
2024-07-08 18:44:50 +02:00
marc tobias
5d12121f6d Github Actions: now use setup-python v4->v5 2024-07-08 17:26:36 +02:00
marc tobias
24f103dcbe Documentation: typo in python package name 2024-07-08 16:44:09 +02:00
marc tobias
0109f167f9 Vagrant: add config for Apple Silicon 2024-07-08 15:35:01 +02:00
Sarah Hoffmann
b63633857e Merge pull request #3463 from lonvia/sqlalchemy14-with-psycopg
Make sure SQLAlchemy can handle the loaded dialect
2024-07-02 18:43:28 +02:00
Sarah Hoffmann
8cb0d5b262 make sure SQLAlchemy can handle the loaded dialect
The psycopg dialect was only added in SQLAlchemy 2.0. To avoid loading
errors when SQLAlchemy 1.4 is installed together with psycopg3,
check that the dialect is really available.
2024-07-02 15:55:23 +02:00
Mateusz Konieczny
e51973f8b1 fix some typos 2024-07-01 15:03:57 +02:00
Sarah Hoffmann
c314a3092c Merge pull request #3458 from lonvia/python-package
Add support for installation via pip
2024-07-01 15:02:01 +02:00
Sarah Hoffmann
8dafd8bcb6 add mtm as maintainer for the Python packages 2024-07-01 14:25:26 +02:00
Sarah Hoffmann
ecf4693a79 improve wording
as per review
2024-06-29 16:27:26 +02:00
Sarah Hoffmann
fa1c402b47 enable CI tests for Ubuntu 24 2024-06-28 11:11:59 +02:00
Sarah Hoffmann
4da4cbfe27 reduce from 3 to 2 packages 2024-06-28 09:13:22 +02:00
Sarah Hoffmann
139cea5720 update documentation for new directory layout 2024-06-26 11:52:47 +02:00
Sarah Hoffmann
e2416f90af installation for Ubuntu 24.04 with packages
Also remove Ubuntu 20.04 instructions.
2024-06-26 11:52:47 +02:00
Sarah Hoffmann
1e88321371 switch to symlink approach for packages
Needed to make building work from sdist and source directory.
2024-06-26 11:52:47 +02:00
Sarah Hoffmann
a93ec09932 adapt packaging readmes 2024-06-26 11:52:47 +02:00
Sarah Hoffmann
9abf2c248e update licenses and discussion links 2024-06-26 11:52:47 +02:00
Sarah Hoffmann
ab746eebaf export UsageError and Configuration in api directly
Library users should not have to deal with the core package directly.
2024-06-26 11:52:47 +02:00
Sarah Hoffmann
3ba330c948 update CI commands for linting 2024-06-26 11:52:47 +02:00
Sarah Hoffmann
aef1357066 adapt cmake to new directory structure 2024-06-26 11:52:47 +02:00
Sarah Hoffmann
5d302a03a6 make use of nominatim-api in db package optional 2024-06-26 11:52:47 +02:00
Sarah Hoffmann
3a8c5df82d adapt bdd tests to new layout 2024-06-26 11:52:47 +02:00
Sarah Hoffmann
44d5148e5f fix merge issues 2024-06-26 11:52:47 +02:00
Sarah Hoffmann
63da70685a fix linting issues 2024-06-26 11:52:47 +02:00
Sarah Hoffmann
2bab0ca060 port unit tests to new python package layout 2024-06-26 11:52:47 +02:00
Sarah Hoffmann
c903559415 move API dependent functions out of args structure 2024-06-26 11:52:47 +02:00
Sarah Hoffmann
6511821001 add packaging for the different subprojects 2024-06-26 11:52:47 +02:00
Sarah Hoffmann
75abf237a6 add missing __init__.py 2024-06-26 11:52:47 +02:00
Sarah Hoffmann
dc7c11a9d1 adapt plugin imports 2024-06-26 11:52:47 +02:00
Sarah Hoffmann
44fface92a add script for in-source execution 2024-06-26 11:52:47 +02:00
Sarah Hoffmann
6e89310a92 split code into submodules 2024-06-26 11:52:47 +02:00
Sarah Hoffmann
0fb4fe8e4d add Python package configuration
The global configuration builds one large package.
2024-06-26 11:52:47 +02:00
Markus Döring
b0067a0345 update Search.md, fix typo (#3454) 2024-06-24 15:24:09 +02:00
Sarah Hoffmann
4c72cdaa86 Merge pull request #3447 from lonvia/avoid-invalidating-large-features
Restrict invalidation of child objects on large street features
2024-06-19 15:06:23 +02:00
Sarah Hoffmann
350bb0e1cd restrict invalidation of child objects on large street features
When streets become very large, it is more likely a mapping error.
So ignore such changes.
2024-06-19 14:23:29 +02:00
Sarah Hoffmann
ad95ff1d06 Merge pull request #3424 from lonvia/importance-csc-import
Implement a lighter format for wikipedia importance tables
2024-05-29 18:06:53 +02:00
Sarah Hoffmann
90eea6b909 adapt database test for wikipedia importance to new tables 2024-05-16 15:23:54 +02:00
Sarah Hoffmann
5b02cd22b9 add tests for new importance CSV import 2024-05-16 15:23:54 +02:00
Sarah Hoffmann
60b03d506f add CSV format for importance import 2024-05-16 15:23:54 +02:00
Sarah Hoffmann
5c7073901e Merge pull request #3423 from mudnug/patch-1
Update Output place_id documentation to match implementation
2024-05-15 11:26:01 +02:00
Matthew
b33afee468 Update Output place_id documentation to match implementation 2024-05-14 12:00:17 -06:00
Sarah Hoffmann
6a748204ff Merge pull request #3422 from lonvia/drop-non-parented-interpolations
Drop address interpolations when no parent can be found
2024-05-14 16:40:28 +02:00
Sarah Hoffmann
9889c72c55 work around new pylint warnings 2024-05-14 14:50:37 +02:00
Sarah Hoffmann
01f0f453dd drop interpolations when no parent can be found
A housenumber without the place it refers to is of only limited use.
2024-05-14 11:35:14 +02:00
Sarah Hoffmann
7f0d969d71 Merge pull request #3413 from osm-search/mtmail-patch-1
Special-Phrases.md - correct typo
2024-05-06 09:18:09 +02:00
mtmail
a47fa07558 Special-Phrases.md - correct typo 2024-05-05 22:46:21 +02:00
Sarah Hoffmann
2b3ea0abb7 Merge pull request #3411 from lonvia/fix-address-style
Address and street style: switch to explicit choice of highway values
2024-05-05 13:01:20 +02:00
Sarah Hoffmann
755ae0ef94 address and street style: switch to explicit choice of highway values
The non-street values for the highway tag are proliferating.
Switch the style to only include values explicitly choosen.
2024-05-05 11:21:48 +02:00
Sarah Hoffmann
ccb5cf155d Merge pull request #3410 from lonvia/docs-special-phrases
Add documentation of the format for special phrases CSV
2024-05-05 11:14:22 +02:00
Sarah Hoffmann
7080a13c54 fix typo 2024-05-05 09:59:46 +02:00
Sarah Hoffmann
cf2697f8f4 add documentation of special phrases CSV format 2024-05-05 09:59:32 +02:00
Sarah Hoffmann
a6b829e4a0 Merge pull request #3409 from lonvia/docs-secondary-importance
Add documentation for installing a secondary importance file
2024-05-04 15:11:19 +02:00
Sarah Hoffmann
f92e580293 Merge pull request #3408 from lonvia/update-postcode-parents
Reindex postcodes when their parent is deleted
2024-05-04 15:11:05 +02:00
Sarah Hoffmann
bc84db6460 add links to official secondary importance file 2024-05-04 13:13:00 +02:00
Sarah Hoffmann
77631f90fd reindex postcodes that loose their parents
When the parent place of a postcode is deleted, it needs to
be reindexed to get a new parent. Otherwise displaying of
results is broken.
2024-05-04 12:33:26 +02:00
Sarah Hoffmann
332de72045 Merge pull request #3403 from mtmail/project-directory-name
docs: use nominatim-project everywhere
2024-05-02 13:46:43 +02:00
Sarah Hoffmann
a2cf6db61b Merge pull request #3397 from lonvia/improve-handling-unlisted-places
Improve handling addr:place without a place node
2024-05-02 13:46:18 +02:00
marc tobias
82a98f3780 docs: use nominatim-project everywhere 2024-05-02 11:48:06 +02:00
Sarah Hoffmann
7fb3ef4633 add test for preference of full matches on unlisted places 2024-05-02 11:47:35 +02:00
Sarah Hoffmann
8f3845660f add full tokens to addresses
This is now needed to weigh results.
2024-05-02 11:47:35 +02:00
Sarah Hoffmann
d2bf986eae unlisted place names need to go into the address
Housenumbers with unlisted place names should be handled like
any ither housenumbers with missing address terms.
2024-05-02 11:47:35 +02:00
Sarah Hoffmann
9410263485 actions: use newest pytest-asyncio for ubuntu 20 2024-05-02 11:06:45 +02:00
Sarah Hoffmann
82970e2b4f Merge pull request #3390 from lonvia/poi-in-poi
Handle POIs in POIs during reverse lookup
2024-04-11 17:32:01 +02:00
Sarah Hoffmann
f923304eea add slight preference for locating point POIs over POI areas 2024-04-11 10:21:31 +02:00
Sarah Hoffmann
1a0f851d0d Merge pull request #3389 from mtmail/cli-autodiscover-valid-formats
CLI: get valid --format values via autodiscover
2024-04-09 14:58:53 +02:00
marc tobias
28444d9435 CLI: get valid --format values via autodiscover 2024-04-09 14:03:23 +02:00
Sarah Hoffmann
8c54f9d704 Merge pull request #3385 from mtmail/docs-reverse-only
Import documentation: reverse-only only a little faster import
2024-04-03 14:33:54 +02:00
marc tobias
c24dc56c65 Import documentation: reverse-only only a little faster import [skip ci] 2024-04-03 12:07:22 +02:00
Sarah Hoffmann
5c4c98d17e Merge pull request #3384 from mtmail/geocodejson-admin-levels-only-boundaries
geocodejson: admin level output should only print boundaries
2024-04-03 11:52:08 +02:00
Sarah Hoffmann
657aae5f1b Merge pull request #3383 from lonvia/window-searches
Reorganize SQL for place search using window functions
2024-04-03 10:55:10 +02:00
Sarah Hoffmann
38798bba13 increase search area when filtering by postcode 2024-04-02 19:36:16 +02:00
marc tobias
05eb1d5f42 geocodejson: admin level output should only print boundaries 2024-04-02 18:58:09 +02:00
Sarah Hoffmann
fe873ad0e2 adapt tests for windowing SQL
Results with high penalty are now thrown out earlier.
2024-04-02 16:32:49 +02:00
Sarah Hoffmann
bdded69ab6 housenumber position should hint on direction
rather than increasing penalty.
2024-04-02 16:30:50 +02:00
Sarah Hoffmann
9f42c3f3b8 remove restriction on frequent one word names
This is now solved by reducing results with the windowing SQL
during search.
2024-04-02 16:28:17 +02:00
Sarah Hoffmann
424ebd7fe9 split search SQL in windowed search_name lookup and constraint search 2024-04-02 16:28:12 +02:00
Sarah Hoffmann
78c19bc006 minimum counts for tokens should always be 1
to avoid accidental devision by 0.
2024-04-01 14:25:51 +02:00
Sarah Hoffmann
e53eb79923 Merge pull request #3375 from matkoniecz/patch-1
add missing space in taginfo listing
2024-03-27 10:03:45 +01:00
Sarah Hoffmann
c39fc5d180 don't even try heavily penalized searches 2024-03-26 22:00:25 +01:00
Sarah Hoffmann
a96b6a1289 reintroduce cutoffs when searching for very frequent words 2024-03-26 21:46:37 +01:00
Mateusz Konieczny
8f6f113e1c add missing space in taginfo listing
say https://taginfo.openstreetmap.org/tags/shop=guns#projects was listing description

`POI/feature in the search database(except for values: no).`
2024-03-26 15:43:00 +01:00
Sarah Hoffmann
436aff2fd3 Merge pull request #3373 from lonvia/restrict-man-made
Style tweaks: restrict man_made features to be imported
2024-03-25 15:20:47 +01:00
Sarah Hoffmann
44922af20e style: restrict man_made main tag to selected values 2024-03-25 11:46:39 +01:00
Sarah Hoffmann
4315debff5 Merge pull request #3367 from lonvia/address-word-counts
Introduce word usage statistics for addresses
2024-03-18 14:32:26 +01:00
Sarah Hoffmann
ace84ed0e3 use address counts for improving index lookup 2024-03-18 11:25:48 +01:00
Sarah Hoffmann
ff3230a7f3 add penalty for single words that look like stop words 2024-03-18 11:25:48 +01:00
Sarah Hoffmann
07b7fd1dbb add address counts to tokens 2024-03-18 11:25:48 +01:00
Sarah Hoffmann
bb5de9b955 extend word statistics to address index
Word frequency in names is not sufficient to interpolate word
frequency in the address because names of towns, states etc. are
much more frequently used than, say street names.
2024-03-18 11:25:48 +01:00
Sarah Hoffmann
40b87bbadf Merge pull request #3363 from mtmail/docs-link-correction
Docs: correct URL of an internal link
2024-03-14 17:46:34 +01:00
marc tobias
1c195eb1e4 docs: correct URL of an internal link 2024-03-14 13:50:24 +01:00
Sarah Hoffmann
9c48726691 add geometry details for postcode area output 2024-03-12 13:51:29 +01:00
Sarah Hoffmann
4fa349315b Merge pull request #3362 from lonvia/find-postcode-areas
Lookup postcode areas for postcode results
2024-03-12 10:05:16 +01:00
Sarah Hoffmann
50beac8305 remove BDD test for place_id details
It is not reliable.
2024-03-11 21:07:14 +01:00
Sarah Hoffmann
9de6bdd7dd exclude postcode test from legacy and php 2024-03-11 15:28:57 +01:00
Sarah Hoffmann
6e688a0113 postcodes: exclude seen places later
The seen list will only have the postcode area when available but
we want the postcode point excluded as well if the area has been seen.
2024-03-11 15:18:57 +01:00
Sarah Hoffmann
dc7cfd1708 look for postcode areas when finding something in the postcode table 2024-03-11 14:48:24 +01:00
344 changed files with 7536 additions and 5611 deletions

View File

@@ -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.

View File

@@ -27,9 +27,9 @@ runs:
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} lua-dkjson nlohmann-json3-dev libspatialite7 libsqlite3-mod-spatialite
if [ "$FLAVOUR" == "oldstuff" ]; then
pip3 install MarkupSafe==2.0.1 python-dotenv psycopg2==2.7.7 jinja2==2.8 psutil==5.4.2 pyicu==2.9 osmium PyYAML==5.1 sqlalchemy==1.4.31 datrie asyncpg aiosqlite
pip3 install MarkupSafe==2.0.1 python-dotenv jinja2==2.8 psutil==5.4.2 pyicu==2.9 osmium PyYAML==5.1 sqlalchemy==1.4.31 psycopg==3.1.7 datrie asyncpg aiosqlite
else
sudo apt-get install -y -qq python3-icu python3-datrie python3-pyosmium python3-jinja2 python3-psutil python3-psycopg2 python3-dotenv python3-yaml
sudo apt-get install -y -qq python3-icu python3-datrie python3-pyosmium python3-jinja2 python3-psutil python3-dotenv python3-yaml
pip3 install sqlalchemy psycopg aiosqlite
fi
shell: bash

View File

@@ -65,7 +65,7 @@ jobs:
- name: Unpack Nominatim
run: tar xf nominatim-src.tar.bz2
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: 3.7
if: matrix.flavour == 'oldstuff'
@@ -80,23 +80,23 @@ jobs:
flavour: ${{ matrix.flavour }}
lua: ${{ matrix.lua }}
- name: Install test prerequsites (behave from apt)
- name: Install test prerequisites (behave from apt)
run: sudo apt-get install -y -qq python3-behave
if: matrix.flavour == 'ubuntu-20'
- name: Install test prerequsites (behave from pip)
- name: Install test prerequisites (behave from pip)
run: pip3 install behave==1.2.6
if: (matrix.flavour == 'oldstuff') || (matrix.flavour == 'ubuntu-22')
- name: Install test prerequsites (from apt for Ununtu 2x)
- name: Install test prerequisites (from apt for Ununtu 2x)
run: sudo apt-get install -y -qq python3-pytest python3-pytest-asyncio uvicorn
if: matrix.flavour != 'oldstuff'
- name: Install newer pytest-asyncio
run: pip3 install -U pytest-asyncio==0.21.1
run: pip3 install -U pytest-asyncio
if: matrix.flavour == 'ubuntu-20'
- name: Install test prerequsites (from pip for Ubuntu 18)
- name: Install test prerequisites (from pip for Ubuntu 18)
run: pip3 install pytest pytest-asyncio uvicorn
if: matrix.flavour == 'oldstuff'
@@ -105,12 +105,12 @@ jobs:
- name: Install latest pylint
run: pip3 install -U pylint
if: matrix.flavour != 'oldstuff'
if: matrix.flavour == 'ubuntu-22'
- name: Python linting
run: python3 -m pylint nominatim
run: python3 -m pylint src
working-directory: Nominatim
if: matrix.flavour != 'oldstuff'
if: matrix.flavour == 'ubuntu-22'
- name: Python unit tests
run: python3 -m pytest test/python
@@ -118,7 +118,8 @@ jobs:
- name: BDD tests
run: |
python3 -m behave -DREMOVE_TEMPLATE=1 -DBUILDDIR=$GITHUB_WORKSPACE/build --format=progress3
export PATH=$GITHUB_WORKSPACE/build/osm2pgsql:$PATH
python3 -m behave -DREMOVE_TEMPLATE=1 --format=progress3
working-directory: Nominatim/test/bdd
- name: Install mypy and typechecking info
@@ -126,7 +127,7 @@ jobs:
if: matrix.flavour != 'oldstuff'
- name: Python static typechecking
run: python3 -m mypy --strict nominatim
run: python3 -m mypy --strict src
working-directory: Nominatim
if: matrix.flavour != 'oldstuff'
@@ -165,12 +166,13 @@ jobs:
with:
cmake-args: -DBUILD_MODULE=on
- name: Install test prerequsites
- name: Install test prerequisites
run: sudo apt-get install -y -qq python3-behave
- name: BDD tests (legacy tokenizer)
run: |
python3 -m behave -DREMOVE_TEMPLATE=1 -DBUILDDIR=$GITHUB_WORKSPACE/build -DAPI_ENGINE=php -DTOKENIZER=legacy --format=progress3
export PATH=$GITHUB_WORKSPACE/build/osm2pgsql:$PATH
python3 -m behave -DREMOVE_TEMPLATE=1 -DSERVER_MODULE_PATH=$GITHUB_WORKSPACE/build/module -DAPI_ENGINE=php -DTOKENIZER=legacy --format=progress3
working-directory: Nominatim/test/bdd
@@ -212,12 +214,13 @@ jobs:
with:
flavour: 'ubuntu-22'
- name: Install test prerequsites
- name: Install test prerequisites
run: sudo apt-get install -y -qq python3-behave
- name: BDD tests (php)
run: |
python3 -m behave -DREMOVE_TEMPLATE=1 -DBUILDDIR=$GITHUB_WORKSPACE/build -DAPI_ENGINE=php --format=progress3
export PATH=$GITHUB_WORKSPACE/build/osm2pgsql:$PATH
python3 -m behave -DREMOVE_TEMPLATE=1 -DAPI_ENGINE=php --format=progress3
working-directory: Nominatim/test/bdd
@@ -227,16 +230,16 @@ jobs:
strategy:
matrix:
name: [Ubuntu-20, Ubuntu-22]
name: [Ubuntu-22, Ubuntu-24]
include:
- name: Ubuntu-20
image: "ubuntu:20.04"
ubuntu: 20
install_mode: install-apache
- name: Ubuntu-22
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 }}
@@ -292,6 +295,16 @@ jobs:
mkdir data-env-reverse
working-directory: /home/nominatim
- name: Add nominatim to path
run: |
sudo ln -s /home/nominatim/nominatim-venv/bin/nominatim /usr/local/bin/nominatim
if: matrix.ubuntu == 24
- name: Need lua binary
run: |
sudo apt-get install -y lua5.4 lua-dkjson
if: matrix.ubuntu == 24
- name: Print version
run: nominatim --version
working-directory: /home/nominatim/nominatim-project
@@ -324,9 +337,18 @@ jobs:
run: apt-get install -y python3-pip
shell: bash
- name: Run update
- name: Install osmium (Ubuntu 22)
run: |
pip3 install --user osmium
if: matrix.ubuntu == 22
- name: Install osmium (Ubuntu 24)
run: |
/home/nominatim/nominatim-venv/bin/pip install osmium
if: matrix.ubuntu == 24
- name: Run update
run: |
nominatim replication --init
NOMINATIM_REPLICATION_MAX_DIFF=1 nominatim replication --once
working-directory: /home/nominatim/nominatim-project

4
.gitignore vendored
View File

@@ -1,9 +1,13 @@
*.log
*.pyc
*.swp
docs/develop/*.png
site-html
build
dist
.coverage
.vagrant
data/country_osm_grid.sql.gz

View File

@@ -13,6 +13,10 @@ 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,chained-comparison,attribute-defined-outside-init
disable=too-few-public-methods,duplicate-code,too-many-ancestors,bad-option-value,no-self-use,not-context-manager,use-dict-literal,chained-comparison,attribute-defined-outside-init,too-many-boolean-expressions,contextmanager-generator-missing-cleanup
good-names=i,j,x,y,m,t,fd,db,cc,x1,x2,y1,y2,pt,k,v,nr
[DESIGN]
max-returns=7

View File

@@ -19,7 +19,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
project(nominatim)
set(NOMINATIM_VERSION_MAJOR 4)
set(NOMINATIM_VERSION_MINOR 4)
set(NOMINATIM_VERSION_MINOR 5)
set(NOMINATIM_VERSION_PATCH 0)
set(NOMINATIM_VERSION "${NOMINATIM_VERSION_MAJOR}.${NOMINATIM_VERSION_MINOR}.${NOMINATIM_VERSION_PATCH}")
@@ -46,8 +46,6 @@ set(BUILD_IMPORTER on CACHE BOOL "Build everything for importing/updating the da
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")
@@ -72,7 +70,7 @@ endif()
# python (imports/updates only)
#-----------------------------------------------------------------------------
if (BUILD_IMPORTER)
if (BUILD_IMPORTER OR BUILD_API)
find_package(PythonInterp 3.7 REQUIRED)
endif()
@@ -188,22 +186,6 @@ 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
#-----------------------------------------------------------------------------
@@ -221,20 +203,22 @@ if (BUILD_IMPORTER)
DESTINATION ${CMAKE_INSTALL_BINDIR}
RENAME nominatim)
install(DIRECTORY nominatim
DESTINATION ${NOMINATIM_LIBDIR}/lib-python
FILES_MATCHING PATTERN "*.py"
PATTERN "paths.py" EXCLUDE
PATTERN __pycache__ EXCLUDE)
if (EXISTS ${PHP_BIN})
configure_file(${PROJECT_SOURCE_DIR}/cmake/paths-py.tmpl paths-py.installed)
else()
configure_file(${PROJECT_SOURCE_DIR}/cmake/paths-py-no-php.tmpl paths-py.installed)
endif()
install(FILES ${PROJECT_BINARY_DIR}/paths-py.installed
DESTINATION ${NOMINATIM_LIBDIR}/lib-python/nominatim
RENAME paths.py)
foreach (submodule nominatim_db nominatim_api)
install(DIRECTORY src/${submodule}
DESTINATION ${NOMINATIM_LIBDIR}/lib-python
FILES_MATCHING PATTERN "*.py"
PATTERN "paths.py" EXCLUDE
PATTERN __pycache__ EXCLUDE)
install(FILES ${PROJECT_BINARY_DIR}/paths-py.installed
DESTINATION ${NOMINATIM_LIBDIR}/lib-python/${submodule}
RENAME paths.py)
endforeach()
install(DIRECTORY lib-sql DESTINATION ${NOMINATIM_LIBDIR})
@@ -287,3 +271,7 @@ if (INSTALL_MUNIN_PLUGINS)
munin/nominatim_requests
DESTINATION ${NOMINATIM_MUNINDIR})
endif()
message(WARNING "Building with CMake is deprecated and will be removed in Nominatim 5.0."
"Use Nominatim pip packages instead.\n"
"See https://nominatim.org/release-docs/develop/admin/Installation/#downloading-and-building-nominatim")

View File

@@ -75,7 +75,10 @@ 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`
* CMakeLists.txt
* [ ] update `ChangeLog` (copy information from patch releases from release branch)
* [ ] complete `docs/admin/Migration.md`
* [ ] update EOL dates in `SECURITY.md`
@@ -100,3 +103,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
View File

@@ -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>.

View File

@@ -1,3 +1,34 @@
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
@@ -8,7 +39,7 @@
* 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 SQLAchemy
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

202
LICENSES/Apache-2.0.txt Normal file
View 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
View 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
View 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 src
pytest:
pytest test/python
lint:
pylint 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

View File

@@ -1,5 +1,4 @@
[![Build Status](https://github.com/osm-search/Nominatim/workflows/CI%20Tests/badge.svg)](https://github.com/osm-search/Nominatim/actions?query=workflow%3A%22CI+Tests%22)
[![codecov](https://codecov.io/gh/osm-search/Nominatim/branch/master/graph/badge.svg?token=8P1LXrhCMy)](https://codecov.io/gh/osm-search/Nominatim)
Nominatim
=========
@@ -48,20 +47,31 @@ A quick summary of the necessary steps:
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).

View File

@@ -9,10 +9,10 @@ versions.
| Version | End of support for security updates |
| ------- | ----------------------------------- |
| 4.5.x | 2026-09-12 |
| 4.4.x | 2026-03-07 |
| 4.3.x | 2025-09-07 |
| 4.2.x | 2024-11-24 |
| 4.1.x | 2024-08-05 |
## Reporting a Vulnerability

30
Vagrantfile vendored
View File

@@ -34,6 +34,14 @@ 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
@@ -69,28 +77,32 @@ Vagrant.configure("2") do |config|
end
end
config.vm.define "ubuntu20" do |sub|
sub.vm.box = "generic/ubuntu2004"
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-20.sh"
s.path = "vagrant/Install-on-Ubuntu-24.sh"
s.privileged = false
s.args = [checkout]
end
end
config.vm.define "ubuntu20-apache" do |sub|
sub.vm.box = "generic/ubuntu2004"
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-20.sh"
s.path = "vagrant/Install-on-Ubuntu-24.sh"
s.privileged = false
s.args = [checkout, "install-apache"]
end
end
config.vm.define "ubuntu20-nginx" do |sub|
sub.vm.box = "generic/ubuntu2004"
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-20.sh"
s.path = "vagrant/Install-on-Ubuntu-24.sh"
s.privileged = false
s.args = [checkout, "install-nginx"]
end

View File

@@ -4,8 +4,8 @@ import os
sys.path.insert(1, '@NOMINATIM_LIBDIR@/lib-python')
from nominatim import cli
from nominatim import version
from nominatim_db import cli
from nominatim_db import version
version.GIT_COMMIT_HASH = '@GIT_HASH@'

View File

@@ -2,10 +2,10 @@
import sys
import os
sys.path.insert(1, '@CMAKE_SOURCE_DIR@')
sys.path.insert(1, '@CMAKE_SOURCE_DIR@/src')
from nominatim import cli
from nominatim import version
from nominatim_db import cli
from nominatim_db import version
version.GIT_COMMIT_HASH = '@GIT_HASH@'

View File

@@ -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
library
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-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 mkdocs build -d ${CMAKE_CURRENT_BINARY_DIR}/../site-html -f ${CMAKE_CURRENT_BINARY_DIR}/../mkdocs.yml
)
ADD_CUSTOM_TARGET(serve-doc
COMMAND mkdocs serve -f ${CMAKE_CURRENT_BINARY_DIR}/../mkdocs.yml
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)

View File

@@ -239,6 +239,6 @@ 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
nominatim refresh --functions
on the target machine to update the the location of the module.

View File

@@ -1,5 +1,8 @@
# Deploying Nominatim using the PHP frontend
!!! danger
The PHP frontend is deprecated and will be removed in Nominatim 5.0.
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

View File

@@ -1,6 +1,6 @@
# Deploying the Nominatim Python frontend
The Nominatim can be run as a Python-based
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.
@@ -12,30 +12,39 @@ to configure it.
!!! Note
Throughout this page, we assume your Nominatim project directory is
located in `/srv/nominatim-project` and 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.
located in `/srv/nominatim-project`. 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.
### 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://uvicorn.org/)
together with [gunicorn](https://gunicorn.org/) HTTP server. We use
Falcon here as the web framework.
Create a virtual environment for the Python packages and install the necessary
dependencies:
Add the necessary packages to your virtual environment:
``` sh
sudo apt install virtualenv
virtualenv /srv/nominatim-venv
/srv/nominatim-venv/bin/pip install SQLAlchemy PyICU psycopg[binary] \
psycopg2-binary python-dotenv PyYAML falcon uvicorn gunicorn
/srv/nominatim-venv/bin/pip install falcon uvicorn gunicorn
```
### Setting up Nominatim as a systemd job
@@ -69,11 +78,10 @@ Requires=nominatim.socket
[Service]
Type=simple
Environment="PYTHONPATH=/usr/local/lib/nominatim/lib-python/"
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.server.falcon.server:run_wsgi
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

View File

@@ -142,6 +142,25 @@ 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.

View File

@@ -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
@@ -299,6 +302,9 @@ To run Nominatim via webservers like Apache or nginx, please continue reading
#### Testing the PHP frontend
!!! danger
The PHP fronted is deprecated and will be removed in Nominatim 5.0.
You can run a small test server with the PHP frontend like this:
```sh

View File

@@ -4,8 +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 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.
@@ -27,7 +27,26 @@ and can't offer support.
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:
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)
* [osm2pgsql](https://osm2pgsql.org) (1.8+, optional when building with CMake)
* [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)
These will be installed automatically when using pip installation.
When using legacy CMake-based installation:
* [cmake](https://cmake.org/)
* [expat](https://libexpat.github.io/)
@@ -36,37 +55,24 @@ For compiling:
* [zlib](https://www.zlib.net/)
* [ICU](http://site.icu-project.org/)
* [nlohmann/json](https://json.nlohmann.me/)
* [Boost libraries](https://www.boost.org/), including system and filesystem
* [Boost libraries](https://www.boost.org/), including system and file system
* 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.7+)
* [Psycopg2](https://www.psycopg.org) (2.7+)
* [Python Dotenv](https://github.com/theskumar/python-dotenv)
* [psutil](https://github.com/giampaolo/psutil)
* [Jinja2](https://palletsprojects.com/p/jinja/)
* [SQLAlchemy](https://www.sqlalchemy.org/) (1.4.31+ with greenlet support)
* [asyncpg](https://magicstack.github.io/asyncpg) (0.8+)
* [PyICU](https://pypi.org/project/PyICU/)
* [PyYaml](https://pyyaml.org/) (5.1+)
* [datrie](https://github.com/pytries/datrie)
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 running the legacy PHP frontend:
For running the legacy PHP frontend (deprecated, will be removed in Nominatim 5.0):
* [PHP](https://php.net) (7.3+)
* PHP-pgsql
@@ -87,7 +93,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. When using traditional SSDs, 4-5 days are more realistic.
around 2.5 days. When using traditional SSDs, 4-5 days are more realistic.
## Tuning the PostgreSQL database
@@ -99,14 +105,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.
@@ -143,6 +151,23 @@ wget -O Nominatim/data/country_osm_grid.sql.gz https://nominatim.org/data/countr
### Building Nominatim
#### Building the latest development version with pip
Nominatim is easiest to run from its own virtual environment. To create one, run:
sudo apt-get install virtualenv
virtualenv /srv/nominatim-venv
To install Nominatim directly from the source tree into the virtual environment, run:
/srv/nominatim-venv/bin/pip install packaging/nominatim-{db,api}
#### Building in legacy CMake mode
!!! warning
Installing Nominatim through CMake is now deprecated. The infrastructure
will be removed in Nominatim 5.0. Please switch to pip installation.
The code must be built in a separate directory. Create the directory and
change into it.
@@ -169,6 +194,7 @@ sudo make install
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>`
The legacy tokenizer is deprecated and will be removed in Nominatim 5.0
Nominatim installs itself into `/usr/local` per default. To choose a different

View File

@@ -1,12 +1,17 @@
# Database Migrations
Since version 3.7.0 Nominatim offers automatic migrations. Please follow
Nominatim offers automatic migrations since version 3.7. 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
If you are still using CMake for the installation of Nominatim, then you
need to update the software in one step before migrating the database.
It is not recommended to do this while the machine is serving requests.
Below you find additional migrations and hints about other structural and
breaking changes. **Please read them before running the migration.**
@@ -15,6 +20,22 @@ breaking changes. **Please read them before running the migration.**
If you are migrating from a version <3.6, then you still have to follow
the manual migration steps up to 3.6.
## 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

View File

@@ -93,7 +93,7 @@ as the ["Accept-Language" HTTP header](https://developer.mozilla.org/en-US/docs/
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 contratry always
to show results in the local language. Browsers on the contrary always
send the currently chosen browser language.

View File

@@ -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",

View File

@@ -1,5 +1,3 @@
### Nominatim API
!!! Attention
The current version of Nominatim implements two different search frontends:
the old PHP frontend and the new Python frontend. They have a very similar

View File

@@ -115,7 +115,7 @@ as the ["Accept-Language" HTTP header](https://developer.mozilla.org/en-US/docs/
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 contratry always
to show results in the local language. Browsers on the contrary always
send the currently chosen browser language.

View File

@@ -152,7 +152,7 @@ as the ["Accept-Language" HTTP header](https://developer.mozilla.org/en-US/docs/
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 contratry always
to show results in the local language. Browsers on the contrary always
send the currently chosen browser language.
### Result restriction
@@ -165,7 +165,7 @@ results and thus give a preference to some results over others.
|-----------| ----- | ------- |
| countrycodes | comma-separated list of country codes | _unset_ |
Filer that limits the search results to one or more countries.
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.

View File

@@ -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

View File

@@ -191,7 +191,7 @@ They take _key match lists_ for main and extra names respectively.
Address tags will be used to build up the address of an object.
`set_address_tags()` takes a table with arbitrary fields pointing to
_key match lists_. To fields have a special meaning:
_key match lists_. Two fields have a special meaning:
* __main__: defines
the tags that make a full address object out of the OSM object. This
@@ -218,7 +218,7 @@ are accepted, all other values are discarded.
main = {'addr:housenumber'},
extra = {'addr:*'},
postcode = {'postal_code', 'postcode', 'addr:postcode'},
country = {'country-code', 'ISO3166-1'}
country = {'country_code', 'ISO3166-1'}
}
```
@@ -227,7 +227,7 @@ are accepted, all other values are discarded.
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
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.

View File

@@ -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

View File

@@ -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

View 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._

View File

@@ -12,11 +12,16 @@ 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

View File

@@ -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 [principal tags in import style](Import-Styles.md#set_main_tags-principal-tags)
* **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.

View File

@@ -17,6 +17,11 @@ they can be configured.
## Legacy tokenizer
!!! danger
The Legacy tokenizer is deprecated and will be removed in Nominatim 5.0.
If you still use a database with the legacy tokenizer, you must reimport
it using the ICU tokenizer below.
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
@@ -52,7 +57,7 @@ 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.
See [Advanced installations](../admin/Advanced-Installations.md#using-an-external-postgresql-database) for details.
There are no other configuration options for the legacy tokenizer. All
normalization functions are hard-coded.
@@ -175,7 +180,7 @@ The following is a list of sanitizers that are shipped with Nominatim.
##### split-name-list
::: nominatim.tokenizer.sanitizers.split_name_list
::: nominatim_db.tokenizer.sanitizers.split_name_list
options:
members: False
heading_level: 6
@@ -183,7 +188,7 @@ The following is a list of sanitizers that are shipped with Nominatim.
##### strip-brace-terms
::: nominatim.tokenizer.sanitizers.strip_brace_terms
::: nominatim_db.tokenizer.sanitizers.strip_brace_terms
options:
members: False
heading_level: 6
@@ -191,7 +196,7 @@ The following is a list of sanitizers that are shipped with Nominatim.
##### tag-analyzer-by-language
::: nominatim.tokenizer.sanitizers.tag_analyzer_by_language
::: nominatim_db.tokenizer.sanitizers.tag_analyzer_by_language
options:
members: False
heading_level: 6
@@ -199,7 +204,7 @@ The following is a list of sanitizers that are shipped with Nominatim.
##### clean-housenumbers
::: nominatim.tokenizer.sanitizers.clean_housenumbers
::: nominatim_db.tokenizer.sanitizers.clean_housenumbers
options:
members: False
heading_level: 6
@@ -207,7 +212,7 @@ The following is a list of sanitizers that are shipped with Nominatim.
##### clean-postcodes
::: nominatim.tokenizer.sanitizers.clean_postcodes
::: nominatim_db.tokenizer.sanitizers.clean_postcodes
options:
members: False
heading_level: 6
@@ -215,7 +220,7 @@ The following is a list of sanitizers that are shipped with Nominatim.
##### clean-tiger-tags
::: nominatim.tokenizer.sanitizers.clean_tiger_tags
::: nominatim_db.tokenizer.sanitizers.clean_tiger_tags
options:
members: False
heading_level: 6
@@ -223,7 +228,7 @@ The following is a list of sanitizers that are shipped with Nominatim.
#### delete-tags
::: nominatim.tokenizer.sanitizers.delete_tags
::: nominatim_db.tokenizer.sanitizers.delete_tags
options:
members: False
heading_level: 6
@@ -231,7 +236,7 @@ The following is a list of sanitizers that are shipped with Nominatim.
#### tag-japanese
::: nominatim.tokenizer.sanitizers.tag_japanese
::: nominatim_db.tokenizer.sanitizers.tag_japanese
options:
members: False
heading_level: 6

View File

@@ -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:
@@ -41,38 +41,55 @@ It has the following additional requirements:
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)
* [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.18
* [mkdocstrings-python](https://mkdocstrings.github.io/python/)
* [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.
In particular, pylint tends to have a lot of breaking changes between versions.
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 pytest-asyncio pylint \
mypy types-PyYAML types-jinja2 types-psycopg2 types-psutil \
types-ujson types-requests types-Pygments typing-extensions\
httpx asgi-lifespan
sudo apt install libsqlite3-mod-spatialite php-cli
```
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:
```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 pylint \
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
```
echo 'export PATH=~/.local/bin:$PATH' > ~/.profile
Now enter the virtual environment whenever you want to develop:
```sh
. ~/nominatim-dev-venv/bin/activate
```
For installing the PHP development tools, run:
```sh
sudo apt install php-cgi phpunit php-codesniffer
```
If your distribution does not have PHPUnit 7.3+, you can install it (as well
@@ -85,24 +102,47 @@ composer global require "phpunit/phpunit=8.*"
```
The binaries are found in `.config/composer/vendor/bin`. You need to add this
to your PATH as well:
to your PATH:
```
echo 'export PATH=~/.config/composer/vendor/bin:$PATH' > ~/.profile
```
### 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:
```
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).
@@ -113,18 +153,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
@@ -136,7 +172,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
```

View File

@@ -52,7 +52,7 @@ the function.
### Sanitizer configuration
::: nominatim.tokenizer.sanitizers.config.SanitizerConfig
::: nominatim_db.tokenizer.sanitizers.config.SanitizerConfig
options:
heading_level: 6
@@ -73,14 +73,14 @@ adding extra attributes) or completely replace the list with a different one.
#### PlaceInfo - information about the place
::: nominatim.data.place_info.PlaceInfo
::: nominatim_db.data.place_info.PlaceInfo
options:
heading_level: 6
#### PlaceName - extended naming information
::: nominatim.data.place_name.PlaceName
::: nominatim_db.data.place_name.PlaceName
options:
heading_level: 6
@@ -139,12 +139,12 @@ They can be found in the directory
## Custom token analysis module
::: nominatim.tokenizer.token_analysis.base.AnalysisModule
::: nominatim_db.tokenizer.token_analysis.base.AnalysisModule
options:
heading_level: 6
::: nominatim.tokenizer.token_analysis.base.Analyzer
::: nominatim_db.tokenizer.token_analysis.base.Analyzer
options:
heading_level: 6

View File

@@ -78,7 +78,6 @@ 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)
@@ -91,7 +90,7 @@ The tests can be configured with a set of environment variables (`behave -D key=
* `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
module shared library file (only needed for legacy tokenizer)
* `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
@@ -122,23 +121,6 @@ and compromises the following data:
API tests should only be testing the functionality of the website PHP code.
Most tests should be formulated as BDD DB creation tests (see below) instead.
#### Code Coverage (PHP engine only)
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

View File

@@ -130,16 +130,16 @@ 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
::: nominatim_db.tokenizer.base.AbstractTokenizer
options:
heading_level: 6
### Python Analyzer Class
::: nominatim.tokenizer.base.AbstractAnalyzer
::: nominatim_db.tokenizer.base.AbstractAnalyzer
options:
heading_level: 6

View File

@@ -34,3 +34,8 @@ th {
.md-footer__inner {
display: none;
}
.headerlink {
filter: grayscale(100%);
font-size: 80%;
}

View File

@@ -1,11 +1,13 @@
# Configuration
When using Nominatim through the library, it can be configured in exactly
the same way as when running as a service. This means that you should have
created a [project directory](../admin/Import.md#creating-the-project-directory)
which contains all files belonging to the Nominatim instance. It can also contain
an `.env` file with configuration options. Setting configuration parameters
via environment variables works as well.
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:
@@ -20,7 +22,7 @@ configuration parameters, see the [Configuration page](../customize/Settings.md)
## `Configuration` class
::: nominatim.config.Configuration
::: nominatim_api.Configuration
options:
members:
- get_bool

View File

@@ -1,20 +1,21 @@
# Getting Started
The Nominatim search frontend can directly be used as a Python library in
scripts and applications. When you have imported your own Nominatim database,
then it is no longer necessary to run a full web service for it and access
the database through http requests. There are
also less constraints on the kinds of data that can be accessed. The library
allows to get access to more detailed information about the objects saved
in the database.
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.
!!! danger
The library interface is currently in an experimental stage. There might
be some smaller adjustments to the public interface until the next version.
!!! warning
The library also misses a proper installation routine, so some manipulation
of the PYTHONPATH is required. At the moment, use is only recommended for
developers with some experience in Python.
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
@@ -22,14 +23,18 @@ 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.
It is not yet possible to install it in the usual way via pip or inside a
virtualenv. To get access to the library you need to set an appropriate
`PYTHONPATH`. With the default installation, the python library can be found
under `/usr/local/share/nominatim/lib-python`. If you have installed
Nominatim under a different prefix, adapt the `/usr/local/` part accordingly.
You can also point the `PYTHONPATH` to the Nominatim source code.
The Nominatim frontend library is contained in the Python package `nominatim-api`.
You can install the latest released version directly from pip:
### A simple search example
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
@@ -40,15 +45,13 @@ This code snippet implements a simple search for the town of 'Brugge':
!!! example
=== "NominatimAPIAsync"
``` python
from pathlib import Path
import asyncio
import nominatim.api as napi
import nominatim_api as napi
async def search(query):
api = napi.NominatimAPIAsync(Path('.'))
return await api.search(query)
async with napi.NominatimAPIAsync() as api:
return await api.search(query)
results = asyncio.run(search('Brugge'))
if not results:
@@ -59,13 +62,10 @@ This code snippet implements a simple search for the town of 'Brugge':
=== "NominatimAPI"
``` python
from pathlib import Path
import nominatim_api as napi
import nominatim.api as napi
api = napi.NominatimAPI(Path('.'))
results = api.search('Brugge')
with napi.NominatimAPI() as api:
results = api.search('Brugge')
if not results:
print('Cannot find Brugge')
@@ -88,7 +88,7 @@ implementations. The documentation itself will usually refer only to
available only for the synchronous or asynchronous version, this will be
explicitly mentioned.
### Defining which database to use
## Defining which database to use
The [Configuration](../admin/Import.md#configuration-setup-in-env)
section explains how Nominatim is configured using the
@@ -97,76 +97,120 @@ The same configuration mechanism is used with the
Nominatim API library. You should therefore be sure you are familiar with
the section.
The constructor of the 'Nominatim API class' takes one mandatory parameter:
the path to the [project directory](../admin/Import.md#creating-the-project-directory).
You should have set up this directory as part of the Nominatim import.
Any configuration found in the `.env` file in this directory will automatically
used.
Yo may also configure Nominatim be setting environment variables.
Normally, Nominatim will check the operating system environment. This can be
overwritten by giving the constructor a dictionary of configuration parameters.
Let us look up 'Brugge' in the special database named 'belgium' instead of the
standard 'nominatim' database:
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
from pathlib import Path
import asyncio
import nominatim.api as napi
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):
api = napi.NominatimAPIAsync(Path('.'), environ=config_params)
return await api.search(query)
async with napi.NominatimAPIAsync(environ=config_params) as api:
return await api.search(query)
results = asyncio.run(search('Brugge'))
```
=== "NominatimAPI"
``` python
from pathlib import Path
import nominatim.api as napi
import nominatim_api as napi
config_params = {
'NOMINATIM_DATABASE_DSN': 'pgsql:dbname=belgium'
}
api = napi.NominatimAPI(Path('.'), environ=config_params)
results = api.search('Brugge')
with napi.NominatimAPI(environ=config_params) as api:
results = api.search('Brugge')
```
### Presenting results to humans
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.
All search functions return the raw results from the database. There is no
full human-readable label. To create such a label, you need two things:
## 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
* adapt the result to the language you wish to use for display
* 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
from pathlib import Path
import asyncio
import nominatim.api as napi
import nominatim_api as napi
async def search(query):
api = napi.NominatimAPIAsync(Path('.'))
return await api.search(query, address_details=True)
async with napi.NominatimAPIAsync() as api:
return await api.search(query, address_details=True)
results = asyncio.run(search('Brugge'))
@@ -178,13 +222,10 @@ Again searching for 'Brugge', this time with a nicely formatted result:
=== "NominatimAPI"
``` python
from pathlib import Path
import nominatim_api as napi
import nominatim.api as napi
api = napi.NominatimAPI(Path('.'))
results = api.search('Brugge', address_details=True)
with napi.NominatimAPI() as api:
results = api.search('Brugge', address_details=True)
locale = napi.Locales(['fr', 'en'])
for i, result in enumerate(results):
@@ -240,7 +281,7 @@ 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 `adlin_level` was used, what category the place
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.

View File

@@ -5,26 +5,26 @@ in the query functions of the API object.
## Place identification
The [details](NominatimAPI.md#nominatim.api.core.NominatimAPI.details) and
[lookup](NominatimAPI.md#nominatim.api.core.NominatimAPI.lookup) functions
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
::: nominatim_api.PlaceID
options:
heading_level: 6
### OsmID
::: nominatim.api.OsmID
::: nominatim_api.OsmID
options:
heading_level: 6
## Geometry types
::: nominatim.api.GeometryFormat
::: nominatim_api.GeometryFormat
options:
heading_level: 6
members_order: source
@@ -33,14 +33,14 @@ types for place identification are listed. All types are dataclasses.
### Point
::: nominatim.api.Point
::: nominatim_api.Point
options:
heading_level: 6
show_signature_annotations: True
### Bbox
::: nominatim.api.Bbox
::: nominatim_api.Bbox
options:
heading_level: 6
show_signature_annotations: True
@@ -54,9 +54,7 @@ orthogonal to restriction by address ranks, which groups places by their
geographic extent.
::: nominatim.api.DataLayer
::: nominatim_api.DataLayer
options:
heading_level: 6
members_order: source

View File

@@ -24,12 +24,11 @@ the placex table:
```
import asyncio
from pathlib import Path
import sqlalchemy as sa
from nominatim.api import NominatimAPIAsync
from nominatim_api import NominatimAPIAsync
async def print_table_size():
api = NominatimAPIAsync(Path('.'))
api = NominatimAPIAsync()
async with api.begin() as conn:
cnt = await conn.scalar(sa.select(sa.func.count()).select_from(conn.t.placex))
@@ -45,7 +44,7 @@ asyncio.run(print_table_size())
## SearchConnection class
::: nominatim.api.SearchConnection
::: nominatim_api.SearchConnection
options:
members:
- scalar

View File

@@ -6,7 +6,7 @@ to instantiate a separate instance for each thread.
### NominatimAPI
::: nominatim.api.NominatimAPI
::: nominatim_api.NominatimAPI
options:
members:
- __init__
@@ -25,7 +25,7 @@ to instantiate a separate instance for each thread.
### NominatimAPIAsync
::: nominatim.api.NominatimAPIAsync
::: nominatim_api.NominatimAPIAsync
options:
members:
- __init__

View File

@@ -12,7 +12,7 @@ functions that allow further processing of the results.
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
::: nominatim_api.SourceTable
options:
heading_level: 6
members_order: source
@@ -31,7 +31,7 @@ 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
::: nominatim_api.AddressLine
options:
heading_level: 6
members_order: source
@@ -43,7 +43,7 @@ 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
::: nominatim_api.WordInfo
options:
heading_level: 6
@@ -53,6 +53,6 @@ Results are always returned with the full list of available names.
### Locale
::: nominatim.api.Locales
::: nominatim_api.Locales
options:
heading_level: 6

View 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")

View File

@@ -20,6 +20,54 @@ CREATE TYPE place_importance as (
wikipedia TEXT
);
{% if 'wikimedia_importance' in db.tables %}
CREATE OR REPLACE FUNCTION get_wikipedia_match(extratags HSTORE, country_code varchar(2))
RETURNS wikipedia_article_match
AS $$
DECLARE
i INT;
wiki_article_title TEXT;
wiki_article_language TEXT;
result wikipedia_article_match;
entry RECORD;
BEGIN
IF extratags ? 'wikipedia' and strpos(extratags->'wikipedia', ':') IN (3,4) THEN
wiki_article_language := lower(trim(split_part(extratags->'wikipedia', ':', 1)));
wiki_article_title := trim(substr(extratags->'wikipedia',
strpos(extratags->'wikipedia', ':') + 1));
FOR result IN
SELECT language, title, importance FROM wikimedia_importance
WHERE language = wiki_article_language
and title = replace(wiki_article_title, ' ', '_')
LOOP
RETURN result;
END LOOP;
END IF;
FOREACH wiki_article_language IN ARRAY ARRAY['ar','bg','ca','cs','da','de','en','es','eo','eu','fa','fr','ko','hi','hr','id','it','he','lt','hu','ms','nl','ja','no','pl','pt','kk','ro','ru','sk','sl','sr','fi','sv','tr','uk','vi','vo','war','zh']
LOOP
IF extratags ? ('wikipedia:' || wiki_article_language) THEN
wiki_article_title := extratags->('wikipedia:' || wiki_article_language);
FOR result IN
SELECT language, title, importance FROM wikimedia_importance
WHERE language = wiki_article_language
and title = replace(wiki_article_title, ' ', '_')
LOOP
RETURN result;
END LOOP;
END IF;
END LOOP;
RETURN NULL;
END;
$$
LANGUAGE plpgsql IMMUTABLE;
{% else %}
-- See: http://stackoverflow.com/questions/6410088/how-can-i-mimic-the-php-urldecode-function-in-postgresql
CREATE OR REPLACE FUNCTION decode_url_part(p varchar)
@@ -93,6 +141,7 @@ END;
$$
LANGUAGE plpgsql STABLE;
{% endif %}
CREATE OR REPLACE FUNCTION compute_importance(extratags HSTORE,
country_code varchar(2),
@@ -118,9 +167,16 @@ BEGIN
-- Nothing? Then try with the wikidata tag.
IF result.importance is null AND extratags ? 'wikidata' THEN
FOR match IN SELECT * FROM wikipedia_article
WHERE wd_page_title = extratags->'wikidata'
ORDER BY language = 'en' DESC, langcount DESC LIMIT 1
FOR match IN
{% if 'wikimedia_importance' in db.tables %}
SELECT * FROM wikimedia_importance
WHERE wikidata = extratags->'wikidata'
LIMIT 1
{% else %}
SELECT * FROM wikipedia_article
WHERE wd_page_title = extratags->'wikidata'
ORDER BY language = 'en' DESC, langcount DESC LIMIT 1
{% endif %}
LOOP
result.importance := match.importance;
result.wikipedia := match.language || ':' || match.title;

View File

@@ -67,10 +67,6 @@ BEGIN
END LOOP;
END IF;
IF parent_place_id is null THEN
RETURN 0;
END IF;
RETURN parent_place_id;
END;
$$
@@ -183,6 +179,13 @@ BEGIN
ST_PointOnSurface(NEW.linegeo),
NEW.linegeo);
-- Cannot find a parent street. We will not be able to display a reliable
-- address, so drop entire interpolation.
IF NEW.parent_place_id is NULL THEN
DELETE FROM location_property_osmline where place_id = OLD.place_id;
RETURN NULL;
END IF;
NEW.token_info := token_strip_info(NEW.token_info);
IF NEW.address ? '_inherited' THEN
NEW.address := hstore('interpolation', NEW.address->'interpolation');
@@ -219,10 +222,11 @@ BEGIN
-- formatted postcode and therefore 'postcode' contains a derived
-- variant.
CASE WHEN address ? 'postcode' THEN placex.postcode ELSE NULL::text END as postcode,
substring(address->'housenumber','[0-9]+')::integer as hnr
(address->'housenumber')::integer as hnr
FROM placex, generate_series(1, array_upper(waynodes, 1)) nodeidpos
WHERE osm_type = 'N' and osm_id = waynodes[nodeidpos]::BIGINT
and address is not NULL and address ? 'housenumber'
and address->'housenumber' ~ '^[0-9]{1,6}$'
and ST_Distance(NEW.linegeo, geometry) < 0.0005
ORDER BY nodeidpos
LOOP

View File

@@ -481,24 +481,20 @@ BEGIN
name_vector := array_merge(name_vector, hnr_vector);
END IF;
IF is_place_addr THEN
addr_place_ids := token_addr_place_search_tokens(token_info);
IF not addr_place_ids <@ parent_name_vector THEN
-- make sure addr:place terms are always searchable
nameaddress_vector := array_merge(nameaddress_vector, addr_place_ids);
-- If there is a housenumber, also add the place name as a name,
-- so we can search it by the usual housenumber+place algorithms.
IF hnr_vector is not null THEN
name_vector := array_merge(name_vector, addr_place_ids);
END IF;
END IF;
END IF;
-- Cheating here by not recomputing all terms but simply using the ones
-- from the parent object.
nameaddress_vector := array_merge(nameaddress_vector, parent_name_vector);
nameaddress_vector := array_merge(nameaddress_vector, parent_address_vector);
-- make sure addr:place terms are always searchable
IF is_place_addr THEN
addr_place_ids := token_addr_place_search_tokens(token_info);
IF hnr_vector is not null AND not addr_place_ids <@ parent_name_vector
THEN
name_vector := array_merge(name_vector, hnr_vector);
END IF;
nameaddress_vector := array_merge(nameaddress_vector, addr_place_ids);
END IF;
END;
$$
LANGUAGE plpgsql;
@@ -731,10 +727,12 @@ BEGIN
{% if not disable_diff_updates %}
-- The following is not needed until doing diff updates, and slows the main index process down
IF NEW.rank_address > 0 THEN
IF NEW.rank_address between 2 and 27 THEN
IF (ST_GeometryType(NEW.geometry) in ('ST_Polygon','ST_MultiPolygon') AND ST_IsValid(NEW.geometry)) THEN
-- Performance: We just can't handle re-indexing for country level changes
IF st_area(NEW.geometry) < 1 THEN
IF (NEW.rank_address < 26 and st_area(NEW.geometry) < 1)
OR (NEW.rank_address >= 26 and st_area(NEW.geometry) < 0.01)
THEN
-- mark items within the geometry for re-indexing
-- RAISE WARNING 'placex poly insert: % % % %',NEW.osm_type,NEW.osm_id,NEW.class,NEW.type;
@@ -749,9 +747,11 @@ BEGIN
or name is not null
or (NEW.rank_address >= 16 and address ? 'place'));
END IF;
ELSE
ELSEIF ST_GeometryType(NEW.geometry) not in ('ST_LineString', 'ST_MultiLineString')
OR ST_Length(NEW.geometry) < 0.5
THEN
-- mark nearby items for re-indexing, where 'nearby' depends on the features rank_search and is a complete guess :(
diameter := update_place_diameter(NEW.rank_search);
diameter := update_place_diameter(NEW.rank_address);
IF diameter > 0 THEN
-- RAISE WARNING 'placex point insert: % % % % %',NEW.osm_type,NEW.osm_id,NEW.class,NEW.type,diameter;
IF NEW.rank_search >= 26 THEN
@@ -1403,6 +1403,8 @@ BEGIN
{% if debug %}RAISE WARNING 'placex_delete:12 % %',OLD.osm_type,OLD.osm_id;{% endif %}
UPDATE location_postcode SET indexed_status = 2 WHERE parent_place_id = OLD.place_id;
RETURN OLD;
END;

View File

@@ -164,18 +164,44 @@ CREATE OR REPLACE FUNCTION get_country_code(place geometry)
DECLARE
place_centre GEOMETRY;
nearcountry RECORD;
countries TEXT[];
BEGIN
place_centre := ST_PointOnSurface(place);
-- RAISE WARNING 'get_country_code, start: %', ST_AsText(place_centre);
-- Try for a OSM polygon
FOR nearcountry IN
SELECT country_code from location_area_country
WHERE country_code is not null and st_covers(geometry, place_centre) limit 1
LOOP
RETURN nearcountry.country_code;
END LOOP;
SELECT array_agg(country_code) FROM location_area_country
WHERE country_code is not null and st_covers(geometry, place_centre)
INTO countries;
IF array_length(countries, 1) = 1 THEN
RETURN countries[1];
END IF;
IF array_length(countries, 1) > 1 THEN
-- more than one country found, confirm against the fallback data what to choose
FOR nearcountry IN
SELECT country_code FROM country_osm_grid
WHERE ST_Covers(geometry, place_centre) AND country_code = ANY(countries)
ORDER BY area ASC
LOOP
RETURN nearcountry.country_code;
END LOOP;
-- Still nothing? Choose the country code with the smallest partition number.
-- And failing that, just go by the alphabet.
FOR nearcountry IN
SELECT cc,
(SELECT partition FROM country_name WHERE country_code = cc) as partition
FROM unnest(countries) cc
ORDER BY partition, cc
LOOP
RETURN nearcountry.cc;
END LOOP;
-- Should never be reached.
RETURN countries[1];
END IF;
-- RAISE WARNING 'osm fallback: %', ST_AsText(place_centre);

View File

@@ -21,11 +21,17 @@ CREATE INDEX IF NOT EXISTS idx_placex_parent_place_id
ON placex USING BTREE (parent_place_id) {{db.tablespace.search_index}}
WHERE parent_place_id IS NOT NULL;
---
-- Used to find postcode areas after a search in location_postcode.
CREATE INDEX IF NOT EXISTS idx_placex_postcode_areas
ON placex USING BTREE (country_code, postcode) {{db.tablespace.search_index}}
WHERE osm_type = 'R' AND class = 'boundary' AND type = 'postal_code';
---
CREATE INDEX IF NOT EXISTS idx_placex_geometry ON placex
USING GIST (geometry) {{db.tablespace.search_index}};
-- Index is needed during import but can be dropped as soon as a full
-- geometry index is in place. The partial index is almost as big as the full
-- index.
---
DROP INDEX IF EXISTS idx_placex_geometry_lower_rank_ways;
---
CREATE INDEX IF NOT EXISTS idx_placex_geometry_reverse_lookupPolygon
@@ -55,7 +61,6 @@ CREATE INDEX IF NOT EXISTS idx_postcode_postcode
---
DROP INDEX IF EXISTS idx_placex_geometry_address_area_candidates;
DROP INDEX IF EXISTS idx_placex_geometry_buildings;
DROP INDEX IF EXISTS idx_placex_geometry_lower_rank_ways;
DROP INDEX IF EXISTS idx_placex_wikidata;
DROP INDEX IF EXISTS idx_placex_rank_address_sector;
DROP INDEX IF EXISTS idx_placex_rank_boundaries_sector;
@@ -76,6 +81,9 @@ CREATE INDEX IF NOT EXISTS idx_postcode_postcode
type TEXT,
deferred BOOLEAN
);
---
CREATE INDEX IF NOT EXISTS idx_location_postcode_parent_place_id
ON location_postcode USING BTREE (parent_place_id) {{db.tablespace.address_index}};
{% endif %}
-- Indices only needed for search.

View File

@@ -273,28 +273,15 @@ GRANT SELECT ON import_polygon_delete TO "{{config.DATABASE_WEBUSER}}";
DROP SEQUENCE IF EXISTS file;
CREATE SEQUENCE file start 1;
-- null table so it won't error
-- deliberately no drop - importing the table is expensive and static, if it is already there better to avoid removing it
CREATE TABLE IF NOT EXISTS wikipedia_article (
language text NOT NULL,
title text NOT NULL,
langcount integer,
othercount integer,
totalcount integer,
lat double precision,
lon double precision,
importance double precision,
osm_type character(1),
osm_id bigint,
wd_page_title text,
instance_of text
);
CREATE TABLE IF NOT EXISTS wikipedia_redirect (
language text,
from_title text,
to_title text
);
{% if 'wikimedia_importance' not in db.tables and 'wikipedia_article' not in db.tables %}
-- create dummy tables here, if nothing was imported
CREATE TABLE wikimedia_importance (
language TEXT NOT NULL,
title TEXT NOT NULL,
importance double precision NOT NULL,
wikidata TEXT
) {{db.tablespace.address_data}};
{% endif %}
-- osm2pgsql does not create indexes on the middle tables for Nominatim
-- Add one for lookup of associated street relations.

View File

@@ -1,15 +0,0 @@
# Creates and installs manual page
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/create-manpage.tmpl create_manpage.py)
find_program(ARGPARSEMANPAGE argparse-manpage)
ADD_CUSTOM_TARGET(manpage
COMMAND ${ARGPARSEMANPAGE} --pyfile ${CMAKE_CURRENT_BINARY_DIR}/create_manpage.py
--function get_parser --project-name Nominatim
--url https://nominatim.org > ${CMAKE_CURRENT_SOURCE_DIR}/nominatim.1
--author 'the Nominatim developer community'
--author-email info@nominatim.org
)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/nominatim.1 DESTINATION share/man/man1 )

12
man/create-manpage.py Normal file
View File

@@ -0,0 +1,12 @@
import sys
import os
from pathlib import Path
sys.path.append(str(Path(__file__, '..', '..', 'src').resolve()))
from nominatim_db.cli import get_set_parser
def get_parser():
parser = get_set_parser()
return parser.parser

View File

@@ -1,12 +0,0 @@
#!/usr/bin/env python3
import sys
import os
sys.path.append('@PROJECT_SOURCE_DIR@')
from nominatim.cli import get_set_parser
def get_parser():
parser = get_set_parser()
return parser.parser

View File

@@ -3,7 +3,7 @@
nominatim
.SH SYNOPSIS
.B nominatim
[-h] {import,freeze,replication,special-phrases,add-data,index,refresh,admin,export,serve,search,reverse,lookup,details,status} ...
[-h] [--version] {import,freeze,replication,special-phrases,add-data,index,refresh,admin,export,convert,serve,search,reverse,lookup,details,status} ...
.SH DESCRIPTION
Command\-line tools for importing, updating, administrating and
.br
@@ -12,6 +12,9 @@ nominatim
.SH OPTIONS
.TP
\fB\-\-version\fR
Print Nominatim version and exit
.SS
\fBSub-commands\fR
@@ -41,7 +44,10 @@ nominatim
Analyse and maintain the database.
.TP
\fBnominatim\fR \fI\,export\/\fR
Export addresses as CSV file from the database.
Export places as CSV file from the database.
.TP
\fBnominatim\fR \fI\,convert\/\fR
Convert an existing database into a different format. (EXPERIMENTAL)
.TP
\fBnominatim\fR \fI\,serve\/\fR
Start a simple web server for serving the API.
@@ -59,13 +65,15 @@ nominatim
Execute API details query.
.TP
\fBnominatim\fR \fI\,status\/\fR
Execute API status query.
.SH OPTIONS 'nominatim import'
usage: nominatim import [-h] [-q] [-v] [--project-dir DIR] [-j NUM]
(--osm-file FILE | --continue {load-data,indexing,db-postprocess})
[--osm-file FILE]
[--continue {import-from-file,load-data,indexing,db-postprocess}]
[--osm2pgsql-cache SIZE] [--reverse-only]
[--no-partitions] [--no-updates] [--ignore-errors]
[--index-noanalyse]
[--no-partitions] [--no-updates] [--offline]
[--ignore-errors] [--index-noanalyse]
[--prepare-database]
Create a new Nominatim database from an OSM file.
.br
@@ -102,7 +110,7 @@ Number of parallel threads to use
OSM file to be imported (repeat for importing multiple files)
.TP
\fB\-\-continue\fR {load\-data,indexing,db\-postprocess}
\fB\-\-continue\fR {import\-from\-file,load\-data,indexing,db\-postprocess}
Continue an import that was interrupted
.TP
@@ -121,6 +129,10 @@ Do not partition search indices (speeds up import of single country extracts)
\fB\-\-no\-updates\fR
Do not keep tables that are only needed for updating the database later
.TP
\fB\-\-offline\fR
Do not attempt to load any additional data from the internet
.TP
\fB\-\-ignore\-errors\fR
Continue import even when errors in SQL are present
@@ -129,6 +141,10 @@ Continue import even when errors in SQL are present
\fB\-\-index\-noanalyse\fR
Do not perform analyse operations during index (expert only)
.TP
\fB\-\-prepare\-database\fR
Create the database but do not import any data
.SH OPTIONS 'nominatim freeze'
usage: nominatim freeze [-h] [-q] [-v] [--project-dir DIR] [-j NUM]
@@ -171,8 +187,8 @@ Number of parallel threads to use
.SH OPTIONS 'nominatim replication'
usage: nominatim replication [-h] [-q] [-v] [--project-dir DIR] [-j NUM]
[--init] [--no-update-functions]
[--check-for-updates] [--once] [--no-index]
[--osm2pgsql-cache SIZE]
[--check-for-updates] [--once] [--catch-up]
[--no-index] [--osm2pgsql-cache SIZE]
[--socket-timeout SOCKET_TIMEOUT]
Update the database using an online replication service.
@@ -229,7 +245,7 @@ Initialise the update process
.TP
\fB\-\-no\-update\-functions\fR
Do not update the trigger function to support differential updates.
Do not update the trigger function to support differential updates (EXPERT)
.TP
\fB\-\-check\-for\-updates\fR
@@ -239,6 +255,10 @@ Check if new updates are available and exit
\fB\-\-once\fR
Download and apply updates only once. When not set, updates are continuously applied
.TP
\fB\-\-catch\-up\fR
Download and apply updates until no new data is available on the server
.TP
\fB\-\-no\-index\fR
Do not index the new data. Only usable together with \-\-once
@@ -290,6 +310,20 @@ usage: nominatim special-phrases [-h] [-q] [-v] [--project-dir DIR] [-j NUM]
.br
'test/testdb/full_en_phrases_test.csv'.
.br
.br
The import can be further configured to ignore specific key/value pairs.
.br
This is particularly useful when importing phrases from the wiki. The
.br
default configuration excludes some very common tags like building=yes.
.br
The configuration can be customized by putting a file `phrase\-settings.json`
.br
with custom rules into the project directory or by using the `\-\-config`
.br
option to point to another configuration file.
.br
@@ -350,7 +384,7 @@ usage: nominatim add-data [-h] [-q] [-v] [--project-dir DIR] [-j NUM]
.br
data. See the online documentation at
.br
https://nominatim.org/release\-docs/latest/admin/Import/#installing\-tiger\-housenumber\-data\-for\-the\-us
https://nominatim.org/release\-docs/latest/customize/Tiger/
.br
for more information.
.br
@@ -465,10 +499,11 @@ Maximum/finishing rank
.SH OPTIONS 'nominatim refresh'
usage: nominatim refresh [-h] [-q] [-v] [--project-dir DIR] [-j NUM]
[--postcodes] [--word-counts] [--address-levels]
[--functions] [--wiki-data] [--importance]
[--website] [--no-diff-updates]
[--enable-debug-statements]
[--postcodes] [--word-tokens] [--word-counts]
[--address-levels] [--functions] [--wiki-data]
[--secondary-importance] [--importance] [--website]
[--data-object OBJECT] [--data-area OBJECT]
[--no-diff-updates] [--enable-debug-statements]
Recompute auxiliary data used by the indexing process.
.br
@@ -512,6 +547,10 @@ Number of parallel threads to use
\fB\-\-postcodes\fR
Update postcode centroid table
.TP
\fB\-\-word\-tokens\fR
Clean up search terms
.TP
\fB\-\-word\-counts\fR
Compute frequency of full\-word search terms
@@ -528,6 +567,10 @@ Update the PL/pgSQL functions in the database
\fB\-\-wiki\-data\fR
Update Wikipedia/data importance numbers
.TP
\fB\-\-secondary\-importance\fR
Update secondary importance raster data
.TP
\fB\-\-importance\fR
Recompute place importances (expensive!)
@@ -536,6 +579,14 @@ Recompute place importances (expensive!)
\fB\-\-website\fR
Refresh the directory that serves the scripts for the web API
.TP
\fB\-\-data\-object\fR OBJECT
Mark the given OSM object as requiring an update (format: [NWR]<id>)
.TP
\fB\-\-data\-area\fR OBJECT
Mark the area around the given OSM object as requiring an update (format: [NWR]<id>)
.TP
\fB\-\-no\-diff\-updates\fR
Do not enable code for propagating updates
@@ -546,7 +597,7 @@ Enable debug warning statements in functions
.SH OPTIONS 'nominatim admin'
usage: nominatim admin [-h] [-q] [-v] [--project-dir DIR] [-j NUM]
(--warm | --check-database | --migrate | --analyse-indexing)
(--warm | --check-database | --migrate | --analyse-indexing | --collect-os-info | --clean-deleted AGE)
[--search-only] [--reverse-only]
[--osm-id OSM_ID | --place-id PLACE_ID]
@@ -588,6 +639,14 @@ Migrate the database to a new software version
\fB\-\-analyse\-indexing\fR
Print performance analysis of the indexing process
.TP
\fB\-\-collect\-os\-info\fR
Generate a report about the host system information
.TP
\fB\-\-clean\-deleted\fR AGE
Clean up deleted relations
.TP
\fB\-\-search\-only\fR
Only pre\-warm tables for search queries
@@ -606,14 +665,17 @@ Analyse indexing of the given Nominatim object
.SH OPTIONS 'nominatim export'
usage: nominatim export [-h] [-q] [-v] [--project-dir DIR] [-j NUM]
[--output-type {continent,country,state,county,city,suburb,street,path}]
[--output-format OUTPUT_FORMAT]
[--output-all-postcodes] [--language LANGUAGE]
[--output-type {country,state,county,city,suburb,street,path}]
[--output-format OUTPUT_FORMAT] [--language LANGUAGE]
[--restrict-to-country COUNTRY_CODE]
[--restrict-to-osm-node ID] [--restrict-to-osm-way ID]
[--restrict-to-osm-relation ID]
Export addresses as CSV file from the database.
Export places as CSV file from the database.
.br
.br
.br
@@ -636,16 +698,12 @@ Base directory of the Nominatim installation (default:.)
Number of parallel threads to use
.TP
\fB\-\-output\-type\fR {continent,country,state,county,city,suburb,street,path}
\fB\-\-output\-type\fR {country,state,county,city,suburb,street,path}
Type of places to output (default: street)
.TP
\fB\-\-output\-format\fR \fI\,OUTPUT_FORMAT\/\fR
Semicolon\-separated list of address types (see \-\-output\-type). Multiple ranks can be merged into one column by simply using a comma\-separated list.
.TP
\fB\-\-output\-all\-postcodes\fR
List all postcodes for address instead of just the most likely one
Semicolon\-separated list of address types (see \-\-output\-type). Additionally accepts:placeid,postcode
.TP
\fB\-\-language\fR \fI\,LANGUAGE\/\fR
@@ -667,21 +725,85 @@ Export only children of this OSM way
\fB\-\-restrict\-to\-osm\-relation\fR ID
Export only children of this OSM relation
.SH OPTIONS 'nominatim convert'
usage: nominatim convert [-h] [-q] [-v] [--project-dir DIR] [-j NUM]
[--format {sqlite}] --output OUTPUT [--with-reverse]
[--with-search] [--with-details]
Convert an existing database into a different format. (EXPERIMENTAL)
.br
.br
Dump a read\-only version of the database in a different format.
.br
At the moment only a SQLite database suitable for reverse lookup
.br
can be created.
.br
.TP
\fB\-\-format\fR {sqlite}
Format of the output database (must be sqlite currently)
.TP
\fB\-\-output\fR \fI\,OUTPUT\/\fR, \fB\-o\fR \fI\,OUTPUT\/\fR
File to write the database to.
.TP
\fB\-q\fR, \fB\-\-quiet\fR
Print only error messages
.TP
\fB\-v\fR, \fB\-\-verbose\fR
Increase verboseness of output
.TP
\fB\-\-project\-dir\fR DIR
Base directory of the Nominatim installation (default:.)
.TP
\fB\-j\fR NUM, \fB\-\-threads\fR NUM
Number of parallel threads to use
.TP
\fB\-\-with\-reverse\fR, \fB\-\-without\-reverse\fR
Enable/disable support for reverse and lookup API (default: enabled)
.TP
\fB\-\-with\-search\fR, \fB\-\-without\-search\fR
Enable/disable support for search API (default: disabled)
.TP
\fB\-\-with\-details\fR, \fB\-\-without\-details\fR
Enable/disable support for details API (default: enabled)
.SH OPTIONS 'nominatim serve'
usage: nominatim serve [-h] [-q] [-v] [--project-dir DIR] [-j NUM]
[--server SERVER]
[--server SERVER] [--engine {php,falcon,starlette}]
Start a simple web server for serving the API.
.br
.br
This command starts the built\-in PHP webserver to serve the website
This command starts a built\-in webserver to serve the website
.br
from the current project directory. This webserver is only suitable
.br
for testing and development. Do not use it in production setups!
.br
.br
There are different webservers available. The default 'php' engine
.br
runs the classic PHP frontend. The other engines are Python servers
.br
which run the new Python frontend code. This is highly experimental
.br
at the moment and may not include the full API.
.br
.br
By the default, the webserver can be accessed at: http://127.0.0.1:8088
.br
@@ -709,12 +831,16 @@ Number of parallel threads to use
\fB\-\-server\fR \fI\,SERVER\/\fR
The address the server will listen to.
.TP
\fB\-\-engine\fR {php,falcon,starlette}
Webserver framework to run. (default: falcon)
.SH OPTIONS 'nominatim search'
usage: nominatim search [-h] [-q] [-v] [--project-dir DIR] [-j NUM]
[--query QUERY] [--street STREET] [--city CITY]
[--county COUNTY] [--state STATE] [--country COUNTRY]
[--postalcode POSTALCODE]
[--format {xml,json,jsonv2,geojson,geocodejson}]
[--query QUERY] [--amenity AMENITY] [--street STREET]
[--city CITY] [--county COUNTY] [--state STATE]
[--country COUNTRY] [--postalcode POSTALCODE]
[--format {xml,geojson,geocodejson,json,jsonv2,debug}]
[--addressdetails] [--extratags] [--namedetails]
[--lang LANGS]
[--polygon-output {geojson,kml,svg,text}]
@@ -758,6 +884,10 @@ Number of parallel threads to use
\fB\-\-query\fR \fI\,QUERY\/\fR
Free\-form query string
.TP
\fB\-\-amenity\fR \fI\,AMENITY\/\fR
Structured query: name and/or type of POI
.TP
\fB\-\-street\fR \fI\,STREET\/\fR
Structured query: housenumber and street
@@ -783,7 +913,7 @@ Structured query: country
Structured query: postcode
.TP
\fB\-\-format\fR {xml,json,jsonv2,geojson,geocodejson}
\fB\-\-format\fR {xml,geojson,geocodejson,json,jsonv2,debug}
Format of result
.TP
@@ -836,8 +966,8 @@ Do not remove duplicates from the result list
.SH OPTIONS 'nominatim reverse'
usage: nominatim reverse [-h] [-q] [-v] [--project-dir DIR] [-j NUM] --lat LAT
--lon LON [--zoom ZOOM]
[--format {xml,json,jsonv2,geojson,geocodejson}]
--lon LON [--zoom ZOOM] [--layer LAYER]
[--format {xml,geojson,geocodejson,json,jsonv2,debug}]
[--addressdetails] [--extratags] [--namedetails]
[--lang LANGS]
[--polygon-output {geojson,kml,svg,text}]
@@ -888,7 +1018,11 @@ Longitude of coordinate to look up (in WGS84)
Level of detail required for the address
.TP
\fB\-\-format\fR {xml,json,jsonv2,geojson,geocodejson}
\fB\-\-layer\fR LAYER
OSM id to lookup in format <NRW><id> (may be repeated)
.TP
\fB\-\-format\fR {xml,geojson,geocodejson,json,jsonv2,debug}
Format of result
.TP
@@ -917,7 +1051,7 @@ Simplify output geometry.Parameter is difference tolerance in degrees.
.SH OPTIONS 'nominatim lookup'
usage: nominatim lookup [-h] [-q] [-v] [--project-dir DIR] [-j NUM] --id OSMID
[--format {xml,json,jsonv2,geojson,geocodejson}]
[--format {xml,geojson,geocodejson,json,jsonv2,debug}]
[--addressdetails] [--extratags] [--namedetails]
[--lang LANGS]
[--polygon-output {geojson,kml,svg,text}]
@@ -960,7 +1094,7 @@ Number of parallel threads to use
OSM id to lookup in format <NRW><id> (may be repeated)
.TP
\fB\-\-format\fR {xml,json,jsonv2,geojson,geocodejson}
\fB\-\-format\fR {xml,geojson,geocodejson,json,jsonv2,debug}
Format of result
.TP

View File

@@ -1,10 +1,14 @@
site_name: Nominatim Manual
theme:
font: false
name: material
features:
- navigation.tabs
- toc.integrate
plugins:
- privacy
copyright: Copyright &copy; Nominatim developer community
docs_dir: ${CMAKE_CURRENT_BINARY_DIR}
docs_dir: docs
site_url: https://nominatim.org
repo_url: https://github.com/openstreetmap/Nominatim
nav:
@@ -29,10 +33,13 @@ nav:
- 'Maintenance' : 'admin/Maintenance.md'
- 'Migration from older Versions' : 'admin/Migration.md'
- 'Troubleshooting' : 'admin/Faq.md'
- 'Installation on Ubuntu 22' : 'admin/Install-on-Ubuntu-22.md'
- 'Installation on Ubuntu 24' : 'admin/Install-on-Ubuntu-24.md'
- 'Customization Guide':
- 'Overview': 'customize/Overview.md'
- 'Import Styles': 'customize/Import-Styles.md'
- 'Configuration Settings': 'customize/Settings.md'
- 'API Result Formatting': 'customize/Result-Formatting.md'
- 'Per-Country Data': 'customize/Country-Settings.md'
- 'Place Ranking' : 'customize/Ranking.md'
- 'Importance' : 'customize/Importance.md'
@@ -57,9 +64,6 @@ nav:
- 'Setup for Development' : 'develop/Development-Environment.md'
- 'Testing' : 'develop/Testing.md'
- 'External Data Sources': 'develop/data-sources.md'
- 'Appendix':
- 'Installation on Ubuntu 20' : 'appendix/Install-on-Ubuntu-20.md'
- 'Installation on Ubuntu 22' : 'appendix/Install-on-Ubuntu-22.md'
markdown_extensions:
- codehilite
- admonition
@@ -68,14 +72,21 @@ markdown_extensions:
alternate_style: true
- def_list
- toc:
permalink:
toc_depth: 4
permalink: 🔗
extra_css: [extra.css, styles.css]
exclude_docs: |
mk_install_instructions.py
site_dir: site-html
plugins:
- search
- mkdocstrings:
handlers:
python:
paths: ["${PROJECT_SOURCE_DIR}"]
paths: ["src"]
options:
show_source: False
show_bases: False
- gen-files:
scripts:
- docs/mk_install_instructions.py

18
nominatim-cli.py Executable file
View File

@@ -0,0 +1,18 @@
#!/usr/bin/env python3
# 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.
# For a full list of authors see the git log.
"""
Helper script for development to run nominatim from the source directory.
"""
from pathlib import Path
import sys
sys.path.insert(1, str((Path(__file__) / '..' / 'src').resolve()))
from nominatim_db import cli
exit(cli.nominatim(module_dir=None, osm2pgsql_path=None))

View File

@@ -1,56 +0,0 @@
# SPDX-License-Identifier: GPL-2.0-only
#
# This file is part of Nominatim. (https://nominatim.org)
#
# Copyright (C) 2023 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Helper classes and functions for formatting results into API responses.
"""
from typing import Type, TypeVar, Dict, List, Callable, Any, Mapping
from collections import defaultdict
T = TypeVar('T') # pylint: disable=invalid-name
FormatFunc = Callable[[T, Mapping[str, Any]], str]
class FormatDispatcher:
""" Helper class to conveniently create formatting functions in
a module using decorators.
"""
def __init__(self) -> None:
self.format_functions: Dict[Type[Any], Dict[str, FormatFunc[Any]]] = defaultdict(dict)
def format_func(self, result_class: Type[T],
fmt: str) -> Callable[[FormatFunc[T]], FormatFunc[T]]:
""" Decorator for a function that formats a given type of result into the
selected format.
"""
def decorator(func: FormatFunc[T]) -> FormatFunc[T]:
self.format_functions[result_class][fmt] = func
return func
return decorator
def list_formats(self, result_type: Type[Any]) -> List[str]:
""" Return a list of formats supported by this formatter.
"""
return list(self.format_functions[result_type].keys())
def supports_format(self, result_type: Type[Any], fmt: str) -> bool:
""" Check if the given format is supported by this formatter.
"""
return fmt in self.format_functions[result_type]
def format_result(self, result: Any, fmt: str, options: Mapping[str, Any]) -> str:
""" Convert the given result into a string using the given format.
The format is expected to be in the list returned by
`list_formats()`.
"""
return self.format_functions[type(result)][fmt](result, options)

View File

@@ -1,21 +0,0 @@
# SPDX-License-Identifier: GPL-2.0-only
#
# This file is part of Nominatim. (https://nominatim.org)
#
# Copyright (C) 2023 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Implementation of API version v1 (aka the legacy version).
"""
#pylint: disable=useless-import-alias
from nominatim.api.v1.server_glue import (ASGIAdaptor as ASGIAdaptor,
EndpointFunc as EndpointFunc,
ROUTES as ROUTES)
import nominatim.api.v1.format as _format
list_formats = _format.dispatch.list_formats
supports_format = _format.dispatch.supports_format
format_result = _format.dispatch.format_result

View File

@@ -1,573 +0,0 @@
# SPDX-License-Identifier: GPL-2.0-only
#
# This file is part of Nominatim. (https://nominatim.org)
#
# Copyright (C) 2023 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Generic part of the server implementation of the v1 API.
Combine with the scaffolding provided for the various Python ASGI frameworks.
"""
from typing import Optional, Any, Type, Callable, NoReturn, Dict, cast
from functools import reduce
import abc
import dataclasses
import math
from urllib.parse import urlencode
import sqlalchemy as sa
from nominatim.errors import UsageError
from nominatim.config import Configuration
import nominatim.api as napi
import nominatim.api.logging as loglib
from nominatim.api.v1.format import dispatch as formatting
from nominatim.api.v1.format import RawDataList
from nominatim.api.v1 import helpers
CONTENT_TEXT = 'text/plain; charset=utf-8'
CONTENT_XML = 'text/xml; charset=utf-8'
CONTENT_HTML = 'text/html; charset=utf-8'
CONTENT_JSON = 'application/json; charset=utf-8'
CONTENT_TYPE = {'text': CONTENT_TEXT, 'xml': CONTENT_XML, 'debug': CONTENT_HTML}
class ASGIAdaptor(abc.ABC):
""" Adapter class for the different ASGI frameworks.
Wraps functionality over concrete requests and responses.
"""
content_type: str = CONTENT_TEXT
@abc.abstractmethod
def get(self, name: str, default: Optional[str] = None) -> Optional[str]:
""" Return an input parameter as a string. If the parameter was
not provided, return the 'default' value.
"""
@abc.abstractmethod
def get_header(self, name: str, default: Optional[str] = None) -> Optional[str]:
""" Return a HTTP header parameter as a string. If the parameter was
not provided, return the 'default' value.
"""
@abc.abstractmethod
def error(self, msg: str, status: int = 400) -> Exception:
""" Construct an appropriate exception from the given error message.
The exception must result in a HTTP error with the given status.
"""
@abc.abstractmethod
def create_response(self, status: int, output: str, num_results: int) -> Any:
""" Create a response from the given parameters. The result will
be returned by the endpoint functions. The adaptor may also
return None when the response is created internally with some
different means.
The response must return the HTTP given status code 'status', set
the HTTP content-type headers to the string provided and the
body of the response to 'output'.
"""
@abc.abstractmethod
def base_uri(self) -> str:
""" Return the URI of the original request.
"""
@abc.abstractmethod
def config(self) -> Configuration:
""" Return the current configuration object.
"""
def build_response(self, output: str, status: int = 200, num_results: int = 0) -> Any:
""" Create a response from the given output. Wraps a JSONP function
around the response, if necessary.
"""
if self.content_type == CONTENT_JSON and status == 200:
jsonp = self.get('json_callback')
if jsonp is not None:
if any(not part.isidentifier() for part in jsonp.split('.')):
self.raise_error('Invalid json_callback value')
output = f"{jsonp}({output})"
self.content_type = 'application/javascript; charset=utf-8'
return self.create_response(status, output, num_results)
def raise_error(self, msg: str, status: int = 400) -> NoReturn:
""" Raise an exception resulting in the given HTTP status and
message. The message will be formatted according to the
output format chosen by the request.
"""
if self.content_type == CONTENT_XML:
msg = f"""<?xml version="1.0" encoding="UTF-8" ?>
<error>
<code>{status}</code>
<message>{msg}</message>
</error>
"""
elif self.content_type == CONTENT_JSON:
msg = f"""{{"error":{{"code":{status},"message":"{msg}"}}}}"""
elif self.content_type == CONTENT_HTML:
loglib.log().section('Execution error')
loglib.log().var_dump('Status', status)
loglib.log().var_dump('Message', msg)
msg = loglib.get_and_disable()
raise self.error(msg, status)
def get_int(self, name: str, default: Optional[int] = None) -> int:
""" Return an input parameter as an int. Raises an exception if
the parameter is given but not in an integer format.
If 'default' is given, then it will be returned when the parameter
is missing completely. When 'default' is None, an error will be
raised on a missing parameter.
"""
value = self.get(name)
if value is None:
if default is not None:
return default
self.raise_error(f"Parameter '{name}' missing.")
try:
intval = int(value)
except ValueError:
self.raise_error(f"Parameter '{name}' must be a number.")
return intval
def get_float(self, name: str, default: Optional[float] = None) -> float:
""" Return an input parameter as a flaoting-point number. Raises an
exception if the parameter is given but not in an float format.
If 'default' is given, then it will be returned when the parameter
is missing completely. When 'default' is None, an error will be
raised on a missing parameter.
"""
value = self.get(name)
if value is None:
if default is not None:
return default
self.raise_error(f"Parameter '{name}' missing.")
try:
fval = float(value)
except ValueError:
self.raise_error(f"Parameter '{name}' must be a number.")
if math.isnan(fval) or math.isinf(fval):
self.raise_error(f"Parameter '{name}' must be a number.")
return fval
def get_bool(self, name: str, default: Optional[bool] = None) -> bool:
""" Return an input parameter as bool. Only '0' is accepted as
an input for 'false' all other inputs will be interpreted as 'true'.
If 'default' is given, then it will be returned when the parameter
is missing completely. When 'default' is None, an error will be
raised on a missing parameter.
"""
value = self.get(name)
if value is None:
if default is not None:
return default
self.raise_error(f"Parameter '{name}' missing.")
return value != '0'
def get_accepted_languages(self) -> str:
""" Return the accepted languages.
"""
return self.get('accept-language')\
or self.get_header('accept-language')\
or self.config().DEFAULT_LANGUAGE
def setup_debugging(self) -> bool:
""" Set up collection of debug information if requested.
Return True when debugging was requested.
"""
if self.get_bool('debug', False):
loglib.set_log_output('html')
self.content_type = CONTENT_HTML
return True
return False
def get_layers(self) -> Optional[napi.DataLayer]:
""" Return a parsed version of the layer parameter.
"""
param = self.get('layer', None)
if param is None:
return None
return cast(napi.DataLayer,
reduce(napi.DataLayer.__or__,
(getattr(napi.DataLayer, s.upper()) for s in param.split(','))))
def parse_format(self, result_type: Type[Any], default: str) -> str:
""" Get and check the 'format' parameter and prepare the formatter.
`result_type` is the type of result to be returned by the function
and `default` the format value to assume when no parameter is present.
"""
fmt = self.get('format', default=default)
assert fmt is not None
if not formatting.supports_format(result_type, fmt):
self.raise_error("Parameter 'format' must be one of: " +
', '.join(formatting.list_formats(result_type)))
self.content_type = CONTENT_TYPE.get(fmt, CONTENT_JSON)
return fmt
def parse_geometry_details(self, fmt: str) -> Dict[str, Any]:
""" Create details structure from the supplied geometry parameters.
"""
numgeoms = 0
output = napi.GeometryFormat.NONE
if self.get_bool('polygon_geojson', False):
output |= napi.GeometryFormat.GEOJSON
numgeoms += 1
if fmt not in ('geojson', 'geocodejson'):
if self.get_bool('polygon_text', False):
output |= napi.GeometryFormat.TEXT
numgeoms += 1
if self.get_bool('polygon_kml', False):
output |= napi.GeometryFormat.KML
numgeoms += 1
if self.get_bool('polygon_svg', False):
output |= napi.GeometryFormat.SVG
numgeoms += 1
if numgeoms > self.config().get_int('POLYGON_OUTPUT_MAX_TYPES'):
self.raise_error('Too many polygon output options selected.')
return {'address_details': True,
'geometry_simplification': self.get_float('polygon_threshold', 0.0),
'geometry_output': output
}
async def status_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> Any:
""" Server glue for /status endpoint. See API docs for details.
"""
result = await api.status()
fmt = params.parse_format(napi.StatusResult, 'text')
if fmt == 'text' and result.status:
status_code = 500
else:
status_code = 200
return params.build_response(formatting.format_result(result, fmt, {}),
status=status_code)
async def details_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> Any:
""" Server glue for /details endpoint. See API docs for details.
"""
fmt = params.parse_format(napi.DetailedResult, 'json')
place_id = params.get_int('place_id', 0)
place: napi.PlaceRef
if place_id:
place = napi.PlaceID(place_id)
else:
osmtype = params.get('osmtype')
if osmtype is None:
params.raise_error("Missing ID parameter 'place_id' or 'osmtype'.")
place = napi.OsmID(osmtype, params.get_int('osmid'), params.get('class'))
debug = params.setup_debugging()
locales = napi.Locales.from_accept_languages(params.get_accepted_languages())
result = await api.details(place,
address_details=params.get_bool('addressdetails', False),
linked_places=params.get_bool('linkedplaces', True),
parented_places=params.get_bool('hierarchy', False),
keywords=params.get_bool('keywords', False),
geometry_output = napi.GeometryFormat.GEOJSON
if params.get_bool('polygon_geojson', False)
else napi.GeometryFormat.NONE,
locales=locales
)
if debug:
return params.build_response(loglib.get_and_disable())
if result is None:
params.raise_error('No place with that OSM ID found.', status=404)
output = formatting.format_result(result, fmt,
{'locales': locales,
'group_hierarchy': params.get_bool('group_hierarchy', False),
'icon_base_url': params.config().MAPICON_URL})
return params.build_response(output, num_results=1)
async def reverse_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> Any:
""" Server glue for /reverse endpoint. See API docs for details.
"""
fmt = params.parse_format(napi.ReverseResults, 'xml')
debug = params.setup_debugging()
coord = napi.Point(params.get_float('lon'), params.get_float('lat'))
details = params.parse_geometry_details(fmt)
details['max_rank'] = helpers.zoom_to_rank(params.get_int('zoom', 18))
details['layers'] = params.get_layers()
details['locales'] = napi.Locales.from_accept_languages(params.get_accepted_languages())
result = await api.reverse(coord, **details)
if debug:
return params.build_response(loglib.get_and_disable(), num_results=1 if result else 0)
if fmt == 'xml':
queryparts = {'lat': str(coord.lat), 'lon': str(coord.lon), 'format': 'xml'}
zoom = params.get('zoom', None)
if zoom:
queryparts['zoom'] = zoom
query = urlencode(queryparts)
else:
query = ''
fmt_options = {'query': query,
'extratags': params.get_bool('extratags', False),
'namedetails': params.get_bool('namedetails', False),
'addressdetails': params.get_bool('addressdetails', True)}
output = formatting.format_result(napi.ReverseResults([result] if result else []),
fmt, fmt_options)
return params.build_response(output, num_results=1 if result else 0)
async def lookup_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> Any:
""" Server glue for /lookup endpoint. See API docs for details.
"""
fmt = params.parse_format(napi.SearchResults, 'xml')
debug = params.setup_debugging()
details = params.parse_geometry_details(fmt)
details['locales'] = napi.Locales.from_accept_languages(params.get_accepted_languages())
places = []
for oid in (params.get('osm_ids') or '').split(','):
oid = oid.strip()
if len(oid) > 1 and oid[0] in 'RNWrnw' and oid[1:].isdigit():
places.append(napi.OsmID(oid[0].upper(), int(oid[1:])))
if len(places) > params.config().get_int('LOOKUP_MAX_COUNT'):
params.raise_error('Too many object IDs.')
if places:
results = await api.lookup(places, **details)
else:
results = napi.SearchResults()
if debug:
return params.build_response(loglib.get_and_disable(), num_results=len(results))
fmt_options = {'extratags': params.get_bool('extratags', False),
'namedetails': params.get_bool('namedetails', False),
'addressdetails': params.get_bool('addressdetails', True)}
output = formatting.format_result(results, fmt, fmt_options)
return params.build_response(output, num_results=len(results))
async def _unstructured_search(query: str, api: napi.NominatimAPIAsync,
details: Dict[str, Any]) -> napi.SearchResults:
if not query:
return napi.SearchResults()
# Extract special format for coordinates from query.
query, x, y = helpers.extract_coords_from_query(query)
if x is not None:
assert y is not None
details['near'] = napi.Point(x, y)
details['near_radius'] = 0.1
# If no query is left, revert to reverse search.
if x is not None and not query:
result = await api.reverse(details['near'], **details)
if not result:
return napi.SearchResults()
return napi.SearchResults(
[napi.SearchResult(**{f.name: getattr(result, f.name)
for f in dataclasses.fields(napi.SearchResult)
if hasattr(result, f.name)})])
query, cls, typ = helpers.extract_category_from_query(query)
if cls is not None:
assert typ is not None
return await api.search_category([(cls, typ)], near_query=query, **details)
return await api.search(query, **details)
async def search_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> Any:
""" Server glue for /search endpoint. See API docs for details.
"""
fmt = params.parse_format(napi.SearchResults, 'jsonv2')
debug = params.setup_debugging()
details = params.parse_geometry_details(fmt)
details['countries'] = params.get('countrycodes', None)
details['excluded'] = params.get('exclude_place_ids', None)
details['viewbox'] = params.get('viewbox', None) or params.get('viewboxlbrt', None)
details['bounded_viewbox'] = params.get_bool('bounded', False)
details['dedupe'] = params.get_bool('dedupe', True)
max_results = max(1, min(50, params.get_int('limit', 10)))
details['max_results'] = max_results + min(10, max_results) \
if details['dedupe'] else max_results
details['min_rank'], details['max_rank'] = \
helpers.feature_type_to_rank(params.get('featureType', ''))
if params.get('featureType', None) is not None:
details['layers'] = napi.DataLayer.ADDRESS
else:
details['layers'] = params.get_layers()
details['locales'] = napi.Locales.from_accept_languages(params.get_accepted_languages())
# unstructured query parameters
query = params.get('q', None)
# structured query parameters
queryparts = {}
for key in ('amenity', 'street', 'city', 'county', 'state', 'postalcode', 'country'):
details[key] = params.get(key, None)
if details[key]:
queryparts[key] = details[key]
try:
if query is not None:
if queryparts:
params.raise_error("Structured query parameters"
"(amenity, street, city, county, state, postalcode, country)"
" cannot be used together with 'q' parameter.")
queryparts['q'] = query
results = await _unstructured_search(query, api, details)
else:
query = ', '.join(queryparts.values())
results = await api.search_address(**details)
except UsageError as err:
params.raise_error(str(err))
if details['dedupe'] and len(results) > 1:
results = helpers.deduplicate_results(results, max_results)
if debug:
return params.build_response(loglib.get_and_disable(), num_results=len(results))
if fmt == 'xml':
helpers.extend_query_parts(queryparts, details,
params.get('featureType', ''),
params.get_bool('namedetails', False),
params.get_bool('extratags', False),
(str(r.place_id) for r in results if r.place_id))
queryparts['format'] = fmt
moreurl = params.base_uri() + '/search?' + urlencode(queryparts)
else:
moreurl = ''
fmt_options = {'query': query, 'more_url': moreurl,
'exclude_place_ids': queryparts.get('exclude_place_ids'),
'viewbox': queryparts.get('viewbox'),
'extratags': params.get_bool('extratags', False),
'namedetails': params.get_bool('namedetails', False),
'addressdetails': params.get_bool('addressdetails', False)}
output = formatting.format_result(results, fmt, fmt_options)
return params.build_response(output, num_results=len(results))
async def deletable_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> Any:
""" Server glue for /deletable endpoint.
This is a special endpoint that shows polygons that have been
deleted or are broken in the OSM data but are kept in the
Nominatim database to minimize disruption.
"""
fmt = params.parse_format(RawDataList, 'json')
async with api.begin() as conn:
sql = sa.text(""" SELECT p.place_id, country_code,
name->'name' as name, i.*
FROM placex p, import_polygon_delete i
WHERE p.osm_id = i.osm_id AND p.osm_type = i.osm_type
AND p.class = i.class AND p.type = i.type
""")
results = RawDataList(r._asdict() for r in await conn.execute(sql))
return params.build_response(formatting.format_result(results, fmt, {}))
async def polygons_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> Any:
""" Server glue for /polygons endpoint.
This is a special endpoint that shows polygons that have changed
their size but are kept in the Nominatim database with their
old area to minimize disruption.
"""
fmt = params.parse_format(RawDataList, 'json')
sql_params: Dict[str, Any] = {
'days': params.get_int('days', -1),
'cls': params.get('class')
}
reduced = params.get_bool('reduced', False)
async with api.begin() as conn:
sql = sa.select(sa.text("""osm_type, osm_id, class, type,
name->'name' as name,
country_code, errormessage, updated"""))\
.select_from(sa.text('import_polygon_error'))
if sql_params['days'] > 0:
sql = sql.where(sa.text("updated > 'now'::timestamp - make_interval(days => :days)"))
if reduced:
sql = sql.where(sa.text("errormessage like 'Area reduced%'"))
if sql_params['cls'] is not None:
sql = sql.where(sa.text("class = :cls"))
sql = sql.order_by(sa.literal_column('updated').desc()).limit(1000)
results = RawDataList(r._asdict() for r in await conn.execute(sql, sql_params))
return params.build_response(formatting.format_result(results, fmt, {}))
EndpointFunc = Callable[[napi.NominatimAPIAsync, ASGIAdaptor], Any]
ROUTES = [
('status', status_endpoint),
('details', details_endpoint),
('reverse', reverse_endpoint),
('lookup', lookup_endpoint),
('search', search_endpoint),
('deletable', deletable_endpoint),
('polygons', polygons_endpoint),
]

View File

@@ -1,28 +0,0 @@
# SPDX-License-Identifier: GPL-2.0-only
#
# This file is part of Nominatim. (https://nominatim.org)
#
# Copyright (C) 2023 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Subcommand definitions for the command-line tool.
"""
# mypy and pylint disagree about the style of explicit exports,
# see https://github.com/PyCQA/pylint/issues/6006.
# pylint: disable=useless-import-alias
from nominatim.clicmd.setup import SetupAll as SetupAll
from nominatim.clicmd.replication import UpdateReplication as UpdateReplication
from nominatim.clicmd.api import (APISearch as APISearch,
APIReverse as APIReverse,
APILookup as APILookup,
APIDetails as APIDetails,
APIStatus as APIStatus)
from nominatim.clicmd.index import UpdateIndex as UpdateIndex
from nominatim.clicmd.refresh import UpdateRefresh as UpdateRefresh
from nominatim.clicmd.add_data import UpdateAddData as UpdateAddData
from nominatim.clicmd.admin import AdminFuncs as AdminFuncs
from nominatim.clicmd.freeze import SetupFreeze as SetupFreeze
from nominatim.clicmd.special_phrases import ImportSpecialPhrases as ImportSpecialPhrases
from nominatim.clicmd.export import QueryExport as QueryExport
from nominatim.clicmd.convert import ConvertDB as ConvertDB

View File

@@ -1,373 +0,0 @@
# SPDX-License-Identifier: GPL-2.0-only
#
# This file is part of Nominatim. (https://nominatim.org)
#
# Copyright (C) 2023 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Subcommand definitions for API calls from the command line.
"""
from typing import Dict, Any
import argparse
import logging
import json
import sys
from nominatim.clicmd.args import NominatimArgs
import nominatim.api as napi
import nominatim.api.v1 as api_output
from nominatim.api.v1.helpers import zoom_to_rank, deduplicate_results
import nominatim.api.logging as loglib
# Do not repeat documentation of subcommand classes.
# pylint: disable=C0111
LOG = logging.getLogger()
STRUCTURED_QUERY = (
('amenity', 'name and/or type of POI'),
('street', 'housenumber and street'),
('city', 'city, town or village'),
('county', 'county'),
('state', 'state'),
('country', 'country'),
('postalcode', 'postcode')
)
EXTRADATA_PARAMS = (
('addressdetails', 'Include a breakdown of the address into elements'),
('extratags', ("Include additional information if available "
"(e.g. wikipedia link, opening hours)")),
('namedetails', 'Include a list of alternative names')
)
def _add_api_output_arguments(parser: argparse.ArgumentParser) -> None:
group = parser.add_argument_group('Output arguments')
group.add_argument('--format', default='jsonv2',
choices=['xml', 'json', 'jsonv2', 'geojson', 'geocodejson', 'debug'],
help='Format of result')
for name, desc in EXTRADATA_PARAMS:
group.add_argument('--' + name, action='store_true', help=desc)
group.add_argument('--lang', '--accept-language', metavar='LANGS',
help='Preferred language order for presenting search results')
group.add_argument('--polygon-output',
choices=['geojson', 'kml', 'svg', 'text'],
help='Output geometry of results as a GeoJSON, KML, SVG or WKT')
group.add_argument('--polygon-threshold', type=float, default = 0.0,
metavar='TOLERANCE',
help=("Simplify output geometry."
"Parameter is difference tolerance in degrees."))
class APISearch:
"""\
Execute a search query.
This command works exactly the same as if calling the /search endpoint on
the web API. See the online documentation for more details on the
various parameters:
https://nominatim.org/release-docs/latest/api/Search/
"""
def add_args(self, parser: argparse.ArgumentParser) -> None:
group = parser.add_argument_group('Query arguments')
group.add_argument('--query',
help='Free-form query string')
for name, desc in STRUCTURED_QUERY:
group.add_argument('--' + name, help='Structured query: ' + desc)
_add_api_output_arguments(parser)
group = parser.add_argument_group('Result limitation')
group.add_argument('--countrycodes', metavar='CC,..',
help='Limit search results to one or more countries')
group.add_argument('--exclude_place_ids', metavar='ID,..',
help='List of search object to be excluded')
group.add_argument('--limit', type=int, default=10,
help='Limit the number of returned results')
group.add_argument('--viewbox', metavar='X1,Y1,X2,Y2',
help='Preferred area to find search results')
group.add_argument('--bounded', action='store_true',
help='Strictly restrict results to viewbox area')
group = parser.add_argument_group('Other arguments')
group.add_argument('--no-dedupe', action='store_false', dest='dedupe',
help='Do not remove duplicates from the result list')
def run(self, args: NominatimArgs) -> int:
if args.format == 'debug':
loglib.set_log_output('text')
api = napi.NominatimAPI(args.project_dir)
params: Dict[str, Any] = {'max_results': args.limit + min(args.limit, 10),
'address_details': True, # needed for display name
'geometry_output': args.get_geometry_output(),
'geometry_simplification': args.polygon_threshold,
'countries': args.countrycodes,
'excluded': args.exclude_place_ids,
'viewbox': args.viewbox,
'bounded_viewbox': args.bounded,
'locales': args.get_locales(api.config.DEFAULT_LANGUAGE)
}
if args.query:
results = api.search(args.query, **params)
else:
results = api.search_address(amenity=args.amenity,
street=args.street,
city=args.city,
county=args.county,
state=args.state,
postalcode=args.postalcode,
country=args.country,
**params)
if args.dedupe and len(results) > 1:
results = deduplicate_results(results, args.limit)
if args.format == 'debug':
print(loglib.get_and_disable())
return 0
output = api_output.format_result(
results,
args.format,
{'extratags': args.extratags,
'namedetails': args.namedetails,
'addressdetails': args.addressdetails})
if args.format != 'xml':
# reformat the result, so it is pretty-printed
json.dump(json.loads(output), sys.stdout, indent=4, ensure_ascii=False)
else:
sys.stdout.write(output)
sys.stdout.write('\n')
return 0
class APIReverse:
"""\
Execute API reverse query.
This command works exactly the same as if calling the /reverse endpoint on
the web API. See the online documentation for more details on the
various parameters:
https://nominatim.org/release-docs/latest/api/Reverse/
"""
def add_args(self, parser: argparse.ArgumentParser) -> None:
group = parser.add_argument_group('Query arguments')
group.add_argument('--lat', type=float, required=True,
help='Latitude of coordinate to look up (in WGS84)')
group.add_argument('--lon', type=float, required=True,
help='Longitude of coordinate to look up (in WGS84)')
group.add_argument('--zoom', type=int,
help='Level of detail required for the address')
group.add_argument('--layer', metavar='LAYER',
choices=[n.name.lower() for n in napi.DataLayer if n.name],
action='append', required=False, dest='layers',
help='OSM id to lookup in format <NRW><id> (may be repeated)')
_add_api_output_arguments(parser)
def run(self, args: NominatimArgs) -> int:
if args.format == 'debug':
loglib.set_log_output('text')
api = napi.NominatimAPI(args.project_dir)
result = api.reverse(napi.Point(args.lon, args.lat),
max_rank=zoom_to_rank(args.zoom or 18),
layers=args.get_layers(napi.DataLayer.ADDRESS | napi.DataLayer.POI),
address_details=True, # needed for display name
geometry_output=args.get_geometry_output(),
geometry_simplification=args.polygon_threshold,
locales=args.get_locales(api.config.DEFAULT_LANGUAGE))
if args.format == 'debug':
print(loglib.get_and_disable())
return 0
if result:
output = api_output.format_result(
napi.ReverseResults([result]),
args.format,
{'extratags': args.extratags,
'namedetails': args.namedetails,
'addressdetails': args.addressdetails})
if args.format != 'xml':
# reformat the result, so it is pretty-printed
json.dump(json.loads(output), sys.stdout, indent=4, ensure_ascii=False)
else:
sys.stdout.write(output)
sys.stdout.write('\n')
return 0
LOG.error("Unable to geocode.")
return 42
class APILookup:
"""\
Execute API lookup query.
This command works exactly the same as if calling the /lookup endpoint on
the web API. See the online documentation for more details on the
various parameters:
https://nominatim.org/release-docs/latest/api/Lookup/
"""
def add_args(self, parser: argparse.ArgumentParser) -> None:
group = parser.add_argument_group('Query arguments')
group.add_argument('--id', metavar='OSMID',
action='append', required=True, dest='ids',
help='OSM id to lookup in format <NRW><id> (may be repeated)')
_add_api_output_arguments(parser)
def run(self, args: NominatimArgs) -> int:
if args.format == 'debug':
loglib.set_log_output('text')
api = napi.NominatimAPI(args.project_dir)
if args.format == 'debug':
print(loglib.get_and_disable())
return 0
places = [napi.OsmID(o[0], int(o[1:])) for o in args.ids]
results = api.lookup(places,
address_details=True, # needed for display name
geometry_output=args.get_geometry_output(),
geometry_simplification=args.polygon_threshold or 0.0,
locales=args.get_locales(api.config.DEFAULT_LANGUAGE))
output = api_output.format_result(
results,
args.format,
{'extratags': args.extratags,
'namedetails': args.namedetails,
'addressdetails': args.addressdetails})
if args.format != 'xml':
# reformat the result, so it is pretty-printed
json.dump(json.loads(output), sys.stdout, indent=4, ensure_ascii=False)
else:
sys.stdout.write(output)
sys.stdout.write('\n')
return 0
class APIDetails:
"""\
Execute API details query.
This command works exactly the same as if calling the /details endpoint on
the web API. See the online documentation for more details on the
various parameters:
https://nominatim.org/release-docs/latest/api/Details/
"""
def add_args(self, parser: argparse.ArgumentParser) -> None:
group = parser.add_argument_group('Query arguments')
objs = group.add_mutually_exclusive_group(required=True)
objs.add_argument('--node', '-n', type=int,
help="Look up the OSM node with the given ID.")
objs.add_argument('--way', '-w', type=int,
help="Look up the OSM way with the given ID.")
objs.add_argument('--relation', '-r', type=int,
help="Look up the OSM relation with the given ID.")
objs.add_argument('--place_id', '-p', type=int,
help='Database internal identifier of the OSM object to look up')
group.add_argument('--class', dest='object_class',
help=("Class type to disambiguated multiple entries "
"of the same object."))
group = parser.add_argument_group('Output arguments')
group.add_argument('--addressdetails', action='store_true',
help='Include a breakdown of the address into elements')
group.add_argument('--keywords', action='store_true',
help='Include a list of name keywords and address keywords')
group.add_argument('--linkedplaces', action='store_true',
help='Include a details of places that are linked with this one')
group.add_argument('--hierarchy', action='store_true',
help='Include details of places lower in the address hierarchy')
group.add_argument('--group_hierarchy', action='store_true',
help='Group the places by type')
group.add_argument('--polygon_geojson', action='store_true',
help='Include geometry of result')
group.add_argument('--lang', '--accept-language', metavar='LANGS',
help='Preferred language order for presenting search results')
def run(self, args: NominatimArgs) -> int:
place: napi.PlaceRef
if args.node:
place = napi.OsmID('N', args.node, args.object_class)
elif args.way:
place = napi.OsmID('W', args.way, args.object_class)
elif args.relation:
place = napi.OsmID('R', args.relation, args.object_class)
else:
assert args.place_id is not None
place = napi.PlaceID(args.place_id)
api = napi.NominatimAPI(args.project_dir)
locales = args.get_locales(api.config.DEFAULT_LANGUAGE)
result = api.details(place,
address_details=args.addressdetails,
linked_places=args.linkedplaces,
parented_places=args.hierarchy,
keywords=args.keywords,
geometry_output=napi.GeometryFormat.GEOJSON
if args.polygon_geojson
else napi.GeometryFormat.NONE,
locales=locales)
if result:
output = api_output.format_result(
result,
'json',
{'locales': locales,
'group_hierarchy': args.group_hierarchy})
# reformat the result, so it is pretty-printed
json.dump(json.loads(output), sys.stdout, indent=4, ensure_ascii=False)
sys.stdout.write('\n')
return 0
LOG.error("Object not found in database.")
return 42
class APIStatus:
"""
Execute API status query.
This command works exactly the same as if calling the /status endpoint on
the web API. See the online documentation for more details on the
various parameters:
https://nominatim.org/release-docs/latest/api/Status/
"""
def add_args(self, parser: argparse.ArgumentParser) -> None:
formats = api_output.list_formats(napi.StatusResult)
group = parser.add_argument_group('API parameters')
group.add_argument('--format', default=formats[0], choices=formats,
help='Format of result')
def run(self, args: NominatimArgs) -> int:
status = napi.NominatimAPI(args.project_dir).status()
print(api_output.format_result(status, args.format, {}))
return 0

View File

@@ -1,236 +0,0 @@
# 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.
""" Non-blocking database connections.
"""
from typing import Callable, Any, Optional, Iterator, Sequence
import logging
import select
import time
import psycopg2
from psycopg2.extras import wait_select
# psycopg2 emits different exceptions pre and post 2.8. Detect if the new error
# module is available and adapt the error handling accordingly.
try:
import psycopg2.errors # pylint: disable=no-name-in-module,import-error
__has_psycopg2_errors__ = True
except ImportError:
__has_psycopg2_errors__ = False
from nominatim.typing import T_cursor, Query
LOG = logging.getLogger()
class DeadlockHandler:
""" Context manager that catches deadlock exceptions and calls
the given handler function. All other exceptions are passed on
normally.
"""
def __init__(self, handler: Callable[[], None], ignore_sql_errors: bool = False) -> None:
self.handler = handler
self.ignore_sql_errors = ignore_sql_errors
def __enter__(self) -> 'DeadlockHandler':
return self
def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> bool:
if __has_psycopg2_errors__:
if exc_type == psycopg2.errors.DeadlockDetected: # pylint: disable=E1101
self.handler()
return True
elif exc_type == psycopg2.extensions.TransactionRollbackError \
and exc_value.pgcode == '40P01':
self.handler()
return True
if self.ignore_sql_errors and isinstance(exc_value, psycopg2.Error):
LOG.info("SQL error ignored: %s", exc_value)
return True
return False
class DBConnection:
""" A single non-blocking database connection.
"""
def __init__(self, dsn: str,
cursor_factory: Optional[Callable[..., T_cursor]] = None,
ignore_sql_errors: bool = False) -> None:
self.dsn = dsn
self.current_query: Optional[Query] = None
self.current_params: Optional[Sequence[Any]] = None
self.ignore_sql_errors = ignore_sql_errors
self.conn: Optional['psycopg2._psycopg.connection'] = None
self.cursor: Optional['psycopg2._psycopg.cursor'] = None
self.connect(cursor_factory=cursor_factory)
def close(self) -> None:
""" Close all open connections. Does not wait for pending requests.
"""
if self.conn is not None:
if self.cursor is not None:
self.cursor.close()
self.cursor = None
self.conn.close()
self.conn = None
def connect(self, cursor_factory: Optional[Callable[..., T_cursor]] = None) -> None:
""" (Re)connect to the database. Creates an asynchronous connection
with JIT and parallel processing disabled. If a connection was
already open, it is closed and a new connection established.
The caller must ensure that no query is pending before reconnecting.
"""
self.close()
# Use a dict to hand in the parameters because async is a reserved
# word in Python3.
self.conn = psycopg2.connect(**{'dsn': self.dsn, 'async': True}) # type: ignore
assert self.conn
self.wait()
if cursor_factory is not None:
self.cursor = self.conn.cursor(cursor_factory=cursor_factory)
else:
self.cursor = self.conn.cursor()
# Disable JIT and parallel workers as they are known to cause problems.
# Update pg_settings instead of using SET because it does not yield
# errors on older versions of Postgres where the settings are not
# implemented.
self.perform(
""" UPDATE pg_settings SET setting = -1 WHERE name = 'jit_above_cost';
UPDATE pg_settings SET setting = 0
WHERE name = 'max_parallel_workers_per_gather';""")
self.wait()
def _deadlock_handler(self) -> None:
LOG.info("Deadlock detected (params = %s), retry.", str(self.current_params))
assert self.cursor is not None
assert self.current_query is not None
assert self.current_params is not None
self.cursor.execute(self.current_query, self.current_params)
def wait(self) -> None:
""" Block until any pending operation is done.
"""
while True:
with DeadlockHandler(self._deadlock_handler, self.ignore_sql_errors):
wait_select(self.conn)
self.current_query = None
return
def perform(self, sql: Query, args: Optional[Sequence[Any]] = None) -> None:
""" Send SQL query to the server. Returns immediately without
blocking.
"""
assert self.cursor is not None
self.current_query = sql
self.current_params = args
self.cursor.execute(sql, args)
def fileno(self) -> int:
""" File descriptor to wait for. (Makes this class select()able.)
"""
assert self.conn is not None
return self.conn.fileno()
def is_done(self) -> bool:
""" Check if the connection is available for a new query.
Also checks if the previous query has run into a deadlock.
If so, then the previous query is repeated.
"""
assert self.conn is not None
if self.current_query is None:
return True
with DeadlockHandler(self._deadlock_handler, self.ignore_sql_errors):
if self.conn.poll() == psycopg2.extensions.POLL_OK:
self.current_query = None
return True
return False
class WorkerPool:
""" A pool of asynchronous database connections.
The pool may be used as a context manager.
"""
REOPEN_CONNECTIONS_AFTER = 100000
def __init__(self, dsn: str, pool_size: int, ignore_sql_errors: bool = False) -> None:
self.threads = [DBConnection(dsn, ignore_sql_errors=ignore_sql_errors)
for _ in range(pool_size)]
self.free_workers = self._yield_free_worker()
self.wait_time = 0.0
def finish_all(self) -> None:
""" Wait for all connection to finish.
"""
for thread in self.threads:
while not thread.is_done():
thread.wait()
self.free_workers = self._yield_free_worker()
def close(self) -> None:
""" Close all connections and clear the pool.
"""
for thread in self.threads:
thread.close()
self.threads = []
self.free_workers = iter([])
def next_free_worker(self) -> DBConnection:
""" Get the next free connection.
"""
return next(self.free_workers)
def _yield_free_worker(self) -> Iterator[DBConnection]:
ready = self.threads
command_stat = 0
while True:
for thread in ready:
if thread.is_done():
command_stat += 1
yield thread
if command_stat > self.REOPEN_CONNECTIONS_AFTER:
self._reconnect_threads()
ready = self.threads
command_stat = 0
else:
tstart = time.time()
_, ready, _ = select.select([], self.threads, [])
self.wait_time += time.time() - tstart
def _reconnect_threads(self) -> None:
for thread in self.threads:
while not thread.is_done():
thread.wait()
thread.connect()
def __enter__(self) -> 'WorkerPool':
return self
def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None:
self.finish_all()
self.close()

View File

@@ -1,254 +0,0 @@
# 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.
"""
Specialised connection and cursor functions.
"""
from typing import Optional, Any, Callable, ContextManager, Dict, cast, overload, Tuple, Iterable
import contextlib
import logging
import os
import psycopg2
import psycopg2.extensions
import psycopg2.extras
from psycopg2 import sql as pysql
from nominatim.typing import SysEnv, Query, T_cursor
from nominatim.errors import UsageError
LOG = logging.getLogger()
class Cursor(psycopg2.extras.DictCursor):
""" A cursor returning dict-like objects and providing specialised
execution functions.
"""
# pylint: disable=arguments-renamed,arguments-differ
def execute(self, query: Query, args: Any = None) -> None:
""" Query execution that logs the SQL query when debugging is enabled.
"""
if LOG.isEnabledFor(logging.DEBUG):
LOG.debug(self.mogrify(query, args).decode('utf-8'))
super().execute(query, args)
def execute_values(self, sql: Query, argslist: Iterable[Tuple[Any, ...]],
template: Optional[Query] = None) -> None:
""" Wrapper for the psycopg2 convenience function to execute
SQL for a list of values.
"""
LOG.debug("SQL execute_values(%s, %s)", sql, argslist)
psycopg2.extras.execute_values(self, sql, argslist, template=template)
def scalar(self, sql: Query, args: Any = None) -> Any:
""" Execute query that returns a single value. The value is returned.
If the query yields more than one row, a ValueError is raised.
"""
self.execute(sql, args)
if self.rowcount != 1:
raise RuntimeError("Query did not return a single row.")
result = self.fetchone()
assert result is not None
return result[0]
def drop_table(self, name: str, if_exists: bool = True, cascade: bool = False) -> None:
""" Drop the table with the given name.
Set `if_exists` to False if a non-existent table should raise
an exception instead of just being ignored. If 'cascade' is set
to True then all dependent tables are deleted as well.
"""
sql = 'DROP TABLE '
if if_exists:
sql += 'IF EXISTS '
sql += '{}'
if cascade:
sql += ' CASCADE'
self.execute(pysql.SQL(sql).format(pysql.Identifier(name)))
class Connection(psycopg2.extensions.connection):
""" A connection that provides the specialised cursor by default and
adds convenience functions for administrating the database.
"""
@overload # type: ignore[override]
def cursor(self) -> Cursor:
...
@overload
def cursor(self, name: str) -> Cursor:
...
@overload
def cursor(self, cursor_factory: Callable[..., T_cursor]) -> T_cursor:
...
def cursor(self, cursor_factory = Cursor, **kwargs): # type: ignore
""" Return a new cursor. By default the specialised cursor is returned.
"""
return super().cursor(cursor_factory=cursor_factory, **kwargs)
def table_exists(self, table: str) -> bool:
""" Check that a table with the given name exists in the database.
"""
with self.cursor() as cur:
num = cur.scalar("""SELECT count(*) FROM pg_tables
WHERE tablename = %s and schemaname = 'public'""", (table, ))
return num == 1 if isinstance(num, int) else False
def table_has_column(self, table: str, column: str) -> bool:
""" Check if the table 'table' exists and has a column with name 'column'.
"""
with self.cursor() as cur:
has_column = cur.scalar("""SELECT count(*) FROM information_schema.columns
WHERE table_name = %s
and column_name = %s""",
(table, column))
return has_column > 0 if isinstance(has_column, int) else False
def index_exists(self, index: str, table: Optional[str] = None) -> bool:
""" Check that an index with the given name exists in the database.
If table is not None then the index must relate to the given
table.
"""
with self.cursor() as cur:
cur.execute("""SELECT tablename FROM pg_indexes
WHERE indexname = %s and schemaname = 'public'""", (index, ))
if cur.rowcount == 0:
return False
if table is not None:
row = cur.fetchone()
if row is None or not isinstance(row[0], str):
return False
return row[0] == table
return True
def drop_table(self, name: str, if_exists: bool = True, cascade: bool = False) -> None:
""" Drop the table with the given name.
Set `if_exists` to False if a non-existent table should raise
an exception instead of just being ignored.
"""
with self.cursor() as cur:
cur.drop_table(name, if_exists, cascade)
self.commit()
def server_version_tuple(self) -> Tuple[int, int]:
""" Return the server version as a tuple of (major, minor).
Converts correctly for pre-10 and post-10 PostgreSQL versions.
"""
version = self.server_version
if version < 100000:
return (int(version / 10000), int((version % 10000) / 100))
return (int(version / 10000), version % 10000)
def postgis_version_tuple(self) -> Tuple[int, int]:
""" Return the postgis version installed in the database as a
tuple of (major, minor). Assumes that the PostGIS extension
has been installed already.
"""
with self.cursor() as cur:
version = cur.scalar('SELECT postgis_lib_version()')
version_parts = version.split('.')
if len(version_parts) < 2:
raise UsageError(f"Error fetching Postgis version. Bad format: {version}")
return (int(version_parts[0]), int(version_parts[1]))
def extension_loaded(self, extension_name: str) -> bool:
""" Return True if the hstore extension is loaded in the database.
"""
with self.cursor() as cur:
cur.execute('SELECT extname FROM pg_extension WHERE extname = %s', (extension_name, ))
return cur.rowcount > 0
class ConnectionContext(ContextManager[Connection]):
""" Context manager of the connection that also provides direct access
to the underlying connection.
"""
connection: Connection
def connect(dsn: str) -> ConnectionContext:
""" Open a connection to the database using the specialised connection
factory. The returned object may be used in conjunction with 'with'.
When used outside a context manager, use the `connection` attribute
to get the connection.
"""
try:
conn = psycopg2.connect(dsn, connection_factory=Connection)
ctxmgr = cast(ConnectionContext, contextlib.closing(conn))
ctxmgr.connection = conn
return ctxmgr
except psycopg2.OperationalError as err:
raise UsageError(f"Cannot connect to database: {err}") from err
# Translation from PG connection string parameters to PG environment variables.
# Derived from https://www.postgresql.org/docs/current/libpq-envars.html.
_PG_CONNECTION_STRINGS = {
'host': 'PGHOST',
'hostaddr': 'PGHOSTADDR',
'port': 'PGPORT',
'dbname': 'PGDATABASE',
'user': 'PGUSER',
'password': 'PGPASSWORD',
'passfile': 'PGPASSFILE',
'channel_binding': 'PGCHANNELBINDING',
'service': 'PGSERVICE',
'options': 'PGOPTIONS',
'application_name': 'PGAPPNAME',
'sslmode': 'PGSSLMODE',
'requiressl': 'PGREQUIRESSL',
'sslcompression': 'PGSSLCOMPRESSION',
'sslcert': 'PGSSLCERT',
'sslkey': 'PGSSLKEY',
'sslrootcert': 'PGSSLROOTCERT',
'sslcrl': 'PGSSLCRL',
'requirepeer': 'PGREQUIREPEER',
'ssl_min_protocol_version': 'PGSSLMINPROTOCOLVERSION',
'ssl_max_protocol_version': 'PGSSLMAXPROTOCOLVERSION',
'gssencmode': 'PGGSSENCMODE',
'krbsrvname': 'PGKRBSRVNAME',
'gsslib': 'PGGSSLIB',
'connect_timeout': 'PGCONNECT_TIMEOUT',
'target_session_attrs': 'PGTARGETSESSIONATTRS',
}
def get_pg_env(dsn: str,
base_env: Optional[SysEnv] = None) -> Dict[str, str]:
""" Return a copy of `base_env` with the environment variables for
PostgreSQL set up from the given database connection string.
If `base_env` is None, then the OS environment is used as a base
environment.
"""
env = dict(base_env if base_env is not None else os.environ)
for param, value in psycopg2.extensions.parse_dsn(dsn).items():
if param in _PG_CONNECTION_STRINGS:
env[_PG_CONNECTION_STRINGS[param]] = value
else:
LOG.error("Unknown connection parameter '%s' ignored.", param)
return env

View File

@@ -1,242 +0,0 @@
# 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.
"""
Main work horse for indexing (computing addresses) the database.
"""
from typing import Optional, Any, cast
import logging
import time
import psycopg2.extras
from nominatim.tokenizer.base import AbstractTokenizer
from nominatim.indexer.progress import ProgressLogger
from nominatim.indexer import runners
from nominatim.db.async_connection import DBConnection, WorkerPool
from nominatim.db.connection import connect, Connection, Cursor
from nominatim.typing import DictCursorResults
LOG = logging.getLogger()
class PlaceFetcher:
""" Asynchronous connection that fetches place details for processing.
"""
def __init__(self, dsn: str, setup_conn: Connection) -> None:
self.wait_time = 0.0
self.current_ids: Optional[DictCursorResults] = None
self.conn: Optional[DBConnection] = DBConnection(dsn,
cursor_factory=psycopg2.extras.DictCursor)
with setup_conn.cursor() as cur:
# need to fetch those manually because register_hstore cannot
# fetch them on an asynchronous connection below.
hstore_oid = cur.scalar("SELECT 'hstore'::regtype::oid")
hstore_array_oid = cur.scalar("SELECT 'hstore[]'::regtype::oid")
psycopg2.extras.register_hstore(self.conn.conn, oid=hstore_oid,
array_oid=hstore_array_oid)
def close(self) -> None:
""" Close the underlying asynchronous connection.
"""
if self.conn:
self.conn.close()
self.conn = None
def fetch_next_batch(self, cur: Cursor, runner: runners.Runner) -> bool:
""" Send a request for the next batch of places.
If details for the places are required, they will be fetched
asynchronously.
Returns true if there is still data available.
"""
ids = cast(Optional[DictCursorResults], cur.fetchmany(100))
if not ids:
self.current_ids = None
return False
assert self.conn is not None
self.current_ids = runner.get_place_details(self.conn, ids)
return True
def get_batch(self) -> DictCursorResults:
""" Get the next batch of data, previously requested with
`fetch_next_batch`.
"""
assert self.conn is not None
assert self.conn.cursor is not None
if self.current_ids is not None and not self.current_ids:
tstart = time.time()
self.conn.wait()
self.wait_time += time.time() - tstart
self.current_ids = cast(Optional[DictCursorResults],
self.conn.cursor.fetchall())
return self.current_ids if self.current_ids is not None else []
def __enter__(self) -> 'PlaceFetcher':
return self
def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None:
assert self.conn is not None
self.conn.wait()
self.close()
class Indexer:
""" Main indexing routine.
"""
def __init__(self, dsn: str, tokenizer: AbstractTokenizer, num_threads: int):
self.dsn = dsn
self.tokenizer = tokenizer
self.num_threads = num_threads
def has_pending(self) -> bool:
""" Check if any data still needs indexing.
This function must only be used after the import has finished.
Otherwise it will be very expensive.
"""
with connect(self.dsn) as conn:
with conn.cursor() as cur:
cur.execute("SELECT 'a' FROM placex WHERE indexed_status > 0 LIMIT 1")
return cur.rowcount > 0
def index_full(self, analyse: bool = True) -> None:
""" Index the complete database. This will first index boundaries
followed by all other objects. When `analyse` is True, then the
database will be analysed at the appropriate places to
ensure that database statistics are updated.
"""
with connect(self.dsn) as conn:
conn.autocommit = True
def _analyze() -> None:
if analyse:
with conn.cursor() as cur:
cur.execute('ANALYZE')
if self.index_by_rank(0, 4) > 0:
_analyze()
if self.index_boundaries(0, 30) > 100:
_analyze()
if self.index_by_rank(5, 25) > 100:
_analyze()
if self.index_by_rank(26, 30) > 1000:
_analyze()
if self.index_postcodes() > 100:
_analyze()
def index_boundaries(self, minrank: int, maxrank: int) -> int:
""" Index only administrative boundaries within the given rank range.
"""
total = 0
LOG.warning("Starting indexing boundaries using %s threads",
self.num_threads)
with self.tokenizer.name_analyzer() as analyzer:
for rank in range(max(minrank, 4), min(maxrank, 26)):
total += self._index(runners.BoundaryRunner(rank, analyzer))
return total
def index_by_rank(self, minrank: int, maxrank: int) -> int:
""" Index all entries of placex in the given rank range (inclusive)
in order of their address rank.
When rank 30 is requested then also interpolations and
places with address rank 0 will be indexed.
"""
total = 0
maxrank = min(maxrank, 30)
LOG.warning("Starting indexing rank (%i to %i) using %i threads",
minrank, maxrank, self.num_threads)
with self.tokenizer.name_analyzer() as analyzer:
for rank in range(max(1, minrank), maxrank + 1):
total += self._index(runners.RankRunner(rank, analyzer), 20 if rank == 30 else 1)
if maxrank == 30:
total += self._index(runners.RankRunner(0, analyzer))
total += self._index(runners.InterpolationRunner(analyzer), 20)
return total
def index_postcodes(self) -> int:
"""Index the entries of the location_postcode table.
"""
LOG.warning("Starting indexing postcodes using %s threads", self.num_threads)
return self._index(runners.PostcodeRunner(), 20)
def update_status_table(self) -> None:
""" Update the status in the status table to 'indexed'.
"""
with connect(self.dsn) as conn:
with conn.cursor() as cur:
cur.execute('UPDATE import_status SET indexed = true')
conn.commit()
def _index(self, runner: runners.Runner, batch: int = 1) -> int:
""" Index a single rank or table. `runner` describes the SQL to use
for indexing. `batch` describes the number of objects that
should be processed with a single SQL statement
"""
LOG.warning("Starting %s (using batch size %s)", runner.name(), batch)
with connect(self.dsn) as conn:
psycopg2.extras.register_hstore(conn)
with conn.cursor() as cur:
total_tuples = cur.scalar(runner.sql_count_objects())
LOG.debug("Total number of rows: %i", total_tuples)
conn.commit()
progress = ProgressLogger(runner.name(), total_tuples)
if total_tuples > 0:
with conn.cursor(name='places') as cur:
cur.execute(runner.sql_get_objects())
with PlaceFetcher(self.dsn, conn) as fetcher:
with WorkerPool(self.dsn, self.num_threads) as pool:
has_more = fetcher.fetch_next_batch(cur, runner)
while has_more:
places = fetcher.get_batch()
# asynchronously get the next batch
has_more = fetcher.fetch_next_batch(cur, runner)
# And insert the current batch
for idx in range(0, len(places), batch):
part = places[idx:idx + batch]
LOG.debug("Processing places: %s", str(part))
runner.index_places(pool.next_free_worker(), part)
progress.add(len(part))
LOG.info("Wait time: fetcher: %.2fs, pool: %.2fs",
fetcher.wait_time, pool.wait_time)
conn.commit()
return progress.done()

View File

@@ -1,196 +0,0 @@
# 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.
"""
Mix-ins that provide the actual commands for the indexer for various indexing
tasks.
"""
from typing import Any, List
import functools
from psycopg2 import sql as pysql
import psycopg2.extras
from nominatim.data.place_info import PlaceInfo
from nominatim.tokenizer.base import AbstractAnalyzer
from nominatim.db.async_connection import DBConnection
from nominatim.typing import Query, DictCursorResult, DictCursorResults, Protocol
# pylint: disable=C0111
def _mk_valuelist(template: str, num: int) -> pysql.Composed:
return pysql.SQL(',').join([pysql.SQL(template)] * num)
def _analyze_place(place: DictCursorResult, analyzer: AbstractAnalyzer) -> psycopg2.extras.Json:
return psycopg2.extras.Json(analyzer.process_place(PlaceInfo(place)))
class Runner(Protocol):
def name(self) -> str: ...
def sql_count_objects(self) -> Query: ...
def sql_get_objects(self) -> Query: ...
def get_place_details(self, worker: DBConnection,
ids: DictCursorResults) -> DictCursorResults: ...
def index_places(self, worker: DBConnection, places: DictCursorResults) -> None: ...
class AbstractPlacexRunner:
""" Returns SQL commands for indexing of the placex table.
"""
SELECT_SQL = pysql.SQL('SELECT place_id FROM placex ')
UPDATE_LINE = "(%s, %s::hstore, %s::hstore, %s::int, %s::jsonb)"
def __init__(self, rank: int, analyzer: AbstractAnalyzer) -> None:
self.rank = rank
self.analyzer = analyzer
@functools.lru_cache(maxsize=1)
def _index_sql(self, num_places: int) -> pysql.Composed:
return pysql.SQL(
""" UPDATE placex
SET indexed_status = 0, address = v.addr, token_info = v.ti,
name = v.name, linked_place_id = v.linked_place_id
FROM (VALUES {}) as v(id, name, addr, linked_place_id, ti)
WHERE place_id = v.id
""").format(_mk_valuelist(AbstractPlacexRunner.UPDATE_LINE, num_places))
def get_place_details(self, worker: DBConnection, ids: DictCursorResults) -> DictCursorResults:
worker.perform("""SELECT place_id, extra.*
FROM placex, LATERAL placex_indexing_prepare(placex) as extra
WHERE place_id IN %s""",
(tuple((p[0] for p in ids)), ))
return []
def index_places(self, worker: DBConnection, places: DictCursorResults) -> None:
values: List[Any] = []
for place in places:
for field in ('place_id', 'name', 'address', 'linked_place_id'):
values.append(place[field])
values.append(_analyze_place(place, self.analyzer))
worker.perform(self._index_sql(len(places)), values)
class RankRunner(AbstractPlacexRunner):
""" Returns SQL commands for indexing one rank within the placex table.
"""
def name(self) -> str:
return f"rank {self.rank}"
def sql_count_objects(self) -> pysql.Composed:
return pysql.SQL("""SELECT count(*) FROM placex
WHERE rank_address = {} and indexed_status > 0
""").format(pysql.Literal(self.rank))
def sql_get_objects(self) -> pysql.Composed:
return self.SELECT_SQL + pysql.SQL(
"""WHERE indexed_status > 0 and rank_address = {}
ORDER BY geometry_sector
""").format(pysql.Literal(self.rank))
class BoundaryRunner(AbstractPlacexRunner):
""" Returns SQL commands for indexing the administrative boundaries
of a certain rank.
"""
def name(self) -> str:
return f"boundaries rank {self.rank}"
def sql_count_objects(self) -> pysql.Composed:
return pysql.SQL("""SELECT count(*) FROM placex
WHERE indexed_status > 0
AND rank_search = {}
AND class = 'boundary' and type = 'administrative'
""").format(pysql.Literal(self.rank))
def sql_get_objects(self) -> pysql.Composed:
return self.SELECT_SQL + pysql.SQL(
"""WHERE indexed_status > 0 and rank_search = {}
and class = 'boundary' and type = 'administrative'
ORDER BY partition, admin_level
""").format(pysql.Literal(self.rank))
class InterpolationRunner:
""" Returns SQL commands for indexing the address interpolation table
location_property_osmline.
"""
def __init__(self, analyzer: AbstractAnalyzer) -> None:
self.analyzer = analyzer
def name(self) -> str:
return "interpolation lines (location_property_osmline)"
def sql_count_objects(self) -> str:
return """SELECT count(*) FROM location_property_osmline
WHERE indexed_status > 0"""
def sql_get_objects(self) -> str:
return """SELECT place_id
FROM location_property_osmline
WHERE indexed_status > 0
ORDER BY geometry_sector"""
def get_place_details(self, worker: DBConnection, ids: DictCursorResults) -> DictCursorResults:
worker.perform("""SELECT place_id, get_interpolation_address(address, osm_id) as address
FROM location_property_osmline WHERE place_id IN %s""",
(tuple((p[0] for p in ids)), ))
return []
@functools.lru_cache(maxsize=1)
def _index_sql(self, num_places: int) -> pysql.Composed:
return pysql.SQL("""UPDATE location_property_osmline
SET indexed_status = 0, address = v.addr, token_info = v.ti
FROM (VALUES {}) as v(id, addr, ti)
WHERE place_id = v.id
""").format(_mk_valuelist("(%s, %s::hstore, %s::jsonb)", num_places))
def index_places(self, worker: DBConnection, places: DictCursorResults) -> None:
values: List[Any] = []
for place in places:
values.extend((place[x] for x in ('place_id', 'address')))
values.append(_analyze_place(place, self.analyzer))
worker.perform(self._index_sql(len(places)), values)
class PostcodeRunner(Runner):
""" Provides the SQL commands for indexing the location_postcode table.
"""
def name(self) -> str:
return "postcodes (location_postcode)"
def sql_count_objects(self) -> str:
return 'SELECT count(*) FROM location_postcode WHERE indexed_status > 0'
def sql_get_objects(self) -> str:
return """SELECT place_id FROM location_postcode
WHERE indexed_status > 0
ORDER BY country_code, postcode"""
def get_place_details(self, worker: DBConnection, ids: DictCursorResults) -> DictCursorResults:
return ids
def index_places(self, worker: DBConnection, places: DictCursorResults) -> None:
worker.perform(pysql.SQL("""UPDATE location_postcode SET indexed_status = 0
WHERE place_id IN ({})""")
.format(pysql.SQL(',').join((pysql.Literal(i[0]) for i in places))))

View File

@@ -1,15 +0,0 @@
# 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.
"""
Path settings for extra data used by Nominatim.
"""
from pathlib import Path
PHPLIB_DIR = (Path(__file__) / '..' / '..' / 'lib-php').resolve()
SQLLIB_DIR = (Path(__file__) / '..' / '..' / 'lib-sql').resolve()
DATA_DIR = (Path(__file__) / '..' / '..' / 'data').resolve()
CONFIG_DIR = (Path(__file__) / '..' / '..' / 'settings').resolve()

View File

@@ -1,92 +0,0 @@
# 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.
"""
Helper functions for executing external programs.
"""
from typing import Any, Mapping, IO
import logging
import os
import subprocess
import urllib.request as urlrequest
from nominatim.typing import StrPath
from nominatim.version import NOMINATIM_VERSION
from nominatim.db.connection import get_pg_env
LOG = logging.getLogger()
def run_php_server(server_address: str, base_dir: StrPath) -> None:
""" Run the built-in server from the given directory.
"""
subprocess.run(['/usr/bin/env', 'php', '-S', server_address],
cwd=str(base_dir), check=True)
def run_osm2pgsql(options: Mapping[str, Any]) -> None:
""" Run osm2pgsql with the given options.
"""
env = get_pg_env(options['dsn'])
cmd = [str(options['osm2pgsql']),
'--slim',
'--log-progress', 'true',
'--number-processes', '1' if options['append'] else str(options['threads']),
'--cache', str(options['osm2pgsql_cache']),
'--style', str(options['osm2pgsql_style'])
]
if str(options['osm2pgsql_style']).endswith('.lua'):
env['LUA_PATH'] = ';'.join((str(options['osm2pgsql_style_path'] / '?.lua'),
os.environ.get('LUAPATH', ';')))
cmd.extend(('--output', 'flex'))
else:
cmd.extend(('--output', 'gazetteer', '--hstore', '--latlon'))
cmd.append('--append' if options['append'] else '--create')
if options['flatnode_file']:
cmd.extend(('--flat-nodes', options['flatnode_file']))
for key, param in (('slim_data', '--tablespace-slim-data'),
('slim_index', '--tablespace-slim-index'),
('main_data', '--tablespace-main-data'),
('main_index', '--tablespace-main-index')):
if options['tablespaces'][key]:
cmd.extend((param, options['tablespaces'][key]))
if options['tablespaces']['main_data']:
env['NOMINATIM_TABLESPACE_PLACE_DATA'] = options['tablespaces']['main_data']
if options['tablespaces']['main_index']:
env['NOMINATIM_TABLESPACE_PLACE_INDEX'] = options['tablespaces']['main_index']
if options.get('disable_jit', False):
env['PGOPTIONS'] = '-c jit=off -c max_parallel_workers_per_gather=0'
if 'import_data' in options:
cmd.extend(('-r', 'xml', '-'))
elif isinstance(options['import_file'], list):
for fname in options['import_file']:
cmd.append(str(fname))
else:
cmd.append(str(options['import_file']))
subprocess.run(cmd, cwd=options.get('cwd', '.'),
input=options.get('import_data'),
env=env, check=True)
def get_url(url: str) -> str:
""" Get the contents from the given URL and return it as a UTF-8 string.
"""
headers = {"User-Agent": f"Nominatim/{NOMINATIM_VERSION!s}"}
try:
request = urlrequest.Request(url, headers=headers)
with urlrequest.urlopen(request) as response: # type: IO[bytes]
return response.read().decode('utf-8')
except Exception:
LOG.fatal('Failed to load URL: %s', url)
raise

View File

@@ -0,0 +1 @@
../../COPYING

View File

@@ -0,0 +1,38 @@
# Nominatim - Frontend Library
Nominatim is a tool to search OpenStreetMap data
by name and address (geocoding) and to generate synthetic addresses of
OSM points (reverse geocoding).
This module implements the library for searching a Nominatim database
imported with the [`nominatim-db`](https://pypi.org/project/nominatim-db/) package.
## Installation
To install the Nominatim API from pypi, run:
pip install nominatim-api
## Running a Nominatim server
You need Falcon or Starlette to run Nominatim as a service, as well as
an ASGI-capable server like uvicorn. To install them from pypi run:
pip install falcon uvicorn
You need to have a Nominatim database imported with the 'nominatim-db'
package. Go to the project directory, then run uvicorn as:
uvicorn --factory nominatim.server.falcon.server:run_wsgi
## Documentation
The full documentation for the Nominatim library can be found at:
https://nominatim.org/release-docs/latest/library/Getting-Started/
The v1 API of the server is documented at:
https://nominatim.org/release-docs/latest/api/Overview/
## License
The source code is available under a GPLv3 license.

View File

@@ -0,0 +1,15 @@
# 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.
# For a full list of authors see the git log.
"""
Path settings for extra data used by Nominatim.
"""
from pathlib import Path
PHPLIB_DIR = None
DATA_DIR = None
SQLLIB_DIR = None
CONFIG_DIR = (Path(__file__) / '..' / 'resources' / 'settings').resolve()

View File

@@ -0,0 +1,58 @@
[project]
name = "nominatim-api"
description = "A tool for building a database of OpenStreetMap for geocoding and for searching the database. Search library."
readme = "README.md"
requires-python = ">=3.7"
license = 'GPL-3.0-or-later'
maintainers = [
{ name = "Sarah Hoffmann", email = "lonvia@denofr.de" },
{ name = "Marc Tobias", email = "mtmail-cpan@gmx.net" }
]
keywords = [ "geocoding", "OpenStreetMap", "search" ]
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Operating System :: OS Independent",
]
dependencies = [
"python-dotenv",
"pyYAML>=5.1",
"SQLAlchemy>=1.4.31",
"psycopg",
"PyICU"
]
dynamic = ["version"]
[project.urls]
Homepage = "https://nominatim.org"
Documentation = "https://nominatim.org/release-docs/latest/"
Issues = "https://github.com/osm-search/Nominatim/issues"
Repository = "https://github.com/osm-search/Nominatim"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.hatch.version]
path = "src/nominatim_api/version.py"
pattern = "NOMINATIM_API_VERSION = '(?P<version>[^']+)'"
[tool.hatch.build.targets.sdist]
include = [
"src/nominatim_api",
"src/nominatim_db/config.py",
"settings",
"extra_src/paths.py"
]
exclude = [
"src/nominatim_api/config.py"
]
[tool.hatch.build.targets.wheel]
packages = ["src/nominatim_api"]
[tool.hatch.build.targets.wheel.force-include]
"src/nominatim_db/config.py" = "nominatim_api/config.py"
"extra_src/paths.py" = "nominatim_api/paths.py"
"settings" = "nominatim_api/resources/settings"

View File

@@ -0,0 +1 @@
../../settings/

1
packaging/nominatim-api/src Symbolic link
View File

@@ -0,0 +1 @@
../../src/

View File

@@ -0,0 +1 @@
../../COPYING

View File

@@ -0,0 +1,54 @@
# Nominatim - DB Backend
Nominatim is a tool to search OpenStreetMap data
by name and address (geocoding) and to generate synthetic addresses of
OSM points (reverse geocoding).
This module implements the database backend for Nominatim and the
command-line tool for importing and maintaining the database.
## Installation
### Prerequisites
Nominatim requires [osm2pgsql](https://osm2pgsql.org/) (>=1.8) for reading
OSM data and [PostgreSQL](https://www.postgresql.org/) (>=9.6) to store the data.
On Ubuntu (>=23.04) and Debian (when using backports), you can install them with:
sudo apt-get install osm2pgsql postgresql-postgis
### Installation from pypi
To install Nominatim from pypi, run:
pip install nominatim-db
## Quick start
First create a project directory for your new Nominatim database, which
is the space for additional configuration and customization:
mkdir nominatim-project
Make sure you run all nominatim commands from within the project directory:
cd nominatim-project
Download an appropriate data extract, for example from
[Geofabrik](https://download.geofabrik.de/) and import the file:
nominatim import --osm-file <downlaoded-osm-data.pbf>
You will need to install the [`nominatim-api`](https://pypi.org/project/nominatim-api/)
package to query the database.
## Documentation
A HTML version of the documentation can be found at
https://nominatim.org/release-docs/latest/ .
## License
The source code is available under a GPLv3 license.

1
packaging/nominatim-db/data Symbolic link
View File

@@ -0,0 +1 @@
../../data/

View File

@@ -0,0 +1,15 @@
# 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.
# For a full list of authors see the git log.
"""
Path settings for extra data used by Nominatim.
"""
from pathlib import Path
PHPLIB_DIR = None
DATA_DIR = (Path(__file__) / '..' / 'resources').resolve()
SQLLIB_DIR = (DATA_DIR / 'lib-sql')
CONFIG_DIR = (DATA_DIR / 'settings')

View File

@@ -0,0 +1 @@
../../lib-sql/

View File

@@ -0,0 +1,71 @@
[project]
name = "nominatim-db"
description = "A tool for building a database of OpenStreetMap for geocoding and for searching the database. Database backend."
readme = "README.md"
requires-python = ">=3.7"
license = 'GPL-3.0-or-later'
maintainers = [
{ name = "Sarah Hoffmann", email = "lonvia@denofr.de" },
{ name = "Marc Tobias", email = "mtmail-cpan@gmx.net" }
]
keywords = [ "geocoding", "OpenStreetMap", "search" ]
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Operating System :: OS Independent",
]
dependencies = [
"psycopg",
"python-dotenv",
"jinja2",
"pyYAML>=5.1",
"datrie",
"psutil",
"PyICU"
]
dynamic = ["version"]
[project.urls]
Homepage = "https://nominatim.org"
Documentation = "https://nominatim.org/release-docs/latest/"
Issues = "https://github.com/osm-search/Nominatim/issues"
Repository = "https://github.com/osm-search/Nominatim"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.hatch.version]
path = "src/nominatim_db/version.py"
pattern = "NOMINATIM_VERSION = parse_version.'(?P<version>[^-]+)"
[tool.hatch.build.targets.sdist]
include = [
"src/nominatim_db",
"scripts",
"lib-sql/**/*.sql",
"settings",
"data/words.sql",
"extra_src/nominatim_db/paths.py"
]
artifacts = [
"data/country_osm_grid.sql.gz"
]
exclude = [
"src/nominatim_db/paths.py"
]
[tool.hatch.build.targets.wheel]
packages = ["src/nominatim_db"]
[tool.hatch.build.targets.wheel.shared-scripts]
"scripts" = "/"
[tool.hatch.build.targets.wheel.force-include]
"lib-sql" = "nominatim_db/resources/lib-sql"
"settings" = "nominatim_db/resources/settings"
"data/country_osm_grid.sql.gz" = "nominatim_db/resources/country_osm_grid.sql.gz"
"data/words.sql" = "nominatim_db/resources/words.sql"
"extra_src/nominatim_db/paths.py" = "nominatim_db/paths.py"

View File

@@ -0,0 +1,5 @@
#!python3
from nominatim_db import cli
exit(cli.nominatim(module_dir=None, osm2pgsql_path=None))

View File

@@ -0,0 +1 @@
../../settings/

1
packaging/nominatim-db/src Symbolic link
View File

@@ -0,0 +1 @@
../../src

View File

@@ -1,9 +1,16 @@
local flex = require('flex-base')
flex.set_main_tags{
highway = {'always',
street_lamp = 'named',
traffic_signals = 'named',
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',
@@ -28,9 +35,7 @@ flex.set_prefilters{delete_keys = {'building', 'source',
'*:prefix', '*:suffix', 'name:prefix:*', 'name:suffix:*',
'name:etymology', 'name:signed', 'name:botanical',
'addr:street:name', 'addr:street:type'},
delete_tags = {highway = {'no', 'turning_circle', 'mini_roundabout',
'noexit', 'crossing', 'give_way', 'stop'},
landuse = {'cemetry', 'no'},
delete_tags = {landuse = {'cemetry', 'no'},
boundary = {'place'}},
extra_keys = {'wikipedia', 'wikipedia:*', 'wikidata', 'capital', 'area'}
}

View File

@@ -23,7 +23,17 @@ flex.set_main_tags{
secondary_link = 'named',
tertiary_link = 'named'},
railway = 'named',
man_made = 'always',
man_made = {'none',
pier = 'always',
tower = 'always',
bridge = 'always',
works = 'named',
water_tower = 'always',
dyke = 'named',
adit = 'named',
lighthouse = 'always',
watermill = 'always',
tunnel = 'always'},
aerialway = 'always',
boundary = {'named',
postal_code = 'always'},
@@ -59,10 +69,10 @@ flex.set_prefilters{delete_keys = {'note', 'note:*', 'source', '*source', 'attri
'noexit', 'crossing', 'give_way', 'stop'},
railway = {'level_crossing', 'no', 'rail', 'switch',
'abandoned', 'signal', 'buffer_stop', 'razed'},
man_made = {'survey_point', 'cutline'},
aerialway = {'pylon', 'no'},
aeroway = {'no'},
amenity = {'no', 'parking_space', 'parking_entrance'},
amenity = {'no', 'parking_space', 'parking_entrance',
'waste_disposal', 'hunting_stand'},
club = {'no'},
craft = {'no'},
leisure = {'no'},

View File

@@ -23,7 +23,17 @@ flex.set_main_tags{
secondary_link = 'named',
tertiary_link = 'named'},
railway = 'named',
man_made = 'always',
man_made = {'none',
pier = 'always',
tower = 'always',
bridge = 'always',
works = 'named',
water_tower = 'always',
dyke = 'named',
adit = 'named',
lighthouse = 'always',
watermill = 'always',
tunnel = 'always'},
aerialway = 'always',
boundary = {'named',
postal_code = 'always'},
@@ -63,10 +73,10 @@ flex.set_prefilters{delete_keys = {'note', 'note:*', 'source', '*source', 'attri
'noexit', 'crossing', 'give_way', 'stop'},
railway = {'level_crossing', 'no', 'rail', 'switch',
'abandoned', 'signal', 'buffer_stop', 'razed'},
man_made = {'survey_point', 'cutline'},
aerialway = {'pylon', 'no'},
aeroway = {'no'},
amenity = {'no', 'parking_space', 'parking_entrance'},
amenity = {'no', 'parking_space', 'parking_entrance',
'waste_disposal', 'hunting_stand'},
club = {'no'},
craft = {'no'},
leisure = {'no'},

View File

@@ -1,9 +1,16 @@
local flex = require('flex-base')
flex.set_main_tags{
highway = {'always',
street_lamp = 'named',
traffic_signals = 'named',
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',
@@ -29,9 +36,7 @@ flex.set_prefilters{delete_keys = {'building', 'source',
'*:prefix', '*:suffix', 'name:prefix:*', 'name:suffix:*',
'name:etymology', 'name:signed', 'name:botanical',
'addr:street:name', 'addr:street:type'},
delete_tags = {highway = {'no', 'turning_circle', 'mini_roundabout',
'noexit', 'crossing', 'give_way', 'stop'},
landuse = {'cemetry', 'no'},
delete_tags = {landuse = {'cemetry', 'no'},
boundary = {'place'}},
extra_keys = {'wikipedia', 'wikipedia:*', 'wikidata', 'capital', 'area'}
}

View File

@@ -35,7 +35,7 @@ function print_taginfo()
for _, k in ipairs(flex.TAGINFO_MAIN.keys) do
local desc = get_key_description(k, 'POI/feature in the search database')
if flex.TAGINFO_MAIN.delete_tags[k] ~= nil then
desc.description = string.format('%s(except for values: %s).', desc.description,
desc.description = string.format('%s (except for values: %s).', desc.description,
table.concat(flex.TAGINFO_MAIN.delete_tags[k], ', '))
end
table.insert(tags, desc)

View File

@@ -2,7 +2,7 @@
#
# This file is part of Nominatim. (https://nominatim.org)
#
# Copyright (C) 2023 by the Nominatim developer community.
# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
The public interface of the Nominatim library.
@@ -14,6 +14,9 @@ import from this file, not from the source files directly.
# See also https://github.com/PyCQA/pylint/issues/6006
# pylint: disable=useless-import-alias
from .errors import (UsageError as UsageError)
from .config import (Configuration as Configuration)
from .core import (NominatimAPI as NominatimAPI,
NominatimAPIAsync as NominatimAPIAsync)
from .connection import (SearchConnection as SearchConnection)
@@ -36,3 +39,7 @@ from .results import (SourceTable as SourceTable,
SearchResult as SearchResult,
SearchResults as SearchResults)
from .localization import (Locales as Locales)
from .result_formatting import (FormatDispatcher as FormatDispatcher,
load_format_dispatcher as load_format_dispatcher)
from .version import NOMINATIM_API_VERSION as __version__

View File

@@ -0,0 +1,12 @@
# 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.
# For a full list of authors see the git log.
# This file is just a placeholder to make the config module available
# during development. It will be replaced by nominatim_db/config.py on
# installation.
# pylint: skip-file
from nominatim_db.config import *

View File

@@ -2,7 +2,7 @@
#
# This file is part of Nominatim. (https://nominatim.org)
#
# Copyright (C) 2023 by the Nominatim developer community.
# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Extended SQLAlchemy connection class that also includes access to the schema.
@@ -14,16 +14,16 @@ import asyncio
import sqlalchemy as sa
from sqlalchemy.ext.asyncio import AsyncConnection
from nominatim.typing import SaFromClause
from nominatim.db.sqlalchemy_schema import SearchTables
from nominatim.db.sqlalchemy_types import Geometry
from nominatim.api.logging import log
from .typing import SaFromClause
from .sql.sqlalchemy_schema import SearchTables
from .sql.sqlalchemy_types import Geometry
from .logging import log
T = TypeVar('T')
class SearchConnection:
""" An extended SQLAlchemy connection class, that also contains
then table definitions. The underlying asynchronous SQLAlchemy
the table definitions. The underlying asynchronous SQLAlchemy
connection can be accessed with the 'connection' property.
The 't' property is the collection of Nominatim tables.
"""

View File

@@ -1,13 +1,14 @@
# SPDX-License-Identifier: GPL-2.0-only
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
# Copyright (C) 2023 by the Nominatim developer community.
# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Implementation of classes for API access via libraries.
"""
from typing import Mapping, Optional, Any, AsyncIterator, Dict, Sequence, List, Tuple
from typing import Mapping, Optional, Any, AsyncIterator, Dict, Sequence, List,\
Union, Tuple, cast
import asyncio
import sys
import contextlib
@@ -16,18 +17,18 @@ from pathlib import Path
import sqlalchemy as sa
import sqlalchemy.ext.asyncio as sa_asyncio
from nominatim.errors import UsageError
from nominatim.db.sqlalchemy_schema import SearchTables
from nominatim.db.async_core_library import PGCORE_LIB, PGCORE_ERROR
import nominatim.db.sqlite_functions
from nominatim.config import Configuration
from nominatim.api.connection import SearchConnection
from nominatim.api.status import get_status, StatusResult
from nominatim.api.lookup import get_detailed_place, get_simple_place
from nominatim.api.reverse import ReverseGeocoder
from nominatim.api.search import ForwardGeocoder, Phrase, PhraseType, make_query_analyzer
import nominatim.api.types as ntyp
from nominatim.api.results import DetailedResult, ReverseResult, SearchResults
from .errors import UsageError
from .sql.sqlalchemy_schema import SearchTables
from .sql.async_core_library import PGCORE_LIB, PGCORE_ERROR
from .config import Configuration
from .sql import sqlite_functions, sqlalchemy_functions #pylint: disable=unused-import
from .connection import SearchConnection
from .status import get_status, StatusResult
from .lookup import get_detailed_place, get_simple_place
from .reverse import ReverseGeocoder
from .search import ForwardGeocoder, Phrase, PhraseType, make_query_analyzer
from . import types as ntyp
from .results import DetailedResult, ReverseResult, SearchResults
class NominatimAPIAsync: #pylint: disable=too-many-instance-attributes
@@ -38,8 +39,10 @@ class NominatimAPIAsync: #pylint: disable=too-many-instance-attributes
This class shares most of the functions with its synchronous
version. There are some additional functions or parameters,
which are documented below.
This class should usually be used as a context manager in 'with' context.
"""
def __init__(self, project_dir: Path,
def __init__(self, project_dir: Optional[Union[str, Path]] = None,
environ: Optional[Mapping[str, str]] = None,
loop: Optional[asyncio.AbstractEventLoop] = None) -> None:
""" Initiate a new frontend object with synchronous API functions.
@@ -107,16 +110,16 @@ class NominatimAPIAsync: #pylint: disable=too-many-instance-attributes
raise UsageError(f"SQlite database '{params.get('dbname')}' does not exist.")
else:
dsn = self.config.get_database_params()
query = {k: v for k, v in dsn.items()
query = {k: str(v) for k, v in dsn.items()
if k not in ('user', 'password', 'dbname', 'host', 'port')}
dburl = sa.engine.URL.create(
f'postgresql+{PGCORE_LIB}',
database=dsn.get('dbname'),
username=dsn.get('user'),
password=dsn.get('password'),
host=dsn.get('host'),
port=int(dsn['port']) if 'port' in dsn else None,
database=cast(str, dsn.get('dbname')),
username=cast(str, dsn.get('user')),
password=cast(str, dsn.get('password')),
host=cast(str, dsn.get('host')),
port=int(cast(str, dsn['port'])) if 'port' in dsn else None,
query=query)
engine = sa_asyncio.create_async_engine(dburl, **extra_args)
@@ -127,7 +130,7 @@ class NominatimAPIAsync: #pylint: disable=too-many-instance-attributes
@sa.event.listens_for(engine.sync_engine, "connect")
def _on_sqlite_connect(dbapi_con: Any, _: Any) -> None:
dbapi_con.run_async(lambda conn: conn.enable_load_extension(True))
nominatim.db.sqlite_functions.install_custom_functions(dbapi_con)
sqlite_functions.install_custom_functions(dbapi_con)
cursor = dbapi_con.cursor()
cursor.execute("SELECT load_extension('mod_spatialite')")
cursor.execute('SELECT SetDecimalPrecision(7)')
@@ -166,6 +169,14 @@ class NominatimAPIAsync: #pylint: disable=too-many-instance-attributes
await self._engine.dispose()
async def __aenter__(self) -> 'NominatimAPIAsync':
return self
async def __aexit__(self, *_: Any) -> None:
await self.close()
@contextlib.asynccontextmanager
async def begin(self) -> AsyncIterator[SearchConnection]:
""" Create a new connection with automatic transaction handling.
@@ -351,9 +362,11 @@ class NominatimAPI:
""" This class provides a thin synchronous wrapper around the asynchronous
Nominatim functions. It creates its own event loop and runs each
synchronous function call to completion using that loop.
This class should usually be used as a context manager in 'with' context.
"""
def __init__(self, project_dir: Path,
def __init__(self, project_dir: Optional[Union[str, Path]] = None,
environ: Optional[Mapping[str, str]] = None) -> None:
""" Initiate a new frontend object with synchronous API functions.
@@ -376,13 +389,22 @@ class NominatimAPI:
This function also closes the asynchronous worker loop making
the NominatimAPI object unusable.
"""
self._loop.run_until_complete(self._async_api.close())
self._loop.close()
if not self._loop.is_closed():
self._loop.run_until_complete(self._async_api.close())
self._loop.close()
def __enter__(self) -> 'NominatimAPI':
return self
def __exit__(self, *_: Any) -> None:
self.close()
@property
def config(self) -> Configuration:
""" Provide read-only access to the [configuration](#Configuration)
""" Provide read-only access to the [configuration](Configuration.md)
used by the API.
"""
return self._async_api.config

View File

@@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
# Copyright (C) 2022 by the Nominatim developer community.
# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Custom exception and error classes for Nominatim.

View File

@@ -2,7 +2,7 @@
#
# This file is part of Nominatim. (https://nominatim.org)
#
# Copyright (C) 2023 by the Nominatim developer community.
# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Helper functions for localizing names of results.

View File

@@ -2,7 +2,7 @@
#
# This file is part of Nominatim. (https://nominatim.org)
#
# Copyright (C) 2023 by the Nominatim developer community.
# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Functions for specialised logging with HTML output.

Some files were not shown because too many files have changed in this diff Show More