Skip to content

Commit

Permalink
Integrated StreamingSegmentBytes into Int16GeoTiffTile
Browse files Browse the repository at this point in the history
Signed-off-by: jbouffard <jbouffard@azavea.com>
  • Loading branch information
jbouffard committed Dec 5, 2016
1 parent cc716f7 commit ac2bac5
Showing 1 changed file with 38 additions and 39 deletions.
Expand Up @@ -68,50 +68,49 @@ class Int32GeoTiffTile(

def crop(gridBounds: GridBounds): MutableArrayTile = {
val arr = Array.ofDim[Byte](gridBounds.size * IntConstantNoDataCellType.bytes)
val segments = segmentBytes.intersectingSegments
var counter = 0

if (segmentLayout.isStriped) {
cfor(0)(_ < segmentCount, _ + 1) { i =>
val segmentGridBounds = segmentLayout.getGridBounds(i)
if (gridBounds.intersects(segmentGridBounds)) {
val segment = getSegment(i)

val result = gridBounds.intersection(segmentGridBounds).get
val intersection = Intersection(segmentGridBounds, result, segmentLayout)

val adjStart = intersection.start * IntConstantNoDataCellType.bytes
val adjEnd = intersection.end * IntConstantNoDataCellType.bytes
val adjCols = intersection.cols * IntConstantNoDataCellType.bytes
val adjWidth = result.width * IntConstantNoDataCellType.bytes

cfor(adjStart)(_ < adjEnd, _ + adjCols) { i =>
System.arraycopy(segment.bytes, i, arr, counter, adjWidth)
counter += adjWidth
}
}
cfor(0)(_ < segments.length, _ + 1) { i =>
val segmentId = segments(i)
val segment = getSegment(segmentId)
val segmentGridBounds = segmentLayout.getGridBounds(segmentId)

val result = gridBounds.intersection(segmentGridBounds).get
val intersection = Intersection(segmentGridBounds, result, segmentLayout)

val adjStart = intersection.start * IntConstantNoDataCellType.bytes
val adjEnd = intersection.end * IntConstantNoDataCellType.bytes
val adjCols = intersection.cols * IntConstantNoDataCellType.bytes
val adjWidth = result.width * IntConstantNoDataCellType.bytes

cfor(adjStart)(_ < adjEnd, _ + adjCols) { i =>
System.arraycopy(segment.bytes, i, arr, counter, adjWidth)
counter += adjWidth
}
}
} else {
cfor(0)(_ < segmentCount, _ + 1) { i =>
val segmentGridBounds = segmentLayout.getGridBounds(i)
if (gridBounds.intersects(segmentGridBounds)) {
val segment = getSegment(i)
val segmentTransform = segmentLayout.getSegmentTransform(i)

val result = gridBounds.intersection(segmentGridBounds).get
val intersection = Intersection(segmentGridBounds, result, segmentLayout)

val adjStart = intersection.start * IntConstantNoDataCellType.bytes
val adjEnd = intersection.end * IntConstantNoDataCellType.bytes
val adjTileWidth = intersection.tileWidth * IntConstantNoDataCellType.bytes
val adjWidth= result.width * IntConstantNoDataCellType.bytes

cfor(adjStart)(_ < adjEnd, _ + adjTileWidth) { i =>
val col = segmentTransform.indexToCol(i / IntConstantNoDataCellType.bytes)
val row = segmentTransform.indexToRow(i / IntConstantNoDataCellType.bytes)
val j = (row - gridBounds.rowMin) * gridBounds.width + (col - gridBounds.colMin)
System.arraycopy(segment.bytes, i, arr, j * IntConstantNoDataCellType.bytes, adjWidth)
}
}
cfor(0)(_ < segments.length, _ + 1) { i =>
val segmentId = segments(i)
val segment = getSegment(segmentId)
val segmentGridBounds = segmentLayout.getGridBounds(segmentId)
val segmentTransform = segmentLayout.getSegmentTransform(segmentId)

val result = gridBounds.intersection(segmentGridBounds).get
val intersection = Intersection(segmentGridBounds, result, segmentLayout)

val adjStart = intersection.start * IntConstantNoDataCellType.bytes
val adjEnd = intersection.end * IntConstantNoDataCellType.bytes
val adjTileWidth = intersection.tileWidth * IntConstantNoDataCellType.bytes
val adjWidth= result.width * IntConstantNoDataCellType.bytes

cfor(adjStart)(_ < adjEnd, _ + adjTileWidth) { i =>
val col = segmentTransform.indexToCol(i / IntConstantNoDataCellType.bytes)
val row = segmentTransform.indexToRow(i / IntConstantNoDataCellType.bytes)
val j = (row - gridBounds.rowMin) * gridBounds.width + (col - gridBounds.colMin)
System.arraycopy(segment.bytes, i, arr, j * IntConstantNoDataCellType.bytes, adjWidth)
}
}
}
IntArrayTile.fromBytes(arr, gridBounds.width, gridBounds.height, cellType)
Expand Down

0 comments on commit ac2bac5

Please sign in to comment.