[英]How do I add the Postgis distance to the result set
Here's my current query which currently returns the name and point of eligible results ordered by distance, how can I include the distance as well in the result set? 这是我当前的查询,该查询当前返回按距离排序的合格结果的名称和点,如何在结果集中包括距离?
Query: 查询:
select name, ST_AsText(location) from places where ST_DWithin(
ST_GeogFromText('SRID=4326;POINT($point)'),
location,
$distance
) ORDER BY ST_Distance(
ST_GeogFromText('SRID=4326;POINT($point)'),
location
)
$distance
and $point
will need to be guarded against sql injection in due course obviously. $distance
和$point
显然需要在适当时候防止sql注入。
SELECT name,
ST_AsText(location),
ST_Distance(ST_GeogFromText('SRID=4326;POINT($point)'),location)
FROM places
WHERE ST_DWithin(ST_GeogFromText('SRID=4326;POINT($point)'), location, $distance)
ORDER BY ST_Distance( ST_GeogFromText('SRID=4326;POINT($point)'), location);
However, for your query to work location should also be casted to a geography (if it is not). 但是,为了使查询正常工作,还应该将位置转换为地理位置(如果不是)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.