locationtech-labs / geopyspark

GeoTrellis for PySpark
Other
179 stars 59 forks source link

[GeoNotebook] Allow for data to be clipped out of a TMSLayer #386

Open lossyrob opened 7 years ago

lossyrob commented 7 years ago

We want to support the functionality of clipping raster data out in a GeoNotebook.

With the TMSData, we'll want to optionally supply a method get_data as in here https://github.com/geotrellis/geonotebook/blob/feature/geotrellis/geonotebook/wrappers/raster.py#L120.

We can simply allow this to be passed into the TMSData as something like

class TMSRasterData(object):
    def __init__(self, tms, name=None, get_data_func=None):
     #...
    def get_data(self, window=None, masked=True, axis=2, **kwargs):
       if get_data_func is not None:
          return  get_Data_func(window, masked, axis, **kwargs)
      else:
          return None

The next part of this is that the Layer says whether or not it can subset. So in __init__ for InProcessTileLayer, we say something like

if isinstance(self.data, TMSData):
  self.can_subset = self.data.get_data_func is not None

and also provide the subset method:

def subset(self, annotation, **kwargs):
        return annotation.subset(self, **kwargs)

See these functions for usage: https://github.com/geotrellis/geonotebook/blob/feature/geotrellis/geonotebook/annotations.py#L58 and https://github.com/geotrellis/geonotebook/blob/feature/geotrellis/geonotebook/annotations.py#L77

lossyrob commented 7 years ago

This would require the corresponding get_data_func from geopyspark in situations where appropriate, to make it easy for users to start up the server, and pass it in as a TMSData layer with the appropriate data fetching function.