ST_Contains。查找范围内的所有道路

ST_Contains. Find all road that are within the scope

我正在尝试找到范围内的所有道路。

这是我的要求:

select osm_id, 
name,
from planet_osm_roads 
where ST_Contains(ST_GeomFromEWKT('SRID=900913;POLYGON((4355764.028 6715445.513, 4364401.418 6715674.192, 4364248.577 6708736.416, 4354808.572 6709155.795, 4355764.028 6715445.513))'), way)
LIMIT 100;

或者那个:

select osm_id, 
name,
from planet_osm_roads 
where ST_Contains(ST_GeomFromText('LINESTRING(4355764.028 6715445.513, 4364401.418 6715674.192, 4364248.577 6708736.416, 4354808.572 6709155.795, 4355764.028 6715445.513)', 900913), way)
LIMIT 100;

我做的一切都放在本地数据库上,需要的数据都有。

这样的多边形:

查询结果为空。 告诉我哪里出了问题。谢谢

ST_Contains 可能不适合这份工作

ST_Contains — Returns true if and only if no points of B lie in the exterior of A, and at least one point of the interior of B lies in the interior of A.

由于这些是道路,因此至少其中的某些部分会位于您的多边形之外。这意味着 ST_Contains 将 return 为假。也许 ST_Intersects 可能是更好的选择。

错误出在空间参考中。 这是一个有效的请求:

select osm_id, name,  
ST_AsText(ST_Transform(way,4326)) from planet_osm_roads 
where ST_Contains(ST_Transform(ST_GeomFromText('POLYGON((39.128494  51.716394, 39.206085 51.71767, 39.204712 51.678942, 39.119911 51.681284, 39.128494 51.716394))',4326),900913), way)  
LIMIT 120;

ST_Transform — Returns 一个新几何,其坐标转换为整数参数引用的 SRID。