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

avoid GeoAttrsError by using more robust target extent calculation in… #3560

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,16 @@ object TileRDDReproject {
implicit val sc = bufferedTiles.context

val sourceDataGridExtent = metadata.layout.createAlignedGridExtent(metadata.extent)
val passthroughGridExtent = ReprojectRasterExtent(sourceDataGridExtent, metadata.crs, destCrs)
val targetDataExtent = passthroughGridExtent.extent
val (targetCellSize:CellSize,targetDataExtent:Extent)=
targetLayout match {
case Right(l) => {
(l.cellSize, l.createAlignedGridExtent(ProjectedExtent(metadata.extent,metadata.crs).reproject(destCrs)).extent)
}
case Left(l) => {
val passthroughGridExtent = ReprojectRasterExtent(sourceDataGridExtent, metadata.crs, destCrs)
(passthroughGridExtent.cellSize,passthroughGridExtent.extent)
}
}

val targetPartitioner: Option[Partitioner] = partitioner.orElse(bufferedTiles.partitioner)

Expand Down Expand Up @@ -112,7 +120,7 @@ object TileRDDReproject {
layoutScheme.levelFor(targetDataExtent, ct)

case None =>
layoutScheme.levelFor(targetDataExtent, passthroughGridExtent.cellSize)
layoutScheme.levelFor(targetDataExtent, targetCellSize)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ import geotrellis.spark.reproject.Reproject.Options
import geotrellis.spark.testkit._
import geotrellis.vector._
import geotrellis.proj4._

import spire.syntax.cfor._
import org.apache.spark._

import org.scalatest.funspec.AnyFunSpec

class TileRDDReprojectSpec extends AnyFunSpec with TestEnvironment {
Expand Down Expand Up @@ -328,4 +326,23 @@ class TileRDDReprojectSpec extends AnyFunSpec with TestEnvironment {
afterMetadata.layout should be (beforeMetadata.layout)
}
}

describe("Very small cube at high latitude") {
it("should reproject without error") {
val layout = LayoutDefinition(RasterExtent(Extent(-120.550992, 71.82628788888888, -120.5421031111111, 71.83517677777778),32,32),32,32)
val targetLayout = LayoutDefinition(RasterExtent(Extent(585180.0, 7971640.0, 585820.0, 7972280.0),32,32),32,32)
val extent = Extent(-120.550992, 71.834899, -120.550792, 71.835099)
val cube: TileLayerRDD[SpatialKey] = TileLayerRDDBuilders.createTileLayerRDD(sc,ByteArrayTile.fill(1,32,32),layout.tileLayout,LatLng)

val utm = CRS.fromEpsgCode(32610)

val badMetadata = cube.metadata.copy(crs = LatLng, extent = extent,layout = layout)
val result = TileRDDReproject(ContextRDD(cube,badMetadata), utm, Right(targetLayout), 16,Reproject.Options.DEFAULT,None)
//should not throw an error
val resultMetadata = result._2.metadata
targetLayout should be (resultMetadata.layout)
utm should be (resultMetadata.crs)

}
}
}
Loading