def union(rasters):
if sum([rasters[<NUM_LIT:0>].x_cell_size == i.x_cell_size for i in rasters]) == len(rasters)and sum([rasters[<NUM_LIT:0>].y_cell_size == i.y_cell_size for i in rasters]) == len(rasters)and sum([rasters[<NUM_LIT:0>].projection.ExportToProj4() == i.projection.ExportToProj4() for i in rasters]) == len(rasters):<EOL><INDENT>if sum([rasters[<NUM_LIT:0>].nodata_value == i.nodata_value for i in rasters]) == len(rasters):<EOL><INDENT>ndv = rasters[<NUM_LIT:0>].nodata_value<EOL><DEDENT>else:<EOL><INDENT>ndv = np.nan<EOL><DEDENT>if ndv == None:<EOL><INDENT>ndv = np.nan<EOL><DEDENT>if sum([rasters[<NUM_LIT:0>].datatype == i.datatype for i in rasters]) == len(rasters):<EOL><INDENT>datatype = rasters[<NUM_LIT:0>].datatype<EOL><DEDENT>else:<EOL><INDENT>datatype = None<EOL><DEDENT>projection = rasters[<NUM_LIT:0>].projection<EOL>lonmin = min([i.xmin for i in rasters])<EOL>lonmax = max([i.xmax for i in rasters])<EOL>latmin = min([i.ymin for i in rasters])<EOL>latmax = max([i.ymax for i in rasters])<EOL>shape = (np.abs(np.floor((latmax-latmin)/rasters[<NUM_LIT:0>].y_cell_size)).astype(int), np.floor((lonmax-lonmin)/rasters[<NUM_LIT:0>].x_cell_size).astype(int))<EOL>out = ndv*np.ones(shape)<EOL>outmask = np.ones(shape).astype(bool)<EOL>for i in rasters:<EOL><INDENT>(row, col) = map_pixel(i.xmin, i.ymax, rasters[<NUM_LIT:0>].x_cell_size, rasters[<NUM_LIT:0>].y_cell_size, lonmin, latmax)<EOL>out[row:row+i.shape[<NUM_LIT:0>], col:col+i.shape[<NUM_LIT:1>]] = np.where(i.raster.data != i.nodata_value, i.raster.data,out[row:row+i.shape[<NUM_LIT:0>], col:col+i.shape[<NUM_LIT:1>]])<EOL>outmask[row:row+i.shape[<NUM_LIT:0>], col:col+i.shape[<NUM_LIT:1>]] = np.where(i.raster.mask == False, False,outmask[row:row+i.shape[<NUM_LIT:0>], col:col+i.shape[<NUM_LIT:1>]])<EOL><DEDENT>out = np.ma.masked_array(out, mask=outmask, fill_value=ndv)<EOL>return GeoRaster(out, (lonmin, rasters[<NUM_LIT:0>].x_cell_size, <NUM_LIT:0.0>, latmax, <NUM_LIT:0.0>, rasters[<NUM_LIT:0>].y_cell_size), nodata_value=ndv, projection=projection, datatype=datatype)<EOL><DEDENT>else:<EOL><INDENT>raise RasterGeoError('<STR_LIT>')<EOL><DEDENT>
Union of rasters

Usage:
    union(rasters)
where:
    rasters is a list of GeoRaster objects