def __init__(self, obj, geography=False): """ Initialize on the spatial object. """ self.is_geometry = isinstance(obj, (GEOSGeometry, PostGISAdapter)) # Getting the WKB (in string form, to allow easy pickling of # the adaptor) and the SRID from the geometry or raster. if self.is_geometry: self.ewkb = bytes(obj.ewkb) self._adapter = Binary(self.ewkb) else: self.ewkb = to_pgraster(obj) self.srid = obj.srid self.geography = geography
def __init__(self, obj, geography=False): """ Initialize on the spatial object. """ self.is_geometry = isinstance(obj, (Geometry, PostGISAdapter)) # Getting the WKB (in string form, to allow easy pickling of # the adaptor) and the SRID from the geometry or raster. if self.is_geometry: self.ewkb = bytes(obj.ewkb) self._adapter = Binary(self.ewkb) else: self.ewkb = to_pgraster(obj) self.srid = obj.srid self.geography = geography
def extract_snodas_data(self, snodas_tar, outdir=None): rasters = {} with tempdirectory() as temp: if not outdir: outdir = temp tar = tarfile.open(snodas_tar) print('Extracting {}\n\tto temp dir {}'.format(snodas_tar, temp)) tar.extractall(temp) gzipped = glob.glob(os.path.join(temp, '*.gz')) for idx, f in enumerate(gzipped, start=1): print( 'Unzipping file {} of {}: {}'.format( idx, len(gzipped), os.path.basename(f), ), ) outpath = os.path.join( outdir, os.path.splitext(os.path.basename(f))[0], ) with gzip.open(f, 'rb') as f_in, \ open(outpath, 'wb') as f_out: shutil.copyfileobj(f_in, f_out) hdrs = [] for ext in HDR_EXTS: hdrs.extend(glob.glob(os.path.join(outdir, '*{}'.format(ext)))) for idx, hdr in enumerate(hdrs, start=1): print( 'Importing {} of {}: {}'.format( idx, len(hdrs), os.path.basename(hdr), ), ) self.trim_header(hdr) file_info = self.parse_filename(hdr) rasters[self.snodas_type_from_file_info(file_info)] = { 'raster': BytesIO(to_pgraster(GDALRaster(hdr)).encode()), 'info': file_info } return rasters
def deconstruct_raster(self, value): return to_pgraster(value)
import re