Show
Ignore:
Timestamp:
03/21/09 09:55:58 (3 years ago)
Author:
mloskot
Message:

gdal2wktraster: Calculate real raster extent for regular blocking and insert it to RASTER_COLUMNS. Added calculate_geoxy() and calculate_bounding_box() functions. This is much more usable/stable version of raster blocking support. All loading modes tested using GDAL test dataset: utm.tif, 512x512, 1 band, 1BUI. TODO: Test with multi-band datasets.

Files:
1 modified

Legend:

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

    r3919 r3920  
    274274    return (int(nx), int(ny)) 
    275275 
     276def calculate_geoxy(ds, xy): 
     277    """Calculate georeferenced coordinate from given x and y""" 
     278    assert ds is not None 
     279    assert xy is not None 
     280    assert len(xy) == 2 
     281 
     282    gt = ds.GetGeoTransform() 
     283    xgeo = gt[0] + gt[1] * xy[0] + gt[2] * xy[1]; 
     284    ygeo = gt[3] + gt[4] * xy[0] + gt[5] * xy[1]; 
     285 
     286    return (xgeo, ygeo) 
     287 
     288def calculate_bounding_box(ds): 
     289    """Calculate georeferenced coordinates of spatial extent of raster dataset""" 
     290    assert ds is not None 
     291 
     292    # UL, LL, UR, LR 
     293    dim = ( (0,0),(0,ds.RasterYSize),(ds.RasterXSize,0),(ds.RasterXSize,ds.RasterYSize) ) 
     294 
     295    ext = (calculate_geoxy(ds, dim[0]), calculate_geoxy(ds, dim[1]), 
     296           calculate_geoxy(ds, dim[2]), calculate_geoxy(ds, dim[3])) 
     297 
     298    return ext 
    276299 
    277300def check_hex(hex, bytes_size = None): 
     
    437460    pixel_types = collect_pixel_types(ds, band_from, band_to) 
    438461    nodata_values = collect_nodata_values(ds, band_from, band_to) 
    439     extent = ((0,0), (1,0), (1,1), (0,1)) # TODO: Generate polygon geometry containing raster/all tiles 
     462    extent = calculate_bounding_box(ds) 
    440463    sql = make_sql_addrastercolumn(options, pixel_types, nodata_values, pixel_size, block_size, extent) 
    441464    options.output.write(sql) 
     
    573596        rb = 'true' 
    574597        bs = ( blocksize[0], blocksize[1] ) 
    575         extgeom = "ST_GeometryFromText('POLYGON((%f %f,%f %f,%f %f,%f %f,%f %f))', %d)" % \ 
     598        extgeom = "ST_Box2D(ST_GeometryFromText('POLYGON((%f %f,%f %f,%f %f,%f %f,%f %f))', %d))" % \ 
    576599                  (extent[0][0], extent[0][1], extent[1][0], extent[1][1], 
    577600                   extent[2][0], extent[2][1], extent[3][0], extent[3][1],