Skip to content

Commit c4fe47c

Browse files
authored
Merge pull request #430 from jbouffard/bug-fix/save-stitched
Refactored the saveStitched Method
2 parents a93fb0b + d6f4a0f commit c4fe47c

File tree

2 files changed

+35
-28
lines changed

2 files changed

+35
-28
lines changed

geopyspark-backend/geotrellis/src/main/scala/geopyspark/geotrellis/SpatialTiledRasterLayer.scala

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -192,36 +192,36 @@ class SpatialTiledRasterLayer(
192192
PythonTranslator.toPython[Tile, ProtoTile](contextRDD.stitch.tile)
193193
}
194194

195-
def save_stitched(path: String): Unit =
196-
_save_stitched(path, None, None)
197-
198-
def save_stitched(path: String, cropBounds: ArrayList[Double]): Unit =
199-
_save_stitched(path, Some(cropBounds), None)
200-
201-
def save_stitched(path: String, cropBounds: ArrayList[Double], cropDimensions: ArrayList[Int]): Unit =
202-
_save_stitched(path, Some(cropBounds), Some(cropDimensions))
203-
204-
private def _save_stitched(path: String, cropBounds: Option[ArrayList[Double]], cropDimensions: Option[ArrayList[Int]]): Unit = {
205-
195+
def saveStitched(path: String): Unit =
196+
saveStitched(path, None, None)
197+
198+
def saveStitched(path: String, cropBounds: java.util.Map[String, Double]): Unit =
199+
saveStitched(path, Some(cropBounds), None)
200+
201+
def saveStitched(
202+
path: String,
203+
cropBounds: java.util.Map[String, Double],
204+
cropDimensions: ArrayList[Int]
205+
): Unit =
206+
saveStitched(path, Some(cropBounds), Some(cropDimensions))
207+
208+
def saveStitched(
209+
path: String,
210+
cropBounds: Option[java.util.Map[String, Double]],
211+
cropDimensions: Option[ArrayList[Int]]
212+
): Unit = {
206213
val contextRDD = ContextRDD(
207214
rdd.map({ case (k, v) => (k, v.band(0)) }),
208215
rdd.metadata
209216
)
217+
210218
val stitched: Raster[Tile] = contextRDD.stitch()
211219

212220
val adjusted = {
213-
val cropExtent =
214-
cropBounds.map { b =>
215-
val bounds = b.asScala.toArray
216-
Extent(bounds(0), bounds(1), bounds(2), bounds(3))
217-
}
218-
219221
val cropped =
220-
cropExtent match {
221-
case Some(extent) =>
222-
stitched.crop(extent)
223-
case None =>
224-
stitched
222+
cropBounds match {
223+
case Some(extent) => stitched.crop(extent.toExtent)
224+
case None => stitched
225225
}
226226

227227
val resampled =

geopyspark/geotrellis/layer.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,26 +1112,33 @@ def save_stitched(self, path, crop_bounds=None, crop_dimensions=None):
11121112
"""Stitch all of the rasters within the Layer into one raster.
11131113
11141114
Args:
1115-
path (str): The path of the geotiff to save.
1116-
crop_bounds (list, optional): bounds with which to crop the raster before saving.
1117-
crop_dimensions (list, optional): cols and rows of the image to save
1115+
path (str): The path of the geotiff to save. The path must be on the local file system.
1116+
crop_bounds (:class:`~geopyspark.geotrellis.Extent`, optional): The sub ``Extent`` with
1117+
which to crop the raster before saving. If ``None``, then the whole raster will be
1118+
saved.
1119+
crop_dimensions (tuple(int) or list(int), optional): cols and rows of the image to save
1120+
represented as either a tuple or list. If ``None`` then all cols and rows of the
1121+
raster will be save.
11181122
11191123
Note:
11201124
This can only be used on ``LayerType.SPATIAL`` ``TiledRasterLayer``\s.
1125+
1126+
Note:
1127+
If ``crop_dimensions`` is set then ``crop_bounds`` must also be set.
11211128
"""
11221129

11231130
if self.layer_type != LayerType.SPATIAL:
11241131
raise ValueError("Only TiledRasterLayers with a layer_type of Spatial can use stitch()")
11251132

11261133
if crop_bounds:
11271134
if crop_dimensions:
1128-
self.srdd.save_stitched(path, list(crop_bounds), list(crop_dimensions))
1135+
self.srdd.saveStitched(path, crop_bounds._asdict(), list(crop_dimensions))
11291136
else:
1130-
self.srdd.save_stitched(path, list(crop_bounds))
1137+
self.srdd.saveStitched(path, crop_bounds._asdict())
11311138
elif crop_dimensions:
11321139
raise Exception("crop_dimensions requires crop_bounds")
11331140
else:
1134-
self.srdd.save_stitched(path)
1141+
self.srdd.saveStitched(path)
11351142

11361143
def star_series(self, geometries, fn):
11371144
if not self.layer_type == LayerType.SPACETIME:

0 commit comments

Comments
 (0)