Skip to content

Commit

Permalink
Merge pull request #606 from jbouffard/bug-fix/celltype
Browse files Browse the repository at this point in the history
CellType Representation and Conversion Fixes
  • Loading branch information
echeipesh committed Jan 5, 2018
2 parents 5b87a40 + 85cd2e4 commit ce5e03f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ abstract class TiledRasterLayer[K: SpatialComponent: JsonFormat: ClassTag: Bound
withRDD(rdd.mapValues { x => MultibandTile(x.bands.map { y => y.localPowValue(d) }) })

def convertDataType(newType: String): TiledRasterLayer[_] =
withRDD(rdd.convert(CellType.fromName(newType)))
withContextRDD(rdd.convert(CellType.fromName(newType)).asInstanceOf[ContextRDD[K, MultibandTile, TileLayerMetadata[K]]])

def normalize(oldMin: Double, oldMax: Double, newMin: Double, newMax: Double): TiledRasterLayer[K] =
withRDD {
Expand Down
10 changes: 6 additions & 4 deletions geopyspark/geotrellis/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def convert_data_type(self, new_type, no_data_value=None):

new_type = CellType(new_type).value

if no_data_value:
if no_data_value is not None:
if 'bool' in new_type:
raise ValueError("Cannot add user defined types to Bool")
elif 'raw' in new_type:
Expand Down Expand Up @@ -1150,19 +1150,21 @@ def convert_data_type(self, new_type, no_data_value=None):
ValueError: If ``no_data_value`` is set and ``new_type`` is a boolean.
"""

if no_data_value:
new_type = CellType(new_type).value

if no_data_value is not None:
if 'bool' in new_type:
raise ValueError("Cannot add user defined types to Bool")
elif 'raw' in new_type:
raise ValueError("Cannot add user defined types to raw values")

no_data_constant = CellType(new_type).value + "ud" + str(no_data_value)
no_data_constant = new_type + "ud" + str(no_data_value)

return TiledRasterLayer(self.layer_type,
self.srdd.convertDataType(no_data_constant))
else:
return TiledRasterLayer(self.layer_type,
self.srdd.convertDataType(CellType(new_type).value))
self.srdd.convertDataType(new_type))

def reproject(self, target_crs, resample_method=ResampleMethod.NEAREST_NEIGHBOR):
"""Reproject rasters to ``target_crs``.
Expand Down

0 comments on commit ce5e03f

Please sign in to comment.