PostGIS实现聚类分析-ST_ClusterDBSCAN

摘要:简要介绍了聚类的一些概念原理,介绍了Postgis相关聚类函数,详细介绍了ST_ClusterDBSCAN 的使用,并以河南省POI数据为例做了相关实验分析。其实主要就是看官网文档,再结合实际的需求应用,详细内容参见公众号。

 

http://mp.weixin.qq.com/s?__biz=MzI2NTU5NTk5NA==&mid=100000076&idx=1&sn=a5b066ce7a02f611a0b9cd827ee3e6e2&chksm=6a9bbc795dec356f9746a43c667c5fda48675cdb34a0ba1722c2ab9d1a704f3d107e4565a6bb#rd

 

推荐下公众号,后续主要更新开源GIS相关知识技能,包括PostgreSQL、PostGIS、Geoserver等,欢迎关注学习交流:)

[root@iZbp1avc1olq9krqsni6tuZ postgres]# sudo yum install -y postgis35_15 Last metadata expiration check: 2:13:26 ago on Mon 23 Jun 2025 11:07:10 AM CST. Error: Problem: cannot install the best candidate for the job - nothing provides geos313 >= 3.13.0 needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides gdal310-libs >= 3.10.0 needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides proj95 >= 9.5.1 needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides libjson-c.so.5()(64bit) needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides libgeos_c.so.1()(64bit) needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides libproj.so.25()(64bit) needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides libstdc++.so.6(GLIBCXX_3.4.29)(64bit) needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides libjson-c.so.5(JSONC_0.14)(64bit) needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides hdf5 needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides libSFCGAL.so.2()(64bit) needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides xerces-c needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides libgeotiff17 needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides libgdal.so.36()(64bit) needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 (try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
最新发布
06-24
<think>我们已经在阿里云Linux3系统上安装了PostgreSQL15,现在需要安装PostGIS3.5.2扩展。根据引用[1]中的步骤,我们需要从源码编译安装PostGIS。但是,在编译过程中可能会遇到依赖问题(如缺少geos、gdal、proj等)。以下步骤将指导你解决这些依赖问题并成功安装PostGIS。###步骤1:安装编译工具和基础依赖```bashsudoyumgroupinstall"DevelopmentTools"sudoyuminstallwgetunzip```###步骤2:安装PostGIS所需依赖库根据引用[1]和引用[3],我们需要安装以下依赖库:-GEOS(GeometryEngine-OpenSource)-PROJ(坐标投影库)-GDAL(GeospatialDataAbstractionLibrary)-JSON-C-libxml2-protobuf(可选,但PostGIS某些功能需要)####2.1安装GEOS```bash#下载GEOS(注意:PostGIS3.5.2要求GEOS>=3.6,这里安装3.13)wgethttps://download.osgeo.org/geos/geos-3.13.0.tar.bz2tar-xvfgeos-3.13.0.tar.bz2cdgeos-3.13.0./configure--prefix=/usr/localmake-j$(nproc)sudomakeinstall```####2.2安装PROJ```bash#安装PROJ(注意:PostGIS3.5.2要求PROJ>=6.1,这里安装9.5)wgethttps://download.osgeo.org/proj/proj-9.5.0.tar.gztar-xvfproj-9.5.0.tar.gzcdproj-9.5.0./configure--prefix=/usr/localmake-j$(nproc)sudomakeinstall```####2.3安装GDAL```bash#安装GDAL(注意:PostGIS3.5.2要求GDAL>=2.4,这里安装3.10.0)wgethttps://download.osgeo.org/gdal/3.10.0/gdal-3.10.0.tar.gztar-xvfgdal-3.10.0.tar.gzcdgdal-3.10.0./configure--prefix=/usr/localmake-j$(nproc)sudomakeinstall```####2.4安装JSON-C```bashwgethttps://s3.amazonaws.com/json-c_releases/releases/json-c-0.17.tar.gztar-xvfjson-c-0.17.tar.gzcdjson-c-0.17./configure--prefix=/usr/localmakesudomakeinstall```####2.5安装libxml2```bash#下载libxml2(注意版本)wgethttp://xmlsoft.org/sources/libxml2-2.9.12.tar.gztar-xvflibxml2-2.9.12.tar.gzcdlibxml2-2.9.12./configure--prefix=/usr/localmakesudomakeinstall```####2.6安装protobuf-c(如果需要)```bashwgethttps://github.com/protocolbuffers/protobuf/releases/download/v3.15.8/protobuf-cpp-3.15.8.tar.gztar-xvfprotobuf-cpp-3.15.8.tar.gzcdprotobuf-3.15.8./configure--prefix=/usr/localmakesudomakeinstall```###步骤3:配置动态链接库路径```bash#更新动态链接库缓存sudoldconfig```###步骤4:编译安装PostGIS3.5.2```bashwgethttps://download.osgeo.org/postgis/source/postgis-3.5.2.tar.gztar-zxvfpostgis-3.5.2.tar.gzcdpostgis-3.5.2#配置(注意:根据你的PostgreSQL安装路径调整pg_config路径,通常为/usr/pgsql-15/bin/pg_config)./configure\--with-pgconfig=/usr/pgsql-15/bin/pg_config\--with-geosconfig=/usr/local/bin/geos-config\--with-projdir=/usr/local\--with-gdalconfig=/usr/local/bin/gdal-config\--with-jsondir=/usr/local\--with-xml2config=/usr/local/bin/xml2-config\--with-protobufdir=/usr/local#编译并安装makesudomakeinstall```###步骤5:在PostgreSQL中启用PostGIS扩展```bash#切换到postgres用户sudo-iupostgres#连接到你的数据库psql-dyour_database#在数据库内执行CREATEEXTENSIONpostgis;CREATEEXTENSIONpostgis_topology;--可选```###步骤6:验证安装```sqlSELECTPostGIS_Version();```###常见问题解决1.**configure:error:couldnotfindgeos-config**确保GEOS已正确安装,且`geos-config`位于`/usr/local/bin`(或安装路径)并已加入`PATH`。2.**动态库加载失败**运行`sudoldconfig`更新动态链接库缓存。3.**权限问题**如引用[3]所述,如果`makeinstall`时权限不足,可使用`sudo`执行,然后调整目录所有者:```bashsudomakeinstall#假设安装到/usr/local,通常不需要调整,如果安装到其他目录可能需要调整#chown-Rpostgres:postgres/path/to/installation```###相关问题1.如何在PostgreSQL中管理PostGIS扩展的版本升级?2.如何优化PostGIS的空间查询性能?3.在阿里云环境中如何配置PostGIS的高可用架构?4.如何将Shapefile数据导入PostGIS数据库?[^1]:PostGIS官方安装文档[^2]:PostgreSQLRPM仓库的版本命名规范[^3]:阿里云环境下的PostgreSQL服务管理指南</think>### 解决阿里云 Linux3 系统安装 PostGIS 3.5.2 的依赖问题 在阿里云 Linux3 系统上编译安装 PostGIS 3.5.2 for PostgreSQL 15 时,缺少 `geos313`、`gdal310-libs`、`proj95` 等依赖的问题可通过以下步骤解决: --- #### **1. 安装基础编译工具** ```bash sudo yum groupinstall "Development Tools" sudo yum install epel-release wget unzip ``` --- #### **2. 手动编译安装依赖库** > **核心思路**:PostGIS 依赖的空间库需手动编译安装,阿里云官方仓库可能不包含最新版本。 ##### **(1) 安装 GEOS 3.13** ```bash wget https://download.osgeo.org/geos/geos-3.13.0.tar.bz2 tar -xvf geos-3.13.0.tar.bz2 cd geos-3.13.0 ./configure --prefix=/usr/local make -j $(nproc) sudo make install ``` ##### **(2) 安装 PROJ 9.5** ```bash wget https://download.osgeo.org/proj/proj-9.5.0.tar.gz tar -xvf proj-9.5.0.tar.gz cd proj-9.5.0 ./configure --prefix=/usr/local make -j $(nproc) sudo make install ``` ##### **(3) 安装 GDAL 3.10** ```bash wget https://download.osgeo.org/gdal/3.10.0/gdal-3.10.0.tar.gz tar -xvf gdal-3.10.0.tar.gz cd gdal-3.10.0 ./configure --prefix=/usr/local make -j $(nproc) sudo make install ``` ##### **(4) 安装 JSON-C** ```bash wget https://s3.amazonaws.com/json-c_releases/releases/json-c-0.17.tar.gz tar -xvf json-c-0.17.tar.gz cd json-c-0.17 ./configure --prefix=/usr/local make sudo make install ``` --- #### **3. 配置动态链接库** ```bash # 更新库路径 echo "/usr/local/lib" | sudo tee /etc/ld.so.conf.d/local.conf sudo ldconfig # 验证路径 ldconfig -p | grep -E 'geos|proj|gdal' ``` --- #### **4. 编译安装 PostGIS 3.5.2** ```bash wget https://download.osgeo.org/postgis/source/postgis-3.5.2.tar.gz tar -zxvf postgis-3.5.2.tar.gz cd postgis-3.5.2 # 关键配置(路径需匹配实际安装位置) ./configure \ --with-pgconfig=/usr/pgsql-15/bin/pg_config \ --with-geosconfig=/usr/local/bin/geos-config \ --with-projdir=/usr/local \ --with-gdalconfig=/usr/local/bin/gdal-config \ --with-jsondir=/usr/local \ LDFLAGS="-L/usr/local/lib" \ CPPFLAGS="-I/usr/local/include" make sudo make install ``` --- #### **5. 在 PostgreSQL 中启用扩展** ```bash sudo -iu postgres psql -d your_database # 执行SQL命令 CREATE EXTENSION postgis; SELECT PostGIS_Version(); -- 验证输出应为 "3.5.2" ``` --- #### **故障排除** - **`configure` 报错 "library not found"** 检查 `LDFLAGS` 和 `CPPFLAGS` 路径是否包含 `/usr/local/lib` 和 `/usr/local/include`。 - **`make install` 权限不足** 使用 `sudo` 执行,或参考引用[3]调整目录权限: ```bash sudo chown -R postgres:postgres /usr/pgsql-15/share/extension/ ``` - **运行时加载失败** 确保 PostgreSQL 服务重启前执行 `sudo ldconfig`。 --- #### **验证依赖关系** ```bash # 检查动态库链接 ldd /usr/pgsql-15/lib/postgis-3.so | grep -E 'geos|proj|gdal' # 预期输出示例 libgeos_c.so.1 => /usr/local/lib/libgeos_c.so.1 libproj.so.25 => /usr/local/lib/libproj.so.25 libgdal.so.32 => /usr/local/lib/libgdal.so.32 ``` --- ### **相关问题** 1. 如何在已运行的 PostgreSQL 15 实例中安全升级 PostGIS 版本? 2. PostGIS 空间索引的类型和优化方法有哪些? 3. 如何将 Shapefile 数据高效导入 PostGIS 数据库? 4. 阿里云环境中如何监控 PostGIS 的空间查询性能? > 引用说明: > 依赖库编译步骤参考了 GIS 库的标准安装流程[^1],权限调整方法借鉴了信创云环境中的实践[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

gerrywhu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值