-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix missing spatial reference when generating index geom.
Fix SR transformations in MosaicGeometry. Add NDVI and Clip expressions. Fix projection issues in RST_Tessellate.
- Loading branch information
milos.colic
committed
Sep 8, 2023
1 parent
f220d75
commit cd47656
Showing
16 changed files
with
404 additions
and
59 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
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
55 changes: 55 additions & 0 deletions
55
src/main/scala/com/databricks/labs/mosaic/core/raster/operator/NDVI.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,55 @@ | ||
package com.databricks.labs.mosaic.core.raster.operator | ||
|
||
import com.databricks.labs.mosaic.core.raster.MosaicRaster | ||
import com.databricks.labs.mosaic.core.raster.gdal_raster.MosaicRasterGDAL | ||
import com.databricks.labs.mosaic.utils.PathUtils | ||
|
||
object NDVI { | ||
|
||
def emptyCopy(raster: MosaicRaster, path: String): MosaicRaster = { | ||
val driver = raster.getRaster.GetDriver() | ||
val newRaster = driver.Create(path, raster.xSize, raster.ySize, raster.numBands, raster.getRaster.GetRasterBand(1).getDataType) | ||
newRaster.SetGeoTransform(raster.getRaster.GetGeoTransform) | ||
newRaster.SetProjection(raster.getRaster.GetProjection) | ||
MosaicRasterGDAL(newRaster, path, isTemp = true) | ||
} | ||
|
||
def compute(raster: MosaicRaster, redIndex: Int, nirIndex: Int): MosaicRaster = { | ||
|
||
val redBand = raster.getRaster.GetRasterBand(redIndex) | ||
val nirBand = raster.getRaster.GetRasterBand(nirIndex) | ||
|
||
val numLines = redBand.GetYSize | ||
val lineSize = redBand.GetXSize | ||
|
||
val ndviPath = PathUtils.createTmpFilePath(raster.uuid.toString, raster.getExtension) | ||
val ndviRaster = emptyCopy(raster, ndviPath) | ||
|
||
var outputLine: Array[Double] = null | ||
var redScanline: Array[Double] = null | ||
var nirScanline: Array[Double] = null | ||
val dataType = org.gdal.gdalconst.gdalconstConstants.GDT_Float64 | ||
for (line <- Range(0, numLines)) { | ||
redScanline = Array.fill[Double](lineSize)(0.0) | ||
nirScanline = Array.fill[Double](lineSize)(0.0) | ||
redBand.ReadRaster(0, line, lineSize, 1, dataType, redScanline) | ||
nirBand.ReadRaster(0, line, lineSize, 1, dataType, nirScanline) | ||
|
||
outputLine = redScanline.zip(nirScanline).map { case (red, nir) => | ||
if (red + nir == 0) 0.0 | ||
else (nir - red) / (red + nir) | ||
} | ||
ndviRaster.getRaster | ||
.GetRasterBand(1) | ||
.WriteRaster(0, line, lineSize, 1, dataType, outputLine.array) | ||
} | ||
outputLine = null | ||
redScanline = null | ||
nirScanline = null | ||
|
||
ndviRaster.flushCache() | ||
|
||
ndviRaster | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/scala/com/databricks/labs/mosaic/core/raster/operator/proj/RasterProject.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,29 @@ | ||
package com.databricks.labs.mosaic.core.raster.operator.proj | ||
|
||
import com.databricks.labs.mosaic.core.raster.MosaicRaster | ||
import com.databricks.labs.mosaic.core.raster.operator.gdal.GDALWarp | ||
import com.databricks.labs.mosaic.utils.PathUtils | ||
import org.gdal.osr.SpatialReference | ||
|
||
object RasterProject { | ||
|
||
def project(raster: MosaicRaster, destCRS: SpatialReference): MosaicRaster = { | ||
val outShortName = raster.getRaster.GetDriver().getShortName | ||
|
||
val resultFileName = PathUtils.createTmpFilePath(raster.uuid.toString, raster.getExtension) | ||
|
||
// Note that Null is the right value here | ||
val authName = destCRS.GetAuthorityName(null) | ||
val authCode = destCRS.GetAuthorityCode(null) | ||
|
||
val result = GDALWarp.executeWarp( | ||
resultFileName, | ||
isTemp = true, | ||
Seq(raster), | ||
command = s"gdalwarp -of $outShortName -t_srs $authName:$authCode -r cubic -overwrite -co COMPRESS=PACKBITS" | ||
) | ||
|
||
result | ||
} | ||
|
||
} |
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.