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
.
近くのポイントを取得するには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
" を利用するのだろうか? 何百万ものポイントがある場合、両方とも非常に高速に実行できますか?
別の質問ですが、セルの 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)
ますか? データ量の多い検索に耐えられるでしょうか?