获取边界框内的点
我试图从我的 postgis 数据库中选择某个边界框内的位置。我试图用这个查询来完成这个任务:
//latlong - latitude, longitude of a place
SELECT * FROM places WHERE St_Contains(St_GeomFromText('Polygon((:top_left_long :top_left_lat, :bottom_right_long :bottom_right_lat))'), latlong);
首先 - 我收到以下错误:
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: :top_left_lat
这是什么意思?第二个问题 - 我是否按良好顺序输入这些参数?我的意思是 - 先经度,然后纬度?
I'm trying to choose places from my postgis db that are inside a certain bounding box. I'm trying to accomplish this with this query:
//latlong - latitude, longitude of a place
SELECT * FROM places WHERE St_Contains(St_GeomFromText('Polygon((:top_left_long :top_left_lat, :bottom_right_long :bottom_right_lat))'), latlong);
First of all - I get the following error:
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: :top_left_lat
What does it mean? And the second issue - am I feeding these parameters in good order? I mean - first longitude, then latitude?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是我在旧项目中使用的查询:
the_geom 是我的几何列
注:MakeBox2D取左上角和右下
Here is a query I used in an old project:
the_geom was my geometry column
Note: MakeBox2D take top-left and right-bottom
根据这些参数,您无法构建多边形。
多边形是由 1 个外部边界和 0 个或多个内部边界定义的平面。每个内部边界在多边形中定义一个洞。三角形是具有 3 个不同的、不共线的顶点且没有内部边界的多边形。
外部边界 LinearRing 定义表面的“顶部”,即外部边界看起来以逆时针方向穿过边界的表面的一侧。内部 LinearRings 将具有相反的方向,并且从“顶部”观察时显示为顺时针方向。
多边形的断言(定义有效多边形的规则)如下:
a) 多边形是拓扑封闭的;
b) Polygon 的边界由一组 LinearRing 组成,这些 LinearRing 构成其外部和内部边界;
c) 边界交叉中的两个环和多边形边界中的环不能相交于一点,但
仅作为切线,例如
(取自地理信息的 OpenGIS 实现规范 - 简单要素访问 - 第 1 部分:通用架构)
使用这些参数,您可以创建 box2d 或创建馈送所有单独点的多边形。
两个快速注意事项:
St_GeomFromText
将无法ST_SetSRID
定义您的坐标系,这样您就不会得到不愉快的结果With those arguments you can't build a Polygon.
A Polygon is a planar Surface defined by 1 exterior boundary and 0 or more interior boundaries. Each interior boundary defines a hole in the Polygon. A Triangle is a polygon with 3 distinct, non-collinear vertices and no interior boundary.
The exterior boundary LinearRing defines the “top” of the surface which is the side of the surface from which the exterior boundary appears to traverse the boundary in a counter clockwise direction. The interior LinearRings will have the opposite orientation, and appear as clockwise when viewed from the “top”.
The assertions for Polygons (the rules that define valid Polygons) are as follows:
a) Polygons are topologically closed;
b) The boundary of a Polygon consists of a set of LinearRings that make up its exterior and interior boundaries;
c) No two Rings in the boundary cross and the Rings in the boundary of a Polygon may intersect at a Point but
only as a tangent, e.g.
(taken from OpenGIS Implementation Specification for Geographic information - Simple feature access - Part 1: Common architecture)
With those arguments ou can either create a box2d or create the polygon feeding all the indidual points.
Two quick notes:
St_GeomFromText
will not workST_SetSRID
to define your coordinate system so that you don't have unpleasant results我认为这是因为
:top_left_long
和其他参数没有被您的值替换。可以在执行之前打印 SQL 查询吗?
I think it's because
:top_left_long
and other params are not replaced by your values.Can you print the SQL query before the execution?