-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add examples/geospatial-python-urban-analysis-with-postgis project
- Loading branch information
Showing
72 changed files
with
14,545 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
examples/geospatial-python-urban-analysis-with-postgis/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Base image with Python | ||
FROM python:3.12 | ||
|
||
# Set the working directory | ||
WORKDIR /app | ||
|
||
# Install dependencies | ||
RUN apt-get update && apt-get install -y \ | ||
libgdal-dev \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Install Python dependencies | ||
COPY requirements.txt . | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
# Copy the script | ||
COPY transport.py . | ||
|
||
# Run the script when the container starts | ||
CMD ["python", "transport.py"] |
139 changes: 139 additions & 0 deletions
139
examples/geospatial-python-urban-analysis-with-postgis/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
# 🌍 Geospatial Urban Analysis Project | ||
|
||
## 📌 Overview | ||
|
||
This project focuses on **geospatial data analysis** for urban environments, particularly analyzing **pedestrian zones, transportation networks, census data, and geographic boundaries**. The dataset includes **shapefiles, GeoJSON, Parquet, and raster files**, allowing advanced **spatial processing and visualization**. | ||
|
||
The project uses **PostgreSQL with PostGIS**, **Docker**, and **GeoPandas**, enabling **efficient spatial queries, ETL pipelines, and geospatial machine learning models**. | ||
|
||
### ✨ **Key Features** | ||
|
||
- 🏙 **Urban Infrastructure Analysis**: Analyzes bike paths, subway entrances, and school locations. | ||
- 📊 **Geospatial Data Processing**: Supports various spatial formats (Shapefile, GeoJSON, Parquet, Raster). | ||
- 🔄 **ETL Pipelines**: Extract, transform, and load urban data into **PostGIS**. | ||
- 🤖 **Geospatial Machine Learning**: Clustering models to optimize urban planning decisions. | ||
- 🗺 **Interactive Mapping**: Generates visualizations using **Folium and Matplotlib**. | ||
|
||
--- | ||
|
||
## 🛠 **Requirements** | ||
|
||
Before running the project, ensure you have the following dependencies installed: | ||
|
||
### 💻 **System Requirements** | ||
|
||
- 🐳 **Docker** (for PostgreSQL with PostGIS) | ||
- 🐍 **Python 3.8+** | ||
|
||
### 📦 **Python Dependencies** | ||
|
||
All required Python libraries are listed in `requirements.txt`. Install them using: | ||
|
||
```sh | ||
pip install -r requirements.txt | ||
``` | ||
|
||
Main dependencies: | ||
|
||
- 🌍 **GeoPandas**: Geospatial data processing. | ||
- 🗄 **PostgreSQL & PostGIS**: Geospatial database support. | ||
- 📈 **Matplotlib & Folium**: Data visualization. | ||
- 🤖 **Scikit-learn**: Clustering and machine learning models. | ||
|
||
--- | ||
|
||
## 🚀 **Setup & Installation** | ||
|
||
### 📂 **1. Clone the Repository** | ||
|
||
```sh | ||
git clone [email protected]:nanlabs/backend-reference.git | ||
cd examples/geospatial-python-urban-analysis-with-postgis | ||
``` | ||
|
||
### 🏗 **2. Set Up a Virtual Environment** | ||
|
||
Create and activate a Python virtual environment: | ||
|
||
```sh | ||
python -m venv env | ||
source env/bin/activate # On macOS/Linux | ||
env\Scripts\activate # On Windows | ||
``` | ||
|
||
Once activated, install dependencies: | ||
|
||
```sh | ||
pip install -r requirements.txt | ||
``` | ||
|
||
### 🐳 **3. Set Up Docker with PostgreSQL and PostGIS** | ||
|
||
Ensure that **Docker** is installed and running. Then, start the database with: | ||
|
||
```sh | ||
docker-compose up -d | ||
``` | ||
|
||
This will: | ||
|
||
- 🛢 Start a **PostgreSQL database** with **PostGIS** extensions enabled. | ||
- 📌 Create the necessary **database schema** for storing geospatial data. | ||
|
||
## 📖 **Working with Notebooks** | ||
|
||
To start the analysis and visualization: | ||
|
||
```sh | ||
jupyter notebook | ||
``` | ||
|
||
Then, open one of the notebooks in the `notebooks/` directory. | ||
|
||
The notebooks cover: | ||
|
||
- 🌍 **Geospatial Data Exploration**: Loading and visualizing spatial datasets. | ||
- 🚇 **Urban Accessibility Analysis**: Assessing accessibility of public transport. | ||
- 🤖 **Clustering and Machine Learning**: Applying spatial clustering algorithms. | ||
|
||
|
||
### 📌 **Pipelines Overview** | ||
The project includes **several geospatial data processing pipelines**, located in `src/pipelines/`: | ||
|
||
- 🚌 **`bus_stop_analysis.py`**: Analyzes bus stops and their spatial distribution. | ||
- 📍 **`optimal_stop_pipeline.py`**: Computes the best locations for public transportation stops. | ||
- 🗺 **`shapefile_to_raster.py`**: Converts vector-based shapefiles into raster format for GIS applications. | ||
|
||
### ⚙️ **Running Pipelines** | ||
To execute a pipeline, use the following command: | ||
|
||
```sh | ||
PYTHON=. python -m src.pipelines.bus_stop_analysis | ||
``` | ||
|
||
Replace `bus_stop_analysis` with the pipeline you want to run. | ||
|
||
Each pipeline processes geospatial data **efficiently**, ensuring the data is ready for **urban planning and visualization**. | ||
|
||
--- | ||
|
||
## 🏗 **Project Structure** | ||
|
||
```sh | ||
. | ||
├── Dockerfile # 🐳 Docker configuration for Python environment | ||
├── docker-compose.yml # 🛢 PostgreSQL + PostGIS setup | ||
├── requirements.txt # 📦 Python dependencies | ||
├── config.py # ⚙️ Configuration settings | ||
├── data/ # 🌍 Raw geospatial datasets | ||
├── notebooks/ # 📖 Jupyter Notebooks for geospatial analysis | ||
├── scripts/ # 🔄 Data processing scripts | ||
├── src/ # 🏗 Source code | ||
│ ├── database/ # 🗄 Database connection and queries | ||
│ ├── etl/ # 🔄 ETL pipeline for spatial data | ||
│ ├── ml/ # 🤖 Machine learning models for clustering | ||
│ ├── pipelines/ # 📌 Spatial data processing workflows | ||
│ ├── visualization/ # 🗺 Map and data visualization modules | ||
``` | ||
|
||
--- |
4 changes: 4 additions & 0 deletions
4
examples/geospatial-python-urban-analysis-with-postgis/config.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
DB_CONNECTION = "postgresql://user:password@host:port/dbname" | ||
POPULATION_DENSITY_RASTER = "data/population_density.tif" | ||
DISTRICTS_URL = "https://cdn.buenosaires.gob.ar/datosabiertos/datasets/ministerio-de-educacion/comunas/comunas.geojson" | ||
EPSG_TARGET = 3857 # Standard coordinate reference system (CRS) |
1 change: 1 addition & 0 deletions
1
...ian Zone Shapefile (Tabular)_20241220/geo_export_a7bb075a-41dc-445f-8244-8430e90a8dde.cpg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
UTF-8 |
Binary file added
BIN
+21 MB
...ian Zone Shapefile (Tabular)_20241220/geo_export_a7bb075a-41dc-445f-8244-8430e90a8dde.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions
1
...ian Zone Shapefile (Tabular)_20241220/geo_export_a7bb075a-41dc-445f-8244-8430e90a8dde.prj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GEOGCS["WGS84(DD)", DATUM["WGS84", SPHEROID["WGS84", 6378137.0, 298.257223563]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH], AUTHORITY["EPSG","4326"]] |
Binary file added
BIN
+3 MB
...ian Zone Shapefile (Tabular)_20241220/geo_export_a7bb075a-41dc-445f-8244-8430e90a8dde.shp
Binary file not shown.
Binary file added
BIN
+80.7 KB
...ian Zone Shapefile (Tabular)_20241220/geo_export_a7bb075a-41dc-445f-8244-8430e90a8dde.shx
Binary file not shown.
1 change: 1 addition & 0 deletions
1
...ian Zone Shapefile (Tabular)_20250127/geo_export_8aa884d0-7056-4b1e-94ff-62eb7b00d65c.cpg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
UTF-8 |
Binary file added
BIN
+21 MB
...ian Zone Shapefile (Tabular)_20250127/geo_export_8aa884d0-7056-4b1e-94ff-62eb7b00d65c.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions
1
...ian Zone Shapefile (Tabular)_20250127/geo_export_8aa884d0-7056-4b1e-94ff-62eb7b00d65c.prj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GEOGCS["WGS84(DD)", DATUM["WGS84", SPHEROID["WGS84", 6378137.0, 298.257223563]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH], AUTHORITY["EPSG","4326"]] |
Binary file added
BIN
+3 MB
...ian Zone Shapefile (Tabular)_20250127/geo_export_8aa884d0-7056-4b1e-94ff-62eb7b00d65c.shp
Binary file not shown.
Binary file added
BIN
+80.7 KB
...ian Zone Shapefile (Tabular)_20250127/geo_export_8aa884d0-7056-4b1e-94ff-62eb7b00d65c.shx
Binary file not shown.
Binary file added
BIN
+379 KB
examples/geospatial-python-urban-analysis-with-postgis/data/census/caba/cabaxrdatos.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions
1
examples/geospatial-python-urban-analysis-with-postgis/data/census/caba/cabaxrdatos.prj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PROJCS["POSGAR_94_Argentina_3",GEOGCS["GCS_POSGAR 94",DATUM["D_POSGAR_1994",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",-90],PARAMETER["central_meridian",-66],PARAMETER["scale_factor",1],PARAMETER["false_easting",3500000],PARAMETER["false_northing",0],UNIT["Meter",1]] |
1 change: 1 addition & 0 deletions
1
examples/geospatial-python-urban-analysis-with-postgis/data/census/caba/cabaxrdatos.qpj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PROJCS["POSGAR 94 / Argentina 3",GEOGCS["POSGAR 94",DATUM["Posiciones_Geodesicas_Argentinas_1994",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6694"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4694"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",-90],PARAMETER["central_meridian",-66],PARAMETER["scale_factor",1],PARAMETER["false_easting",3500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","22183"]] |
Binary file added
BIN
+1.13 MB
examples/geospatial-python-urban-analysis-with-postgis/data/census/caba/cabaxrdatos.shp
Binary file not shown.
Binary file added
BIN
+27.9 KB
examples/geospatial-python-urban-analysis-with-postgis/data/census/caba/cabaxrdatos.shx
Binary file not shown.
Binary file added
BIN
+205 KB
examples/geospatial-python-urban-analysis-with-postgis/data/census/caba/census.tif
Binary file not shown.
Oops, something went wrong.