Packages

  • package root
    Definition Classes
    root
  • package com
    Definition Classes
    root
  • package precisely
    Definition Classes
    com
  • package bigdata
    Definition Classes
    precisely
  • package li
    Definition Classes
    bigdata
  • package spark
    Definition Classes
    li
  • package api

    Provides classes and code snippets to simplify usage of Spatial APIs in Location Intelligence SDK For Big Data.

    Provides classes and code snippets to simplify usage of Spatial APIs in Location Intelligence SDK For Big Data.
    For more information regarding the Usage Guide or API Docs, follow the below links:
    Geo Spatial SDKs
    Location Intelligence SDK For Big Data User Guide

    • Starting a spark session:
    import org.apache.spark.sql.SparkSession
    // The config is required to set run the legacy UDFs used in the Spatial APIs.
    val session = SparkSession.builder.appName("Example")
        .master("yarn")
        .getOrCreate;
    • Using DownloadManager capable of downloading remote resources (files like TAB, SHAPE, etc.) to a node local path. Supports downloading from HDFS, S3, Google Storage or Local (default).

      NOTE: For Downloading from S3 or Google Storage, you need to either have respective environment variables like AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY or provide configurations in spark session.
    import com.pb.downloadmanager.api.downloaders.LocalFilePassthroughDownloader
    import com.pb.downloadmanager.api.downloaders.hadoop.{HDFSDownloader, S3Downloader, GoogleDownloader}
    import com.pb.downloadmanager.api.{DownloadManagerBuilder}
    val downloadManager = new DownloadManagerBuilder("/home/hadoop/data")
      .addDownloader(new S3Downloader(session.sparkContext.hadoopConfiguration))
      .addDownloader(new GoogleDownloader(session.sparkContext.hadoopConfiguration))
      .addDownloader(new HDFSDownloader(session.sparkContext.hadoopConfiguration))
      .addDownloader(new LocalFilePassthroughDownloader())
      .build()


    • PointInPolygon Operation:
    import com.precisely.bigdata.li.spark.api.SpatialAPI
    val pointInPolygonDF = SpatialAPI.pointInPolygon(inputDF = inputDF,
                tableFileType = tabFileType,
                tableFilePath = tableFilePath,
                tableFileName = tableFileName,
                libraries = libraries,
                longitude = longitude, latitude = latitude,
                includeEmptySearchResults = true,
                outputFields = outputFields,
                downloadManager = downloadManager
    )
    
    // Defaults:
    // downloadManager = null, libraries = null, includeEmptySearchResults = true


    • SearchNearest Operation:
    import com.precisely.bigdata.li.spark.api.SpatialAPI
    val searchNearestDF = SpatialAPI.searchNearest(inputDF = fabricDF,
                tableFileType = tableFileType,
                tableFilePath = tableFilePath,
                tableFileName = tableFileName,
                libraries = libraries,
                maxCandidates = maxCandidates,
                distanceValue = distanceValue,
                distanceUnit = distanceUnit,
                distanceColumnName = distanceColumnName,
                geometryStringType = geometryStringType,
                geometryColumnName = geometryColumnName,
                includeEmptySearchResults = includeEmptySearchResults,
                outputFields = outputFields,
                downloadManager = downloadManager
    )
    
    // Defaults:
    // distanceColumnName = "distance", downloadManager = null, libraries = null, includeEmptySearchResults = true, maxCandidates = 1000


    • JoinByDistance Operation:
    import com.precisely.bigdata.li.spark.api.SpatialAPI
    import com.precisely.bigdata.li.spark.api.util.DistanceJoinOption.DistanceJoinOption
    import com.precisely.bigdata.li.spark.api.util.LimitMethods
    val joinedDF = SpatialAPI.joinByDistance(df1 = df1,
                  df2 = df2,
                  df1Longitude = longitude1,
                  df1Latitude = latitude1,
                  df2Longitude = longitude2,
                  df2Latitude = latitude2,
                  searchRadius = searchRadius,
                  distanceUnit = distanceUnit,
                  geoHashPrecision = geoHashPrecision,
                  options = Map(
                            DistanceJoinOption.DistanceColumnName -> distanceColumnName,
                            DistanceJoinOption.LimitMatches -> limit,
                            DistanceJoinOption.LimitMethod -> LimitMethods.RowNumber
                  )
    )
    
    // Defaults:
    // geoHashPrecision = 7, options = null


    • HexagonGeneration Operation:
    import com.precisely.bigdata.li.spark.api.SpatialAPI
    val hexGenDF = SpatialAPI.generateHexagon(
                  sparkSession = session,
                  minLongitude = minLongitude,
                  minLatitude = minLatitude,
                  maxLongitude = maxLongitude,
                  maxLatitude = maxLatitude,
                  hexLevel = hexLevel,
                  containerLevel = containerLevel,
                  numOfPartitions = numOfPartitions,
                  maximumNumOfRowsPerPartition = maxNumberOfRows
    )
    
    // Defaults:
    // hexLevel = 1, containerLevel = 1, numOfPartitions = 1, maximumNumOfRowsPerPartition = 1


    • Registering the SQL Functions as UDFs:
    import com.precisely.bigdata.li.spark.api.udf.SQLRegistrator
    SQLRegistrator.registerAll();
    inputDF.createOrReplaceTempView("inputTable")
    val pointGeometry = spark.sql("SELECT ST_Point(X, Y, 'epsg:4326') as point_geom, * from inputTable")
    val wktGeometry = spark.sql("SELECT ST_GeomFromWKT(WKT) as geom, * from inputTable")
    
    // Currently Available SQL Functions
    // ST_Point, ST_GeomFromWKT, ST_GeomFromWKB, ST_GeomFromKML, ST_GeomFromGeoJSON,
    // ST_ToGeoJSON, ST_ToKML, ST_ToWKB, ST_ToWKT, ST_Buffer, ST_Union, ST_Transform,
    // ST_Intersection, ST_ConvexHull, ST_Within, ST_Disjoint, ST_Intersects,
    // ST_IsNullGeom, ST_Overlaps, ST_GeoHash, ST_GeoHashBoundary, ST_HexHash, ST_HexHashBoundary,
    // ST_SquareHash, ST_SquareHashBoundary, ST_X, ST_XMax, ST_XMin, ST_Y, ST_YMax, ST_YMin,
    // ST_Area, ST_Distance, ST_Length, ST_Perimeter
    Definition Classes
    spark
  • package feature
    Definition Classes
    api
  • package table
    Definition Classes
    api
  • package udf
    Definition Classes
    api
  • package util
    Definition Classes
    api
  • JoinByDistance
  • SpatialAPI
  • SpatialImplicits

