PostGIS  2.1.10dev-r@@SVN_REVISION@@
def raster2pgsql.parse_command_line ( )
Collects, parses and validates command line arguments.

Definition at line 80 of file raster2pgsql.py.

Referenced by main().

81  """Collects, parses and validates command line arguments."""
82 
83  prs = OptionParser(version="%prog $Revision: 12060 $")
84 
85  # Mandatory parameters
86  grp0 = OptionGroup(prs, "Source and destination",
87  "*** Mandatory parameters always required ***")
88  grp0.add_option("-r", "--raster", dest="raster", action="append", default=None,
89  help="append raster to list of input files, at least one raster "
90  "file required. You may use wildcards (?,*) for specifying multiple files.")
91  grp0.add_option("-t", "--table", dest="table", action="store", default=None,
92  help="raster destination in form of [<schema>.]<table> or base raster table for overview level>1, required")
93  prs.add_option_group(grp0);
94 
95  # Optional parameters - raster manipulation
96  grp_r = OptionGroup(prs, "Raster processing",
97  "Optional parameters used to manipulate input raster dataset")
98  grp_r.add_option("-s", "--srid", dest="srid", action="store", type="int", default=-1,
99  help="assign output raster with specified SRID")
100  grp_r.add_option("-b", "--band", dest="band", action="store", type="int", default=None,
101  help="specify number of the band to be extracted from raster file")
102  grp_r.add_option("-k", "--block-size", dest="block_size", action="store", default=None,
103  help="cut raster(s) into tiles to be inserted one by table row."
104  "BLOCK_SIZE is expressed as WIDTHxHEIGHT. Incomplete tiles are completed with nodata values")
105  grp_r.add_option("-R", "--register", dest="register", action="store_true", default=False,
106  help="register the raster as a filesystem (out-db) raster")
107  grp_r.add_option("-l", "--overview-level", dest="overview_level", action="store", type="int", default=1,
108  help='create overview tables named as o_<LEVEL>_<RASTER_TABLE> and '
109  'populate with GDAL-provided overviews (regular blocking only)')
110  prs.add_option_group(grp_r);
111 
112  # Optional parameters - database/table manipulation
113  grp_t = OptionGroup(prs, 'Database processing',
114  'Optional parameters used to manipulate database objects')
115  grp_t.add_option('-c', '--create', dest='create_table', action='store_true', default=False,
116  help='create new table and populate it with raster(s), this is the default mode')
117  grp_t.add_option('-a', '--append', dest='append_table', action='store_true', default=False,
118  help='append raster(s) to an existing table')
119  grp_t.add_option("-d", "--drop", dest="drop_table", action="store_true", default=False,
120  help="drop table, create new one and populate it with raster(s)")
121  grp_t.add_option("-f", "--field", dest="column", action="store", default=g_rt_column,
122  help="specify name of destination raster column, default is 'rast'")
123  grp_t.add_option("-F", "--filename", dest="filename", action="store_true", default=False,
124  help="add a column with the name of the file")
125  grp_t.add_option("-I", "--index", dest="index", action="store_true", default=False,
126  help="create a GiST index on the raster column")
127  grp_t.add_option("-M", "--vacuum", dest="vacuum", action="store_true", default=False,
128  help="issue VACUUM command against all generated tables")
129  grp_t.add_option('-V', '--create-raster-overviews', dest='create_raster_overviews_table',
130  action='store_true', default=False,
131  help='create RASTER_OVERVIEWS table used to store overviews metadata')
132  prs.add_option_group(grp_t);
133 
134  # Other optional parameters
135  grp_u = OptionGroup(prs, "Miscellaneous", "Other optional parameters")
136  grp_u.add_option("-e", "--endian", dest="endian", action="store", type="int", default=g_rt_endian,
137  help="control endianness of generated binary output of raster; "
138  "specify 0 for XDR and 1 for NDR (default); "
139  "only NDR output is supported now")
140  grp_u.add_option("-w", "--raster-version", dest="version",
141  action="store", type="int", default=g_rt_version,
142  help="specify version of raster protocol, default is 0; "
143  "only value of zero is supported now")
144  grp_u.add_option("-o", "--output", dest="output", action="store", default=sys.stdout,
145  help="specify output file, otherwise send to stdout")
146  grp_u.add_option("-v", "--verbose", dest="verbose", action="store_true", default=False,
147  help="verbose mode. Useful for debugging")
148  prs.add_option_group(grp_u);
149 
150  (opts, args) = prs.parse_args()
151 
152  # Validate options
153  if opts.create_table and opts.drop_table and opts.append_table:
154  prs.error("options -c, -a and -d are mutually exclusive")
155  if opts.create_table and opts.drop_table:
156  prs.error("options -c and -d are mutually exclusive")
157  if opts.create_table and opts.append_table:
158  prs.error("options -c and -a are mutually exclusive")
159  if opts.append_table and opts.drop_table:
160  prs.error("options -a and -d are mutually exclusive")
161  if (not opts.create_table and not opts.drop_table and not opts.append_table) or opts.drop_table:
162  opts.create_table = True
163 
164  if opts.raster is None:
165  prs.error("use option -r to specify at least one input raster. Wildcards (?,*) are accepted.")
166 
167  if opts.block_size is not None and len(opts.raster) != 1:
168  prs.error("regular blocking supports single-raster input only")
169 
170  if opts.block_size is not None:
171  if len(opts.block_size.split('x')) != 2 and len(opts.block_size.split('X')) != 2:
172  prs.error("invalid format of block size, expected WIDTHxHEIGHT")
173 
174  if opts.overview_level > 1 and opts.block_size is None:
175  prs.error("regular blocking mode required to enable overviews support (level > 1)")
176 
177  if opts.create_raster_overviews_table and opts.overview_level <= 1:
178  prs.error('create table for RASTER_OVERVIEWS available only if overviews import requested')
179 
180  # XXX: Now, if --band=Nth, then only Nth band of all specified rasters is dumped/imported
181  # This behavior can be changed to support only single-raster input if --band option used.
182  #if opts.band is not None and len(opts.raster) > 1:
183  # prs.error("option -b requires single input raster only, specify -r option only once")
184 
185  if opts.table is None:
186  prs.error("use option -t to specify raster destination table")
187  if len(opts.table.split('.')) > 2:
188  prs.error("invalid format of table name specified with option -t, expected [<schema>.]table")
189 
190  if opts.output is None:
191  prs.error("failed to initialise output file, try to use option -o explicitly")
192 
193  if opts.version is not None:
194  if opts.version != g_rt_version:
195  prs.error("invalid version of WKT Raster protocol specified, only version 0 is supported")
196  else:
197  prs.error("use option -w to specify version of WKT Raster protocol")
198 
199  if opts.endian is not None:
200  if opts.endian != NDR and opts.endian != XDR:
201  prs.error("invalid endianness value, valid ones are 0 for NDR or 1 for XDR")
202  else:
203  prs.error("use option -e to specify endianness of binary output")
204 
205  return (opts, args)
206 
207 
def parse_command_line()
Definition: raster2pgsql.py:80

Here is the caller graph for this function: