PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ copy_to()

def rtreader.RasterReader.copy_to (   self,
  file,
  raster_format = 'TIFF',
  output_format = 'HEX',
  sep = '\t' 
)
Proxy for SQL command COPY TO,
Converts selected rasters to specified raster_format with output sent either to 
single hex-based plain text file or one or more binary files in raster_format,
one raster binary file per tuple from the raster table.
The BIN output uses HEX output as intermediate stage.
raster_format - TIFF|JPEG|PNG
output_format - HEX|BIN; BIN is a binary file in raster_format
sep - if output_format=HEX, separates rid value from hex-encoded binary.

Definition at line 76 of file rtreader.py.

76  def copy_to(self, file, raster_format='TIFF', output_format='HEX', sep='\t'):
77  """
78  Proxy for SQL command COPY TO,
79  Converts selected rasters to specified raster_format with output sent either to
80  single hex-based plain text file or one or more binary files in raster_format,
81  one raster binary file per tuple from the raster table.
82  The BIN output uses HEX output as intermediate stage.
83  raster_format - TIFF|JPEG|PNG
84  output_format - HEX|BIN; BIN is a binary file in raster_format
85  sep - if output_format=HEX, separates rid value from hex-encoded binary.
86  """
87  import os.path
88  filehex = file # No extension added, may be user-defiened
89  with open(filehex, 'w') as f:
90  select = "SELECT rid, encode(ST_As%s(%s), 'hex') As rt FROM %s" % (raster_format, self._column, self._table)
91  if self._where is not None and len(self._where) > 0:
92  select += ' WHERE %s' % self._where
93  sql = "COPY (%s) TO STDOUT (DELIMITER '%s')" % (select, sep)
94  cur = self._conn.cursor()
95  cur.copy_expert(sql, f)
96 
97  if output_format == 'BIN':
98  import binascii
99  with open(filehex, 'r') as f:
100  dirname = os.path.dirname(file)
101  ext = raster_format.lower()
102  for line in f.readlines():
103  rid, raster = line.split()
104  filebin = self._table + '_' + self._column + '_' + rid + '.' + ext
105  filebin = os.path.join(dirname, filebin)
106  with open(filebin, 'w+') as fbin:
107  fbin.write(binascii.unhexlify(raster))
108 

References rtreader.RasterReader._column, rtreader.RasterReader._conn, rtreader.RasterReader._connect(), rtreader.RasterReader._connstr, rtreader.RasterReader._log(), rtreader.RasterReader._logging, rtreader.RasterReader._query_pixel_types(), rtreader.RasterReader._query_raster_size(), rtreader.RasterReader._query_single_row(), rtreader.RasterReader._sizes, rtreader.RasterReader._table, rtreader.RasterReader._where, and rtreader.RasterReader.num_bands.

Here is the call graph for this function: