获取边界框内的点

发布于 2024-10-20 16:58:59 字数 468 浏览 5 评论 0原文

我试图从我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你的笑 2024-10-27 16:58:59

这是我在旧项目中使用的查询:

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 是我的几何列
注:MakeBox2D取左上角和右下

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

骄傲 2024-10-27 16:58:59

根据这些参数,您无法构建多边形

多边形是由 1 个外部边界和 0 个或多个内部边界定义的平面。每个内部边界在多边形中定义一个洞。三角形是具有 3 个不同的、不共线的顶点且没有内部边界的多边形。

外部边界 LinearRing 定义表面的“顶部”,即外部边界看起来以逆时针方向穿过边界的表面的一侧。内部 LinearRings 将具有相反的方向,并且从“顶部”观察时显示为顺时针方向。

多边形的断言(定义有效多边形的规则)如下:

a) 多边形是拓扑封闭的;

b) Polygon 的边界由一组 LinearRing 组成,这些 LinearRing 构成其外部和内部边界;

c) 边界交叉中的两个环和多边形边界中的环不能相交于一点,但
仅作为切线,例如

(取自地理信息的 OpenGIS 实现规范 - 简单要素访问 - 第 1 部分:通用架构

使用这些参数,您可以创建 box2d 或创建馈送所有单独点的多边形。

两个快速注意事项:

  1. 确保您的参数是字符串,否则 St_GeomFromText 将无法
  2. 使用 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:

  1. make sure your arguments are strings or St_GeomFromText will not work
  2. use ST_SetSRID to define your coordinate system so that you don't have unpleasant results
土豪 2024-10-27 16:58:59

我认为这是因为 :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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文