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