PostGIS SRID不存在的问题处理

本文涉及的产品
RDS MySQL DuckDB 分析主实例,基础系列 4核8GB
RDS MySQL DuckDB 分析主实例,集群系列 4核8GB
RDS AI 助手,专业版
简介:

标签

PostgreSQL , PostGIS , SRID , spatial_ref_sys


背景

GIS数据有一定的标准来表示它的数据,

The OpenGIS "Simple Features Specification for SQL" defines standard GIS object types, 
the functions required to manipulate them, and a set of meta-data tables. 
In order to ensure that meta-data remain consistent, 
operations such as creating and removing a spatial column are carried out through special procedures defined by OpenGIS.

There are two OpenGIS meta-data tables: 
SPATIAL_REF_SYS and GEOMETRY_COLUMNS. 
The SPATIAL_REF_SYS table holds the numeric IDs and textual descriptions of coordinate systems used in the spatial database.

http://www.sharpgis.net/post/2007/05/05/Spatial-references2c-coordinate-systems2c-projections2c-datums2c-ellipsoids-e28093-confusing

当你使用PostGIS时,如果报这样的错误,说明SRID的信息没有写入spatial_ref_sys表,PostgreSQL无法找到合适的GIS数据表达方法。

ERROR: invalid SRID: 5514 not found in spatial_ref_sys  

http://gis.stackexchange.com/questions/187770/change-srid-of-geometry-column

stackoverflow中也有类似的提问

问题

I have in my table column geom with geometry, data type of this column is geometry(Point,102067).   
I want to change SRID from 102067 to 5514, but if I use this command  
  
select UpdateGeometrySRID('my_schema', 'table', 'geom', 5514) ;  
  
docs say: ERROR: invalid SRID: 5514 not found in spatial_ref_sys CONTEXT:   
SQL statement "SELECT UpdateGeometrySRID('',$1,$2,$3,$4)"  
  
I found, that EPSG:5514 = EPSG:102067 (both is S-JTSK_Krovak_East_North),   
but in second table I have EPSG:5514, and for example comand ST_Contains says: Operation on mixed SRID geometries.  

回答

The error happened because EPSG:5514 is no added in spatal_ref_sys table. So you can add it using the following query.  
  
  
INSERT into spatial_ref_sys (srid, auth_name, auth_srid, proj4text, srtext) values ( 5514, 'EPSG', 5514, '+proj=krovak +lat_0=49.5 +lon_0=24.83333333333333 +alpha=30.28813972222222 +k=0.9999 +x_0=0 +y_0=0 +ellps=bessel +towgs84=589,76,480,0,0,0,0 +units=m +no_defs ', 'PROJCS["S-JTSK / Krovak East North",GEOGCS["S-JTSK",DATUM["System_Jednotne_Trigonometricke_Site_Katastralni",SPHEROID["Bessel 1841",6377397.155,299.1528128,AUTHORITY["EPSG","7004"]],TOWGS84[589,76,480,0,0,0,0],AUTHORITY["EPSG","6156"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4156"]],PROJECTION["Krovak"],PARAMETER["latitude_of_center",49.5],PARAMETER["longitude_of_center",24.83333333333333],PARAMETER["azimuth",30.28813972222222],PARAMETER["pseudo_standard_parallel_1",78.5],PARAMETER["scale_factor",0.9999],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["X",EAST],AXIS["Y",NORTH],AUTHORITY["EPSG","5514"]]');  
  
  
Source: https://epsg.io/5514  
  
Click on the side menu under PostGIS to see the insert query.  
  
Check if SRID-5514 is inserted using:  
  
SELECT * FROM spatial_ref_sys WHERE srid = 5514;  
Once you have inserted it, you can then change the SRID of your geometry column using the code:  
  
SELECT UpdateGeometrySRID('your_schema', 'table', 'geom', 5514);  
You can then check the change using:  
  
SELECT ST_SRID(geom) FROM table LIMIT 1;  

解决方法也很简单,插入SRS数据即可,找到postgis对应的版本SQL。

https://raw.githubusercontent.com/greenplum-db/postgis/4fefce57cbd28e006db60070434611228294bef3/spatial_ref_sys.sql

参考

http://spatialreference.org/ref/epsg/4326/

http://gis.stackexchange.com/questions/187770/change-srid-of-geometry-column

目录
相关文章
|
存储 缓存 安全
virtiofs per-inode DAX 介绍
## 背景信息 1. 什么是 virtiofs? virtiofs 是一种用于在 host/guest 之间共享文件的文件系统,由 Redhat 开源,它使得不同 guest 之间能够以快速、一致、安全的方式共享同一个 host 目录树结构,目前广泛应用于 Kata Container 作为容器的 rootfs。 2. 什么是 DAX? DAX (Direct Access) 最初是针对于
3512 0
virtiofs per-inode DAX 介绍
|
算法 Linux 网络安全
Centos7 Linux系统下生成https的crt和key证书
Centos7 Linux系统下生成https的crt和key证书
827 0
|
5月前
|
存储 人工智能 文字识别
PDF解析迎来技术革新!阿里新产品实现复杂文档端到端结构化处理
前言9月24日云栖大会现场,由阿里巴巴爱橙科技数据技术及产品团队自主研发的 PDF解析神器正式亮相并同步开源模型。这款基于Logics-Parsing模型构建的AI工具直指当前PDF解析领域的技术痛点,显著提升复杂文档的结构…
808 0
PDF解析迎来技术革新!阿里新产品实现复杂文档端到端结构化处理
|
5月前
|
人工智能 运维 中间件
CTI中间件:现代呼叫中心的核心开发平台
乐科CTI中间件助力企业高效构建智能呼叫中心,集成通信与业务系统,支持多协议、AI融合、高可用部署,广泛应用于客服、营销等场景,降低开发成本,提升运维效率。
|
存储 安全 UED
插上U盘后提示格式化怎么解决?4个方法帮你
在使用u盘的时候,很多人都可能遇到过电脑插入U盘后系统弹出提示要求将U盘格式化。面对这个问题,如果U盘里有重要的数据,会让人感到不知所措。今天的内容就和大家一起讨论一下这个问题的原因和解决方法,并提供恢复U盘数据的方法。
|
关系型数据库 Serverless 定位技术
PostgreSQL如何使用GIS函数计算两个点连线的中间点?
PostgreSQL如何使用GIS函数计算两个点连线的中间点?
529 62
|
关系型数据库 Serverless 定位技术
PostgreSQL GIS函数判断两条线有交点的函数是什么?
PostgreSQL GIS函数判断两条线有交点的函数是什么?
999 60
|
缓存 JavaScript 前端开发
vue3+elementplus后台管理系统,实现用户登录
vue3+elementplus后台管理系统,实现用户登录
|
关系型数据库 数据库 PostgreSQL
深入理解 PostgreSQL 的 JOIN 连接
深入理解 PostgreSQL 的 JOIN 连接
719 4
|
定位技术 数据库
EndNote导入文献引用后无法显示期刊名称的解决办法
EndNote导入文献引用后无法显示期刊名称的解决办法
1082 1