Skip to content

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

Merged
echeipesh merged 13 commits into
locationtech:masterfrom
pomadchin:fix/tile-hierarchy
Oct 24, 2019
Merged

echeipesh merged 13 commits into
locationtech:masterfrom
pomadchin:fix/tile-hierarchy

Conversation

@pomadchin

@pomadchin pomadchin commented Oct 22, 2019 •

Copy link
Copy Markdown
Member

Overview

This PR makes Tile, ArrayTile and MultibandTile abstract classes. In our types hierarchy Tile types extend CellGrid and Grid. In 2.x both Tile and CellGrid were traits, and in 3.x CellGrid became an abstract class, so we had a not very usual case, where traits extended abstract classes. This is not possible in Java and creates problems on Spark, for more details looks into #3134

This is the idea suggested by @echeipesh and it is probably the best solution.

Checklist

Demo

scala> :javap geotrellis.raster.Tile
  Size 11433 bytes
  MD5 checksum 973688ee6c0ddfd43788d33a6cee0989
  Compiled from "Tile.scala"
public abstract class geotrellis.raster.Tile extends geotrellis.raster.CellGrid<java.lang.Object> implements geotrellis.raster.IterableTile, geotrellis.raster.MappableTile<geotrellis.raster.Tile>
scala> classOf[geotrellis.raster.CellGrid[_]].isAssignableFrom(classOf[geotrellis.raster.Tile])
res0: Boolean = true

scala> classOf[geotrellis.raster.CellGrid[_]].isInstance(geotrellis.raster.IntConstantTile(1,2,3))
res1: Boolean = true

scala> classOf[geotrellis.raster.CellGrid[Int]].isAssignableFrom(classOf[geotrellis.raster.Tile])
res2: Boolean = true

Closes #3134

@metasim metasim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow... that's it?

Did you confirm that new Raster(tile, extent) works in Java?

@pomadchin

Copy link
Copy Markdown
Member Author

@metasim yep:

raster > run
[info] Running RasterInstantiation 
[success] Total time: 3 s, completed Oct 22, 2019 12:27:02 PM

@metasim

metasim commented Oct 22, 2019

Copy link
Copy Markdown
Member

I wonder if the following should preemptively converted to abstract classes:

  • geotrellis.raster.RasterRegion
  • geotrellis.raster.RasterSource
  • geotrellis.raster.MosaicRasterSource
  • geotrellis.raster.ProjectedRasterLike
  • geotrellis.raster.DelegatingTile
  • geotrellis.raster.ConstantTile
  • geotrellis.raster.MutableArrayTile

@metasim
metasim self-requested a review October 22, 2019 16:39
@pomadchin

pomadchin commented Oct 22, 2019 •

Copy link
Copy Markdown
Member Author

@metasim should be (was in progress)

@pomadchin pomadchin changed the title Make Tile, ArrayTile and MultibandTile abstract classes All CellGrid and Grid inherited traits should be abstract classes Oct 22, 2019
@pomadchin pomadchin changed the title All CellGrid and Grid inherited traits should be abstract classes All traits that inherit CellGrid and Grid should be abstract classes Oct 22, 2019
@metasim
metasim self-requested a review October 22, 2019 19:14
@metasim

metasim commented Oct 22, 2019

Copy link
Copy Markdown
Member

Got some more feedback:

I think this should be the definition for ProjectedRasterLike:

trait ProjectedRasterLike  { _: CellGrid[Int] =>
  def crs: CRS
  def extent: Extent
}

@pomadchin

Copy link
Copy Markdown
Member Author

@metasim do you want it to be a mixin?

@metasim

metasim commented Oct 22, 2019 •

Copy link
Copy Markdown
Member

In RF it's used as a means to show conformity among a few different types for operations that want, say just an Extent or CRS, etc.

Not sure if that qualifies as a mix-in, or just "shape compliance" like an old-style interface.

@pomadchin

Copy link
Copy Markdown
Member Author

@metasim sweet, thanks for looking into it that hard 💯

@pomadchin

Copy link
Copy Markdown
Member Author

@metasim do we even need this constrain? _: CellGrid[Int] =>

@metasim

metasim commented Oct 22, 2019

Copy link
Copy Markdown
Member

Yes, we need the constraint, because it forces cols and rows to exist. Could use structural types, but ick.

@metasim

metasim commented Oct 22, 2019 •

Copy link
Copy Markdown
Member

Maybe this instead?

trait ProjectedRasterLike {
  def crs: CRS
  def extent: Extent
  def cellType: CellType
  def cols: Int
  def rows: Int
}

@pomadchin

Copy link
Copy Markdown
Member Author

@metasim will look into what is possible to do here

@echeipesh

Copy link
Copy Markdown
Contributor

My vote is for

trait ProjectedRasterLike {
  def crs: CRS
  def extent: Extent
  def cellType: CellType
  def cols: Int
  def rows: Int
}

... version. Trait self typing is another of those weird scala features that isn't really necessary (?). Also proposed variation is more flexible since it doesn't mention CellGrid.

@pomadchin

pomadchin commented Oct 23, 2019 •

Copy link
Copy Markdown
Member Author

@echeipesh yep, my point was that we don't need _: CellGrid[Int] => since it doesnt expose functions that @metasim wants (this was discussed in a gitter channel)

@echeipesh echeipesh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, solves the problem. Wish we could just remove N from CellGrid but that is a tricky thing to do with time we have right now.

@echeipesh

Copy link
Copy Markdown
Contributor

3.1.0 release

@pomadchin

Copy link
Copy Markdown
Member Author

requesting the last quick look at the ProjectedRasterLike @metasim @echeipesh

…ow we would like to expose more similar functions
* Fix StreamingByteReader over-allocation past EOF

* Add util project to CI tests
@echeipesh

Copy link
Copy Markdown
Contributor

@pomadchin this looks good to me. Need changelog entry and version bump to 3.1.0

@echeipesh
echeipesh merged commit d15a758 into locationtech:master Oct 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

trait extending abstract class in various GeoTrellis types results in Java incompatibility.

3 participants