Coder Social home page Coder Social logo

phanvantrong / nairobi-busstops Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jkariscodes/nairobi-busstops

0.0 0.0 0.0 3.63 MB

Web GIS application demonstrating the use of various libraries and frameworks in showin bus stops in Nairobi Central Business District

License: GNU General Public License v3.0

JavaScript 81.49% Python 0.84% CSS 17.51% HTML 0.12% Dockerfile 0.03%

nairobi-busstops's Introduction

Nairobi Bus Stops WebMap

image

A simple Web GIS application developed in Django and Leaflet. This app renders bus stops from the database and parses them into GeoJSON which are then displayed in the web map.

Requirements

  1. Python - https://www.python.org/downloads/
  2. PostgreSQL - https://www.postgresql.org/download/
  3. PostGIS - https://postgis.net/install/
  4. Docker (optional but fast to deploy). - https://docs.docker.com/get-docker/

Dependencies include:

  • Django - Python web framework used to serve the data stored in database in a web page.
  • Psycopg2 - Python-based database adapter used to connect and support database operations
  • Whitenoise - Third-party library that supports serving of static files in Django-based apps.

Cloning the Repository

Clone the repository

git clone https://github.com/jkariukidev/djangoleaflet.git

cd djangoleaflet

Install python packages using pip

pip install -r requirements.txt

Configuring Django Project

python manage.py runserver

makemigrations into your database (PostgreSQL with PostGIS used)

python manage.py migrate

Create admin user

python manage.py createsuperuser

Adding Models from Dataset

If using different dataset with a different model. The mapping in models.py has to be changed.

python manage.py shell

    from onyeshamap import loadbusstops

    loadbusstops.run()

    exit()

Run the development server.

python manage.py runserver

Raw JSON data can be viewed at http://localhost:8000/data

Map can be viewed at http://localhost:8000

Docker Deployment

Environment variables

After cloning the project and assuming docker is installed, create and environment variable file. A sample .env file has been provided here. It contains:

  • ENVIRONMENT - Variable referring to the environment of running this project, whether development or production. The default in settings.py is production but can be changed. Note that development is for testing purpose.
  • SECRET_KEY - Django cryptographic signing key created when one creates a Django project. Refer documentation for details.
  • DEBUG - Boolean variable that if set TRUE or 1 shows detialed error if encountered and important during development otherwise in a production environment it should striclty be set to False or 0. More reference here.
  • POSTGRES_DB - The default database produced when the image is first started might have a different name defined using this optional environment variable. If it is not supplied, POSTGRES USER's value will be applied.
  • POSTGRES_USER - In order to set a user and password, you can use this optional environment variable along with POSTGRES PASSWORD. This variable will create a database with the same name and grant superuser privileges to the specified user. The Postgres default user will be used if it is not given.
  • POSTGRES_PASSWORD - You must have this environment variable set in order to utilize the PostgreSQL image. It cannot be blank or undefinable. For PostgreSQL, this environment variable controls the superuser password. The POSTGRES USER environment setting specifies the superuser by default.
  • POSTGRES_PORT - Explicit TCP port number for the PostgreSQL/PostGIS database.
  • POSTGRES_HOST - The hostname or IP of the database however, it is set to the name of the container running the database service.

For more on PostgreSQL variables, refer to PostgreSQL on Docker.

Starting Services

There are two services in this project under docker. They include Web and Database services.

Web service

Consists of the initially created Django project and applications that are coded in this project. This service is dependent on the database service. It is defined in the docker configuration.

Database service

This service manages a PostGIS instance which is a PostgreSQL container having PostGIS extension installed to facilitate handling of spatial/GIS/location data. It is defined in the docker configuration.

Run docker-compose up -d to run build and start the containers. The -d switch instructs docker to run the oontainers in 'detached' mode i.e. in the background such that you can use terminal or shell to do other things. You can make use of Docker Desktop which has a user-friendly dashboard showing containers, images, volumes and their statuses among other things. A screenshot of the dashboard is as shown below.

Stopping Services

To gracefully stop the services, one can make use of the Docker Desktop or alternatively run the folloing command while in project directory. docker compose down and if one wants to remove the persisted data (volumes) run docker compose down -v

Heroku Deployment

This project makes use of heroku YAML file for deployment synonymous to docker. Please refer to Heroku documentation for more details.

Questions

Contact me via:

References

nairobi-busstops's People

Contributors

dependabot[bot] avatar jkaris avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.