[英]st_within as a condition of insert
I have built myself a tracker, and as part of the spec I gave myself for security reasons, i dont want people knowing where I leave my car overnight. 我已经为自己打造了一个追踪器,出于安全原因,我给自己定了规格,我不想让人们知道我整夜离开汽车的地方。
SO I have a concept of exclusion zones, I have the web map only showing data outside said exclusion zones, but I also only want to save data when transmitted that isnt within an exclusion zone (there can be more than one so am thinking subquery 所以我有一个排除区域的概念,我的网络地图只显示了在所述排除区域之外的数据,但是我也只想保存在排除区域内不存在的数据(可能有多个,所以我在考虑子查询)
can anyone help? 有人可以帮忙吗?
It is possible, if not preferrable that this be a stored proc, any ideas (I am useless when it comes to subqueries hence asking) 可能(如果不是可取的话)将其作为存储的proc,则可能有任何想法(当涉及子查询时,我毫无用处,因此询问)
the SQL I am using to get the data (retrospective exclusion zones) is thus 因此,我用来获取数据的SQL(追溯排除区)
SELECT geom
FROM public.data
WHERE layer = %layer_id% and not exists(
SELECT *
FROM public.exclusion_zone
WHERE layer = %layer_id% and ST_CONTAINS(the_geom, geom))
For example, this code returns all geometries (say, points) from public.data
, which are not completely inside geometries (say, polygons) from public.exclusion_zone
: 例如,此代码从
public.data
返回所有几何形状(例如,点),但它们并不完全在public.exclusion_zone
几何形状(例如,多边形)内部:
SELECT *
FROM public.data
WHERE the_geom NOT IN (
SELECT d.the_geom
FROM public.data d, public.exclusion_zone e
WHERE ST_Within (d.the_geom, e.the_geom)
);
or even better (assuming that operations with integer IDs are faster than to compare geometries): 甚至更好(假设具有整数ID的操作比比较几何要快):
SELECT * FROM public.data
WHERE id NOT IN (
SELECT d.id
FROM public.data d, public.exclusion_zone e
WHERE ST_Within (d.the_geom, e.the_geom)
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.