The following Measurement functions are available:
• Area
• ClosestPoints
• Distance
• Length
• Perimeter Area
Description
The Area function calculates and returns the area of given Geometry in the desired unit. The unit must be specified as a parameter while calling the function. The area of a polygon is computed as the area of its exterior ring minus the areas of its interior rings. Points and curves have zero area.
Function Registration
create function Area as 'com.pb.bigdata.spatial.hive.measurement.Area';
Syntax
Area(WritableGeometry geometry, String areaUnits, [String computationType])
Parameters
Description Type
Parameter
The input geometry.
WritableGeometry geometry
The desired return unit type. For valid values, seeArea Unitson page 33.
String areaUnits
Description Type
Parameter
Optional. Indicates the logic to be used to interpret geometry coordinates. The
computation type is based on the coordinate system of the geometry being operated on:
• For geographic (long/lat) coordinate systems: Valid type = SPHERICAL (default)
• For projected coordinate systems: Valid types = CARTESIAN, SPHERICAL (default)
• For engineering coordinate systems: Valid type = CARTESIAN (default)
The geometry coordinates are interpreted using cartesian logic.
CARTESIAN
The geometry coordinates are interpreted using spherical logic.
SPHERICAL String
computationType
Area Units
Valid values for unit are the following area units:
Description
Description Value
square US Survey feet sq survey ft
square nautical miles sq nmi
acres acre
hectares ha
Return Values
Description Return Type
The area of the geometry.
Double
Examples
SELECT Area(FromWkt(t.geometry,'epsg:4267'), 'sq mi', 'SPHERICAL') FROM hivetable t;
SELECT Area(FromWkt(t.geometry,'epsg:4267'), 'sq mi') FROM hivetable t;
ClosestPoints
Description
The ClosestPoints function returns the closest points between two geometries.
Function Registration
create function ClosestPoints as 'com.pb.bigdata.spatial.hive.measurement.ClosestPoints';
Syntax
ClosestPoints(WritableGeometry geometry1, WritableGeometry geometry2)
Parameters
Description Type
Parameter
The first instance of a WritableGeometry.
WritableGeometry geometry1
The second instance of a WritableGeometry.
WritableGeometry geometry2
Return Values
Description Return Type
The closest points between the two geometries. The geometries that intersect are at distance zero from each other, and in this case a shared point is returned.
Array<WritableGeometry>
Examples
SELECT ToWKT(result.points[0]) AS point1, ToWKT(result.points[1]) AS point2 FROM hivetable t LATERAL VIEW OUTER inline(array(named_struct('points', ClosestPoints(FromWKT(t.geometry1, 'epsg:4326'), FromWkt(t.geometry2, 'epsg:4326'), 'SPHERICAL')))) result;
Distance
Description
The Distance function calculates and returns the distance between two geometries.
Function Registration
create function Distance as 'com.pb.bigdata.spatial.hive.measurement.Distance';
Syntax
Distance(WritableGeometry geometry1, WritableGeometry geometry2, String linearUnits, [String computationType])
Parameters
Description Type
Parameter
The first instance of a WritableGeometry.
WritableGeometry geometry1
The second instance of a WritableGeometry.
WritableGeometry geometry2
The desired return unit type. For valid values, seeLinear Unitson page 36.
String linearUnits
Optional. Indicates the logic to be used to interpret geometry coordinates. The
computation type is based on the coordinate system of the geometry being operated on:
• For geographic (long/lat) coordinate systems: Valid type = SPHERICAL (default)
• For projected coordinate systems: Valid types = CARTESIAN, SPHERICAL (default)
• For engineering coordinate systems: Valid type = CARTESIAN (default)
The geometry coordinates are interpreted using cartesian logic.
CARTESIAN
The geometry coordinates are interpreted using spherical logic.
SPHERICAL String
computationType
Linear Units
The following table lists the valid values for unit type.
Description
Description
US Survey feet survey ft
The distance between the two geometries. Geometries that intersect are at distance zero from each other. Distance is always non-negative.
Double
Examples
SELECT Distance(FromWkt(t.geometry,'epsg:4267'), FromWkt(t.geometry2,'epsg:4267'), 'm', 'SPHERICAL') FROM hivetable t;
SELECT Distance(FromWkt(t.geometry,'epsg:4267'), FromWkt(t.geometry2,'epsg:4267'), 'm') FROM hivetable t;
Length
Description
The Length function calculates and returns the geographic length of a line or polyline geometry object in the desired unit type.
Function Registration
create function Length as 'com.pb.bigdata.spatial.hive.measurement.Length';
Syntax
Length(WritableGeometry geometry, String linearUnits, [String computationType])
Parameters
Description Type
Parameter
The input geometry.
WritableGeometry geometry
The desired return unit type. For valid values, seeLinear Unitson page 38.
String linearUnits
Optional. Indicates the logic to be used to interpret geometry coordinates. The
computation type is based on the coordinate system of the geometry being operated on:
• For geographic (long/lat) coordinate systems: Valid type = SPHERICAL (default)
• For projected coordinate systems: Valid types = CARTESIAN, SPHERICAL (default)
• For engineering coordinate systems: Valid type = CARTESIAN (default)
The geometry coordinates are interpreted using cartesian logic.
CARTESIAN
The geometry coordinates are interpreted using spherical logic.
SPHERICAL String
computationType
Linear Units
Valid values for unit type:
Description Value
miles mi
kilometers km
inches in
feet ft
yards yd
millimeters mm
centimeters cm
meters m
US Survey feet survey ft
nautical miles nmi
Return Values
Description Return Type
The length of the geometry.
Double
Examples
SELECT Length(FromWkt(t.geometry,'epsg:4267'), 'm', 'SPHERICAL') FROM hivetable t;
SELECT Length(FromWkt(t.geometry,'epsg:4267'), 'm') FROM hivetable t;
Perimeter
Description
The Perimeter function calculates and returns the total perimeter of a given geometry in the desired unit type. The Perimeter of a polygon is the sum of the lengths of its rings (both exterior and holes).
The curves are considered as thin polygons.
Function Registration
create function Perimeter as 'com.pb.bigdata.spatial.hive.measurement.Perimeter';
Syntax
Perimeter(WritableGeometry geometry, String linearUnits, [String computationType])
Parameters
Description Type
Parameter
The input geometry.
WritableGeometry geometry
The desired return unit type. For valid values, seeLinear Unitson page 41.
String linearUnits
Optional. Indicates the logic to be used to interpret geometry coordinates. The
computation type is based on the coordinate system of the geometry being operated on:
• For geographic (long/lat) coordinate systems: Valid type = SPHERICAL (default)
• For projected coordinate systems: Valid types = CARTESIAN, SPHERICAL (default)
• For engineering coordinate systems: Valid type = CARTESIAN (default)
The geometry coordinates are interpreted using cartesian logic.
CARTESIAN
The geometry coordinates are interpreted using spherical logic.
SPHERICAL String
computationType
Linear Units
Valid values for unit type:
Description
US Survey feet survey ft
The perimeter of the geometry.
Double
Examples
SELECT Perimeter(FromWkt(t.geometry,'epsg:4267'), 'm', 'SPHERICAL') FROM hivetable t;