简体   繁体   English

在边界框内获取点数

[英]Get points inside a bounding box

I'm trying to choose places from my postgis db that are inside a certain bounding box. 我正在尝试从我的postgis db中选择位于某个边界框内的位置。 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? 我的意思是 - 先经度,然后是纬度?

Here is a query I used in an old project: 这是我在旧项目中使用的查询:

SELECT param1, param2, ... 
FROM messages 
WHERE ST_Contains( 
    ST_SetSRID(
        ST_MakeBox2D(
            ST_Point(0, 50), ST_Point(50,0)
        ), 
        4326
    ), 
    the_geom
)

the_geom was my geometry column Note: MakeBox2D take top-left and right-bottom the_geom是我的几何列注意:MakeBox2D采用左上角和右下角

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. 多边形是由1个外部边界和0个或更多内部边界定义的平面表面。 Each interior boundary defines a hole in the Polygon. 每个内部边界在多边形中定义一个孔。 A Triangle is a polygon with 3 distinct, non-collinear vertices and no interior boundary. 三角形是具有3个不同的非共线顶点且没有内部边界的多边形。

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. 外部边界LinearRing定义了表面的“顶部”,该表面是外部边界以逆时针方向穿过边界的表面的一侧。 The interior LinearRings will have the opposite orientation, and appear as clockwise when viewed from the “top”. 内部LinearRings将具有相反的方向,从“顶部”查看时显示为顺时针方向。

The assertions for Polygons (the rules that define valid Polygons) are as follows: 多边形的断言(定义有效多边形的规则)如下:

a) Polygons are topologically closed; a)多边形在拓扑上是封闭的;

b) The boundary of a Polygon consists of a set of LinearRings that make up its exterior and interior boundaries; b)Polygon的边界由一组构成其外部和内部边界的LinearRings组成;

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, eg c)边界中没有两个环交叉,并且多边形边界中的环可以在一个点处相交但仅作为切线相交,例如

(taken from OpenGIS Implementation Specification for Geographic information - Simple feature access - Part 1: Common architecture ) (摘自OpenGIS地理信息实施规范 - 简单的特征访问 - 第1部分:通用架构

With those arguments ou can either create a box2d or create the polygon feeding all the indidual points. 有了这些参数,你可以创建一个box2d或者创建多边形来提供所有的偶然点。

Two quick notes: 两个快速说明:

  1. make sure your arguments are strings or St_GeomFromText will not work 确保你的参数是字符串或St_GeomFromText不起作用
  2. use ST_SetSRID to define your coordinate system so that you don't have unpleasant results 使用ST_SetSRID定义您的坐标系,这样您就不会有不愉快的结果

I think it's because :top_left_long and other params are not replaced by your values. 我认为这是因为:top_left_long和其他参数不会被您的值替换。

Can you print the SQL query before the execution? 你可以在执行之前打印SQL查询吗?

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

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