Beispiel #1
0
def process(parsed, target, temp_metatile, temp_processed, save_offsetx, save_offsety, save_xsize, save_ysize, nodata, ot, *args, **kwargs):

    scale = parsed.s
    zfactor = parsed.z
    altitude = parsed.alt
    process_hillshade = "gdaldem hillshade -s %s -z %s -alt %s %s -of GTiff %s > /dev/null" %(scale, zfactor, altitude, temp_metatile, temp_processed)
    os.system(process_hillshade)
    nodata = 0
    ot = "-ot Byte"
    # open in numpy
    _, gt, _, nodata, array_numpy = numpy_read(temp_processed)
    processed_numpy = ndimage.median_filter(array_numpy, size=3)
    numpy_save(processed_numpy, target, save_offsetx, save_offsety, save_xsize, save_ysize, gt, nodata, ot)
Beispiel #2
0
def process(parsed, target, temp_metatile, temp_processed, save_offsetx, save_offsety, save_xsize, save_ysize, nodata, ot, *args, **kwargs):

    scale = parsed.s
    process_slopeshade = "gdaldem slope -s %s %s -of GTiff %s > /dev/null" %(scale, temp_metatile, temp_processed)
    os.system(process_slopeshade)
    nodata = 0
    ot = "-ot Byte"
    _, gt, _, nodata, array_numpy = numpy_read(temp_processed)
    array_numpy[array_numpy==nodata] = 0
    # convert to 8 bit and invert values
    array_numpy = -(array_numpy.astype(numpy.uint8)-255)
    array_numpy[array_numpy==0] = 255
    #print array_numpy.shape
    processed_numpy = array_numpy
    #print processed_numpy[1][3]
    numpy_save(processed_numpy, target, save_offsetx, save_offsety, save_xsize, save_ysize, gt, nodata, ot)
Beispiel #3
0
def process(parsed, target, temp_metatile, temp_processed, save_offsetx,
            save_offsety, save_xsize, save_ysize, nodata, ot, *args, **kwargs):

    scale = parsed.s
    process_slopeshade = "gdaldem slope -s %s %s -of GTiff %s > /dev/null" % (
        scale, temp_metatile, temp_processed)
    os.system(process_slopeshade)
    nodata = 0
    ot = "-ot Byte"
    _, gt, _, nodata, array_numpy = numpy_read(temp_processed)
    array_numpy[array_numpy == nodata] = 0
    # convert to 8 bit and invert values
    array_numpy = -(array_numpy.astype(numpy.uint8) - 255)
    array_numpy[array_numpy == 0] = 255
    #print array_numpy.shape
    processed_numpy = array_numpy
    #print processed_numpy[1][3]
    numpy_save(processed_numpy, target, save_offsetx, save_offsety, save_xsize,
               save_ysize, gt, nodata, ot)
Beispiel #4
0
def process(parsed, target, temp_metatile, temp_processed, save_offsetx, save_offsety, save_xsize, save_ysize, nodata, ot, *args, **kwargs):

    temp_voids = tempfile.mktemp() + ".geojson" #"tmp_voids_%s.geojson" % os.getpid()
    with open(temp_voids, "w+"):
        pass
    temp_voids_raster = tempfile.mktemp() #"/tmp/tmp_voids_raster_%s.tif" % os.getpid()
    with open(temp_voids_raster, "w+"):
        pass

    temp_secondary = tempfile.mktemp() #"/tmp/tmp_secondary_%s" % os.getpid()
    with open(temp_voids, "w+"):
        pass

    void_mask = parsed.voids
    secondary_source = parsed.secondary
    tertiary_source = parsed.tertiary
    landmask = parsed.landmask

    nodata = 0
    ot = "-ot Int16"

    # read primary data
    _, gt, _, nodata, primary_dem = numpy_read(temp_metatile)

    # TODO check if valid
    ulx, llx = gt[0], gt[0]
    uly, ury = gt[3], gt[3]
    urx, lrx = ulx + (gt[1] * primary_dem.shape[1]), ulx + (gt[1] * primary_dem.shape[1])
    lly, lry = uly + (gt[5] * primary_dem.shape[0]), uly + (gt[5] * primary_dem.shape[0])

    # read secondary
    clip_secondary = "gdal_translate -projwin %s %s %s %s %s %s" %(ulx, uly, lrx, lry, secondary_source, temp_secondary)
    print "%s: clipping secondary DEM" %(target)
    os.system(clip_secondary)
    _, gt, _, nodata, secondary_dem = numpy_read(temp_secondary)

    # clip void mask
    os.remove(temp_voids)
    clip_void_mask = "ogr2ogr -overwrite -f 'GeoJSON' %s %s -clipsrc %s %s %s %s" %(temp_voids, void_mask, llx, lly, urx, ury)
    print "%s: clipping void mask" %(target)
    os.system(clip_void_mask)
    
    # rasterize void mask
    rasterize_void_mask = "gdal_rasterize -burn 1 -i -te %s %s %s %s -tr %s %s -ot Byte %s %s" %(llx, lly, urx, ury, gt[1], -gt[5], temp_voids, temp_voids_raster)
    print "%s: rasterize void mask" %(target)
    os.system(rasterize_void_mask)
    _, gt, _, nodata, void_mask_raster = numpy_read(temp_voids_raster)
    
    ## numpy_read
    
    # fill gaps by overlaying numpy arrays
    # http://stackoverflow.com/questions/19817955/overlay-part-of-the-matrix-on-top-of-another

    processed_numpy = numpy.where(void_mask_raster != 0, primary_dem, secondary_dem)

    # clean up
    os.remove(temp_voids)
    os.remove(temp_voids_raster)
    os.remove(temp_secondary)
    
    if landmask:
        # read mask to numpy
        temp_landmask = tempfile.mktemp() #"/tmp/tmp_voids_raster_%s.tif" % os.getpid()
        with open(temp_landmask, "w+"):
            pass
        clip_landmask = "gdal_translate -projwin %s %s %s %s %s %s" %(ulx, uly, lrx, lry, landmask, temp_landmask)
        print clip_landmask
        os.system(clip_landmask)
        _, gt, _, nodata, numpy_landmask = numpy_read(temp_landmask)
        os.remove(temp_landmask)

        processed_numpy = numpy.where(numpy_landmask == 1, processed_numpy, 0)

    numpy_save(processed_numpy, target, save_offsetx, save_offsety, save_xsize, save_ysize, gt, nodata, ot)