Configs2026年7月18日·1 分钟阅读

PostGIS — Spatial Database Extension for PostgreSQL

Adds geographic object support to PostgreSQL, enabling location-aware queries with SQL and making Postgres a full spatial database.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
PostGIS Spatial Extension
直接安装命令
npx -y tokrepo@latest install 7377ba60-82e9-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

PostGIS is an extension that turns PostgreSQL into a spatial database capable of storing, indexing, and querying geographic data. It implements the OGC Simple Features specification and adds hundreds of spatial functions, making it possible to perform complex GIS operations entirely within SQL.

What PostGIS Does

  • Stores point, line, polygon, and raster geometry data types in PostgreSQL
  • Provides 300+ spatial functions for analysis, measurement, and transformation
  • Enables spatial indexing via GiST for fast geographic queries
  • Supports coordinate system transformations between 6000+ projections
  • Handles 3D geometries, topology, and geocoding

Architecture Overview

PostGIS installs as a PostgreSQL extension that registers custom data types (geometry, geography, raster) and operators. Spatial indexing uses GiST (Generalized Search Tree) indexes that store bounding boxes for efficient spatial filtering. The extension links against GEOS for geometry operations, PROJ for coordinate transformations, and GDAL for raster format support.

Self-Hosting & Configuration

  • Install via system packages: apt install postgresql-16-postgis-3
  • Enable per-database: CREATE EXTENSION postgis;
  • Add raster support: CREATE EXTENSION postgis_raster;
  • Configure shared_preload_libraries for raster out-db access
  • Use official Docker images with PostGIS pre-installed

Key Features

  • Spatial indexing with R-tree via GiST for sub-millisecond queries
  • Geography type for accurate calculations on the spheroid
  • Raster analysis for satellite imagery and elevation data
  • Network routing support via pgRouting extension
  • Integration with every major GIS tool (QGIS, GeoServer, GDAL)

Comparison with Similar Tools

  • SpatiaLite — SQLite-based spatial DB; PostGIS offers better concurrency and indexing
  • MongoDB Geospatial — Document-based with basic geo queries; PostGIS has richer spatial functions
  • H3 (Uber) — Hexagonal grid indexing system; PostGIS is a full spatial database
  • Tile38 — In-memory geospatial DB for real-time; PostGIS for persistent analytical workloads

FAQ

Q: What is the difference between geometry and geography types? A: Geometry uses planar coordinates (faster math). Geography uses spheroidal coordinates (accurate for large distances). Use geography for global data, geometry for local projections.

Q: How do I import shapefiles into PostGIS? A: Use shp2pgsql (bundled) or ogr2ogr (from GDAL): ogr2ogr -f PostgreSQL PG:dbname=mydb shapefile.shp

Q: Does PostGIS support GeoJSON? A: Yes. Use ST_AsGeoJSON() to export and ST_GeomFromGeoJSON() to import geometries in GeoJSON format.

Q: How large can PostGIS datasets be? A: PostGIS inherits PostgreSQL limits. Tables with hundreds of millions of geometries are common in production when properly indexed.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产