Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All traits that inherit CellGrid and Grid should be abstract classes #3136

Merged
merged 13 commits into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis/build-and-test-set-1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"project doc-examples" compile \
"project vector" test \
"project vectortile" test \
"project util" test \
"project gdal" test \
"project geowave" compile test:compile \
"project hbase" compile \
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Fix `StreamingByteReader` over-allocation when reading past EOF [#3138](https://github.com/locationtech/geotrellis/pull/3138)
- `Tile`, `ArrayTile`, `ConstantTile`, `DelegatingTile`, `MultibandTile`, `MultibandArrayTile`, `RasterRegion`, `RasterSource`, `MosaicRasterSource` converted from `trait` to `abstract class` [#3136](https://github.com/locationtech/geotrellis/pull/3136)

## [3.0.0] - 2019-10-18

### Added
Expand Down
8 changes: 5 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,14 @@ lazy val root = Project("geotrellis", file("."))
cassandra,
`cassandra-spark`,
`doc-examples`,
gdal,
`gdal-spark`,
geomesa,
geotools,
geowave,
hbase,
`hbase-spark`,
layer,
macros,
proj4,
raster,
Expand All @@ -123,12 +126,11 @@ lazy val root = Project("geotrellis", file("."))
spark,
`spark-pipeline`,
`spark-testkit`,
store,
util,
vector,
`vector-testkit`,
vectortile,
gdal,
`gdal-spark`
vectortile
)
.settings(commonSettings: _*)
.enablePlugins(ScalaUnidocPlugin)
Expand Down
2 changes: 1 addition & 1 deletion raster/src/main/scala/geotrellis/raster/ArrayTile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import spire.syntax.cfor._
* tile. Designed to be a near drop-in replacement for Array in many
* cases.
*/
trait ArrayTile extends Tile with Serializable {
abstract class ArrayTile extends Tile with Serializable {

/**
* Return the [[ArrayTile]] equivalent of this ArrayTile.
Expand Down
2 changes: 1 addition & 1 deletion raster/src/main/scala/geotrellis/raster/ConstantTile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import spire.syntax.cfor._
/**
* The trait underlying constant tile types.
*/
trait ConstantTile extends Tile {
abstract class ConstantTile extends Tile {

/** Precomputed view of tile cells as seen by [[get]] method */
protected val iVal: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ package geotrellis.raster
*
* @since 8/22/18
*/
trait DelegatingTile extends Tile {
abstract class DelegatingTile extends Tile {
protected def delegate: Tile

def cellType: CellType =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import spire.math.Integral
* whether they'll have the same CRS. crs allows specifying the CRS on read instead of
* having to make sure at compile time that you're threading CRSes through everywhere correctly.
*/
trait MosaicRasterSource extends RasterSource {
abstract class MosaicRasterSource extends RasterSource {

val sources: NonEmptyList[RasterSource]
val crs: CRS
Expand Down
10 changes: 1 addition & 9 deletions raster/src/main/scala/geotrellis/raster/MultibandTile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,8 @@
package geotrellis.raster

import geotrellis.macros._
import geotrellis.raster.summary._
import geotrellis.vector.Extent

import spire.syntax.cfor._

import java.util.Locale

import math.BigDecimal


object MultibandTile {
/**
* Creates a multiband tile from a sequence of tiles which
Expand All @@ -51,7 +43,7 @@ object MultibandTile {
ArrayMultibandTile(bands)
}

trait MultibandTile extends CellGrid[Int] with MacroCombinableMultibandTile[Tile] with MacroCombineFunctions[Tile, MultibandTile] {
abstract class MultibandTile extends CellGrid[Int] with MacroCombinableMultibandTile[Tile] with MacroCombineFunctions[Tile, MultibandTile] {
def bandCount: Int

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@

package geotrellis.raster

import geotrellis.vector._

import spire.syntax.cfor._


/**
* [[MutableArrayTile]] is an [[ArrayTile]] whose cells can be
* written to (mutated).
*/
trait MutableArrayTile extends ArrayTile {
abstract class MutableArrayTile extends ArrayTile {
def mutable = this

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import geotrellis.vector.Extent
/**
* Conformance interface for entities that are tile-like with a projected extent.
*/
trait ProjectedRasterLike extends CellGrid[Int] {
trait ProjectedRasterLike {
def crs: CRS
def extent: Extent
def cols: Int
def rows: Int
}
2 changes: 1 addition & 1 deletion raster/src/main/scala/geotrellis/raster/RasterRegion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import geotrellis.vector.Extent
/**
* Reference to a pixel region in a [[RasterSource]] that may be read at a later time.
*/
trait RasterRegion extends ProjectedRasterLike with Serializable {
abstract class RasterRegion extends CellGrid[Int] with ProjectedRasterLike with Serializable {
def raster: Option[Raster[MultibandTile]]
}

Expand Down
2 changes: 1 addition & 1 deletion raster/src/main/scala/geotrellis/raster/RasterSource.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import java.util.ServiceLoader
* @groupdesc reproject Functions to resample raster data in target projection.
* @groupprio reproject 2
*/
trait RasterSource extends CellGrid[Long] with RasterMetadata {
abstract class RasterSource extends CellGrid[Long] with RasterMetadata {
/** All available RasterSource metadata */
def metadata: RasterMetadata

Expand Down
2 changes: 1 addition & 1 deletion raster/src/main/scala/geotrellis/raster/Tile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package geotrellis.raster
/**
* Base trait for a Tile.
*/
trait Tile extends CellGrid[Int] with IterableTile with MappableTile[Tile] {
abstract class Tile extends CellGrid[Int] with IterableTile with MappableTile[Tile] {
/**
* Execute a function at each pixel of a [[Tile]]. Two functions
* are given: an integer version which is used if the tile is an
Expand Down
14 changes: 9 additions & 5 deletions util/src/main/scala/geotrellis/util/StreamingByteReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ class StreamingByteReader(rangeReader: RangeReader, chunkSize: Int = 45876) exte
}
}

/** Ensure we can read given number of bytes from current filePosition */
private def ensureChunk(length: Int): Unit = {
/** Ensure we can read given number of bytes from current filePosition
* Returns the length of bytes which have been successfully ensured
*/
private def ensureChunk(length: Int): Int = {
val trimmed: Long = math.min(length.toLong, rangeReader.totalLength - filePosition)
if (!chunkRange.contains(filePosition) || !chunkRange.contains(filePosition + trimmed - 1)) {
val len: Long = math.min(math.max(length, chunkSize), rangeReader.totalLength - filePosition)
Expand All @@ -112,13 +114,15 @@ class StreamingByteReader(rangeReader: RangeReader, chunkSize: Int = 45876) exte

if (filePosition != chunkRange.start + chunkBuffer.position)
chunkBuffer.position((filePosition - chunkRange.start).toInt)

trimmed.toInt
}

def getBytes(length: Int): Array[Byte] = {
ensureChunk(length)
val bytes = Array.ofDim[Byte](length)
val actualLength = ensureChunk(length)
val bytes = Array.ofDim[Byte](actualLength)
chunkBuffer.get(bytes)
filePosition += length
filePosition += actualLength
bytes
}

Expand Down