Postgres空间计算
Posted 再出发
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Postgres空间计算相关的知识,希望对你有一定的参考价值。
select * from eploygon; select * from geometry_columns where f_table_name=\'eploygon\'; ------------------------------------------------------------------------------------------------------------------------------------------------------- SELECT ST_GeomFromText(\'polygon ((117.812658 38.926816,117.813196 38.926622,117.812679 38.925415,117.812065 38.925792,117.812658 38.926816))\', 4326 ); SELECT ST_AsText( ST_GeomFromText(\'polygon ((117.812658 38.926816,117.813196 38.926622,117.812679 38.925415,117.812065 38.925792,117.812658 38.926816))\', 4326 ) ) SELECT gid,geom FROM public.eploygon s where ST_Intersects( ST_GeomFromText(\'polygon ((117.812658 38.926816,117.813196 38.926622,117.812679 38.925415,117.812065 38.925792,117.812658 38.926816))\', 4326 ) , s.geom) ; SELECT ST_GeomFromGeoJSON(\'{"type":"LineString","coordinates":[[0,0],[1,1],[1,1],[2,2]]}\'); select ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON(\'{"type":"LineString","coordinates":[[117.8136920928955,38.92978618569792],[117.81523704528809,38.926781511834875],[117.81620264053345,38.92432760043733],[117.81620264053345,38.92247459068792],[117.81620264053345,38.921489637879205],[117.81624555587769,38.92105558653837]]}\')),4326); ------------------------------------------------------------------------------------------------------------------------------------------------------- --相交切割计算 SELECT ST_Intersection( ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON(\'{"type":"LineString","coordinates":[[117.8136920928955,38.92978618569792],[117.81523704528809,38.926781511834875],[117.81620264053345,38.92432760043733],[117.81620264053345,38.92247459068792],[117.81620264053345,38.921489637879205],[117.81624555587769,38.92105558653837]]}\')),4326) , s.geom) FROM public.eploygon s where ST_Intersects( ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON(\'{"type":"LineString","coordinates":[[117.8136920928955,38.92978618569792],[117.81523704528809,38.926781511834875],[117.81620264053345,38.92432760043733],[117.81620264053345,38.92247459068792],[117.81620264053345,38.921489637879205],[117.81624555587769,38.92105558653837]]}\')),4326) , s.geom) ; SELECT ST_Intersection( ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON(\'{"type":"Polygon","coordinates":[[[117.812658,38.926816],[117.813196,38.926622],[117.812679, 38.925415],[117.812065,38.925792],[117.812658,38.926816]]]}\')),4326) , s.geom) FROM public.eploygon s where ST_Intersects( ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON(\'{"type":"Polygon","coordinates":[[[117.812658,38.926816],[117.813196,38.926622],[117.812679, 38.925415],[117.812065,38.925792],[117.812658,38.926816]]]}\')),4326) , s.geom) ; SELECT ST_AsText(ST_Intersection( ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON(\'{"type":"Point","coordinates":[117.812658,38.926816]}\')),4326) , s.geom)) as a FROM public.eploygon s; SELECT ST_Intersection( ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON(\'{"type":"Point","coordinates":[117.812658,38.926816]}\')),4326) , s.geom) FROM public.eploygon s where ST_Intersects( ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON(\'{"type":"Point","coordinates":[117.812658,38.926816]}\')),4326) , s.geom); ------------------------------------------------------------------------------------------------------------------------------------------------------- --相交计算 SELECT gid,geom FROM public.eploygon s where ST_Intersects( ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON(\'{"type":"LineString","coordinates":[[117.8136920928955,38.92978618569792],[117.81523704528809,38.926781511834875],[117.81620264053345,38.92432760043733],[117.81620264053345,38.92247459068792],[117.81620264053345,38.921489637879205],[117.81624555587769,38.92105558653837]]}\')),4326) , s.geom) ; SELECT gid,geom FROM public.eploygon s where ST_Intersects( ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON(\'{"type":"Polygon","coordinates":[[[117.812658,38.926816],[117.813196,38.926622],[117.812679, 38.925415],[117.812065,38.925792],[117.812658,38.926816]]]}\')),4326) , s.geom) ; SELECT gid,geom FROM public.eploygon s where ST_Intersects( ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON(\'{"type":"Point","coordinates":[117.812658,38.926816]}\')),4326) , s.geom) ; ------------------------------------------------------------------------------------------------------------------------------------------------------- --相交计算测试输出 SELECT gid,geom FROM public.eploygon s where ST_Intersects( ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON(\'{"type":"LineString","coordinates":[[117.8136920928955,38.92978618569792],[117.81523704528809,38.926781511834875],[117.81620264053345,38.92432760043733],[117.81620264053345,38.92247459068792],[117.81620264053345,38.921489637879205],[117.81624555587769,38.92105558653837]]}\')),4326) , s.geom) union select 111111 as gid,ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON(\'{"type":"LineString","coordinates":[[117.8136920928955,38.92978618569792],[117.81523704528809,38.926781511834875],[117.81620264053345,38.92432760043733],[117.81620264053345,38.92247459068792],[117.81620264053345,38.921489637879205],[117.81624555587769,38.92105558653837]]}\')),4326); SELECT gid,geom FROM public.eploygon s where ST_Intersects( ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON(\'{"type":"Polygon","coordinates":[[[117.812658,38.926816],[117.813196,38.926622],[117.812679, 38.925415],[117.812065,38.925792],[117.812658,38.926816]]]}\')),4326) , s.geom) union select 111111 as gid,ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON(\'{"type":"Polygon","coordinates":[[[117.812658,38.926816],[117.813196,38.926622],[117.812679, 38.925415],[117.812065,38.925792],[117.812658,38.926816]]]}\')),4326) ; SELECT gid,geom FROM public.eploygon s where ST_Intersects( ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON(\'{"type":"Point","coordinates":[117.812658,38.926816]}\')),4326) , s.geom) union select 111111 as gid,ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON(\'{"type":"Point","coordinates":[117.812658,38.926816]}\')),4326);
博客地址: http://www.cnblogs.com/defineconst/
博客版权: 本文以学习、研究和分享为主,欢迎转载和各类爬虫,但必须在文章页面明显位置给出原文链接。 如果文中有不妥或者错误的地方还望高手的您指出,以免误人子弟。如果您有更好的建议,不如留言一起讨论,共同进步! 再次感谢您耐心的读完本篇文章。
博客版权: 本文以学习、研究和分享为主,欢迎转载和各类爬虫,但必须在文章页面明显位置给出原文链接。 如果文中有不妥或者错误的地方还望高手的您指出,以免误人子弟。如果您有更好的建议,不如留言一起讨论,共同进步! 再次感谢您耐心的读完本篇文章。
数据库中存储的 postgres 表空间的位置
【中文标题】数据库中存储的 postgres 表空间的位置【英文标题】:Where in the DB is the Location of a postgres tablespace stored 【发布时间】:2016-02-05 10:32:44 【问题描述】:我在 redhat 6 上使用 postgres 9.2
这应该很简单,但我在任何地方都找不到。我正在寻找存储 postgres 表空间位置的数据库表和列,我认为它会在 PG_TABLESPACE 中,但是
select * from pg_tablespace
显示...
postgres=# select * from pg_tablespace;
spcname | spcowner | spcacl | spcoptions
-----------------+----------+--------+------------
pg_default | 10 | |
pg_global | 10 | |
C_TBL_DB91SABIR | 10 | |
(3 rows)
但没有位置,有什么想法保存位置吗?
谢谢
【问题讨论】:
不是确切的答案:SHOW data_directory;
会告诉你当前数据库的位置
嗨@wingedpanther,它显示了 PGDATA 位置,但我正在寻找表空间的目录,我想查询它,以便我可以在表空间被删除时编写删除物理文件夹的脚本丢弃。
试试这个select spcname, pg_tablespace_location(oid) from pg_tablespace;
【参考方案1】:
使用pg_tablespace_location(tablespace_oid)
(PostgreSQL 9.2+)获取tablespace
所在文件系统中的路径。
您将从pg_tablespace
获得tablespace
中的oid
,因此查询应该是
select spcname
,pg_tablespace_location(oid)
from pg_tablespace;
【讨论】:
【参考方案2】:另一个列出所有表空间的超级简单命令
\db+
这将很快为您提供所有表空间详细信息
【讨论】:
【参考方案3】:使用以下查询获取表空间名称表空间位置。
postgres=# select spcname ,pg_tablespace_location(oid) from pg_tablespace;
spcname | pg_tablespace_location
------------+-------------------------------
pg_default |
pg_global |
fastspace | /var/lib/postgresql/data/base
demotbs | /var/lib/postgresql/data
【讨论】:
复制已经接受的答案有什么意义?以上是关于Postgres空间计算的主要内容,如果未能解决你的问题,请参考以下文章