Add SQL OUTSIDE operator for geometry types

This commit is contained in:
Tobie Morgan Hitchcock 2022-04-29 21:41:57 +01:00
parent fb27185435
commit 6f93c38cd2
3 changed files with 11 additions and 1 deletions

View file

@ -193,6 +193,13 @@ pub fn inside_none(a: &Value, b: &Value) -> Result<Value, Error> {
}
}
pub fn outside(a: &Value, b: &Value) -> Result<Value, Error> {
match a.intersects(b) {
true => Ok(Value::False),
false => Ok(Value::True),
}
}
pub fn intersects(a: &Value, b: &Value) -> Result<Value, Error> {
match a.intersects(b) {
true => Ok(Value::True),

View file

@ -109,6 +109,7 @@ impl Expression {
Operator::AllInside => fnc::operate::inside_all(&l, &r),
Operator::AnyInside => fnc::operate::inside_any(&l, &r),
Operator::NoneInside => fnc::operate::inside_none(&l, &r),
Operator::Outside => fnc::operate::outside(&l, &r),
Operator::Intersects => fnc::operate::intersects(&l, &r),
_ => unreachable!(),
}

View file

@ -48,6 +48,7 @@ pub enum Operator {
AllInside, // ⊆
AnyInside, // ⊂
NoneInside, // ⊄
Outside, // ∈
Intersects, // ∩
}
@ -106,6 +107,7 @@ impl fmt::Display for Operator {
Operator::AllInside => write!(f, "ALL INSIDE"),
Operator::AnyInside => write!(f, "ANY INSIDE"),
Operator::NoneInside => write!(f, "NONE INSIDE"),
Operator::Outside => write!(f, "OUTSIDE"),
Operator::Intersects => write!(f, "INTERSECTS"),
}
}
@ -195,7 +197,7 @@ pub fn phrases(i: &str) -> IResult<&str, Operator> {
map(tag_no_case("NONE INSIDE"), |_| Operator::NoneInside),
map(tag_no_case("NOT INSIDE"), |_| Operator::NotInside),
map(tag_no_case("INSIDE"), |_| Operator::Inside),
map(tag_no_case("OUTSIDE"), |_| Operator::NotInside),
map(tag_no_case("OUTSIDE"), |_| Operator::Outside),
map(tag_no_case("INTERSECTS"), |_| Operator::Intersects),
)),
))(i)?;