{"id":23505062,"url":"https://github.com/shreeniraula/osm","last_synced_at":"2025-10-31T09:31:44.070Z","repository":{"id":269611636,"uuid":"907988503","full_name":"ShreeNiraula/osm","owner":"ShreeNiraula","description":"A guide for setting up Nominatim for OpenStreetMap in Nepal. It covers installing dependencies, configuring PostgreSQL with PostGIS, importing Nepal-specific OSM data, setting up Nginx as a reverse proxy, securing with HTTPS, and running Nominatim as a Gunicorn application.","archived":false,"fork":false,"pushed_at":"2025-01-25T22:49:11.000Z","size":6,"stargazers_count":4,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-25T23:32:23.335Z","etag":null,"topics":["geocoding","mapdata","nominatim-api","open-source","openstreetmap","openstreetmap-data"],"latest_commit_sha":null,"homepage":"https://shreeniraula.com.np/","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ShreeNiraula.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-24T19:43:44.000Z","updated_at":"2025-01-25T22:49:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"902e3912-51aa-4494-8104-e5d8411e7817","html_url":"https://github.com/ShreeNiraula/osm","commit_stats":null,"previous_names":["shreeniraula/osm"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShreeNiraula%2Fosm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShreeNiraula%2Fosm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShreeNiraula%2Fosm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShreeNiraula%2Fosm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ShreeNiraula","download_url":"https://codeload.github.com/ShreeNiraula/osm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239172804,"owners_count":19594223,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["geocoding","mapdata","nominatim-api","open-source","openstreetmap","openstreetmap-data"],"created_at":"2024-12-25T09:18:10.951Z","updated_at":"2025-10-31T09:31:38.786Z","avatar_url":"https://github.com/ShreeNiraula.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nominatim 4.5.0 Setup for Open Street Map: Nepal Map Data\n\n###### Date: 24-Dec-2024 \u003cbr\u003e\n\n###### Version: 1.0 \u003c/br\u003e\n\n#### [shreeniraula.com.np](https://shreeniraula.com.np/) | LinkedIn: [ShreeNiraula](https://www.linkedin.com/in/shreeniraula/) | Twitter: [@ShreeNiraula](https://twitter.com/ShreeNiraula) | YouTube: [@ShreeNiraula](https://www.youtube.com/@ShreeNiraula/)\n\nWelcome! This repository walks you through setting up Nominatim, a powerful geocoding tool that works with Open Street Map (OSM) data. This guide is specifically designed for Nepal, making it easy to set up and start using OSM data for geospatial services like location search, reverse geocoding, and more.\n\nThe setup includes everything you need, from installing dependencies to configuring PostgreSQL, setting up Nginx as a reverse proxy, and securing your server with HTTPS. Once set up, you'll have a fully functional Nominatim instance for your own geospatial needs.\n\n## Why Use Nominatim?\n\nHere are some key reasons why Nominatim is a great choice for your geocoding needs:\n\n- **Completely Free**: Nominatim is open-source, meaning you don't have to pay any licensing fees to use it, and you can modify it to suit your needs.\n- **Accurate and Up-to-Date**: It uses Open Street Map, which is constantly updated by contributors around the world, ensuring that the geographic data you’re working with is accurate and current.\n- **Highly Customizable**: You can tweak the setup to focus on specific regions or change configurations to meet the needs of your application.\n- **Privacy-First**: By hosting your own instance of Nominatim, you maintain complete control over your data, offering you peace of mind in terms of privacy.\n- **Built for Scale**: Whether you're running a small app or handling a large number of requests, Nominatim is designed to scale easily, making it suitable for any project.\n\n## Nepali App Examples Using Geocoding:\n\n- **Tootle**: A popular Nepali ride-hailing app that uses geocoding for locating riders and drivers, optimizing travel routes, and managing pick-up points.\n- **Pathao Nepal**: Used for ride services and deliveries, Pathao employs geocoding to find the user's current location and their destination for accurate route mapping.\n- **Hamro Patro**: A Nepali app offering calendar, news, and other local services that might use location-based features for festivals, local events, and nearby places.\n\n## Global Apps Using Geocoding:\n\n- **Uber**: Uses geocoding for ride request locations and destination searches.\n- **Airbnb**: Relies on geocoding to help users search for accommodations by location.\n- **Foursquare**: Uses location data for recommending nearby places to eat, shop, or visit.\n\n## Getting Started\n\nIf you're ready to set up your own Nominatim instance, just follow the steps in this repository. Here's a quick overview of what you'll be doing:\n\n1. **Install Dependencies**: We'll walk you through installing PostgreSQL, PostGIS, osm2pgsql, and the necessary Python packages.\n2. **Set Up PostgreSQL**: We'll create the necessary users and databases for Nominatim and configure PostgreSQL.\n3. **Import OSM Data**: We provide steps to download and import the latest Open Street Map data for Nepal into your Nominatim database.\n4. **Configure the Server**: Set up Nginx as a reverse proxy and secure the server with HTTPS.\n5. **Run Nominatim**: Finally, we guide you through running Nominatim as a Gunicorn application to make it available to your users.\n\nFollow the full instructions in this repository, and you'll have a fully functional Nominatim setup in no time!\n\n## Prerequisites\n\nBefore you begin, ensure your machine meets the following requirements:\n\n- **Debian-based operating system (e.g., Ubuntu)**: This guide assumes you're using a Debian-based distribution like Ubuntu. Other Linux distributions may require different commands or configurations.\n- **Elevated privileges (sudo access)**: You'll need administrator (root) access to install software, configure system settings, and manage users. Ensure you have `sudo` privileges on your machine to carry out these actions.\n- **Set the A Record for the domain name (optional)**\n\n##\n\n### Map the domain name to localhost by editing the hosts file (Optional)\n\n`sudo vi /etc/hosts`\n\n`127.0.0.1 osm.shreeniraula.com.np`\n\n## Nominatim Installation \u0026 Configuration\n\n#### Install necessary packages for PostgreSQL, PostGIS, osm2pgsql, and Python dependencies\n\nFirst, update your package list and install the required dependencies:\n\n```bash\nsudo apt-get install -y osm2pgsql postgresql-postgis postgresql-postgis-scripts \\\npkg-config libicu-dev virtualenv python3-pip acl\n```\n\n#### Create a system user 'nominatim' and set up its home directory\n\n```bash\nsudo useradd -d /srv/nominatim -s /bin/bash -m nominatim\nsudo mkdir -p /srv/nominatim\nsudo chown -R nominatim:nominatim /srv/nominatim\n```\n\nSwitch to the 'nominatim' user to continue with setup\n\n```bash\nsudo -u nominatim bash\ncd\n```\n\nSet environment variables for the 'nominatim' user\n\n```bash\nexport USERNAME=nominatim\nexport USERHOME=/srv/nominatim\nchmod a+x $USERHOME\n```\n\nSwitch to Admin user and create PostgreSQL users for Nominatim and web service\n\n```bash\nsudo -u postgres createuser nominatim\nsudo -u postgres createuser www-data\n```\n\nGrant 'nominatim' user permission to create databases in PostgreSQL\n\n```bash\nsudo -u postgres psql\nALTER USER nominatim WITH CREATEDB;\nCREATE EXTENSION IF NOT EXISTS postgis; # Enable PostGIS extension\n\\du # List PostgreSQL roles\n\\q # Exit PostgreSQL prompt\n```\n\nSwitch back to nominatim user and create a Python virtual environment for Nominatim\n\n```bash\nvirtualenv $USERHOME/nominatim-venv\n```\n\nInstall the latest version of Nominatim using pip\n\n```bash\n$USERHOME/nominatim-venv/bin/pip install nominatim-db\n```\n\nActivate the virtual environment to run Nominatim commands\n\n```bash\n. $USERHOME/nominatim-venv/bin/activate\n```\n\nCreate the Nominatim project directory and navigate into it, setting an environment variable for the directory path\n\n```bash\nmkdir ~/nominatim-project\ncd ~/nominatim-project\nexport PROJECT_DIR=~/nominatim-project\ncd $PROJECT_DIR\n```\n\nDownload the OSM data for Nepal from Geofabrik\n\n```bash\nwget https://download.geofabrik.de/asia/nepal-latest.osm.pbf\n```\n\nSwitch to admin user and grant 'nominatim' user superuser privileges temporarily to import data\n\n```bash\nsudo -u postgres psql\nALTER USER nominatim WITH SUPERUSER;\n\\q\n```\n\nSwitch to 'nominatim' user and import the OSM data into the Nominatim database\n\n```bash\nnominatim import --osm-file nepal-latest.osm.pbf 2\u003e\u00261 | tee setup.log\n```\n\nVerify the Nominatim database setup\n\n```bash\nnominatim admin --check-database\n```\n\nInstall Python dependencies for the Nominatim API to interact with the database\n\n```bash\n$USERHOME/nominatim-venv/bin/pip install psycopg[binary] falcon uvicorn gunicorn\n$USERHOME/nominatim-venv/bin/pip install nominatim-api\n```\n\nTest the Nominatim installation by performing a search for Kathmandu\n\n```bash\nnominatim search --query Kathmandu\n```\n\nSwitch to 'admin' user revoke superuser privileges from the 'nominatim' user\n\n```bash\nsudo -u postgres psql\nALTER USER nominatim WITH NOSUPERUSER;\n\\q\n```\n\nCreate a systemd service to run Nominatim as a Gunicorn application\n\n```bash\nsudo tee /etc/systemd/system/nominatim.service \u003c\u003c EOFNOMINATIMSYSTEMD\n[Unit]\nDescription=Nominatim running as a Gunicorn application\nAfter=network.target\n\n[Service]\nType=simple\nUser=www-data\nGroup=www-data\nWorkingDirectory=/srv/nominatim/nominatim-project\nEnvironment=\"PATH=/srv/nominatim/nominatim-venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"\n\nExecStart=/srv/nominatim/nominatim-venv/bin/gunicorn -b 0.0.0.0:8088 -w 4 -k uvicorn.workers.UvicornWorker nominatim_api.server.falcon.server:run_wsgi\nExecReload=/bin/kill -s HUP $MAINPID\n\nStandardOutput=journal\nStandardError=journal\nPrivateTmp=true\nTimeoutStopSec=5\nKillMode=mixed\n\n[Install]\nWantedBy=multi-user.target\nEOFNOMINATIMSYSTEMD\n```\n\nReload systemd, enable and start the Nominatim service\n\n```bash\nsudo systemctl daemon-reload\nsudo systemctl enable nominatim.service\nsudo systemctl restart nominatim.service\n```\n\n#### Switch to the admin user and install Nginx, then configure it as a reverse proxy for Nominatim\n\nInstall Nginx web server\n\n```bash\nsudo apt-get install -y nginx\n```\n\nConfigure Nginx to act as a reverse proxy for Nominatim by setting up a server block\n\n```bash\nsudo tee /etc/nginx/sites-available/osm.shreeniraula.com.np \u003c\u003c EOF_NGINX_CONF\nserver {\nlisten 80; # Listen on port 80 for incoming HTTP requests\nserver_name osm.shreeniraula.com.np; # Specify the domain name for this server block\n\n    location / {  # Define a location block to handle requests to the root URL\n        proxy_pass http://127.0.0.1:8088;  # Forward requests to the Nominatim service running on localhost:8088\n        proxy_set_header Host \\$host;  # Pass the original host header to the proxied server\n        proxy_set_header X-Real-IP \\$remote_addr;  # Forward the real client IP address\n        proxy_set_header X-Forwarded-For \\$proxy_add_x_forwarded_for;  # Pass along the client’s IP address in the chain\n        proxy_set_header X-Forwarded-Proto \\$scheme;  # Pass along the protocol (HTTP or HTTPS) of the original request\n    }\n\n}\nEOF_NGINX_CONF # Save the configuration to the Nginx sites-available directory\n```\n\nRemove the default symbolic link for the default Nginx configuration\n\n```bash\nsudo rm /etc/nginx/sites-enabled/default\n```\n\nEnable the website configuration by creating a symbolic link\n\n```bash\nsudo ln -s /etc/nginx/sites-available/osm.shreeniraula.com.np /etc/nginx/sites-enabled/\n```\n\nTest the Nginx configuration for any syntax errors\n\n```bash\nsudo nginx -t\n```\n\nRestart Nginx to apply the changes\n\n```bash\nsudo systemctl restart nginx\n```\n\nFix permission issues for Nominatim by ensuring the correct ownership\n\n```bash\nls -ld /run\nsudo chown -R www-data:www-data /srv/nominatim\n```\n\nVerify the Gunicorn version for debugging purposes\n\n```bash\nsudo -u www-data /srv/nominatim/nominatim-venv/bin/gunicorn --version\n```\n\nManually run Gunicorn for troubleshooting if the service does not work\n\n```bash\n/srv/nominatim/nominatim-venv/bin/gunicorn -b 0.0.0.0:8088 -w 4 -k uvicorn.workers.UvicornWorker nominatim_api.server.falcon.server:run_wsgi\n```\n\nCheck the Nominatim service logs for any errors or troubleshooting\n\n```bash\nsudo journalctl -u nominatim.service\n```\n\n##\n\n#### Test the functionality of the Nominatim Python frontend (API) by starting the server and performing a search query\n\n```bash\n# Manually start the Nominatim API server if it is not already running, to enable the frontend for search and geocoding requests\nnominatim serve\n\n# Test the search API with a query for Kathmandu and get the results in JSON format\ncurl http://127.0.0.1:8088/search?q=Kathmandu\u0026format=json\n```\n\n##\n\n#### Install Certbot and configure HTTPS for secure access to the site\n\n```bash\nsudo apt install certbot python3-certbot-nginx\nsudo certbot --nginx -d osm.shreeniraula.com.np\n```\n\n##\n\n#### Querying Open Street Map API for Location Details and Reverse Geocoding in Kathmandu\n\nQuery the Open Street Map API for the location 'Kathmandu' to get details in JSON format\n\n```bash\ncurl https://osm.shreeniraula.com.np/search?q=Kathmandu\u0026format=json\n```\n\nPerform reverse geocoding by passing latitude and longitude to retrieve the address in Chandragiri Municipality, Kathmandu\n\n```bash\ncurl https://osm.shreeniraula.com.np/reverse?lat=27.6892881\u0026lon=85.2321257\u0026format=json\n```\n\n### Congratulations! You have successfully installed the Nominatim API with Open Street Map data.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshreeniraula%2Fosm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshreeniraula%2Fosm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshreeniraula%2Fosm/lists"}