简体   繁体   English

Postgis中的2个点之间的距离,以43米为单位的srid 4326

[英]Distance between 2 POINTs in Postgis in srid 4326 in metres

This is probably a simple question, but I'm not very good at PostGIS and don't fully grok all of this. 这可能是一个简单的问题,但我不是很擅长PostGIS,也没有完全理解这一切。

Basically I have a table ( nodes ) with a POINT column ( point ). 基本上我有一个带有POINT列( point )的表( nodes )。 I have created an index on this column 我在这个专栏上创建了一个索引

create index nodes__points on nodes using gist (point)

The column was created with 该列是用。创建的

select addgeometrycolumn('nodes', 'points', 'POINT', 4326, 2)

I am using srid 4326 because I'm adding data that's in the form (latitude, longitude). 我正在使用srid 4326,因为我正在添加形式(纬度,经度)的数据。 (ie the co-ordinate system where the position of Dublin, Ireland is lat=53.353 lon=-6.264 (which I've added with GeomFromText('POINT(-6.264 53.535)') )). (即爱尔兰都柏林的位置= 53.353 lon = -6.264的坐标系统(我已经使用GeomFromText('POINT(-6.264 53.535)') ))。

For each point, I want to find all points that are roughly within a 1km box centred on that point (so selcet a.id, count(*) from nodes as a, nodes as b where SOME_DISTANCE_FUNCTION_HERE(a.point, b.point, 1000) group by a.id; . It doesn't have to be exact, just a rough hueristic figure. a 1km bbox is fine, a 1km circle is fine. It doesn't have to be exactly 1km, just that order of magnitude. 对于每个点,我想找到大致位于该点中心的1km框内的所有点(因此selcet a.id, count(*) from nodes as a, nodes as b where SOME_DISTANCE_FUNCTION_HERE(a.point, b.point, 1000) group by a.id; .它不一定是精确的,只是一个粗略的人文形象.1km的bbox很好,1km的圆很好。它不一定是1km,只是那个顺序数量级。

The ST_Distance / ST_DWithin /etc. ST_Distance / ST_DWithin / ST_DWithin all use the units of the SRID, which for 4326/WGS64 is degrees (so 1 = 1 degree of lattitude/longitude). 所有都使用SRID的单位,4326 / WGS64是度(因此1 = 1度的纬度/经度)。 But I want to use metres. 但我想用米。

I tried ST_distance_sphere and st_dwithin which can use metres, but if I do that, the explain shows that the index isn't being used. 我尝试了ST_distance_spherest_dwithin ,可以使用米,但如果我这样做, explain显示索引没有被使用。

How can I get roughly what I want, and use the geographical index? 我怎样才能大致得到我想要的东西, 使用地理索引?

UPDATE : This is on PostgreSQL 9.1 and PostGIS 2.0 svn build. 更新 :这是在PostgreSQL 9.1和PostGIS 2.0 svn构建上。

You could use ST_Transform to use meters, also remeber that not all functions are available with geography types but if you really need speed use ST_DWithin, is the fastest way. 您可以使用ST_Transform来使用仪表,还要记住并非所有功能都可用于地理类型,但如果您真的需要速度使用ST_DWithin,则是最快的方法。 Here's an aproximation of conversions between degrees and meters: 这是度数和米之间转换的近似值:

| places | degrees    | distance |
| ------ | ---------- | -------- |
| 0      | 1.0        | 111 km   |
| 1      | 0.1        | 11.1 km  |
| 2      | 0.01       | 1.11 km  |
| 3      | 0.001      | 111 m    |
| 4      | 0.0001     | 11.1 m   |
| 5      | 0.00001    | 1.11 m   |
| 6      | 0.000001   | 0.111 m  |
| 7      | 0.0000001  | 1.11 cm  |
| 8      | 0.00000001 | 1.11 mm  |

自写这篇文章以来,我发现了“地理”而不是PostGIS中的“几何”类型,它可能完全符合我的要求。

老问题,但你只需要像这样: ST_Distance(p.geom::geography, u.geom::geography)其中p和u是两个表的别名

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM