-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added custom grid * Fixed missing IndexID * Changed index system parameter type * Fixed snapshot version in python * Passing IndexSystem instead of IndexSystemName * Updated python path loader * Fixed CustomIndexSystem polyfill for empty polygon * Fixed mosaic context h3 * Fixed mosaic unite tests for custom grid * Added K-ring and K-loop for custom grid * Fixed cell center offset for custom grid * Fixed lon lat order in custom grid * Fixed grid offset for cell geometries * Fixed KNN tests for custom grid * Fixed buffer radius custom grid * Reduced KNN iterations to speed up tests * Fixed python test * Fixed python import * Changed custom grid conf structure * Fixed unit tests for custom grid * Refactored IndexSystemFactory * Fixed unit test for KNN * Added custom grid for python * Fixed R bindings for custom grid * Updated docs for custom grid * Updated docs for custom grid * Fix KNN tests. * Fixed index Y splits * Fixed index KNN resolution * Fixed double build for feature branch * Fixed grid root cell size calculation * Fixed Ring Neighbours tests * Change Raster to Grid reader to use Centroid of raster pixel if pixel area >= cell area. * Fix variable naming issue. * Add grid_distance expression. Improve metadata extraction for rasters. Improve raster subdataset extraction. * Fix broken tests. * Fix band_id being dropped in raster to grid reader. * Fix broken k interpolation. * Improve code coverage. * Fix merge conflicts. * Merge main and fix conflicts. * Merge custom grid and fix conflicts. Fix grid distance functions. Fix grid distance tests. * Fix Kloop broken test. * Defaulted pixel reference to centroid --------- Co-authored-by: Erni Durdevic <[email protected]>
- Loading branch information
Showing
20 changed files
with
299 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/main/scala/com/databricks/labs/mosaic/expressions/index/GridDistance.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.databricks.labs.mosaic.expressions.index | ||
|
||
import com.databricks.labs.mosaic.core.geometry.api.GeometryAPI | ||
import com.databricks.labs.mosaic.core.index.IndexSystem | ||
import org.apache.spark.sql.catalyst.expressions.{BinaryExpression, Expression, ExpressionInfo, NullIntolerant} | ||
import org.apache.spark.sql.catalyst.expressions.codegen.CodegenFallback | ||
import org.apache.spark.sql.types._ | ||
|
||
case class GridDistance(cellId: Expression, cellId2: Expression, indexSystem: IndexSystem, geometryAPIName: String) | ||
extends BinaryExpression | ||
with NullIntolerant | ||
with CodegenFallback { | ||
|
||
val geometryAPI: GeometryAPI = GeometryAPI(geometryAPIName) | ||
|
||
override def right: Expression = cellId2 | ||
|
||
override def left: Expression = cellId | ||
|
||
/** Expression output DataType. */ | ||
override def dataType: DataType = LongType | ||
|
||
override def toString: String = s"grid_distance($cellId, $cellId2)" | ||
|
||
/** Overridden to ensure [[Expression.sql]] is properly formatted. */ | ||
override def prettyName: String = "grid_distance" | ||
|
||
/** | ||
* Generates a set of indices corresponding to kring call over the input | ||
* cell id. | ||
* | ||
* @param input1 | ||
* Any instance containing the cell id. | ||
* @param input2 | ||
* Any instance containing the k. | ||
* @return | ||
* A set of indices. | ||
*/ | ||
// noinspection DuplicatedCode | ||
override def nullSafeEval(input1: Any, input2: Any): Any = { | ||
val cellId = indexSystem.formatCellId(input1, LongType).asInstanceOf[Long] | ||
val cellId2 = indexSystem.formatCellId(input2, LongType).asInstanceOf[Long] | ||
indexSystem.distance(cellId, cellId2) | ||
} | ||
|
||
override def makeCopy(newArgs: Array[AnyRef]): Expression = { | ||
val asArray = newArgs.take(2).map(_.asInstanceOf[Expression]) | ||
val res = GridDistance(asArray(0), asArray(1), indexSystem, geometryAPIName) | ||
res.copyTagsFrom(this) | ||
res | ||
} | ||
|
||
override protected def withNewChildrenInternal(newLeft: Expression, newRight: Expression): Expression = | ||
makeCopy(Array[AnyRef](newLeft, newRight)) | ||
|
||
} | ||
|
||
object GridDistance { | ||
|
||
/** Entry to use in the function registry. */ | ||
def registryExpressionInfo(db: Option[String]): ExpressionInfo = | ||
new ExpressionInfo( | ||
classOf[GridDistance].getCanonicalName, | ||
db.orNull, | ||
"grid_distance", | ||
"_FUNC_(cellId, cellId2) - Returns k distance for given cells.", | ||
"", | ||
""" | ||
| Examples: | ||
| > SELECT _FUNC_(a, b); | ||
| 10 | ||
| """.stripMargin, | ||
"", | ||
"collection_funcs", | ||
"1.0", | ||
"", | ||
"built-in" | ||
) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.