简体   繁体   English

从同一表格中选择的2个点之间的PostGIS距离查询

[英]PostGIS distance query between 2 selected points from same table

This is probably a really easy query, but for some reason, I just can't figure it out.. I have a table with cities (cities) and I want to get the distance between London (cities.city_name='London') and Dundee. 这可能是一个非常简单的查询,但是由于某些原因,我无法弄清楚。.我有一张包含城市(城市)的表,我想知道伦敦之间的距离(cities.city_name ='London')和邓迪。 This is my query: 这是我的查询:

SELECT 
cities.city_name, ST_Distance(cities.the_geom,cities.the_geom)
from cities 
WHERE cities.city_name in ('London','Dundee')

The result is in the ST_Distance field of the output is 0 for both cities. 结果在两个城市的输出的ST_Distance字段中均为0。 I know that I'm missing something, but I don't know what. 我知道我想念什么,但我不知道。 I assume I have to set aliases for the 2 cities, but I don't know how. 我假设必须为这两个城市设置别名,但是我不知道如何。

Can anybody help me out with this? 有人可以帮我吗?

Thanks a ton in advance!! 在此先感谢一吨!

You are comparing distance between the same point in your query: 您正在比较查询中同一点之间的距离:

ST_Distance(cities.the_geom,cities.the_geom) --compares the same column in the list of the two cities:

CITY   | GEOM  |  DISTANCE
-----------------------------------
London | GEOM1 | DISTANCE (GEOM1, GEOM1)
Dundee | GEOM2 | DISTANCE(GEOM2, GEOM2)

Hope you can see my point from table above 希望你能从上表中看到我的观点

Maybe something like this: 也许是这样的:

SELECT ST_Distance(
    (SELECT the_geom FROM cities WHERE city_name ='London'),
    (SELECT the_geom FROM cities WHERE city_name ='Dundee')
)

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

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