This guide sets up a Python environment for working with, analyzing, and visualizing spatial data using PostgreSQL with PostGIS and Folium for interactive mapping.
Start by cloning the project repository to your local machine:
git clone https://github.com/Mannerow/ds-env-setup.git
cd ds-env-setup
Create a virtual environment using Python 3.12:
py -3.12 -m venv venv
source venv/Scripts/activate
You’ll know the environment is active when your terminal prompt changes to something like:
(venv) user@machine ~/project
Upgrade pip to ensure you have the latest version:
python -m pip install --upgrade pip
Install all project dependencies listed in requirements.txt:
python -m pip install -r requirements.txt
- Download PostgreSQL from the official website: PostgreSQL Downloads.
- Follow the installation instructions for your operating system:
- During installation, ensure that you also install the Stack Builder tool.
- Open the PostgreSQL client (pgAdmin).
- Connect to your database and enable PostGIS:
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
- Verify postgis version:
SELECT postgis_full_version();
.env File Example:
DB_USER=your_username
DB_PASSWORD=your_password
DB_HOST=localhost
DB_PORT=5432
DB_NAME=your_database_name
Run the script to test the database connection:
python pgconnect.py
If the connection is successful, you’ll see the output:
Connected to the database successfully!
SQLAlchemy engine created successfully!
python folium_map.py
The script will generate an HTML file named map.html in your project directory. You should see the following output:
Map has been saved to map.html
Option 1: Double-click the map.html file.