locationtech / geotrellis

GeoTrellis is a geographic data processing engine for high performance applications.
http://geotrellis.io
Other
1.34k stars 361 forks source link

Ingest tiff with epsg=4214 and cellsize=1 to epsg=4326/3857, reproject stage throws exception #2883

Open Frophie opened 5 years ago

Frophie commented 5 years ago

test65.zip The data's extent is Extent(95.08999999997889, 29.638333333344512, 117.08999999997889, 40.63833333334451)

  1. 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)
  2. 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())

    Exception is:

    java.lang.RuntimeException: Cannot create a polygon with unclosed exterior: LINESTRING (10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 �, 10585370.379530033 -43326501.216434665, 10585370.379530033 -19785402.545872144, 10585370.379530033 -15432058.691475311, 10585370.379530033 -12852149.168531291, 10585370.379530033 -11001686.719404867, 10585370.379530033 -9548943.815980233, 10585370.379530033 -8345132.177787001, 10585370.379530033 -7310452.73021434, 10585370.379530033 -6396996.863138434, 10585370.379530033 -5573632.602125005, 10585370.379530033 -4818882.670814, 10585370.379530033 -4117201.4402719955, 10585370.379530033 -3456868.9245868796, 10585370.379530033 -2828721.700636435, 10585370.379530033 -2225346.0238280906, 10585370.379530033 -1640539.2137679397, 10585370.379530033 -1068932.4010760786, 10585370.379530033 -505712.1694750724, 10585370.379530033 53597.69151548579, 10585370.379530033 613320.2691363755, 10585370.379530033 1177794.6896019622, 10585370.379530033 1751546.8255789136, 10585370.379530033 2339478.2979788077, 10585370.379530033 2947093.952850384, 10585370.379530033 3580795.646559564, 10585370.379530033 4248284.618167445, 10585370.379530033 4959141.386795022, 11144150.568609994 4959141.386795022, 11702930.757689955 4959141.386795022, 12261710.946769917 4959141.386795022, 12820491.135849878 4959141.386795022, 13379271.324929839 4959141.386795022, 13938051.514009804 4959141.386795022, 14496831.703089762 4959141.386795022, 15055611.892169725 4959141.386795022, 15614392.081249688 4959141.386795022, 16173172.270329649 4959141.386795022, 16731952.45940961 4959141.386795022, 17290732.648489572 4959141.386795022, 17849512.83756953 4959141.386795022, 18408293.026649497 4959141.386795022, 18967073.215729456 4959141.386795022, 19525853.40480942 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4959141.386795022, 20037508.342789244 4248284.618167445, 20037508.342789244 3580795.6465595607, 20037508.342789244 2947093.952850384, 20037508.342789244 2339478.2979788077, 20037508.342789244 1751546.8255789126, 20037508.342789244 1177794.6896019622, 20037508.342789244 613320.269136373, 20037508.342789244 53597.69151548439, 20037508.342789244 -505712.1694750724, 20037508.342789244 -1068932.4010760796, 20037508.342789244 -1640539.2137679406, 20037508.342789244 -2225346.0238280906, 20037508.342789244 -2828721.700636435, 20037508.342789244 -3456868.924586882, 20037508.342789244 -4117201.440271994, 20037508.342789244 -4818882.670814001, 20037508.342789244 -5573632.602125004, 20037508.342789244 -6396996.863138435, 20037508.342789244 -7310452.73021434, 20037508.342789244 -8345132.1777869975, 20037508.342789244 -9548943.815980233, 20037508.342789244 -11001686.719404867, 20037508.342789244 -12852149.168531302, 20037508.342789244 -15432058.691475311, 20037508.342789244 -19785402.545872144, 20037508.342789244 -43326501.21643403, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 20037508.342789244 �, 19525853.40480942 �, 18967073.215729456 �, 18408293.026649497 �, 17849512.83756953 �, 17290732.648489572 �, 16731952.45940961 �, 16173172.270329649 �, 15614392.081249688 �, 15055611.892169725 �, 14496831.703089762 �, 13938051.514009804 �, 13379271.324929839 �, 12820491.135849882 �, 12261710.946769917 �, 11702930.757689955 �, 11144150.568609998 �, 10585370.379530033 �)
    at scala.sys.package$.error(package.scala:27)
    at geotrellis.vector.Polygon$.apply(Polygon.scala:51)
    at geotrellis.vector.reproject.Reproject$.apply(Reproject.scala:59)
    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)

    This one maybe related with #2881 's problem2 (the tile bounds is out of worldExtent).

pomadchin commented 5 years ago

Will look into it, but sounds very much like a precision issue.