我是 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" gist (point)
? 它在高数据量搜索下还能生存吗?