1 /***********************************************************************
2  * Copyright (c) 2019-2025 The MITRE Corporation
3  * This program and the accompanying materials are made available under
4  * the Apache License, Version 2.0 which is available at
5  * https://www.apache.org/licenses/LICENSE-2.0
6  * This software was produced for the U. S. Government under Basic
7  * Contract No. W56KGU-18-D-0004, and is subject to the Rights in
8  * Noncommercial Computer Software and Noncommercial Computer Software
9  * Documentation Clause 252.227-7014 (FEB 2012)
10  ***********************************************************************/
11 
12 package org.locationtech.geomesa.spark.sql
13 
14 import org.apache.spark.sql.{Column, Encoder, Encoders, TypedColumn}
15 import org.locationtech.geomesa.spark.jts.encoders.SpatialEncoders
16 import org.locationtech.geomesa.spark.jts.util.SQLFunctionHelper._
17 import org.locationtech.geomesa.spark.sql.GeometricDistanceFunctions.{ST_Transform, distanceNames}
18 import org.locationtech.jts.geom.Geometry
19 
20 import java.lang
21 
22 
23 /**
24  * DataFrame DSL functions for working with GeoTools
25  */
26 object DataFrameFunctions extends SpatialEncoders {
27 
28   implicit def integerEncoder: Encoder[Integer] = Encoders.INT
29   implicit def doubleEncoder: Encoder[Double] = Encoders.scalaDouble
30   implicit def jDoubleEncoder: Encoder[lang.Double] = Encoders.DOUBLE
31 
32   /**
33    * Group of DataFrame DSL functions associated with determining the relationship
34    * between geometries using GeoTools.
35    */
36   trait SpatialRelations {
37 
38     import org.locationtech.geomesa.spark.jts.udf.SpatialRelationFunctions._
39 
40     def st_distanceSpheroid(left: Column, right: Column): TypedColumn[Any, lang.Double] =
41       udfToColumn(ST_DistanceSphere, relationNames, left, right)
42 
43     def st_lengthSphere(line: Column): TypedColumn[Any, lang.Double] =
44       udfToColumn(ST_LengthSphere, relationNames, line)
45 
46     def st_transform(geom: Column, fromCRS: Column, toCRS: Column): TypedColumn[Any, Geometry] =
47       udfToColumn(ST_Transform, distanceNames, geom, fromCRS, toCRS)
48   }
49 
50   /** Stack of all DataFrame DSL functions. */
51   trait Library extends SpatialRelations
52 }
Line Stmt Id Pos Tree Symbol Tests Code
28 89 1197 - 1209 Select org.apache.spark.sql.Encoders.INT org.apache.spark.sql.Encoders.INT
29 90 1258 - 1278 Select org.apache.spark.sql.Encoders.scalaDouble org.apache.spark.sql.Encoders.scalaDouble
30 91 1333 - 1348 Select org.apache.spark.sql.Encoders.DOUBLE org.apache.spark.sql.Encoders.DOUBLE
41 92 1699 - 1716 Select org.locationtech.geomesa.spark.jts.udf.SpatialRelationFunctions.ST_DistanceSphere org.locationtech.geomesa.spark.jts.udf.SpatialRelationFunctions.ST_DistanceSphere
41 93 1718 - 1731 Select org.locationtech.geomesa.spark.jts.udf.SpatialRelationFunctions.relationNames org.locationtech.geomesa.spark.jts.udf.SpatialRelationFunctions.relationNames
41 94 1698 - 1698 Select org.locationtech.geomesa.spark.sql.DataFrameFunctions.jDoubleEncoder DataFrameFunctions.this.jDoubleEncoder
41 95 1687 - 1745 ApplyToImplicitArgs org.locationtech.geomesa.spark.jts.util.SQLFunctionHelper.udfToColumn org.locationtech.geomesa.spark.jts.util.SQLFunctionHelper.udfToColumn[org.locationtech.jts.geom.Geometry, org.locationtech.jts.geom.Geometry, Double, Object](org.locationtech.geomesa.spark.jts.udf.SpatialRelationFunctions.ST_DistanceSphere, org.locationtech.geomesa.spark.jts.udf.SpatialRelationFunctions.relationNames, left, right)(({ val $u: reflect.runtime.universe.type = scala.reflect.runtime.`package`.universe; val $m: $u.Mirror = scala.reflect.runtime.`package`.universe.runtimeMirror(classOf[org.locationtech.geomesa.spark.sql.DataFrameFunctions$$SpatialRelations].getClassLoader()); $u.TypeTag.apply[org.locationtech.jts.geom.Geometry]($m, { final class $typecreator1 extends TypeCreator { def <init>(): $typecreator1 = { $typecreator1.super.<init>(); () }; def apply[U <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.Mirror[U]): U#Type = { val $u: U = $m$untyped.universe; val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror]; $m.staticClass("org.locationtech.jts.geom.Geometry").asType.toTypeConstructor } }; new $typecreator1() }) }: reflect.runtime.universe.TypeTag[org.locationtech.jts.geom.Geometry]), ({ val $u: reflect.runtime.universe.type = scala.reflect.runtime.`package`.universe; val $m: $u.Mirror = scala.reflect.runtime.`package`.universe.runtimeMirror(classOf[org.locationtech.geomesa.spark.sql.DataFrameFunctions$$SpatialRelations].getClassLoader()); $u.TypeTag.apply[org.locationtech.jts.geom.Geometry]($m, { final class $typecreator2 extends TypeCreator { def <init>(): $typecreator2 = { $typecreator2.super.<init>(); () }; def apply[U <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.Mirror[U]): U#Type = { val $u: U = $m$untyped.universe; val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror]; $m.staticClass("org.locationtech.jts.geom.Geometry").asType.toTypeConstructor } }; new $typecreator2() }) }: reflect.runtime.universe.TypeTag[org.locationtech.jts.geom.Geometry]), ({ val $u: reflect.runtime.universe.type = scala.reflect.runtime.`package`.universe; val $m: $u.Mirror = scala.reflect.runtime.`package`.universe.runtimeMirror(classOf[org.locationtech.geomesa.spark.sql.DataFrameFunctions$$SpatialRelations].getClassLoader()); $u.TypeTag.apply[Double]($m, { final class $typecreator3 extends TypeCreator { def <init>(): $typecreator3 = { $typecreator3.super.<init>(); () }; def apply[U <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.Mirror[U]): U#Type = { val $u: U = $m$untyped.universe; val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror]; $m.staticClass("java.lang.Double").asType.toTypeConstructor } }; new $typecreator3() }) }: reflect.runtime.universe.TypeTag[Double]), DataFrameFunctions.this.jDoubleEncoder)
44 96 1836 - 1851 Select org.locationtech.geomesa.spark.jts.udf.SpatialRelationFunctions.ST_LengthSphere org.locationtech.geomesa.spark.jts.udf.SpatialRelationFunctions.ST_LengthSphere
44 97 1853 - 1866 Select org.locationtech.geomesa.spark.jts.udf.SpatialRelationFunctions.relationNames org.locationtech.geomesa.spark.jts.udf.SpatialRelationFunctions.relationNames
44 98 1835 - 1835 Select org.locationtech.geomesa.spark.sql.DataFrameFunctions.jDoubleEncoder DataFrameFunctions.this.jDoubleEncoder
44 99 1824 - 1873 ApplyToImplicitArgs org.locationtech.geomesa.spark.jts.util.SQLFunctionHelper.udfToColumn org.locationtech.geomesa.spark.jts.util.SQLFunctionHelper.udfToColumn[org.locationtech.jts.geom.LineString, Double, Object](org.locationtech.geomesa.spark.jts.udf.SpatialRelationFunctions.ST_LengthSphere, org.locationtech.geomesa.spark.jts.udf.SpatialRelationFunctions.relationNames, line)(({ val $u: reflect.runtime.universe.type = scala.reflect.runtime.`package`.universe; val $m: $u.Mirror = scala.reflect.runtime.`package`.universe.runtimeMirror(classOf[org.locationtech.geomesa.spark.sql.DataFrameFunctions$$SpatialRelations].getClassLoader()); $u.TypeTag.apply[org.locationtech.jts.geom.LineString]($m, { final class $typecreator1 extends TypeCreator { def <init>(): $typecreator1 = { $typecreator1.super.<init>(); () }; def apply[U <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.Mirror[U]): U#Type = { val $u: U = $m$untyped.universe; val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror]; $m.staticClass("org.locationtech.jts.geom.LineString").asType.toTypeConstructor } }; new $typecreator1() }) }: reflect.runtime.universe.TypeTag[org.locationtech.jts.geom.LineString]), ({ val $u: reflect.runtime.universe.type = scala.reflect.runtime.`package`.universe; val $m: $u.Mirror = scala.reflect.runtime.`package`.universe.runtimeMirror(classOf[org.locationtech.geomesa.spark.sql.DataFrameFunctions$$SpatialRelations].getClassLoader()); $u.TypeTag.apply[Double]($m, { final class $typecreator2 extends TypeCreator { def <init>(): $typecreator2 = { $typecreator2.super.<init>(); () }; def apply[U <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.Mirror[U]): U#Type = { val $u: U = $m$untyped.universe; val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror]; $m.staticClass("java.lang.Double").asType.toTypeConstructor } }; new $typecreator2() }) }: reflect.runtime.universe.TypeTag[Double]), DataFrameFunctions.this.jDoubleEncoder)
47 100 1990 - 2002 Select org.locationtech.geomesa.spark.sql.GeometricDistanceFunctions.ST_Transform org.locationtech.geomesa.spark.sql.GeometricDistanceFunctions.ST_Transform
47 101 2004 - 2017 Select org.locationtech.geomesa.spark.sql.GeometricDistanceFunctions.distanceNames org.locationtech.geomesa.spark.sql.GeometricDistanceFunctions.distanceNames
47 102 1989 - 1989 Select org.locationtech.geomesa.spark.jts.encoders.SpatialEncoders.jtsGeometryEncoder DataFrameFunctions.this.jtsGeometryEncoder
47 103 1978 - 2040 ApplyToImplicitArgs org.locationtech.geomesa.spark.jts.util.SQLFunctionHelper.udfToColumn org.locationtech.geomesa.spark.jts.util.SQLFunctionHelper.udfToColumn[org.locationtech.jts.geom.Geometry, String, String, org.locationtech.jts.geom.Geometry, Object](org.locationtech.geomesa.spark.sql.GeometricDistanceFunctions.ST_Transform, org.locationtech.geomesa.spark.sql.GeometricDistanceFunctions.distanceNames, geom, fromCRS, toCRS)(({ val $u: reflect.runtime.universe.type = scala.reflect.runtime.`package`.universe; val $m: $u.Mirror = scala.reflect.runtime.`package`.universe.runtimeMirror(classOf[org.locationtech.geomesa.spark.sql.DataFrameFunctions$$SpatialRelations].getClassLoader()); $u.TypeTag.apply[org.locationtech.jts.geom.Geometry]($m, { final class $typecreator1 extends TypeCreator { def <init>(): $typecreator1 = { $typecreator1.super.<init>(); () }; def apply[U <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.Mirror[U]): U#Type = { val $u: U = $m$untyped.universe; val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror]; $m.staticClass("org.locationtech.jts.geom.Geometry").asType.toTypeConstructor } }; new $typecreator1() }) }: reflect.runtime.universe.TypeTag[org.locationtech.jts.geom.Geometry]), ({ val $u: reflect.runtime.universe.type = scala.reflect.runtime.`package`.universe; val $m: $u.Mirror = scala.reflect.runtime.`package`.universe.runtimeMirror(classOf[org.locationtech.geomesa.spark.sql.DataFrameFunctions$$SpatialRelations].getClassLoader()); $u.TypeTag.apply[String]($m, { final class $typecreator2 extends TypeCreator { def <init>(): $typecreator2 = { $typecreator2.super.<init>(); () }; def apply[U <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.Mirror[U]): U#Type = { val $u: U = $m$untyped.universe; val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror]; $u.internal.reificationSupport.TypeRef($u.internal.reificationSupport.SingleType($m.staticPackage("scala").asModule.moduleClass.asType.toTypeConstructor, $m.staticModule("scala.Predef")), $u.internal.reificationSupport.selectType($m.staticModule("scala.Predef").asModule.moduleClass, "String"), scala.collection.immutable.Nil) } }; new $typecreator2() }) }: reflect.runtime.universe.TypeTag[String]), ({ val $u: reflect.runtime.universe.type = scala.reflect.runtime.`package`.universe; val $m: $u.Mirror = scala.reflect.runtime.`package`.universe.runtimeMirror(classOf[org.locationtech.geomesa.spark.sql.DataFrameFunctions$$SpatialRelations].getClassLoader()); $u.TypeTag.apply[String]($m, { final class $typecreator3 extends TypeCreator { def <init>(): $typecreator3 = { $typecreator3.super.<init>(); () }; def apply[U <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.Mirror[U]): U#Type = { val $u: U = $m$untyped.universe; val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror]; $u.internal.reificationSupport.TypeRef($u.internal.reificationSupport.SingleType($m.staticPackage("scala").asModule.moduleClass.asType.toTypeConstructor, $m.staticModule("scala.Predef")), $u.internal.reificationSupport.selectType($m.staticModule("scala.Predef").asModule.moduleClass, "String"), scala.collection.immutable.Nil) } }; new $typecreator3() }) }: reflect.runtime.universe.TypeTag[String]), ({ val $u: reflect.runtime.universe.type = scala.reflect.runtime.`package`.universe; val $m: $u.Mirror = scala.reflect.runtime.`package`.universe.runtimeMirror(classOf[org.locationtech.geomesa.spark.sql.DataFrameFunctions$$SpatialRelations].getClassLoader()); $u.TypeTag.apply[org.locationtech.jts.geom.Geometry]($m, { final class $typecreator4 extends TypeCreator { def <init>(): $typecreator4 = { $typecreator4.super.<init>(); () }; def apply[U <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.Mirror[U]): U#Type = { val $u: U = $m$untyped.universe; val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror]; $m.staticClass("org.locationtech.jts.geom.Geometry").asType.toTypeConstructor } }; new $typecreator4() }) }: reflect.runtime.universe.TypeTag[org.locationtech.jts.geom.Geometry]), DataFrameFunctions.this.jtsGeometryEncoder)