common_function/scalars/
geo.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::sync::Arc;
16pub(crate) mod encoding;
17mod geohash;
18mod h3;
19mod helpers;
20mod measure;
21mod relation;
22mod s2;
23mod wkt;
24
25use crate::function_registry::FunctionRegistry;
26
27pub(crate) struct GeoFunctions;
28
29impl GeoFunctions {
30    pub fn register(registry: &FunctionRegistry) {
31        // geohash
32        registry.register(Arc::new(geohash::GeohashFunction));
33        registry.register(Arc::new(geohash::GeohashNeighboursFunction));
34
35        // h3 index
36        registry.register(Arc::new(h3::H3LatLngToCell));
37        registry.register(Arc::new(h3::H3LatLngToCellString));
38
39        // h3 index inspection
40        registry.register(Arc::new(h3::H3CellBase));
41        registry.register(Arc::new(h3::H3CellIsPentagon));
42        registry.register(Arc::new(h3::H3StringToCell));
43        registry.register(Arc::new(h3::H3CellToString));
44        registry.register(Arc::new(h3::H3CellCenterLatLng));
45        registry.register(Arc::new(h3::H3CellResolution));
46
47        // h3 hierarchical grid
48        registry.register(Arc::new(h3::H3CellCenterChild));
49        registry.register(Arc::new(h3::H3CellParent));
50        registry.register(Arc::new(h3::H3CellToChildren));
51        registry.register(Arc::new(h3::H3CellToChildrenSize));
52        registry.register(Arc::new(h3::H3CellToChildPos));
53        registry.register(Arc::new(h3::H3ChildPosToCell));
54        registry.register(Arc::new(h3::H3CellContains));
55
56        // h3 grid traversal
57        registry.register(Arc::new(h3::H3GridDisk));
58        registry.register(Arc::new(h3::H3GridDiskDistances));
59        registry.register(Arc::new(h3::H3GridDistance));
60        registry.register(Arc::new(h3::H3GridPathCells));
61
62        // h3 measurement
63        registry.register(Arc::new(h3::H3CellDistanceSphereKm));
64        registry.register(Arc::new(h3::H3CellDistanceEuclideanDegree));
65
66        // s2
67        registry.register(Arc::new(s2::S2LatLngToCell));
68        registry.register(Arc::new(s2::S2CellLevel));
69        registry.register(Arc::new(s2::S2CellToToken));
70        registry.register(Arc::new(s2::S2CellParent));
71
72        // spatial data type
73        registry.register(Arc::new(wkt::LatLngToPointWkt));
74
75        // spatial relation
76        registry.register(Arc::new(relation::STContains));
77        registry.register(Arc::new(relation::STWithin));
78        registry.register(Arc::new(relation::STIntersects));
79
80        // spatial measure
81        registry.register(Arc::new(measure::STDistance));
82        registry.register(Arc::new(measure::STDistanceSphere));
83        registry.register(Arc::new(measure::STArea));
84    }
85}