Add PostGIS Spatial Operators Support

#81 · open · 1 comments

View on GitHub ↗

maxhelias

PostGIS provides powerful spatial operators (like `<->`, `&&`, `@>`) that can leverage spatial indexes much more efficiently than equivalent functions. Currently, Doctrine doesn't supports custom operators, which means users cannot take advantage of these performance-critical operators in DQL queries. ### PostGIS Operators Overview #### Distance Operators (enable KNN queries) - [ ] `<->` : Distance operator (used for ORDER BY - K-Nearest Neighbors) - [ ] `<#>` : Bounding box distance operator - [ ] `|=|` : Distance operator at their closest point of approach #### Bounding Box Relationship Operators (enable efficient spatial filtering) - [ ] `&&` : Overlaps (bounding boxes overlap) - [ ] `@>` : Contains (A contains B) - [ ] `<@` : Contained by (A is contained by B) - [ ] `~=` : Same (same geometry) - [ ] `<<` : Is left of - [ ] `>>` : Is right of - [ ] `&<` : Overlaps or is left of - [ ] `&>` : Overlaps or is right of - [ ] `<<|` : Is below - [ ] `|>>` : Is above - [ ] `&<|` : Overlaps or is below - [ ] `|&>` : Overlaps or is above ### Proposed Implementation Since Doctrine DQL doesn't natively support custom operators, we'll implement them as DQL functions that generate the operator syntax in SQL. ``` // src/Functions/Operators/ ├── DistanceOperator.php // <-> ├── BBoxDistanceOperator.php // <#> ├── OverlapsOperator.php // && ├── ContainsOperator.php // @> ├── ContainedByOperator.php // <@ ├── SameOperator.php // ~= ├── LeftOperator.php // << ├── RightOperator.php // >> ├── BelowOperator.php // <<| └── AboveOperator.php // |>> ```

Comments

maxhelias

Another proposition here : https://github.com/jsor/doctrine-postgis/issues/15#issuecomment-240662356