- Range query use ST_Contains. Given a query rectangle R and a set of points P, find all the points within R.
- Range join query use ST_Contains. Given a set of Rectangles R and a set of Points S, find all (Point, Rectangle) pairs such that the point is within the rectangle.
- Distance query use ST_Within. Given a point location P and distance D in km, find all points that lie within a distance D from P
- Distance join query use ST_Within. Given a set of Points S1 and a set of Points S2 and a distance D in km, find all (s1, s2) pairs such that s1 is within a distance D from s2 (i.e., s1 belongs to S1 and s2 belongs to S2).
Input: pointString:String, queryRectangle:String
Output: Boolean (true or false)
Definition: Parse the pointString (e.g., "-88.331492,32.324142") and queryRectangle (e.g., "-155.940114,19.081331,-155.618917,19.5307") to a format that you are comfortable with. Then check whether the queryRectangle fully contains the point. Consider on-boundary point.
Input: pointString1:String, pointString2:String, distance:Double
Output: Boolean (true or false)
Definition: Parse the pointString1 (e.g., "-88.331492,32.324142") and pointString2 (e.g., "-88.331492,32.324142") to a format that you are comfortable with. Then check whether the two points are within the given distance. Consider on-boundary point. To simplify the problem, please assume all coordinates are on a planar space and calculate their Euclidean distance.
Range query:
select *
from point
where ST_Contains(point._c0,'-155.940114,19.081331,-155.618917,19.5307')
Range join query:
select *
from rectangle,point
where ST_Contains(rectangle._c0,point._c0)
Distance query:
select *
from point
where ST_Within(point._c0,'-88.331492,32.324142',10)
Distance join query:
select *
from point p1, point p2
where ST_Within(p1._c0, p2._c0, 10)
Demo Link : https://www.youtube.com/watch?v=07KWPT88yIs