kanchanchy commented on code in PR #612:
URL: https://github.com/apache/incubator-sedona/pull/612#discussion_r854656997
##########
sql/src/main/scala/org/apache/spark/sql/sedona_sql/io/GeotiffFileFormat.scala:
##########
@@ -101,4 +126,123 @@ private[spark] class GeotiffFileFormat extends FileFormat
with DataSourceRegiste
}
}
}
+
+ private def isValidGeoTiffSchema(options: Map[String, String], dataSchema:
StructType): Boolean = {
+ val colImage = options.getOrElse("key_image", "image")
+ val fields = dataSchema.fieldNames
+ if (fields.contains(colImage) ){
+ val schemaFields =
dataSchema.fields(dataSchema.fieldIndex(colImage)).dataType.asInstanceOf[StructType]
+ if (schemaFields.fieldNames.length != 6) return false
+ }
+ else {
+ if (fields.length != 6) return false
+ }
+ true
+ }
+
+}
+
+// class for writing geoTiff images
+private class GeotiffFileWriter(savePath: String,
+ options: Map[String, String],
+ dataSchema: StructType,
+ context: TaskAttemptContext) extends
OutputWriter {
+
+ // set writing parameters
+ private val DEFAULT_WRITE_PARAMS: GeoTiffWriteParams = new
GeoTiffWriteParams()
+ DEFAULT_WRITE_PARAMS.setCompressionMode(ImageWriteParam.MODE_EXPLICIT)
+ DEFAULT_WRITE_PARAMS.setCompressionType("LZW")
+ DEFAULT_WRITE_PARAMS.setCompressionQuality(0.75F)
+ DEFAULT_WRITE_PARAMS.setTilingMode(ImageWriteParam.MODE_EXPLICIT)
+ DEFAULT_WRITE_PARAMS.setTiling(512, 512)
+
+ private val hfs = new Path(savePath).getFileSystem(context.getConfiguration)
+
+ override def write(row: InternalRow): Unit = {
+ // retrieving the metadata of a geotiff image
+ var rowFields: InternalRow = row
+ var schemaFields: StructType = dataSchema
+ val fields = dataSchema.fieldNames
+
+ val colImage = options.getOrElse("key_image", "image")
+ val colOrigin = options.getOrElse("key_origin", "origin")
+ val colBands = options.getOrElse("key_n_bands", "nBands")
+ val colWidth = options.getOrElse("key_width", "width")
+ val colHeight = options.getOrElse("key_height", "height")
+ val colWkt = options.getOrElse("key_wkt", "wkt")
+ val colData = options.getOrElse("key_data", "data")
+
+ if (fields.contains(colImage)) {
+ schemaFields =
dataSchema.fields(dataSchema.fieldIndex(colImage)).dataType.asInstanceOf[StructType]
+ rowFields = row.getStruct(dataSchema.fieldIndex(colImage), 6)
+ }
+
+ val tiffOrigin = rowFields.getString(schemaFields.fieldIndex(colOrigin))
+ val tiffBands = rowFields.getInt(schemaFields.fieldIndex(colBands))
+ val tiffWidth = rowFields.getInt(schemaFields.fieldIndex(colWidth))
+ val tiffHeight = rowFields.getInt(schemaFields.fieldIndex(colHeight))
+ val tiffGeometry = rowFields.getString(schemaFields.fieldIndex(colWkt))
Review Comment:
@jiayuasu I pushed the new code. I added new unit tests for testing new
cases added in this commit. Also, updated the documentation accordingly.
--
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]