Example #1
0
    prs.add_option("-v", "--verbose", dest="verbose", action="store_true", default=False,
            help="be excessively verbose and useful for debugging")

    (opts, args) = prs.parse_args()

    if opts.db is None:
        prs.error("use -d option to specify database connection string")
    if opts.table is None:
        prs.error("use -t option to specify raster table")
    if opts.column is None:
        prs.error("use -c option to specify raster column in raster table")

    global VERBOSE
    VERBOSE = opts.verbose

    rast = rtreader.RasterReader(opts.db, opts.table, opts.column)
    logit("Connected to %s" % opts.db)
    logit("Raster width=%d, height=%d, bands=%d" %(rast.width, rast.height, rast.num_bands))
    
    for band in range(1, rast.num_bands + 1):
        logit("--- BAND %d ---------------------------------" % band)
        sys.stderr.write("\n")
        for y in range(1, rast.height + 1):
            scanline = ""
            for x in range(1, rast.width + 1):
                scanline += str(int(rast.get_value(band, x, y))) + '\t'
            print scanline
        print # Bands separator

except rtreader.RasterError, e:
    print "ERROR - ", e
Example #2
0
    (opts, args) = prs.parse_args()

    if opts.db is None:
        prs.error("use -d option to specify database connection string")
    if opts.table is None:
        prs.error("use -t option to specify raster table")
    if opts.column is None:
        prs.error("use -c option to specify raster column in raster table")
    if opts.output is None:
        prs.error("use -o option to specify raster output file")

    global VERBOSE
    VERBOSE = opts.verbose

    rt = rtreader.RasterReader(opts.db, opts.table, opts.column, opts.where)
    if VERBOSE is True:
        rt.logging = True

    logit("Connected to %s" % opts.db)
    logit("Source WKT raster:")
    logit("\trow=%s" % opts.where)
    logit("\twidth=%d, height=%d, bands=%d, pixel types=%s" \
          %(rt.width, rt.height, rt.num_bands, str(rt.pixel_types)))
    logit("Target GeoTIFF: %s" % opts.output)

    out_format = "GTiff"
    out_driver = gdal.GetDriverByName(out_format)
    out_data_type = pt2gdt(rt.pixel_types[0])
    out_ds = out_driver.Create(opts.output, rt.width, rt.height, rt.num_bands,
                               out_data_type)