test65.zip
The data's extent is Extent(95.08999999997889, 29.638333333344512, 117.08999999997889, 40.63833333334451)
reproject to CRS 4326:
val tileRDD: RDD[(ProjectedExtent, MultibandTile)] = HadoopGeoTiffRDD.spatialMultiband(path,
Options(maxTileSize = Some(1024)))(sc)
val targetCRS = CRS.fromEpsgCode(4326)
val metadata = tileRDD.collectMetadata[SpatialKey](FloatingLayoutScheme(256))._2
val contextRdd = tileRDD.tileToLayout(metadata)
val cellSize = contextRdd.metadata.cellSize
val circumference = if (contextRdd.metadata.crs.isGeographic) 360.0 else EARTH_CIRCUMFERENCE
val dist = math.max(cellSize.height, cellSize.width)
val z = (math.log(circumference / (dist * 256)) / math.log(2)).toInt
val zRes = circumference / (math.pow(2, z) * 256)
val nextZRes = circumference / (math.pow(2, z + 1) * 256)
val diff = zRes - dist
val delta = zRes - nextZRes
val zoom: Int =
if (diff / delta > 0.1) {
z.toInt + 1
} else {
z.toInt
}
val layoutCols: Int = math.pow(2, zoom).toInt
val layoutRows: Int = if (zoom == 0) 1 else math.pow(2, zoom - 1).toInt
val layoutDefinition = LayoutDefinition(targetCRS.worldExtent,
TileLayout(layoutCols, layoutRows, 256, 256))
import geotrellis.raster.reproject.Reproject.{Options => RasterReprojectOptions}
val tileLayerRDD = contextRdd.reproject(targetCRS, layoutDefinition,
options = RasterReprojectOptions(method = Bilinear, targetCellSize = Some(layoutDefinition.cellSize)))._2
println(tileLayerRDD.count())
Exception is:
java.lang.IllegalStateException: Latitude is out of range: -3.7587701659156596
at org.osgeo.proj4j.datum.GeocentricConverter.convertGeodeticToGeocentric(GeocentricConverter.java:121)
at org.osgeo.proj4j.BasicCoordinateTransform.datumTransform(BasicCoordinateTransform.java:206)
at org.osgeo.proj4j.BasicCoordinateTransform.transform(BasicCoordinateTransform.java:160)
at geotrellis.proj4.Proj4Transform$$anonfun$apply$1.apply(Transform.scala:36)
at geotrellis.proj4.Proj4Transform$$anonfun$apply$1.apply(Transform.scala:33)
at geotrellis.vector.reproject.Reproject$$anonfun$apply$1.apply(Reproject.scala:47)
at geotrellis.vector.reproject.Reproject$$anonfun$apply$1.apply(Reproject.scala:47)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:234)
at scala.collection.mutable.ArrayOps$ofRef.map(ArrayOps.scala:186)
at geotrellis.vector.reproject.Reproject$.apply(Reproject.scala:47)
at geotrellis.vector.reproject.Reproject$.apply(Reproject.scala:60)
at geotrellis.vector.reproject.Implicits$ReprojectPolygon.reproject(Implicits.scala:53)
at geotrellis.raster.reproject.ReprojectRasterExtent$.reprojectExtent(ReprojectRasterExtent.scala:52)
at geotrellis.raster.reproject.ReprojectRasterExtent$.apply(ReprojectRasterExtent.scala:57)
at geotrellis.raster.reproject.ReprojectRasterExtent$.apply(ReprojectRasterExtent.scala:118)
at geotrellis.raster.reproject.ReprojectRasterExtent$.apply(ReprojectRasterExtent.scala:121)
at geotrellis.spark.reproject.TileRDDReproject$$anonfun$matchReprojectRasterExtent$1$$anonfun$14$$anonfun$apply$4$$anonfun$apply$5.apply(TileRDDReproject.scala:365)
at geotrellis.spark.reproject.TileRDDReproject$$anonfun$matchReprojectRasterExtent$1$$anonfun$14$$anonfun$apply$4$$anonfun$apply$5.apply(TileRDDReproject.scala:363)
at scala.collection.Iterator$$anon$11.next(Iterator.scala:409)
at scala.collection.Iterator$class.foreach(Iterator.scala:893)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1336)
at scala.collection.TraversableOnce$class.reduceLeft(TraversableOnce.scala:185)
at scala.collection.AbstractIterator.reduceLeft(Iterator.scala:1336)
at scala.collection.TraversableOnce$class.reduce(TraversableOnce.scala:208)
at scala.collection.AbstractIterator.reduce(Iterator.scala:1336)
at geotrellis.spark.reproject.TileRDDReproject$$anonfun$matchReprojectRasterExtent$1$$anonfun$14$$anonfun$apply$4.apply(TileRDDReproject.scala:373)
at geotrellis.spark.reproject.TileRDDReproject$$anonfun$matchReprojectRasterExtent$1$$anonfun$14$$anonfun$apply$4.apply(TileRDDReproject.scala:359)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
at scala.concurrent.impl.ExecutionContextImpl$AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
reproject to CRS 3857:
val tileRDD: RDD[(ProjectedExtent, MultibandTile)] = HadoopGeoTiffRDD.spatialMultiband(path,
Options(maxTileSize = Some(1024)))(sc)
val targetCRS = CRS.fromEpsgCode(3857)
val metadata = tileRDD.collectMetadata[SpatialKey](FloatingLayoutScheme(256))._2
val contextRdd = tileRDD.tileToLayout(metadata)
val layoutScheme = ZoomedLayoutScheme(targetCRS, 256, resolutionThreshold = 0.1)
val (zoom, tileLayerRDD) = contextRdd.reproject(targetCRS, layoutScheme, Bilinear)
println(tileLayerRDD.count())
test65.zip The data's extent is
Extent(95.08999999997889, 29.638333333344512, 117.08999999997889, 40.63833333334451)
reproject to CRS 4326:
Exception is:
reproject to CRS 3857:
Exception is:
This one maybe related with #2881 's problem2 (the tile bounds is out of worldExtent).