Show
Ignore:
Timestamp:
04/08/10 11:36:39 (2 years ago)
Author:
pracine
Message:

Ticket 188. Implement a HasNoDataValue? function. Set the HasNodata? flag from gdal2wktraster.py.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • spike/wktraster/scripts/gdal2wktraster.py

    r5259 r5515  
    639639        nodata = band.GetNoDataValue() 
    640640    else: 
    641         # FIXME: What if input dataset does not specify NODATA value? Zero? 
    642641        logit("WARNING: No NODATA flagged in raster_columns metadata. " 
    643642              "In serialized raster, NODATA bytes will have value of 0.\n") 
     
    709708    return hexwkb 
    710709 
    711 def wkblify_band_nodata(band): 
    712     assert band is not None 
    713  
    714     pixtype = gdt2pt(band.DataType)['id'] 
    715     nodata = fetch_band_nodata(band) 
    716  
    717     hexwkb = '' 
    718     hexwkb += wkblify(pt2fmt(pixtype), nodata) 
    719  
    720     return hexwkb 
    721  
    722710def wkblify_band_header(options, band): 
    723711    """Writes band header into HEX-encoded WKB""" 
     
    726714    hexwkb = "" 
    727715 
     716    first4bits = 0 
     717     
     718    # If the register option is enabled, set the first bit to 1 
     719    if options.register: 
     720        first4bits = 128 
     721         
     722    nodata = band.GetNoDataValue() 
     723    # If there is no nodata value, set it to 0. Otherwise set the HasNodata bit to 1 
     724    if nodata is not None: 
     725        first4bits += 64 
     726    else: 
     727        nodata = 0 
     728     
    728729    # Encode pixel type 
    729730    pixtype = gdt2pt(band.DataType)['id'] 
    730     if options.register: 
    731         hexwkb += wkblify('B', pixtype + 128) 
    732     else: 
    733         hexwkb += wkblify('B', pixtype) 
     731    hexwkb += wkblify('B', pixtype + first4bits) 
    734732     
    735733    # Encode NODATA value (or Zero, if NODATA unavailable)  
    736     hexwkb += wkblify_band_nodata(band) 
     734    hexwkb += wkblify(pt2fmt(pixtype), nodata) 
    737735 
    738736    check_hex(hexwkb) 
     
    758756    else: 
    759757        # In-db raster 
    760  
    761         # Real NODATA value or Zero'ed byte(s) 
    762         hexnodata = wkblify_band_nodata(band) 
    763         bytes_per_pixel = len(hexnodata) / 2 # bytes per pixel used to validate hex string 
    764758 
    765759        # Right most column and bottom most row of blocks have