postgres spatial indexing

梦想与她 提交于 2019-12-19 03:59:00

问题


I can't seem to find much documentation on this. What's the simplest way to create a database/table on postgres supporting a query like this SELECT * FROM table WHERE distance(POINT(0,0), table.location) <= 1000m; Where POINT(0,0) and table.location should be latitude/longitude pair, and 1000m is 1000 meters. And how should I go about indexing that table? Thanks.


回答1:


PostgreSQL support indexes on expressions and also partial indexes, you can probably mix them.

This is just a random guess, I don't know if it works, but give it a try:

CREATE INDEX foobar ON table (distance(POINT(0,0), location))
 WHERE distance(POINT(0,0), location) <= 1000;

http://www.postgresql.org/docs/9.0/interactive/indexes-expressional.html

http://www.postgresql.org/docs/9.0/interactive/indexes-partial.html




回答2:


Have you looked into Postgis and contrib/earthdistance?

http://www.postgis.org/

http://www.postgresql.org/docs/9.0/interactive/earthdistance.html



来源:https://stackoverflow.com/questions/3944880/postgres-spatial-indexing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!