私はPostgreSQL/PostGISを初めて使用しています。私は単純なアルゴリズムを解くためにそれを評価しています:半径(メートル)のすべての点を探してみてください。ここに私のテーブルです:それは正しい設計であれば、私はpoint
列にGiSTインデックスを追加どの近接関数が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
、私は知りません。 'points'がすべて挿入されています。SRID=4326
です。
近くのポイントを得るためにそこにいる2つの方法を思わ:
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
" の使用を作るどのアルゴリズムだろうか?何百万というポイントがあれば、両方とも非常に高速に実行できますか?
もう1つの質問ですが、セルのSRIDをクエリするにはどうすればよいですか? 私ができることは、hibernate-spatial-postgisで "com.vividsolutions.jts.geom.Point
"を取得し、返されたポイントからSRIDを取得することです。 SQLでどのようにクエリを実行しますか?ありがとう。
環境:それはを使用する場合、私は知っているどのように
=> 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)
:
=> 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は、私はこれを試してみました"point_index" gist (point)
?データ量の多い検索でも存続しますか?
私は、メインの質問に答えることはできませんが、[ 'ST_SRID'](http://postgis.refractions.net/documentation/manual-1.4/ST_SRID.html)SRIDを使用して取得するための –
はあなたに感謝@ skyhisi – smallufo
'EXPLAIN SELECT ... 'を実行して、どのアルゴリズムを使用しているか確認してください。 – filiprem