我有两个表,分别称为“ District”和“ SensorData”。从这两个表中,我想知道表'SensorData'中的哪些点在'District'多边形内。
我已编写此查询以获取所需的结果:
SELECT combined_sensor_data.point_geom, district.geom_pol
FROM combined_sensor_data, district
WHERE ST_Within(district.geom_pol, combined_sensor_data.point_geom);
但是不幸的是,我在任何地区都没有意义。我确定这是错误的结果。所以我假设我的查询中有一个错误。因此,我要问查询中可能出什么问题了?
答案 0 :(得分:1)
您可以尝试更改参数顺序:
SELECT combined_sensor_data.point_geom, district.geom_pol
FROM combined_sensor_data
JOIN district
ON ST_Within(combined_sensor_data.point_geom, district.geom_pol);
答案 1 :(得分:0)
据我对您问题的理解,看来您想检查table2(“区”)是否也具有与table1(“传感器数据”)中相同的数据点。
您可以为此使用PostgreSQL EXISTS:
select combined_sensor_data.point_geom from combined_sensor_data sd
where exists (select 1 from district d where d.geom_pol=sd.point_geom)
答案 2 :(得分:0)
尝试此查询。它会更改该点是包含在其他表中还是包含在该多边形上。您可能需要更改group by子句
SELECT combined_sensor_data.point_geom, district.geom_pol
bool_or((ST_Contains(T2.geom_pol, T1.point_geom) OR ST_Overlaps(T1.point_geom,T2.geom_pol))) AS my_bool
FROM combined_sensor_data AS T1
CROSS JOIN district AS T2 WHERE my_bool is true
GROUP BY combined_sensor_data.point_geom, district.geom_pol