object SpatialAPI

This class contains all the supported operations methods for spatial operations. Supported spatial operations:

  • PointInPolygon
  • SearchNearest
  • JoinByDistance
  • GenerateHexagon
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. SpatialAPI
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @IntrinsicCandidate() @native()
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  8. def generateHexagon(sparkSession: SparkSession, minLongitude: Double, minLatitude: Double, maxLongitude: Double, maxLatitude: Double, hexLevel: Int = 1, containerLevel: Int = 1, numOfPartitions: Int = 1, maximumNumOfRowsPerPartition: Int = 1): DataFrame

    A HexagonGeneration Operation: This method generates the hexagons within a bounding box defined by minimum and maximum value of longitude and latitude Hexagon output can be used for map display.

    A HexagonGeneration Operation: This method generates the hexagons within a bounding box defined by minimum and maximum value of longitude and latitude Hexagon output can be used for map display.

    sparkSession

    Spark session to be used

    minLongitude

    Minimum longitude value of the bounding box for which hexagons needs to be generated

    minLatitude

    Minimum latitude value of the bounding box for which hexagons needs to be generated

    maxLongitude

    Maximum longitude value of the bounding box for which hexagons needs to be generated

    maxLatitude

    Maximum latitude value of the bounding box for which hexagons needs to be generated

    hexLevel

    The level to generate hexagons for. Must be between 1 and 11.

    containerLevel

    A hint for providing some parallel hexagon generation. Must be less than the hexLevel parameter.

    numOfPartitions

    Number of partitions

    maximumNumOfRowsPerPartition

    Maximum number of rows per partition

    returns

    A dataframe representing the hexagons in WKT format

  9. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @IntrinsicCandidate() @native()
  10. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @IntrinsicCandidate() @native()
  11. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  12. def joinByDistance(df1: DataFrame, df2: DataFrame, df1Longitude: String, df1Latitude: String, df2Longitude: String, df2Latitude: String, searchRadius: Double, distanceUnit: String, geoHashPrecision: Int = 7, options: Map[DistanceJoinOption, Any] = null): DataFrame

    A JoinByDistance Operation: This method joins two dataframes taking longitude and latitude values, one set from each dataframe, representing the location of the record to be joined.

    A JoinByDistance Operation: This method joins two dataframes taking longitude and latitude values, one set from each dataframe, representing the location of the record to be joined. The coordinate values must be in CoordSysConstants.longLatWGS84 coordinate system. This method also takes a searchRadius, which is the buffer around the first point to search for the second point to be inside. The last parameter is a geohash precision that will be used within the calculation.

    df1

    The dataframe to join to

    df2

    The dataframe to be joined

    df1Longitude

    The Longitude value from the first dataframe

    df1Latitude

    The Latitude value from the first dataframe

    df2Longitude

    The Longitude value from the second dataframe

    df2Latitude

    The Latitude value from the second dataframe

    searchRadius

    The buffer length around point 1 to search for point 2

    distanceUnit

    Unit of measurement for searchRadius parameter.

    geoHashPrecision

    The geohash precision value to be used for search

    options

    A key/value map of DistanceJoinOption that apply to the join

    returns

    A dataframe that is the result of the join

  13. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  14. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @IntrinsicCandidate() @native()
  15. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @IntrinsicCandidate() @native()
  16. def pointInPolygon(inputDF: DataFrame, tableFileType: String, tableFilePath: String, tableFileName: String, longitude: String, latitude: String, outputFields: Seq[String], downloadManager: DownloadManager = null, libraries: String = null, includeEmptySearchResults: Boolean = true): DataFrame

    A PointInPolygon Operation: This method filters the point coordinates in input dataframe which are within a specified polygon (for example, the polygon of the continental USA) Adds output fields from polygon table to input dataset as columns.

    A PointInPolygon Operation: This method filters the point coordinates in input dataframe which are within a specified polygon (for example, the polygon of the continental USA) Adds output fields from polygon table to input dataset as columns.

    inputDF

    dataframe of input dataset

    tableFileType

    Type of target polygon data file (either TAB/shape/geodatabase)

    tableFilePath

    Path to polygon data files

    tableFileName

    Name of the TAB/shape/geodatabase file

    longitude

    Name of column containing longitude values in input point data

    latitude

    Name of column containing latitude values in input point data

    outputFields

    The requested fields to be included in the output

    downloadManager

    DownloadManager instance to be used if data is present in S3 or HDFS

    libraries

    libraries in case of geodatabase tableFileType

    includeEmptySearchResults

    if true then an empty search will keep the original input row and the new columns will be null and if false then an empty search will result in the row not appearing in the outputted DataFrame

    returns

    input DataFrame appended with output fields as columns if point coordinates lie within specified polygon

  17. def searchNearest(inputDF: DataFrame, tableFileType: String, tableFilePath: String, tableFileName: String, geometryStringType: String, geometryColumnName: String, outputFields: Seq[String], distanceValue: Double, distanceUnit: String, distanceColumnName: String = "distance", downloadManager: DownloadManager = null, libraries: String = null, maxCandidates: Int = 1000, includeEmptySearchResults: Boolean = true): DataFrame

    A SearchNearest Operation: This method takes in a geometry string (either in GeoJSON, WKT, KML or WKB format) and searches for it in a table of geometries within a specified distance.

    A SearchNearest Operation: This method takes in a geometry string (either in GeoJSON, WKT, KML or WKB format) and searches for it in a table of geometries within a specified distance. Searched geometries counts can be limited by defining maxCandidates parameter. By default, geometries are listed from nearest to farthest.

    inputDF

    dataframe of input dataset

    tableFileType

    Type of target polygon data file (either TAB/shape/geodatabase)

    tableFilePath

    Path to polygon data files

    tableFileName

    Name of the TAB/shape/geodatabase file

    geometryStringType

    Type of geometry string provided in input file. Supported values are WKT/GeoJSON/WKB/KML

    geometryColumnName

    Name of column containing string representation of geometry

    outputFields

    The requested fields to be included in the output

    distanceValue

    The absolute value of distance from source geometry within which target geometries will be searched for.

    distanceUnit

    Unit of measurement for distanceValue parameter. This same unit will also be used when appending distance column in output dataframe.

    distanceColumnName

    Name of the distance column in output dataframe which indicates distance between source geometry and target geometry.

    downloadManager

    DownloadManager instance to be used if data is present in S3 or HDFS

    libraries

    libraries in case of geodatabase tableFileType

    maxCandidates

    Limits the count of target geometries to search for

    includeEmptySearchResults

    if true then an empty search will keep the original input row and the new columns will be null and if false then an empty search will result in the row not appearing in the outputted DataFrame

    returns

    input DataFrame appended with output fields as columns if distance between source geometry and target geometry is within distanceValue. Also, an additional column with name distanceColumnName is returned indicating the distance between source and target geometry and records are ordered by ascending value of this column.

  18. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  19. def toString(): String
    Definition Classes
    AnyRef → Any
  20. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  21. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  22. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

    (Since version 9)

Inherited from AnyRef

Inherited from Any

Ungrouped