Skip to content

Commit 6699954

Browse files
committed
Updated handling of Python TileUDT to handle RasterRefs better.
1 parent a74c77a commit 6699954

File tree

6 files changed

+28
-19
lines changed

6 files changed

+28
-19
lines changed

core/src/main/scala/org/locationtech/rasterframes/ref/DelegatingRasterSource.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ abstract class DelegatingRasterSource(source: URI, delegateBuilder: () => GTRast
4343
f(_delRef)
4444
}
4545
catch {
46-
// On this exeception we attempt to recreate the delegate and read again.
46+
// On this Exeception we attempt to recreate the delegate and read again.
4747
case _: java.nio.BufferUnderflowException =>
4848
_delRef = null
4949
val newDel = delegateBuilder()
@@ -62,7 +62,7 @@ abstract class DelegatingRasterSource(source: URI, delegateBuilder: () => GTRast
6262
override def hashCode(): Int = source.hashCode()
6363

6464
// This helps reduce header reads between serializations
65-
def info: SimpleRasterInfo = SimpleRasterInfo.cache.get(source.toASCIIString, _ =>
65+
def info: SimpleRasterInfo = SimpleRasterInfo(source.toASCIIString, _ =>
6666
retryableRead(rs => SimpleRasterInfo(rs))
6767
)
6868

core/src/main/scala/org/locationtech/rasterframes/ref/GDALRasterSource.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ case class GDALRasterSource(source: URI) extends RasterSource with URIRasterSour
4848
VLMRasterSource(tweaked)
4949
}
5050

51-
protected def tiffInfo = SimpleRasterInfo.cache.get(source.toASCIIString, _ => SimpleRasterInfo(gdal))
51+
protected def tiffInfo = SimpleRasterInfo(source.toASCIIString, _ => SimpleRasterInfo(gdal))
5252

5353
override def crs: CRS = tiffInfo.crs
5454

core/src/main/scala/org/locationtech/rasterframes/ref/SimpleRasterInfo.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ case class SimpleRasterInfo(
4444
)
4545

4646
object SimpleRasterInfo {
47+
// Not a fan of this.... need a better abstraction that doesn't put the
48+
// type-specific logic in here.
49+
def apply(key: String, builder: String => SimpleRasterInfo): SimpleRasterInfo =
50+
cache.get(key, builder)
51+
4752
def apply(info: GeoTiffReader.GeoTiffInfo): SimpleRasterInfo =
4853
SimpleRasterInfo(
4954
info.segmentLayout.totalCols,
@@ -76,10 +81,9 @@ object SimpleRasterInfo {
7681
)
7782
}
7883

79-
private[rasterframes]
80-
lazy val cache = Scaffeine()
84+
private lazy val cache = Scaffeine()
8185
.recordStats()
8286
.build[String, SimpleRasterInfo]
8387

8488
def cacheStats = cache.stats()
85-
}
89+
}

pyrasterframes/src/main/python/pyrasterframes/rf_context.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ def build_info(self):
4949
return self._jrfctx.buildInfo()
5050

5151
# NB: Tightly coupled to `org.locationtech.rasterframes.py.PyRFContext._resolveRasterRef`
52-
def _resolve_raster_ref(self, ref):
52+
def _resolve_raster_ref(self, ref_struct):
5353
f = self.lookup("_resolveRasterRef")
5454
return f(
55-
ref.source.raster_source_kryo,
56-
ref.bandIndex,
57-
ref.subextent.xmin,
58-
ref.subextent.ymin,
59-
ref.subextent.xmax,
60-
ref.subextent.ymax,
55+
ref_struct.source.raster_source_kryo,
56+
ref_struct.bandIndex,
57+
ref_struct.subextent.xmin,
58+
ref_struct.subextent.ymin,
59+
ref_struct.subextent.xmax,
60+
ref_struct.subextent.ymax,
6161
)
6262

6363
@staticmethod

pyrasterframes/src/main/python/pyrasterframes/rf_types.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,16 +421,22 @@ def deserialize(self, datum):
421421
:param datum:
422422
:return: A Tile object from row data.
423423
"""
424-
cell_type = CellType(datum.cell_context.cellType.cellTypeName)
425-
cols = datum.cell_context.dimensions.cols
426-
rows = datum.cell_context.dimensions.rows
424+
427425
cell_data_bytes = datum.cell_data.cells
428426
if cell_data_bytes is None:
429427
if datum.cell_data.ref is None:
430428
raise Exception("Invalid Tile structure. Missing cells and reference")
431429
else:
432430
payload = datum.cell_data.ref
433-
cell_data_bytes = RFContext.active()._resolve_raster_ref(payload)
431+
ref = RFContext.active()._resolve_raster_ref(payload)
432+
cell_type = CellType(ref.cellType().name())
433+
cols = ref.cols()
434+
rows = ref.rows()
435+
cell_data_bytes = ref.tile().toBytes()
436+
else:
437+
cell_type = CellType(datum.cell_context.cellType.cellTypeName)
438+
cols = datum.cell_context.dimensions.cols
439+
rows = datum.cell_context.dimensions.rows
434440

435441
if cell_data_bytes is None:
436442
raise Exception("Unable to fetch cell data from: " + repr(datum))

pyrasterframes/src/main/scala/org/locationtech/rasterframes/py/PyRFContext.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,7 @@ class PyRFContext(implicit sparkSession: SparkSession) extends RasterFunctions
228228
def _resolveRasterRef(srcBin: Array[Byte], bandIndex: jInt, xmin: jDouble, ymin: jDouble, xmax: jDouble, ymax: jDouble): AnyRef = {
229229
val src = KryoSupport.deserialize[RasterSource](ByteBuffer.wrap(srcBin))
230230
val extent = Extent(xmin, ymin, xmax, ymax)
231-
val ref = RasterRef(src, bandIndex, Some(extent), None)
232-
ref.tile.toArrayTile().toBytes()
231+
RasterRef(src, bandIndex, Some(extent), None)
233232
}
234233

235234
def _dfToMarkdown(df: DataFrame, numRows: Int, truncate: Boolean): String = {

0 commit comments

Comments
 (0)