Rail Station Finder is a small Python/Flask application that uses the Bulma CSS framework and Leaflet maps in the front end. The front end is built with vanilla JavaScript, so no build step is required :)
This is the demo application to accompany the Head in the Corner video on YouTube.
The application is based on the new GEOSEARCH
command introduced for the first time in Redis 6.2. For more information, check out its documentation at redis.io.
This application demonstrates how to use GEOSEARCH
as a replacement for the GEORADIUS
command, and how to use the new box search functionality.
Want more Redis content? Subscribe to our YouTube channel for regular uploads!
You can run both the Flask application and Redis using Docker Compose:
$ docker-compose up
To load the sample data in this Docker environment, run the following in a second terminal instance:
$ docker-compose exec app python load_stations.py
Then view the application by pointing your browser at http://localhost:5000
.
(If you are using the Docker Compose setup, skip this section).
To run this example, you'll need Docker (for Redis 6.2) and Python 3 to run the Flask backend. First, clone the repo:
$ git clone https://github.com/redis-developer/introducing-the-geosearch-command.git
$ cd introducing-the-geosearch-command
(If you chose to use docker-compose for both services, you are safe to move on).
To start Redis 6.2 (separately from the flask application), you can run:
$ docker-compose up -d redis
This will use port 6379, so if you have another instance of Redis on that port, you'll need to stop that first.
(If you are using Docker Compose, skip this section).
The backend and data loader use Python 3. Create and activate a virtual environment, and install the dependencies:
$ python3 -m venv venv
$ . ./venv/bin/activate
(venv) $ pip install -r requirements.txt
The sample data provided consists of a KML file (stations.kml
) containing 52 rail stations located around the San Francisco Bay area. Load the data using the Python script provided:
(venv) $ python load_stations.py
Loaded 52 stations.
(If you are using Docker Compose, skip this section).
The application is a Python / Flask application that listens on port 5000. Start it as follows:
(venv) $ export FLASK_ENV=development
(venv) $ flask run
* Environment: development
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 202-259-673
Now use your browser to go to http://127.0.0.1:5000/
and you should see a map of the San Francisco Bay area:
The interface allows you to perform radius and box queries. To being either type, first click on the map at the location you want the query to center on. A red marker will appear, and the latitude and longitude fields in the form will populate:
For a radius query:
Results will appear on the map, and you can hover over each station to see its name:
For a box query:
Results appear in the same way as for a radius search: