1

私はこのチュートリアルを行ってきました: https://databricks.com/notebooks/geomesa-h3-notebook.html

ポリゴン関数 (polygonToH3) は完全に機能しますが、マルチ ポリゴン関数では奇妙な結果が得られます。数百万の H3 インデックスを期待していましたが、少なくとも 10,000 km2 の領域に対して数百のインデックスしか生成しませんでした

val multiPolygonToH3 = udf{ (geometry: Geometry, resolution: Int) => 
  var points: List[GeoCoord] = List()
  var holes: List[java.util.List[GeoCoord]] = List()
  if (geometry.getGeometryType == "MultiPolygon") {
    val numGeometries = geometry.getNumGeometries()
    if (numGeometries > 0) {
      points = List(
        geometry
          .getGeometryN(0)
          .getCoordinates()
          .toList
          .map(coord => new GeoCoord(coord.y, coord.x)): _* )
    }
    if (numGeometries > 1) {
      holes = (1 to (numGeometries - 1)).toList.map(n => {
        List(
          geometry
            .getGeometryN(n)
            .getCoordinates()
            .toList
            .map(coord => new GeoCoord(coord.y, coord.x)): _*).asJava 
      })
    }
  }
  H3.instance.polyfill(points, holes.asJava, resolution).toList 
}
This is the code that calls the above function: 

def ConvertMultiPolyH3(iLGA:Int) : Boolean = {

  var batch_start = System.currentTimeMillis()
  val res = 12
  var sSQL = s"""SELECT * from tca_test_dl.lga 
             WHERE lga_wkt is not null and lga_id = $iLGA and GeometryType = 'MultiPolygon'""".stripMargin
  val dfLGA = sparkSession.sql(sSQL)

  val wktdfLGA = dfLGA.withColumn("lga_geom", st_geomFromWKT(col("lga_wkt")))
                        .withColumn("lga_id", col("lga_id").cast(LongType))
                        .withColumn("state_id", col("state_id").cast(LongType)).cache

  val dfLGA_H3 = wktdfLGA.withColumn("h3_index", multiPolygonToH3(col("lga_geom"),lit(res))).withColumn("h3_index", explode($"h3_index"))
  dfLGA_H3.printSchema()

  val dfLGA_New = dfLGA_H3.drop("lga_wkt", "lga_geom")
  //dfLGA_New.write.mode("append").format("delta").partitionBy("lga_id").save("/mnt/cont-tca-test/delta_lake/lga_h3")
  println(dfLGA_New.count())
  var batch_time = (System.currentTimeMillis() - batch_start)/1000.0/60.0
  batch_time = BigDecimal(batch_time).setScale(2, BigDecimal.RoundingMode.HALF_UP).toDouble
  println(s"LGA H3 conversion for LGA: $iLGA has been processed in $batch_time minutes")

  dfLGA.unpersist()
  wktdfLGA.unpersist()
  dfLGA_H3.unpersist()
  dfLGA_New.unpersist()
  val result = true
  return result
}
4

0 に答える 0