空间查询Postgis

发布于 2025-01-10 20:28:54 字数 954 浏览 3 评论 0原文

我有一个多边形城市和多边形数据,导入到 PostgreSQL、PostGIS 中。这些与城市相交。我需要做的第一件事是将城市表中的 id 打印到另一个表中,但是在执行此操作时,它需要获取多边形所在城市的 id。我尝试了一些函数来执行此操作,但出现错误。你能帮我设计 SQL 命令行吗?

update maden_polygon set objectid = maden_polygon.ilce_id
from (SELECT maden_polygon.ilce_id as id ,ankara_ilce.objectid as ilce_id
FROM maden_polygon , ankara_ilce
WHERE st_intersects(maden_polygon.geom, ankara_ilce.geom)) as maden_polygon 
where maden_polygon.ilce_id = anakara_ilce.object_id

(错误:多次指定表名“maden_polygon”)

我想要做的是将 ankara_ilce 表中的 objectid 列打印到mine_polygon ilce_id 表。 在这样做的同时, 写出哪个矿场的object_id在哪个县境内。

SELECT 
maden_polygon.ilce_id as id ,
ankara_ilce.objectid as ad ,
ankara_ilce.adi as adi
from maden_polygon , ankara_ilce 
where St_intersects(ankara_ilce.geom , maden_polygon.geom  )  as sorgu
where maden_polygon.id = sorgu.id ;

错误:“as”处或附近的语法错误 第 6 行:...intersects(ankara_ilce.geom , maden_polygon.geom ) as sorgu

I have a polygon city and polygon data that I import into PostgreSQL, PostGIS. These intersect with cities. The first thing I need to do is to print the id from the city table to the other table, but while doing this, it needs to get the id of the city where the polygon is located. I tried a few functions to do this but got an error. Can you help me design the SQL command line?

update maden_polygon set objectid = maden_polygon.ilce_id
from (SELECT maden_polygon.ilce_id as id ,ankara_ilce.objectid as ilce_id
FROM maden_polygon , ankara_ilce
WHERE st_intersects(maden_polygon.geom, ankara_ilce.geom)) as maden_polygon 
where maden_polygon.ilce_id = anakara_ilce.object_id

(ERROR: table name "maden_polygon" specified more than once )

What I want to do is to print the objectid column in the ankara_ilce table to the mine_polygon ilce_id table.
While doing this,
Write the object_id of which mine is within the boundaries of which county.

SELECT 
maden_polygon.ilce_id as id ,
ankara_ilce.objectid as ad ,
ankara_ilce.adi as adi
from maden_polygon , ankara_ilce 
where St_intersects(ankara_ilce.geom , maden_polygon.geom  )  as sorgu
where maden_polygon.id = sorgu.id ;

ERROR: syntax error at or near "as"
LINE 6: ...ntersects(ankara_ilce.geom , maden_polygon.geom ) as sorgu

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

两相知 2025-01-17 20:28:54

我认为查询很简单:

UPDATE maden_polygon set objectid = ilce_id
FROM  ankara_ilce
WHERE st_intersects(maden_polygon.geom, ankara_ilce.geom)

但是 - 请注意,如果多边形重叠,st_intersects 可以为每个 maden_polygon 返回多个记录,这可能会给您带来不一致的结果。您可以尝试使用 st_contains 代替(请注意某些记录可能不会以这种方式更新)。或者,您可以匹配一个多边形的质心,例如

UPDATE maden_polygon set objectid = ilce_id
    FROM  ankara_ilce
    WHERE st_within(st_centroid(maden_polygon.geom), ankara_ilce.geom)

祝你好运!

I think the query is a simple as this:

UPDATE maden_polygon set objectid = ilce_id
FROM  ankara_ilce
WHERE st_intersects(maden_polygon.geom, ankara_ilce.geom)

BUT - note that the st_intersects can return multiple records per maden_polygon if your polygons overlap, and that might give you inconsistent results. You could try using st_contains instead (being aware that some records might not update that way). OR, you could match on the centroid of the one polygon e.g.

UPDATE maden_polygon set objectid = ilce_id
    FROM  ankara_ilce
    WHERE st_within(st_centroid(maden_polygon.geom), ankara_ilce.geom)

Good luck!

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