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

Implicit conversions from ProjectedRaster to Tile create confusing semantics #2829

Open
metasim opened this issue Nov 29, 2018 · 11 comments
Open
Labels
technical debt https://en.wikipedia.org/wiki/Technical_debt

Comments

@metasim
Copy link
Member

metasim commented Nov 29, 2018

To wit:

scala> import geotrellis.proj4._
scala> import geotrellis.raster._
scala> import geotrellis.spark.tiling._

scala> val foo = ProjectedRaster(ByteConstantTile(1, 1, 1), LatLng.worldExtent, LatLng)
foo: geotrellis.raster.ProjectedRaster[geotrellis.raster.ByteConstantTile] = ProjectedRaster(Raster(ByteConstantTile(1,1,1,int8),Extent(-180.0, -89.99999, 179.99999, 89.99999)),LatLng)

scala> val bar = foo.convert(IntConstantNoDataCellType)
bar: geotrellis.raster.Tile = IntConstantTile(1,1,1,int32)

scala> bar.extent
<console>:41: error: value extent is not a member of geotrellis.raster.Tile
       bar.extent
           ^

I suggest removing these:

implicit def projectedToRaster[T <: CellGrid](p: ProjectedRaster[T]): Raster[T] =
p.raster
/**
* Implicit conversion from a [[ProjectedRaster]] to a tile.
*/
implicit def projectedToTile[T <: CellGrid](p: ProjectedRaster[T]): T =

I also think the ones from tuples should go to, but the argument isn't as strong. Same for Raster[T].

Related: #1780, #2768

@pomadchin
Copy link
Member

pomadchin commented Nov 29, 2018

Would not be better just to have conversion (and other funcs) function properly implemented there?

@echeipesh
Copy link
Contributor

@pomadchin You'd have to define convert on Raster or ProjectedRaster which is of dubious value for weight.

@pomadchin pomadchin added the technical debt https://en.wikipedia.org/wiki/Technical_debt label Nov 29, 2018
@pomadchin
Copy link
Member

pomadchin commented Nov 29, 2018

Ah indeed; also read a lil bit wrong the issue from phone

@metasim
Copy link
Member Author

metasim commented Nov 29, 2018

I'd actually voice support for having at least mapTile, which Raster has:

def mapTile[A <: CellGrid](f: T => A): ProjectedRaster[A] = ....

At least that way you can get at convert.

I uses convert and interpretAs enough that I wish they were on ProjectedRaster[T], but you'd have to context bound T appropriately, and that does get heavy weight.

@metasim
Copy link
Member Author

metasim commented Nov 29, 2018

Anyone know what happens if you try to @deprecate implicit conversions?

@pomadchin
Copy link
Member

pomadchin commented Nov 29, 2018

@metasim actually a good question: scala/bug#10152 But probably would work as expected.

@metasim
Copy link
Member Author

metasim commented Nov 29, 2018

To followup from above, this is the use case I have a lot of time, especially when GeoTIFFs don't have the NoData value properly set:

val pr = someGeotiff.projectedRaster
val tile = pr.tile.interpretAs(UShortConstantNoDataCellType)
val fixedpr = ProjectedRaster(tile, pr.extent, pr.crs)

@pomadchin
Copy link
Member

@metasim

Welcome to Scala 2.11.12 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_162).
Type in expressions for evaluation. Or try :help.

scala> :paste
// Entering paste mode (ctrl-D to finish)

@deprecated("this method will be removed // dummy conversion", "GeoTrellis")
implicit def intToString(i: Int): String = i.toString


// Exiting paste mode, now interpreting.

intToString: (i: Int)String

scala> val str: String = 25
<console>:12: warning: method intToString is deprecated: this method will be removed // dummy conversion
       val str: String = 25
                         ^
str: String = 25

@metasim
Copy link
Member Author

metasim commented Nov 29, 2018

So how about we start off with just @deprecated, and then in the next breaking release remove them?

@pomadchin
Copy link
Member

It looks like 3.0 release is very close :D we can try to get it merged in

@metasim
Copy link
Member Author

metasim commented Dec 1, 2018

Testing it out now; works as advertised:

MultibandTilePolygonalSummaryHandler.scala:41:113: method featureToRaster in object Raster is deprecated: Implicit conversions considered unsafe
...
MatchingRasters.scala:56:33: method projectedToRaster in object ProjectedRaster is deprecated: Implicit conversions considered unsafe

Need to determine a better message tho...

metasim added a commit to metasim/geotrellis that referenced this issue Dec 1, 2018
Partially addresses locationtech#2829.

Signed-off-by: Simeon H.K. Fitch <fitch@astraea.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
technical debt https://en.wikipedia.org/wiki/Technical_debt
Projects
None yet
Development

No branches or pull requests

3 participants