PostGIS  2.4.9dev-r@@SVN_REVISION@@
rtpixdump.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 #
3 #
4 # Brute-force dump of all pixels of all bands in WKT Raster field/row to text.
5 # This utility is handy for debugging purposes.
6 #
7 # Copyright (C) 2009 Mateusz Loskot <mateusz@loskot.net>
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # as published by the Free Software Foundation; either version 2
12 # of the License, or (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software Foundation,
21 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #
23 
24 import rtreader
25 from optparse import OptionParser
26 import sys
27 
28 def logit(msg):
29  if VERBOSE is True:
30  sys.stderr.write("LOG - " + msg + "\n")
31 
32 
33 try:
34 
35  prs = OptionParser(version="%prog $Revision: 13496 $",
36  usage="%prog -d <DB> -t <TABLE> [-c <COLUMN>]",
37  description="Brute-force dump of all pixel values of WKT Raster dataset")
38  prs.add_option("-d", "--db", dest="db", action="store", default=None,
39  help="PostgreSQL database connection string, required")
40  prs.add_option("-t", "--table", dest="table", action="store", default=None,
41  help="table with raster column [<schema>.]<table>, required")
42  prs.add_option("-c", "--column", dest="column", action="store", default="rast",
43  help="raster column, optional, default=rast")
44  prs.add_option("-w", "--where", dest="where", action="store", default=None,
45  help="SQL WHERE clause to filter record - NOT IMPLEMENTED")
46  prs.add_option("-v", "--verbose", dest="verbose", action="store_true", default=False,
47  help="be excessively verbose and useful for debugging")
48 
49  (opts, args) = prs.parse_args()
50 
51  if opts.db is None:
52  prs.error("use -d option to specify database connection string")
53  if opts.table is None:
54  prs.error("use -t option to specify raster table")
55  if opts.column is None:
56  prs.error("use -c option to specify raster column in raster table")
57 
58  global VERBOSE
59  VERBOSE = opts.verbose
60 
61  rast = rtreader.RasterReader(opts.db, opts.table, opts.column)
62  logit("Connected to %s" % opts.db)
63  logit("Raster width=%d, height=%d, bands=%d" %(rast.width, rast.height, rast.num_bands))
64 
65  for band in range(1, rast.num_bands + 1):
66  logit("--- BAND %d ---------------------------------" % band)
67  sys.stderr.write("\n")
68  for y in range(1, rast.height + 1):
69  scanline = ""
70  for x in range(1, rast.width + 1):
71  scanline += str(int(rast.get_value(band, x, y))) + '\t'
72  print scanline
73  print # Bands separator
74 
75 except rtreader.RasterError, e:
76  print "ERROR - ", e
RASTER driver (read-only)
Definition: rtreader.py:37
def logit(msg)
Definition: rtpixdump.py:28