Created
October 24, 2018 16:26
-
-
Save jbouffard/4f41832359597bd6b7368a436a1c66c0 to your computer and use it in GitHub Desktop.
This is Some Mock Code for the read_to_layout Function for GPS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This is some mock code for the read_to_layout function. | |
Possible location of this module: geopyspark.geotrellis.raster_source.read_to_layout | |
Ideally, it should be accessed like the other reading functions in GPS via the | |
pattern of: gps.raster_source.read_to_layout. | |
""" | |
def read_to_layout(layer_type=LayerType.SPATIAL, # The default param should be removed at some point | |
paths, # Could this be a str, [str] or an RDD[str]? | |
layout=LocalLayout(), | |
target_crs=None, | |
resample_method=ResampleMethod.NEAREST_NEIGHBOR, | |
partition_strategy=None, | |
read_method=ReadMethod.GEOTRELLIS): | |
pysc = get_spark_context() | |
raster_source = pysc._gateway.jvm.geopyspark.geotrellis.vlm.RasterSource | |
check_partition_strategy(partition_strategy, layer_type) | |
# This should be either be a SpatialKey or a SpaceTimeKey. | |
# However, geotrellis-contrib only support spatial data | |
# for the time being | |
key = LayerType(layer_type)._key_name(False) | |
resample_method = ResampleMethod(resample_method) | |
read_method = ReadMethod(read_method) | |
target_crs = crs_to_proj4(target_crs) or None | |
srdd = RasterSource.read(pysc._jsc.sc(), | |
key, | |
paths, | |
layout, | |
target_crs, | |
resample_method, | |
partition_strategy, | |
read_method) | |
return TiledRasterLayer(layer_type, srdd) | |
""" | |
read_to_layout usage | |
""" | |
import geopyspark as gps | |
base_path = "s3://data/data-files/" | |
names = ['area-1/', 'area-2/', 'area-3/'] | |
bands = ['B01', 'B02', 'B03', 'B04', 'B05', 'B06', 'B07', 'B08', 'B8A', 'B09', 'B10', 'B11'] | |
paths = [] | |
for name in names: | |
combined_path = base_path.join(name) | |
for band in bands: | |
paths.append(combined_path.join(band) + '.jp2') | |
# Should create a TiledRasterLayer from the given inputs. | |
# The data will be read in via GDAL and partitioned using | |
# a SpatialPartitioner. | |
# The resulting layer will be reprojected and tiled such that | |
# it matches the given layout. | |
tiled_layout = gps.raster_source.read_to_layout(layer_type=gps.LayerType.SPATIAL, | |
paths=paths, | |
layout=GlobalLayout(), | |
target_crs=3857, | |
partition_strategy=gps.SpatialPartitionStrategy(12), | |
read_method=gps.ReadMethod.GDAL) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment