Karachi-Navigator is a standalone, high-performance navigation engine designed specifically for Karachi’s road network. Unlike traditional mapping applications, this engine operates entirely offline without reliance on external APIs like Google Maps or Mapbox. It utilizes a custom-built geographic dataset and graph-based pathfinding to provide accurate routing and turn-by-turn instructions.
The system creates a graph based on a custom GeoJSON dataset and utilizes Dijkstra's Algorithm to traverse the network and calculate paths.
Follow these steps to set up the project on your local machine:
- It is recommended to use a virtual environment:
pip install -r requirements.txt
- Launch the Server:
python main.py
- The engine will initialize, build the road network from your data files, and start a local server at
http://127.0.0.1:5000.
The repository consists of two core components:
This is the "brain" of the project. It handles:
- Data Parsing: Reads road geometries from GeoJSON and statistical data (speed, distance) from CSV.
- Graph Construction: Uses
NetworkXto create aMultiGraphwhere intersections are nodes and roads are edges. - Spatial Analysis: Uses
Shapelyfor point-in-polygon checks to identify Karachi neighborhoods. - Geometry Math: Implements Haversine formulas for distance and bearing calculations to generate navigation instructions.
A FastAPI wrapper that exposes the engine to the web:
- POST
/calculate_route: Accepts start and end coordinates and returns a JSON response containing the path, time, and instructions. - Static Hosting: Serves the frontend interface directly from the
/staticdirectory.
The engine requires two primary data files located in the data/ directory:
map.geojson: Contains theLineStringgeometries for Karachi's roads andPolygonshapes for various areas.heuristic.csv: Contains statistical data for each road.
The engine utilizes Dijkstra's Algorithm to find the most efficient path. When a request is made:
- Snapping: The engine finds the closest graph nodes to the provided latitude/longitude.
- Weighting: It calculates the shortest path based on the chosen weight, such as
travel_timeordistance. - Instruction Generation: It iterates through the path segments, detecting road name changes to generate "Turn left onto..." or "Travel along..." instructions.