PostGIS is able to store and manage spatial data based on the relational database PostgreSQL. DLA Ganos is compatible with the PostGIS data access interface and can directly load vector data from PostGIS. This topic describes how to use DLA Ganos to load vector data from PostGIS. In this topic, an automatic identification system (AIS) dataset of global vessel trajectories is used as vector data.

Procedure

  1. Initialize a Spark session.
    // Initialize a Spark session.
    val spark = SparkSession.builder
        .appName("Simple Application")
        .config("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
        .config("spark.sql.crossJoin.enabled", "true")
        .config("spark.kryo.registrator", classOf[GanosSparkKryoRegistrator].getName)
        .getOrCreate()
    import spark.implicits. _
    
    // Load the JTS package for the Spark session to process spatio-temporal data.
    spark.withJTS 
    val sc = spark.sparkContext
  2. Load data.
    // Configure connection parameters.
      val dsParams: JMap[String, String] = Map(
        "host" -> "URL of the PostgreSQL database",
        "polardb.ganos" -> "true",
        "dbtype"->"postgis", 
        "port"->"Port of the PostgreSQL database",
        "schema"->"public",
        "database"->"Name of the PostgreSQL database",
        "user"->"Username",
        "passwd"->"Password")
    
    // Load the AIS dataset.
    df = spark.read.format("ganos-geometry")
          .options(dsParams)
          .option("ganos.feature", "AIS")
          .load()
    df.show
  3. View the results.