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

Improve RasterSummary.fromRDD signatures #3469

Open
pomadchin opened this issue Jun 27, 2022 · 0 comments
Open

Improve RasterSummary.fromRDD signatures #3469

pomadchin opened this issue Jun 27, 2022 · 0 comments

Comments

@pomadchin
Copy link
Member

pomadchin commented Jun 27, 2022

At this point the RasterSummary.fromRDD (and similar methods) have the folowing signature:

object RasterSummary {
  // ...
  def fromRDD(rdd: RDD[RasterSource]): RasterSummary[Unit] = ???
  // ...
}

Due to the fact that RDD is invariant, it is pretty hard and inconvenient to use:

// explicit upcast
val sourceRDD: RDD[RasterSource] = sc.parallelize(files).map(GeoTiffRasterSource(uri).reproject(targetCRS): RasterSource)
val summary = RasterSummary.fromRDD(sourceRDD)

What could be nice is to allow subtypes of the RDD to be accepted by RasterSummary methods:

// with no explicit upcast
val sourceRDD = sc.parallelize(files).map(GeoTiffRasterSource(uri).reproject(targetCRS))
val summary = RasterSummary.fromRDD(sourceRDD)

We can work around RDD invariance by defining the following functions singnature (just an example):

def fromRDD[T](rdd: RDD[T])(implicit rs: T => RasterSource): RasterSummary[Unit] = {
  val all = collect(rdd.map(rs(_)), _ => ())
  require(all.size == 1, "multiple CRSs detected")
  all.head
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant