-
Notifications
You must be signed in to change notification settings - Fork 7
Installing the Backend (Database)
When setting up the database, you have two options: basic and advanced. For a basic setup, you'll have access to every feature of OSM Finder except shape comparisons. A basic setup will also take significantly less time to process. For the advanced option, you'll be able to search the database for shapes, but be prepared to wait several hours while the database is set up. Both options require the same first few steps, but step 4 will be different depending on which option you choose.
1. Ensure you have PostgreSQL and PostGIS installed, and then install osm2pgsql version 1.7.1 or higher.
- To install on Windows using prebuilt binaries: https://osm2pgsql.org/doc/install.html#installing-on-windows
- To check for v1.7.1 support on your Linux distribution: https://osm2pgsql.org/doc/install.html#installing-on-linux
- If v1.7.1 isn't available for your Linux distribution (e.g., Ubuntu), follow the building instructions: https://github.com/openstreetmap/osm2pgsql#building
- See the instructions here: https://osm2pgsql.org/doc/manual.html#tuning-the-postgresql-server
- To follow along with the demo, download the data for Washington state at https://download.geofabrik.de/north-america/us.html.
- Generally, the .osm.pbf downloads are preferred since they're quicker to process.
4. Download flex.lua and run the following commands (in Linux):
sudo -u postgres createuser osmuser
sudo -u postgres createdb --encoding=UTF8 --owner=osmuser osm
sudo -u postgres psql osm --command='CREATE EXTENSION postgis;'
sudo -u postgres psql osm --command='CREATE EXTENSION hstore;'
Then, follow the instructions below for either the basic or advanced setup.
For the basic installation, simply run this command:
osm2pgsql -d osm -U osmuser -O flex -S flex.lua washington-latest.osm.pbf
- Note: you may need to move files around and change directory/file permissions appropriately to ensure that the postgres user can access
washington-latest.osm.pbfandflex.lua. - Note: if you get an error saying "peer authentication failed" when you run the last command, check out the solution at https://stackoverflow.com/a/26735105/1941353, but replace user 'postgres' with 'osmuser'.
4.2.1. For the advanced installation, you'll need a C compiler, such as GCC. If you built osm2pgsql from source, you'll likely already have gcc installed. If you didn't, you'll have to figure out which C compiler works best for your system and install it. Once installed, run the following command in the main directory of the repository:
gcc -shared -fPIC -I/usr/include/lua5.3 -llua5.3 -o shapeComparison.so shapeComparison.c
This command compiles and links shapeComparison.c so that it can be used by osm2pgsql. Depending on your operating system and version of Lua installed, you may need to change the -I/usr/include/lua5.3 -llua5.3 part of the command. The /usr/include/lua5.3 file path is simply the directory that contains lua.h and similar Lua v5.3 files. Once you find the same directory on your system, don't forget to prepend the file path with -I. The -llua5.3 part of the command may change to correspond with the Lua version on your system (e.g., -llua5.4), or it may just be -llua, but it will always be prepended with -l.
4.2.2. Once you compile shapeComparison.c without errors, find and open flex.lua in a text editor. At the top, you should see shape_comparison = 0, which disables shapes comparisons by default. Go ahead and change the value to 1 or another option to enable the feature.
4.2.3. Finally, run the following command:
osm2pgsql -d osm -U osmuser -x -O flex -S flex.lua washington-latest.osm.pbf
- Notice the additional
-xargument that's not present in the basic setup option. This ensures that osm2pgsql doesn't skip any node, even nodes without attributes, which is needed to properly compare shapes. - Note: you may need to move files around and change directory/file permissions appropriately to ensure that the postgres user can access
washington-latest.osm.pbfandflex.lua. - Note: if you get an error saying "peer authentication failed" when you run the last command, check out the solution at https://stackoverflow.com/a/26735105/1941353, but replace user 'postgres' with 'osmuser'.
- Note: The interactive terminal that opens is where you'll run the PostgreSQL queries that the frontend generates.
- You can confirm your database was set up correctly by running
\dt. You should see four tables:shapes,linestrings,nodes, andspatial_ref_sys.