This is an implementation of Spark UDF's Writable interface for geometry.
Spatial Spark SQL user defined functions (UDFs) use WritableGeometry to exchange data between two functions. Constructor Hive functions provide a mechanism to get an instance of WritableGeometry from standard geometry formats like WKT, WKB, GeoJSON and KML. For example:
To get an instance of WritableGeometry from WKT:
SELECT ST_GeomFromWKT(t.geometry,'epsg:4267') FROM table t;
To get an instance of WritableGeometry from WKB string:
SELECT ST_GeomFromWKB(t.geometry,'epsg:4267') FROM table t;
Persistence Hive UDFs convert an instance of WritableGeometry to standard formats like WKT, WKB, GeoJSON and KML. For example:
To serialize an instance of WritableGeometry to WKT:
SELECT ST_ToWKT(t.geometry) FROM table t;
The output of Constructor functions can be supplied as input to other Spark SQL functions that perform some operations on it. For example:
To calculate the length of a geometry:
SELECT ST_Length(ST_GeomFromWKT(t.geometry, 'epsg:4267'), 'm', 'SPHERICAL') FROM table t;
To get the distance between two geometries:
SELECT ST_Distance(ST_GeomFromWKT(t.geometry,'epsg:4267'),
ST_GeomFromWKT(t.geometry2,'epsg:4267'), 'm', 'SPHERICAL') FROM table t;
SELECT ST_IsNullGeom(null);
SELECT ST_IsNullGeom(ST_GeomFromWKT("POINT(10 20)"));
SELECT ST_IsNullGeom(ST_Point(x, y, 'epsg:4326')) FROM src;
For more information, see Writable.html.