Geometry SQL Extensions
1. Available functions
These are the Geometry SQL functions available in LeanXcale.
When a function returns a specific data type, it’s a good practice to cast it to the expected one to avoid problems.
1.20. String ST_GeomFromGeoJSON(String geoJson)
Takes as input a geojson representation of a geometry and outputs a geometry object.
1.28. Geom ST_MakePoint(BigDecimal x, BigDecimal y)
Alias for ST_Point(BigDecimal, BigDecimal).
-
Use Geom ST_MakePoint(double x, double y) for better perfomance*
1.29. Geom ST_MakePoint(BigDecimal x, BigDecimal y, BigDecimal z)
Alias for ST_Point(BigDecimal, BigDecimal, BigDecimal)
1.30. Geom ST_Point(BigDecimal x, BigDecimal y)
Constructs a 2D point from coordinates.
Use Geom ST_MakePoint(double x, double y) for better perfomance
1.31. Geom ST_Point(BigDecimal x, BigDecimal y, BigDecimal z)
Constructs a 3D point from coordinates.
1.37. double ST_Distance(Geom geom1, Geom geom2)
Returns the distance between {@code geom1} and {@code geom2}
1.40. Geom ST_Envelope(Geom geom)
Returns the minimum bounding box of {@code geom} (which may be a GEOMETRYCOLLECTION).
1.41. boolean ST_Contains(Geom geom1, Geom geom2)
Returns whether {@code geom1} contains {@code geom2}.
1.42. boolean ST_ContainsProperly(Geom geom1, Geom geom2)
Returns whether {@code geom1} contains {@code geom2} but does not intersect its boundary
1.43. boolean ST_Crosses(Geom geom1, Geom geom2)
Returns whether {@code geom1} crosses {@code geom2}
1.44. boolean ST_Disjoint(Geom geom1, Geom geom2)
Returns whether {@code geom1} and {@code geom2} are disjoint.
1.45. boolean ST_EnvelopesIntersect(Geom geom1, Geom geom2)
Returns whether the envelope of {@code geom1} intersects the envelope of {@code geom2}.
1.47. boolean ST_Intersects(Geom geom1, Geom geom2)
Returns whether {@code geom1} intersects {@code geom2}.
1.48. boolean ST_OrderingEquals(Geom geom1, Geom geom2)
Returns whether {@code geom1} equals {@code geom2} and their coordinates and component Geometries are listed in the same order.
1.50. boolean ST_Touches(Geom geom1, Geom geom2)
Returns whether {@code geom1} touches {@code geom2}.
1.51. boolean ST_Within(Geom geom1, Geom geom2)
Returns whether {@code geom1} is within {@code geom2}.
1.52. boolean ST_DWithin(Geom geom1, Geom geom2, double distance)
Returns whether {@code geom1} and {@code geom2} are within
-
{@code distance} of each other.
1.54. Geom ST_Buffer(Geom geom, double distance, int quadSegs)
Computes a buffer around {@code geom} with .
1.55. Geom ST_Buffer(Geom geom, double bufferSize, String style)
Computes a buffer around {@code geom}.
1.57. Geom ST_Union(Geom geomCollection)
Computes the union of the geometries in {@code geomCollection}.
1.58. Geom ST_Intersection(Geom geom1, Geom geom2)
Computes the intersection of {@code geom1} and {@code geom2}.
2. Using Geometry functions in LeanXcale
Example of how to select all those countries within a distance of 10 degrees from Madrid:
CREATE TABLE countries(
country varchar,
latitude decimal,
longitude decimal,
name varchar,
primary key(country)
);
SELECT name
FROM countries
WHERE
ST_DWithin(
ST_MakePoint(
cast(40.25 as double), cast(3.41 as double)
),
ST_MakePoint(
cast(latitude as double), cast(longitude as double)
),
cast(10 as double)
);