[英]Object in 100 m distance, Error: Operation on mixed SRID geometries
I perform the following query:我执行以下查询:
SELECT * FROM "houses" WHERE (ST_Distance(coordinates, 'POINT(-0.374930 39.478400)'::geometry) < 100)
To find houses around 100 meter distance from: 39.478400, -0.374930查找距离 100 米左右的房屋:39.478400, -0.374930
I'm getting the following error:我收到以下错误:
PG::InternalError: ERROR: Operation on mixed SRID geometries
What is wrong here?这里有什么问题?
"Coordinates" is of type: geometry "coordinates", limit: {:srid=>4326, :type=>"geometry"}
Thank you and Happy Christmas谢谢你,圣诞快乐
The geometry literal 'POINT(-0.374930 39.478400)'::geometry
has no SRID while the geometries in houses.coordinates
have an SRID of 4326
.几何文字
'POINT(-0.374930 39.478400)'::geometry
没有 SRID,而houses.coordinates
中的几何图形的 SRID 为4326
。 You need to pass a geometry with the same SRID, ie using ST_GeomFromText :您需要传递具有相同 SRID 的几何图形,即使用ST_GeomFromText :
...
WHERE ST_Distance(coordinates, ST_GeomFromText('POINT(-0.374930 39.478400)', 4326)) < 100
But keep in mind, that the distance is returned in units of the SRID, which are degrees for SRID 4326 not meters .但请记住,距离以 SRID 为单位返回,对于 SRID 4326 是度数,而不是米。 To retrieve the distance in meters you could use ST_DistanceSphere .
要检索以米为单位的距离,您可以使用ST_DistanceSphere 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.