[安装和使用记录] postgis + postgresql

[安装和使用记录] postgis + postgresql,第1张

[安装和使用记录] postgis + postgresql

文章目录
  • 0 追本溯源
    • 为什么函数名前缀为ST_?
    • 空间几何函数有哪些
  • 1 安装问题
    • 1.1 版本一定要匹配
    • 1.2 先安装postgresql再安装postgis
      • Q1 spatial database creation failed
      • Q2 create database 失败
  • 2 使用问题
    • 2.1 导入shp文件
      • Q1 无法启动postgis gui文件
      • Q2 导入shp失败
      • Q3 注意事项
      • Q4 PostGIS的SRID更新方法
  • 3 最后
  • 4 参考文章

0 追本溯源 为什么函数名前缀为ST_?

官方说明
ST = Spatial Type
以ST_前缀开头的空间几何函数支持SQL/MM标准并符合开放地理空间联盟 (OGC) 的OpenGIS规范。

PostGIS has begun a transition from the existing naming convention to an SQL-MM-centric convention. As a result, most of the functions that you know and love have been renamed using the standard spatial type (ST) prefix. Previous functions are still available, though are not listed in this document where updated functions are equivalent. The non ST_ functions not listed in this documentation are deprecated and will be removed in a future release so STOP USING THEM.

机翻:
PostGIS已经开始从现有的命名约定向以sql - mm为中心的命名约定过渡。
因此,您所熟悉和喜爱的大多数函数都使用标准空间类型(ST)前缀重新命名。
以前的函数仍然可用,但是在更新后的函数是等价的情况下,本文档没有列出。
本文档中未列出的非ST_函数已弃用,并将在未来的版本中删除,因此停止使用它们。

空间几何函数有哪些

中文版本 https://help.aliyun.com/document_detail/67927.html
英文版本 https://postgis.net/docs/reference.html

1 安装问题 1.1 版本一定要匹配

postgis下载地址

postgresql下载地址
下载入口:
(有时候找到了入口并不一定能找到下载的直接地址)
https://postgis.net/windows_downloads/
https://www.postgresql.org/download/windows/

1.2 先安装postgresql再安装postgis

一般就是下一步下一步,遇到问题参考Q(question)列表,或者seo搜索。
postgresql配置

  1. 环境变量配置
    一般需要将postgresql的bin加入环境变量中,方便以后使用方便。

postgis安装

Q1 spatial database creation failed

createdb: 错误: 连接到"localhost" (::1)上的服务器,端口5432失败:Connection refused
(0x0000274D/10061)
服务器是否在该主机上运行并接受TCP/IP连接? 连接到"localhost" (127.0.0.1)上的服务器,端口5432失败:Connection refused (0x0000274D/10061)
服务器是否在该主机上运行并接受TCP/IP连接?


A: postgresql服务没起来,在服务种启动对应版的服务。

这个错误已经遇到好几次了,登录身份验证问题。只能启动一个,如下图。

Q2 create database 失败

我的是乱码,但可以猜测到原因

createdb: 错误: 创建数据库失败: 閿欒: 鏁版嵁搴?“postgis_31_sample” 宸茬粡瀛樺湪
感觉是数据库已经存在,重新安装数据库命名为postgis_14_sample成功 新的问题

A: 上一次安装时已经创建了postgis_31_sample,重新安装数据库命名为postgis_14_sample成功

2 使用问题 2.1 导入shp文件 Q1 无法启动postgis gui文件

shp2pgsql-gui.exe 由于找不到 libintl-9.dll,无法继续执行代码


A1 解决办法
这里只要找到 postgis 安装目录:C:Program FilesPostgreSQL11binpostgisgui,然后复制一份 libintl-8.dll 副本,改名为 libintl-9.dll 即可。

Q2 导入shp失败


A: 需要在新建数据库中,执行 create extension postgis;

Q3 注意事项

选择完一个和多个shp文件后需要在导入列表中手动更改你要导入的schema(目标架构名称)以及SRID(空间坐标系)。

Q4 PostGIS的SRID更新方法
text UpdateGeometrySRID(varchar table_name, varchar column_name, integer srid);
text UpdateGeometrySRID(varchar schema_name, varchar table_name, varchar column_name, integer srid)
text UpdateGeometrySRID(varchar catalog_name, varchar schema_name, varchar table_name, varchar column_name, integer srid);

举例说明
select UpdateGeometrySRID('tablename', 'geom', 4326);
srid可以通过数据库中spatial_ref_sys表格查询,如果没有,则可以自己添加一个PROJ4形式的坐标系参数。
查询SRID
select st_srid(geom) from table;

3 最后

配置好了ide,配置好数据库就可以愉快的撸码了,但问题的处理过程还是记录一下,下次一定还能碰到。

4 参考文章

Postgre及PostGIS安装和使用
PostGIS的SRID更新方法

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5680629.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存