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

Conversation

pomadchin
Copy link
Member

@pomadchin pomadchin commented Oct 22, 2019

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

Copy link
Member

@metasim metasim left a comment

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
Member Author

@metasim yep:

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

@metasim
Copy link
Member

metasim commented Oct 22, 2019

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
Copy link
Member Author

pomadchin commented Oct 22, 2019

@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
Copy link
Member

metasim commented Oct 22, 2019

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
Member Author

@metasim do you want it to be a mixin?

@metasim
Copy link
Member

metasim commented Oct 22, 2019

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
Member Author

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

@pomadchin
Copy link
Member Author

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

@metasim
Copy link
Member

metasim commented Oct 22, 2019

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

@metasim
Copy link
Member

metasim commented Oct 22, 2019

Maybe this instead?

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

@pomadchin
Copy link
Member Author

@metasim will look into what is possible to do here

@echeipesh
Copy link
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
Copy link
Member Author

pomadchin commented Oct 23, 2019

@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)

Copy link
Contributor

@echeipesh echeipesh left a comment

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
Contributor

3.1.0 release

@pomadchin
Copy link
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
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