简体   繁体   English

如何进行通用查询以从 Postgis 几何类型获取点

[英]How to make a generic query to get a point from a Postgis geometry type

I have a geometry field in one of the tables in my PostgreSQL database with the Postgis extension, this field is valued with the following possibilities, POINT, LINESTRING and POLYGON.我的PostgreSQL数据库中的一个表中有一个带有Postgis扩展的几何字段,该字段具有以下可能性:POINT、LINESTRING 和 POLYGON。 I wonder if it is possible to set up a query so that regardless of the point format I can retrieve a POINT contained in geometry to be used in a WHERE clause, so that I can retrieve a tuple that has a point close to the searched one.我想知道是否可以设置一个查询,以便无论点格式如何,我都可以检索包含在几何中的 POINT 以用于 WHERE 子句,这样我就可以检索一个元组,该元组的点与搜索到的元组接近.

DDL:动态链接库:

CREATE TABLE public.contribution (
    id serial4 NOT NULL,
    occurrence timestamp(6) NULL,
    risk_damage bool NOT NULL DEFAULT false,
    victims bool NOT NULL DEFAULT false,
    published varchar(1) NOT NULL DEFAULT 'P'::character varying,
    "desc" varchar(500) NULL,
    "local" geometry NOT NULL,
    id_category int4 NOT NULL,
    id_collaborator int4 NULL,
    id_manager int4 NULL,
    created_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT contribution_pkey PRIMARY KEY (id)
);

"local" column supports POINT, POLYGON and LINESTRING, I would like to make a query that given a coordinate's X and Y value returns tuples that have the coordinate in question, for example: “本地”列支持 POINT、POLYGON 和 LINESTRING,我想查询给定坐标的 X 和 Y 值,返回具有相关坐标的元组,例如:

Select * from contribution where 10.0000 < local.x < 12000 and 20.0000 < local.y < 22.0000

In this situation I need to know if any point of the "local" geometry is in the above range and this is what I need.在这种情况下,我需要知道“局部”几何体的任何一点是否在上述范围内,这就是我所需要的。

Instead of using a range on X and Y, turn it into a polygon and check if this box intersects with the stored geometries:不要在 X 和 Y 上使用范围,而是将其转换为多边形并检查此框是否与存储的几何图形相交:

Select * 
from contribution 
where st_intersects(local,
  ST_SetSRID(
   ST_MakeBox2D(
    ST_Point(10, 20),
    ST_Point(12 ,22)),4326);

And if you were interested in a distance of 1 around 11;21, you could use st_dwithin instead:如果您对 11 左右的距离感兴趣;21,您可以改用st_dwithin

Select * 
from contribution 
where st_dwithin(local,
  ST_SetSRID(
   ST_Point(12, 22),
  ,4326),
  1);

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

相关问题 如何在Postgis中更新复杂几何图形的特定点 - How to update a particular point of a complex geometry in Postgis 如何在Sequelize ORM中插入PostGIS GEOMETRY Point? - How to insert a PostGIS GEOMETRY Point in Sequelize ORM? 如何使用Hibernate和PostGIS从此几何对象中获取字符串 - How can I get a String from this Geometry Object with hibernate and PostGIS 将PostGIS几何类型从Shapely中导入为Python的几何类型吗? - Importing a PostGIS geometry type into Python as a geometry type from Shapely? SELECT FROM 查询与 PostGIS 几何不工作 - SELECT FROM query with PostGIS geometry not working PostGIS:如何使用通用 3D GEOMETRY 列创建表? - PostGIS: How to create a table with a generic 3D GEOMETRY column? 如何使用java在Postgis数据库中存储几何点 - How to store geometry Point in Postgis database using java Java with MyBatis postgreql postgis query - type geometry does not exist 错误 - Java with MyBatis postgreql postgis query - type geometry does not exist error PostGIS 查询 Select 多边形表中的所有多边形,这些多边形具有相交的几何图形,在传递的地理坐标列表中具有一个或多个点 - PostGIS query to Select all Polygons from Polygon table having an intersecting geometry with one or more point in passed list of GeoCoordinates PostGIS几何点或PostgreSQL原生点? - PostGIS geometry point or PostgreSQL native point?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM