哪个邻近函数提供最快并利用 postGIS 中的空间索引?
我是 PostgreSQL / PostGIS 的新手。我正在评估它来解决一个简单的算法:尝试找到半径(米)内的所有点。这是我的表格:
=> \d+ theuser;
Table "public.theuser"
Column | Type | Modifiers | Storage | Description
----------+------------------------+-----------+----------+-------------
id | bigint | not null | plain |
point | geometry | | main |
Indexes:
"theuser_pkey" PRIMARY KEY, btree (id)
"point_index" gist (point)
Referenced by:
...
Has OIDs: no
我在 point
列中添加了要点索引,我不知道这是否是正确的设计。 插入的所有“点”均带有 SRID=4326
。
似乎有两种方法可以获取附近的点:
ST_Distance 、 ST_Distance_Sphere 。 以 2 为例:
select * from theuser where
ST_distance_sphere(point , ST_GeomFromText('POINT(120.9982 24.788)',4326)) < 100;
我想知道哪种算法使用“point_index< /代码>”?如果有数百万个点,两者都可以执行得很快吗?
另一个问题,如何查询小区的SRID(我搜索没有找到答案)? 我所能做的就是通过 hibernate-spatial-postgis 获取 "com.vividsolutions.jts.geom.Point
" ,并从返回的点获取 SRID。我如何在 SQL 中查询它?谢谢。
环境:
=> select version();
version
-----------------------------------------------------------------------------------------------------------
PostgreSQL 8.4.9 on i486-pc-linux-gnu, compiled by GCC gcc-4.4.real (Ubuntu 4.4.3-4ubuntu5) 4.4.3, 32-bit
=> SELECT postgis_lib_version();
postgis_lib_version
---------------------
1.4.0
----更新----
感谢@filiprem,我尝试了这个:
=> explain select * from theuser where
ST_distance_sphere(point , ST_GeomFromText('POINT(120.9982 24.788)',4326)) < 100;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------
Seq Scan on theuser (cost=0.00..1.15 rows=3 width=2644)
Filter: (st_distance_sphere(point, '0101000020E610000080B74082E23F5E407D3F355EBAC93840'::geometry) < 100::double precision)
(2 rows)
我如何知道它是否使用了“point_index”要点(点)
?它能在高数据量搜索下生存吗?
I am new to PostgreSQL / PostGIS. I am evaluating it to solve a simple algorithm : Try to find all points in a radius (meters). Here is my table :
=> \d+ theuser;
Table "public.theuser"
Column | Type | Modifiers | Storage | Description
----------+------------------------+-----------+----------+-------------
id | bigint | not null | plain |
point | geometry | | main |
Indexes:
"theuser_pkey" PRIMARY KEY, btree (id)
"point_index" gist (point)
Referenced by:
...
Has OIDs: no
I add a gist index to the point
column , I don't know if it is the correct design.
All 'points' inserted are with SRID=4326
.
It seems there're 2 ways to get nearby points:
ST_Distance , ST_Distance_Sphere .
Take 2 for example :
select * from theuser where
ST_distance_sphere(point , ST_GeomFromText('POINT(120.9982 24.788)',4326)) < 100;
I wonder which algorithm make use of the "point_index
" ? If there are millions of points , can both execute very fast ?
Another question , how can I query the SRID of a cell (I searched by found no answer) ?
All I can do is by hibernate-spatial-postgis , getting "com.vividsolutions.jts.geom.Point
" , and get the SRID from the returned point. How do I query it in SQL ? Thanks.
Environment :
=> select version();
version
-----------------------------------------------------------------------------------------------------------
PostgreSQL 8.4.9 on i486-pc-linux-gnu, compiled by GCC gcc-4.4.real (Ubuntu 4.4.3-4ubuntu5) 4.4.3, 32-bit
=> SELECT postgis_lib_version();
postgis_lib_version
---------------------
1.4.0
---- updated ----
Thanks @filiprem , I tried this :
=> explain select * from theuser where
ST_distance_sphere(point , ST_GeomFromText('POINT(120.9982 24.788)',4326)) < 100;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------
Seq Scan on theuser (cost=0.00..1.15 rows=3 width=2644)
Filter: (st_distance_sphere(point, '0101000020E610000080B74082E23F5E407D3F355EBAC93840'::geometry) < 100::double precision)
(2 rows)
How do I know if it makes use of the "point_index" gist (point)
? Will it survive under high data volume searching ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我曾经听说 ST_DWithin 是最快的,实际上在文档中他们说新版本 ST_DWithin 已进行调整。
它还使用边界框比较和索引:
I heard once that ST_DWithin is the fastest, actually in the documentation they say that in newer versions ST_DWithin has been tunned up.
Also it uses bounding box comparitions and indexes: