PostGIS  2.1.10dev-r@@SVN_REVISION@@
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 77 of file rtreader.py.

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.

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

Here is the call graph for this function: