WritableGeometry - Spectrum_Location_Intelligence_for_Big_Data - 5.2.1

Location Intelligence SDK for Big Data Guide

Product type
Software
Portfolio
Locate
Product family
Spectrum
Product
Spatial Big Data > Location Intelligence SDK for Big Data
Version
5.2.1
Language
English
Product name
Location Intelligence for Big Data
Title
Location Intelligence SDK for Big Data Guide
Copyright
2024
First publish date
2015
Last updated
2024-10-16
Published on
2024-10-16T13:55:01.634374

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;
The ST_IsNullGeom UDF provides the capability to perform a null check on an instance of WritableGeometry. The ST_IsNullGeom function returns true if the geometry is NULL or empty; otherwise, it returns false. The result type is a boolean.
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.