Skip to content

Commit

Permalink
Merge pull request #169 from jbouffard/crs-fix
Browse files Browse the repository at this point in the history
CRS Param Fix
  • Loading branch information
echeipesh committed May 4, 2017
2 parents d73ddbf + 1689a8e commit dc5afb0
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions geopyspark/geotrellis/rdd.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def to_tiled_layer(self, extent=None, layout=None, crs=None, tile_size=256,
Args:
extent (:ref:`extent`, optional): Specify layout extent, must also specify layout.
layout (:ref:`tile_layout`, optional): Specify tile layout, must also specify extent.
crs (str, int, optional): Ignore CRS from records and use given one instead.
crs (str or int, optional): Ignore CRS from records and use given one instead.
tile_size (int, optional): Pixel dimensions of each tile, if not using layout.
resample_method (str, optional): The resample method to use for the reprojection.
This is represented by a constant. If none is specified, then ``NEARESTNEIGHBOR``
Expand All @@ -152,7 +152,7 @@ def collect_metadata(self, extent=None, layout=None, crs=None, tile_size=256):
Args:
extent (:ref:`extent`, optional): Specify layout extent, must also specify layout.
layout (:ref:`tile_layout`, optional): Specify tile layout, must also specify extent.
crs (str, int, optional): Ignore CRS from records and use given one instead.
crs (str or int, optional): Ignore CRS from records and use given one instead.
tile_size (int, optional): Pixel dimensions of each tile, if not using layout.
Note:
Expand All @@ -168,6 +168,9 @@ def collect_metadata(self, extent=None, layout=None, crs=None, tile_size=256):
if not crs:
crs = ""

if isinstance(crs, int):
crs = str(crs)

if extent and layout:
json_metadata = self.srdd.collectMetadata(extent, layout, crs)
elif not extent and not layout:
Expand All @@ -181,7 +184,7 @@ def reproject(self, target_crs, resample_method=NEARESTNEIGHBOR):
"""Reproject every individual raster to `target_crs`, does not sample past tile boundary
Args:
target_crs (int, str): The CRS to reproject to. Can either be the EPSG code,
target_crs (str or int): The CRS to reproject to. Can either be the EPSG code,
well-known name, or a PROJ.4 projection string.
resample_method (str, optional): The resample method to use for the reprojection.
This is represented by a constant. If none is specified, then `NEARESTNEIGHBOR`
Expand All @@ -194,6 +197,9 @@ def reproject(self, target_crs, resample_method=NEARESTNEIGHBOR):
if resample_method not in RESAMPLE_METHODS:
raise ValueError(resample_method, " Is not a known resample method.")

if isinstance(target_crs, int):
target_crs = str(target_crs)

return RasterRDD(self.geopysc, self.rdd_type,
self.srdd.reproject(target_crs, resample_method))

Expand Down Expand Up @@ -360,7 +366,7 @@ def rasterize(cls, geopysc, rdd_type, geometry, extent, crs, cols, rows,
string or a ``Polygon``. If the value is a string, it must be the WKT string,
geometry format.
extent (:ref:`extent`): The ``extent`` of the new raster.
crs (str): The CRS the new raster should be in.
crs (str or int): The CRS the new raster should be in.
cols (int): The number of cols the new raster should have.
rows (int): The number of rows the new raster should have.
fill_value (int): The value to fill the raster with.
Expand All @@ -387,6 +393,9 @@ def rasterize(cls, geopysc, rdd_type, geometry, extent, crs, cols, rows,
except:
raise TypeError(geometry, "Needs to be either a Shapely Geometry or a string")

if isinstance(crs, int):
crs = str(crs)

if instant and rdd_type != SPATIAL:
srdd = geopysc._jvm.geopyspark.geotrellis.TemporalTiledRasterRDD.rasterize(
geopysc.sc, geometry, extent, crs, instant, cols, rows, fill_value)
Expand Down Expand Up @@ -417,7 +426,7 @@ def reproject(self, target_crs, extent=None, layout=None, scheme=FLOAT, tile_siz
"""Reproject RDD as tiled raster layer, samples surrounding tiles.
Args:
target_crs (int, str): The CRS to reproject to. Can either be the EPSG code,
target_crs (str or int): The CRS to reproject to. Can either be the EPSG code,
well-known name, or a PROJ.4 projection string.
extent (:ref:`extent`, optional): Specify layout extent, must also specify layout.
layout (:ref:`tile_layout`, optional): Specify tile layout, must also specify extent.
Expand All @@ -444,6 +453,9 @@ def reproject(self, target_crs, extent=None, layout=None, scheme=FLOAT, tile_siz
if resample_method not in RESAMPLE_METHODS:
raise ValueError(resample_method, " Is not a known resample method.")

if isinstance(target_crs, int):
target_crs = str(target_crs)

if extent and layout:
srdd = self.srdd.reproject(extent, layout, target_crs, resample_method)
elif not extent and not layout:
Expand Down

0 comments on commit dc5afb0

Please sign in to comment.