jiayuasu commented on a change in pull request #552:
URL: https://github.com/apache/incubator-sedona/pull/552#discussion_r722892657
##########
File path:
sql/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala
##########
@@ -1167,3 +1167,46 @@ case class ST_SubDivideExplode(children:
Seq[Expression]) extends Generator {
override protected def doGenCode(ctx: CodegenContext, ev: ExprCode):
ExprCode = ev
}
+
+
+case class ST_MakePolygon(inputExpressions: Seq[Expression])
+ extends Expression with CodegenFallback {
+ override def nullable: Boolean = true
+ private val geometryFactory = new GeometryFactory()
+
+ override def eval(input: InternalRow): Any = {
+ inputExpressions.betweenLength(1, 2)
+ val exteriorRing = inputExpressions.head
+ val possibleHolesRaw =
inputExpressions.tail.headOption.map(_.eval(input).asInstanceOf[ArrayData])
+ val numOfElements = possibleHolesRaw.map(_.numElements()).getOrElse(0)
+
+ val holes = (0 until numOfElements).map(el => possibleHolesRaw match {
+ case Some(value) => Some(value.getArray(el))
+ case None => None
+ }).filter(_.nonEmpty)
+ .map(el => el.map(_.toGeometry))
+ .flatMap{
+ case maybeLine: Option[LineString] =>
+ maybeLine.map(line =>
geometryFactory.createLinearRing(line.getCoordinates))
+ case _ => None
+ }
+
+ exteriorRing.toGeometry(input) match {
+ case geom: LineString =>
+ try {
+ val poly = new
Polygon(geometryFactory.createLinearRing(geom.getCoordinates), holes.toArray,
geometryFactory)
+ poly.toGenericArrayData
+ }
+ catch {
+ case e: Exception => null
Review comment:
Sounds good to me!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]