This project is a comprehensive spatial database solution designed to simplify the process of data collection, comparison, and mapping during market research and analysis. It integrates various geospatial tools into a unified Docker-based workflow.
The system is built on a microservices architecture orchestrated by Docker Compose:
- Database: PostGIS (Spatial Data Storage)
- Backend: Flask (API & Geocoding Service)
- Geospatial Server: GeoServer (WMS/WFS Services)
- Frontend: MapStore (Web GIS Client) & PgAdmin (Database Management)
This system uses Docker and Docker Compose to build and run all services. This ensures easy deployment and migration to any local or cloud environment.
The docker-compose.yml orchestrates the following services:
postgres: PostGIS database service for storing spatial data.- Image:
postgis/postgis:15-3.3 - Port:
5432
- Image:
pgadmin: Web interface for managing the PostgreSQL database.- Port:
5050
- Port:
geocoder_worker: Background service that converts addresses to coordinates using the Amap API.geoserver: Open-source server for sharing geospatial data.- Image:
kartoza/geoserver:2.27.1 - Port:
8080
- Image:
geoserver_setup: One-time script to configure GeoServer on startup.mapstore: Web GIS client for creating, saving, and sharing maps.- Image:
geosolutionsit/mapstore2:latest - Port:
3050
- Image:
geoserver_auto_publish: Tool to automatically publish new PostGIS layers to GeoServer.
-
Install Docker: Ensure Docker and Docker Compose are installed on your system.
-
Clone Repository: Clone this repository and navigate to the project root.
-
Configure API Keys: Create a
.envfile or updatedocker-compose.ymlwith your Amap API Key.- Amap API Key: Get a key from: https://lbs.amap.com/api/webservice/guide/api/georegeo
geocoder_worker: environment: AMAP_KEY: YOUR_API_KEY_HERE
-
Initial Data (Optional): Edit
init-scripts/init.sqlandinit-scripts/comparable_products.csvto customize initial data. -
Run: Build and start the containers.
docker-compose up --build
Once the services are running, access them via your browser:
-
URL:
http://localhost:5050 -
Email:
admin@company.com -
Password:
admin -
Right-click a table -> "View/Edit Data" -> "All Rows".
-
Note: When adding a new entry with an address, the geocoding service runs automatically within 10 seconds.
- URL:
http://localhost:3050/mapstore/ - Username:
admin - Password:
admin
Steps to Add a Layer:
- Create a new map.
- Click
+to add a catalog service. - Select WFS service type.
- Service URL:
http://geoserver:8080/geoserver/wfs - Search and add your layer to the map.
-
Start Services:
docker-compose up --build
-
Stop & Clean:
docker-compose down --volumes --remove-orphans
-
Find all projects within 5000m of project id=1:
SELECT * FROM project_data WHERE ST_DWithin( geom_wgs84::geography, (SELECT geom_wgs84 FROM project_data WHERE id = 1)::geography, 5000 );
-
Calculate distance to target (id=99) and update:
UPDATE project_data SET distance_to_target_km = ST_Distance( geom_wgs84::geography, (SELECT geom_wgs84 FROM project_data WHERE id = 99)::geography ) / 1000;
-
Public Transit Integration: Upload transit data to enable complex spatial queries (e.g., find apartments within 500m of a subway station with rent < X).
-
Efficiency Analysis: Create charts to analyze the correlation between distance to transit and cost efficiency.
-
Travel Time: Extend
geocoder_workerto calculate walking/biking time to the nearest station using the Amap API.
This project demonstrates rigorous handling of complex geospatial data standards:
- Dual Coordinate System Support: The system automatically manages both global WGS-84 (EPSG:4326) and the national standard GCJ-02 (EPSG:4490) coordinate systems.
- Automated Transformation: The geocoding worker integrates a robust conversion algorithm to transform Amap API results (GCJ-02) into WGS-84 for global analysis compatibility while preserving the original national standard coordinates for local compliance and accuracy.
This project is licensed under the GNU Affero General Public License v3.0 (AGPLv3). See the LICENSE file for details.
本项目是一个综合的空间数据库解决方案,旨在简化市场研究和分析过程中的数据收集、比较和地图绘制流程。它将各种地理空间工具集成到一个统一的基于 Docker 的工作流程中。
该系统基于微服务架构,由 Docker Compose 编排:
- 数据库: PostGIS (空间数据存储)
- 后端: Flask (API 及地理编码服务)
- 地理空间服务器: GeoServer (WMS/WFS 服务)
- 前端: MapStore (Web GIS 客户端) & PgAdmin (数据库管理)
该系统使用 Docker 和 Docker Compose 来构建和运行所有服务。这确保了可以轻松部署和迁移到任何本地或云环境。
docker-compose.yml 文件编排了以下服务:
postgres: 用于存储空间数据的 PostGIS 数据库服务。- 镜像:
postgis/postgis:15-3.3 - 端口:
5432
- 镜像:
pgadmin: 用于管理 PostgreSQL 数据库的网页界面。- 端口:
5050
- 端口:
geocoder_worker: 后台服务,使用高德地图 API 将地址转换为地理坐标。geoserver: 用于托管地理空间数据的开源服务器。- 镜像:
kartoza/geoserver:2.27.1 - 端口:
8080
- 镜像:
geoserver_setup: 用于在启动时自动配置 GeoServer 的一次性脚本。mapstore: 用于创建、保存和共享地图的 Web GIS 客户端。- 镜像:
geosolutionsit/mapstore2:latest - 端口:
3050
- 镜像:
geoserver_auto_publish: 自动将新的 PostGIS 图层发布到 GeoServer 的工具服务。
-
安装 Docker:确保您的系统上已安装 Docker 和 Docker Compose。
-
克隆仓库:克隆此代码库并导航到项目根目录。
-
配置 API 密钥:创建
.env文件或更新docker-compose.yml中的高德地图 API 密钥。- 高德地图 API Key: 申请密钥:https://lbs.amap.com/api/webservice/guide/api/georegeo
geocoder_worker: environment: AMAP_KEY: YOUR_API_KEY_HERE
-
初始数据(可选):编辑
init-scripts/init.sql和init-scripts/comparable_products.csv以自定义初始数据。 -
运行:构建并启动容器。
docker-compose up --build
服务运行后,通过浏览器访问:
-
地址:
http://localhost:5050 -
邮箱:
admin@company.com -
密码:
admin -
右键单击表 -> “查看/编辑数据” -> “所有行”。
-
注意:当添加带有地址的新条目时,地理编码服务将在 10 秒内在后台自动运行。
- 地址:
http://localhost:3050/mapstore/ - 用户名:
admin - 密码:
admin
添加图层步骤:
- 创建一个新地图。
- 点击
+号添加目录服务。 - 选择 WFS 服务类型。
- 服务地址:
http://geoserver:8080/geoserver/wfs - 搜索并将图层添加到地图。
-
启动服务:
docker-compose up --build
-
停止并清理:
docker-compose down --volumes --remove-orphans
-
选择 id=1 项目附近 5000m 的所有项目:
SELECT * FROM project_data WHERE ST_DWithin( geom_wgs84::geography, (SELECT geom_wgs84 FROM project_data WHERE id = 1)::geography, 5000 );
-
计算所有项目到项目 id=99 的直线距离并更新字段:
UPDATE project_data SET distance_to_target_km = ST_Distance( geom_wgs84::geography, (SELECT geom_wgs84 FROM project_data WHERE id = 99)::geography ) / 1000;
-
公共交通集成:上传公交或地铁数据,进行复杂的空间查询(如:查找距离地铁站 500m 内且租金低于 X 的房源)。
-
坪效分析:创建图表分析距离与坪效(sqm efficiency)的相关性。
-
出行时间计算:扩展
geocoder_worker,利用高德 API 计算步行或骑行到最近地铁站的时间。
本项目展示了对复杂地理空间数据标准的严谨处理能力:
-
双坐标系支持:系统自动管理全球通用的 WGS-84 (EPSG:4326) 和国家标准 GCJ-02 (EPSG:4490) 两种坐标系。
-
自动转换与合规:地理编码服务集成了转换算法,将高德地图 API 返回的火星坐标 (GCJ-02) 转换为 WGS-84 以进行通用空间分析,同时保留原始国家标准坐标,确保数据在本地应用中的精确性与合规性。
本项目采用 GNU Affero General Public License v3.0 (AGPLv3) 许可证。详情请参阅 LICENSE 文件。