Skip to content

Commit db9928d

Browse files
committed
gis
1 parent 428937d commit db9928d

File tree

4 files changed

+158
-0
lines changed

4 files changed

+158
-0
lines changed

201704/20170408_01.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
## Greenplum 自定义复合类型 数组
2+
3+
### 作者
4+
digoal
5+
6+
### 日期
7+
2017-04-08
8+
9+
### 标签
10+
PostgreSQL , Greenplum , composite type array
11+
12+
----
13+
14+
## 背景
15+
如果你现在要在Greenplum中创建一个复合类型,是不会自动给你创建对应的数组类型的。(而实际上PostgreSQL 在2007年已经支持了这个功能)
16+
17+
Greenplum需要等到5.0,才能使用上它了。
18+
19+
https://github.com/greenplum-db/gpdb/commit/8954a537ee6199a80c38581fd3cd7ed463abbdea
20+
21+
```
22+
Support arrays of composite types
23+
Backport from upstream with this commit:
24+
25+
commit bc8036f
26+
Author: Tom Lane <[email protected]>
27+
Date: Fri May 11 17:57:14 2007 +0000
28+
29+
Support arrays of composite types, including the rowtypes of regular tables
30+
and views (but not system catalogs, nor sequences or toast tables). Get rid
31+
of the hardwired convention that a type's array type is named exactly "_type",
32+
instead using a new column pg_type.typarray to provide the linkage. (It still
33+
will be named "_type", though, except in odd corner cases such as
34+
maximum-length type names.)
35+
36+
Along the way, make tracking of owner and schema dependencies for types more
37+
uniform: a type directly created by the user has these dependencies, while a
38+
table rowtype or auto-generated array type does not have them, but depends on
39+
its parent object instead.
40+
41+
David Fetter, Andrew Dunstan, Tom Lane
42+
master (#1) 5.0.0-alpha.1 5.0.0-alpha.0
43+
1 parent 5b33bee commit 8954a537ee6199a80c38581fd3cd7ed463abbdea @HaozhouWang HaozhouWang committed on 9 Mar 2016
44+
```
45+
46+
https://www.postgresql.org/docs/8.2/static/sql-createtype.html
47+
48+
Array Types
49+
50+
```
51+
Whenever a user-defined base data type is created, PostgreSQL automatically creates an associated array type,
52+
whose name consists of the base type's name prepended with an underscore.
53+
The parser understands this naming convention, and translates requests for columns of type foo[] into requests for type _foo.
54+
The implicitly-created array type is variable length and uses the built-in input and output functions array_in and array_out.
55+
56+
You might reasonably ask why there is an ELEMENT option, if the system makes the correct array type automatically.
57+
The only case where it's useful to use ELEMENT is when you are making a fixed-length type that happens to be internally an array of a number of identical things,
58+
and you want to allow these things to be accessed directly by subscripting, in addition to whatever operations you plan to provide for the type as a whole.
59+
For example, type name allows its constituent char elements to be accessed this way.
60+
A 2-D point type could allow its two component numbers to be accessed like point[0] and point[1].
61+
62+
Note that this facility only works for fixed-length types whose internal form is exactly a sequence of identical fixed-length fields.
63+
A subscriptable variable-length type must have the generalized internal representation used by array_in and array_out. For historical reasons
64+
(i.e., this is clearly wrong but it's far too late to change it),
65+
subscripting of fixed-length array types starts from zero, rather than from one as for variable-length arrays.
66+
```

