This repository provides a Python-based solution for optimizing routes and prioritizing landmarks for urban navigation, specifically focusing on Kathmandu. The system uses OpenStreetMap (OSM) data and custom algorithms to:
- Optimize routes between landmarks and buildings based on shortest travel times.
- Prioritize landmarks near buildings, using a clustering method (DBSCAN) to categorize and rank landmarks by size and type.
This solution integrates several key functionalities, including:
- Landmark selection and clustering based on proximity.
- Route optimization based on travel time.
- Generation of hash-based route directions for navigation.
The output consists of a CSV and JSON file with each building’s corresponding priority landmark, optimized route, and travel hash.
route_optimizer.py
: Contains the logic for route optimization, including finding nearest nodes, computing shortest paths, and generating route hashes.select_landmarks.py
: Contains the logic for selecting and ranking landmarks based on their proximity to buildings using clustering techniques.utils.py
: Utility functions for data preprocessing, distance calculation, and bearing calculation.main.py
: The main script that integrates all the functionalities, processes data, and saves the results to CSV and JSON files.requirements.txt
: The list of required dependencies for the project.
The route optimization process involves:
- Graph Construction: A walkable graph of Kathmandu is constructed using the
osmnx
library to fetch data from OpenStreetMap. - Shortest Path Calculation: Using NetworkX, the shortest path between a landmark and a building is calculated based on travel time, considering edge speeds and travel times derived from OSM data.
- Route Hash Generation: A route hash is generated based on the directions (cardinal bearings) and distances along the path.
The landmark prioritization process involves:
- Clustering: DBSCAN is used to cluster landmarks based on their geographical proximity. H3 hexagons are employed to categorize landmarks into geographical areas.
- Ranking: Clusters are ranked by size, and landmarks are prioritized according to a predefined order (e.g., temple, tourist spot, bus stop).
- Noise Handling: Landmarks that do not fit well into any cluster (outliers) are handled separately and included in the final prioritization.
- Haversine Distance: Calculates the geographical distance between two points (latitude, longitude) using the Haversine formula.
- Initial Compass Bearing: Calculates the initial compass bearing from one geographic point to another.
- Data Loading and Preprocessing: Functions to load CSV files containing building and landmark data, preprocess them, and handle missing or incorrect entries.
- Data Crawling and Preprocessing: Calls functions to crawl building and landmark data, preprocess the data, and clean up any inconsistencies.
- Route and Landmark Integration: Iterates through buildings and landmarks, prioritizes the closest landmark for each building, and calculates the optimized route.
- Result Saving: Saves the final results (including route hashes) into a CSV and JSON format for further analysis or application development.
This file lists the dependencies needed to run the project. These libraries and tools include data manipulation, geospatial analysis, machine learning, and visualization packages.
To set up the project environment and run the system, follow these steps:
Make sure you have Python 3.8+ installed. It is recommended to create a virtual environment for this project to avoid conflicts with other Python projects.
-
Create a virtual environment (optional but recommended):
python -m venv route_optimizer_env
-
Activate the virtual environment:
- For Windows:
.\route_optimizer_env\Scripts\activate
- For macOS/Linux:
source route_optimizer_env/bin/activate
- For Windows:
With the virtual environment activated, install the necessary dependencies listed in the requirements.txt
file:
pip install -r requirements.txt
After the dependencies are installed, you can run the main script, main.py
, to execute the route optimization and landmark prioritization:
python main.py
The script will:
- Crawl the building and landmark data.
- Process and clean the data.
- Prioritize landmarks for each building.
- Optimize routes and generate route hashes.
- Save the results in both CSV and JSON formats.
After running the script, the following output files will be created:
ktm_buildings_with_landmarks.csv
: Contains the building data along with the associated prioritized landmark.ktm_buildings_with_hashes.csv
: Contains the building data with route hashes, representing the optimized path from a landmark to the building.ktm_buildings_with_hashes.json
: A JSON representation of the same data for use in web applications or APIs.
Ensure that you have the necessary input data files, such as cleaned_landmarks.csv
and kathmandu_buildings.csv
, placed in the ./data/
directory.
route_optimizer.py
: Contains the classRouteOptimizer
for performing route optimization using shortest path algorithms and generating route hashes.select_landmarks.py
: Contains the classLandmarkPriority
for clustering landmarks and selecting the most relevant ones based on proximity and priority.utils.py
: Utility functions for data handling, distance calculations, and preprocessing.main.py
: Main script that orchestrates data crawling, processing, and integration of route optimization and landmark prioritization.requirements.txt
: Dependency file listing all required libraries.
Below is a list of Python libraries required for this project:
osmnx
: For downloading and processing OpenStreetMap (OSM) data to build a walkable graph.networkx
: For performing graph-based operations like finding the shortest path.numpy
: For numerical operations and data manipulation.pandas
: For handling CSV files and data frames.scikit-learn
: For DBSCAN clustering of landmarks.h3
: For working with H3 hexagons and spatial indexing.geopandas
: For geospatial data manipulation.shapely
: For geometric operations.tqdm
: For displaying progress bars during execution.joblib
: For parallel processing (if applicable).
This project is licensed under the Apache License. See the LICENSE file for more details.
- OpenStreetMap: https://www.openstreetmap.org
- OSMnx: https://osmnx.readthedocs.io/en/stable/
- DBSCAN Clustering: https://scikit-learn.org/stable/modules/generated/sklearn.cluster.DBSCAN.html
This system provides a robust framework for urban navigation by integrating geospatial analysis with route optimization and landmark prioritization. It can be extended for use in other cities or to include additional features like multi-modal transport analysis.