哪个邻近函数提供最快并利用 postGIS 中的空间索引?

发布于 2024-12-20 04:56:41 字数 2546 浏览 5 评论 0原文

我是 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_DistanceST_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

も让我眼熟你 2024-12-27 04:56:41

我曾经听说 ST_DWithin 是最快的,实际上在文档中他们说新版本 ST_DWithin 已进行调整。

1.3之前,ST_Expand通常与&&结合使用。和
ST_Distance达到和1.3.4之前这个函数相同的效果
基本上是该结构的简写。从1.3.4开始,ST_D内
使用更短路距离函数,这应该使它更
对于更大的缓冲区,比之前的版本更高效。

它还使用边界框比较和索引:

此函数调用将自动包含一个边界框
比较将利用任何可用的索引
几何形状。

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.

Prior to 1.3, ST_Expand was commonly used in conjunction with && and
ST_Distance to achieve the same effect and in pre-1.3.4 this function
was basically short-hand for that construct. From 1.3.4, ST_DWithin
uses a more short-circuit distance function which should make it more
efficient than prior versions for larger buffer regions.

Also it uses bounding box comparitions and indexes:

This function call will automatically include a bounding box
comparison that will make use of any indexes that are available on the
geometries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文