def clip(self, shp, keep=False, *args, **kwargs):
df = pd.DataFrame(zonal_stats(shp, self.raster, nodata=self.nodata_value, all_touched=True,<EOL>raster_out=True, affine=Affine.from_gdal(*self.geot),<EOL>geojson_out=keep,))<EOL>if keep:<EOL><INDENT>df['<STR_LIT>'] = df.properties.apply(lambda x: GeoRaster(x['<STR_LIT>'],<EOL>Affine.to_gdal(x['<STR_LIT>']),<EOL>nodata_value=x['<STR_LIT>'],<EOL>projection=self.projection,<EOL>datatype=self.datatype))<EOL>cols = list(set([i for i in df.properties[<NUM_LIT:0>].keys()]).intersection(set(shp.columns)))<EOL>df2 = pd.DataFrame([df.properties.apply(lambda x: x[i]) for i in cols<EOL>]).T.merge(df[['<STR_LIT>']], left_index=True, right_index=True,)<EOL>df2.columns = cols+['<STR_LIT>']<EOL>df2 = df2.merge(df[['<STR_LIT:id>']], left_index=True, right_index=True)<EOL>df2.set_index('<STR_LIT:id>', inplace=True)<EOL>return df2<EOL><DEDENT>else:<EOL><INDENT>df['<STR_LIT>'] = df.apply(lambda x: GeoRaster(x.mini_raster_array,<EOL>Affine.to_gdal(x.mini_raster_affine),<EOL>nodata_value=x.mini_raster_nodata,<EOL>projection=self.projection,<EOL>datatype=self.datatype), axis=<NUM_LIT:1>)<EOL>return df['<STR_LIT>'].values<EOL><DEDENT>
Clip raster using shape, where shape is either a GeoPandas DataFrame, shapefile,
or some other geometry format used by python-raster-stats

Returns list of GeoRasters or Pandas DataFrame with GeoRasters and additional information

Usage:

clipped = geo.clip(shape, keep=False)

where:
keep: Boolean (Default False), returns Georasters and Geometry information