1. Guide to Backend and Database Setup for GeoBee Dashboard Development
This article serves as a comprehensive guide for setting up the backend and database for the GeoBee Dashboard, which is focused on geospatial analysis for waste collection in Tangerang City. We’ll cover how to install and configure PostGIS, set up the Python environment, and implement the workflow for uploading shapefiles and raster data.
1. Setting Up and Installing PostGIS
PostGIS is an essential extension for PostgreSQL that adds support for geographic objects, enabling us to store and query spatial data. Here’s how to install and enable PostGIS and the PostGIS Raster extension:
Step 1: Install PostgreSQL and PostGIS
- Install PostgreSQL:
- Depending on your operating system, follow the instructions to install PostgreSQL from the official PostgreSQL website.
- Install PostGIS:
- Once PostgreSQL is installed, you can install PostGIS from stack builder, guide in this video below: https://youtu.be/yt17xL_Q8No?si=lmKlIbgtJBC85PPu
Step 2: Enable PostGIS and PostGIS Raster Extension
- Connect to PostgreSQL:
- Access the PostgreSQL prompt:
bash
sudo -u postgres psql
- Access the PostgreSQL prompt:
- Create a new database (if not already created):
CREATE DATABASE your_db_name;
- Enable PostGIS in your database:
\c your_db_name
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_raster;- This will enable the spatial features and raster support in your database.
Step 3: Verify Installation
- Verify that the extensions are installed by running:
sql
\dx
- You should see
postgis
andpostgis_raster
listed.
- You should see
2. Setting Up the Python Environment
To get the backend running, we’ll set up a Python environment that includes all the necessary dependencies for the GeoBee Dashboard.
Step 1: Clone the Project Repository
- Clone the GitHub Repository:
git clone https://github.com/syauqiakm/geobee-dashboard.git
cd geobee-dashboard/Backend
Step 2: Set Up a Python Virtual Environment
- Create a Virtual Environment:
python3 -m venv venv
- Activate the Virtual Environment:
- On Linux/Mac:
source venv/bin/activate
- On Windows:
.\venv\Scripts\activate
- On Linux/Mac:
Step 3: Install Dependencies
- Install Required Packages:
- Assuming the project has a
requirements.txt
file, install the dependencies:pip install -r requirements.txt
- If there’s no
requirements.txt
, manually install the key packages:pip install fastapi uvicorn sqlalchemy psycopg2-binary geoalchemy2 shapely
- Assuming the project has a
Step 4: Test the Environment Setup
- Run the Application:
- Start the FastAPI server to ensure everything is configured properly:
uvicorn main:app --reload
- Start the FastAPI server to ensure everything is configured properly:
- Access the API:
- Open your browser and navigate to
http://127.0.0.1:8000/docs
to see the interactive API documentation.
- Open your browser and navigate to
3. Shapefile and Raster Feature Workflow
Understanding the workflow for handling shapefiles and raster data is crucial for smooth operation in the GeoBee Dashboard. The process involves multiple steps from the frontend to the backend and back to the frontend. Below is an illustration to help you visualize the workflow:
Workflow Overview
[Placeholder Image – Insert actual image link]
- Upload from Frontend:
- Users upload shapefiles or raster data through the GeoBee Dashboard interface.
- Backend Processing:
- The backend receives the files, converts them into database-compatible formats, and stores the data in PostGIS.
- Data Retrieval:
- The frontend requests the processed data from the backend, which then queries the PostGIS database.
- Display on Frontend:
- The frontend renders the retrieved data, displaying maps, layers, or other geospatial visualizations.
This simplified workflow helps users understand how geospatial data moves through the system, ensuring that each component works harmoniously.
Conclusion
With PostGIS set up, the Python environment configured, and a clear understanding of the shapefile and raster workflow, your GeoBee Dashboard is well-prepared for effective geospatial analysis. This setup will enable efficient storage, processing, and visualization of spatial data, empowering decision-making for waste management in Tangerang City.