201704/20170408_02.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
## invalid SRID: xxxx not found in spatial_ref_sys
2+
3+
### 作者
4+
digoal
5+
6+
### 日期
7+
2017-04-08
8+
9+
### 标签
10+
PostgreSQL , PostGIS , SRID , spatial_ref_sys
11+
12+
----
13+
14+
## 背景
15+
GIS数据有一定的标准来表示它的数据,
16+
17+
```
18+
The OpenGIS "Simple Features Specification for SQL" defines standard GIS object types,
19+
the functions required to manipulate them, and a set of meta-data tables.
20+
In order to ensure that meta-data remain consistent,
21+
operations such as creating and removing a spatial column are carried out through special procedures defined by OpenGIS.
22+
23+
There are two OpenGIS meta-data tables:
24+
SPATIAL_REF_SYS and GEOMETRY_COLUMNS.
25+
The SPATIAL_REF_SYS table holds the numeric IDs and textual descriptions of coordinate systems used in the spatial database.
26+
```
27+
28+
http://www.sharpgis.net/post/2007/05/05/Spatial-references2c-coordinate-systems2c-projections2c-datums2c-ellipsoids-e28093-confusing
29+
30+
当你使用PostGIS时,如果报这样的错误,说明SRID的信息没有写入spatial_ref_sys表,PostgreSQL无法找到合适的GIS数据表达方法。
31+
32+
```
33+
ERROR: invalid SRID: 5514 not found in spatial_ref_sys
34+
```
35+
36+
http://gis.stackexchange.com/questions/187770/change-srid-of-geometry-column
37+
38+
stackoverflow中也有类似的提问
39+
40+
问题
41+
42+
```
43+
I have in my table column geom with geometry, data type of this column is geometry(Point,102067).
44+
I want to change SRID from 102067 to 5514, but if I use this command
45+
46+
select UpdateGeometrySRID('my_schema', 'table', 'geom', 5514) ;
47+
48+
docs say: ERROR: invalid SRID: 5514 not found in spatial_ref_sys CONTEXT:
49+
SQL statement "SELECT UpdateGeometrySRID('',$1,$2,$3,$4)"
50+
51+
I found, that EPSG:5514 = EPSG:102067 (both is S-JTSK_Krovak_East_North),
52+
but in second table I have EPSG:5514, and for example comand ST_Contains says: Operation on mixed SRID geometries.
53+
```
54+
55+
回答
56+
57+
```
58+
The error happened because EPSG:5514 is no added in spatal_ref_sys table. So you can add it using the following query.
59+
60+
61+
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"]]');
62+
63+
64+
Source: https://epsg.io/5514
65+
66+
Click on the side menu under PostGIS to see the insert query.
67+
68+
Check if SRID-5514 is inserted using:
69+
70+
SELECT * FROM spatial_ref_sys WHERE srid = 5514;
71+
Once you have inserted it, you can then change the SRID of your geometry column using the code:
72+
73+
SELECT UpdateGeometrySRID('your_schema', 'table', 'geom', 5514);
74+
You can then check the change using:
75+
76+
SELECT ST_SRID(geom) FROM table LIMIT 1;
77+
```
78+
79+
解决方法也很简单,插入SRS数据即可,找到postgis对应的版本SQL。
80+
81+
https://raw.githubusercontent.com/greenplum-db/postgis/4fefce57cbd28e006db60070434611228294bef3/spatial_ref_sys.sql
82+
83+
## 参考
84+
http://spatialreference.org/ref/epsg/4326/
85+
86+
http://gis.stackexchange.com/questions/187770/change-srid-of-geometry-column
87+
88+

201704/readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
### 文章列表
22
----
3+
##### 20170408_02.md [《invalid SRID: xxxx not found in spatial_ref_sys》](20170408_02.md)
4+
##### 20170408_01.md [《Greenplum 自定义复合类型 数组》](20170408_01.md)
35
##### 20170405_02.md [《PostgreSQL 10.0 preview 变化 - 逻辑复制pg_hba.conf变化,不再使用replication条目》](20170405_02.md)
46
##### 20170405_01.md [《PostgreSQL 10.0 preview 功能增强 - BRIN 索引更新smooth化》](20170405_01.md)
57
##### 20170402_01.md [《PostgreSQL 转义、UNICODE、与SQL注入》](20170402_01.md)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ digoal's|PostgreSQL|文章|归类
2828

2929
### 未归类文档如下
3030
----
31+
##### 201704/20170408_02.md [《invalid SRID: xxxx not found in spatial_ref_sys》](201704/20170408_02.md)
32+
##### 201704/20170408_01.md [《Greenplum 自定义复合类型 数组》](201704/20170408_01.md)
3133
##### 201704/20170405_02.md [《PostgreSQL 10.0 preview 变化 - 逻辑复制pg_hba.conf变化,不再使用replication条目》](201704/20170405_02.md)
3234
##### 201704/20170405_01.md [《PostgreSQL 10.0 preview 功能增强 - BRIN 索引更新smooth化》](201704/20170405_01.md)
3335
##### 201704/20170402_01.md [《PostgreSQL 转义、UNICODE、与SQL注入》](201704/20170402_01.md)

0 commit comments

Comments
 (0)