Esempio n. 1
0
def coastaldem(Input_Workspace, grdNamePth, InFeatureClass, OutRaster, seaLevel, version = None):
	'''Sets elevations for water and other areas in digital elevation model.

	Parameters
	----------
	Input_Workspace : str
		Input workspace, output raster will be written to this location.
	grdNamePth : str
		Path to the input DEM grid.
	InFeatureClass : str
		Path to the LandSea feature class.
	OutRaster : str
		Output DEM grid name.
	seaLevel : float
		Elevation at which to make the sea.
	version : str (optional)
		StreamStats Data Preparation Tools version number
	
	Returns
	-------
	OutRaster : raster
		Output raster with coastal areas corrected.

	Notes
	-----
	Outputs are written to the workspace.
	'''
	if version:
		arcpy.AddMessage('StreamStats Data Preparation Tools version: %s'%(version))

	try:
		# set working folder
		arcpy.env.workspace = Input_Workspace
		arcpy.env.scratchWorkspace = arcpy.env.workspace

		arcpy.env.extent = grdNamePth
		arcpy.env.snapRaster = grdNamePth
		arcpy.env.outputCoordinateSystem = grdNamePth
		arcpy.env.cellSize = grdNamePth

		# this is assuming land is 1 and sea is -1
		arcpy.PolygonToRaster_conversion(InFeatureClass, "Land", "mskg")
		
		mskg = Raster("mskg") # load the mask grid
		grdName = Raster(grdNamePth) # load the 
		
		seag = Con(mskg == -1, float(seaLevel))

		landg = Con((mskg == 1) & (grdName <= 0), 1, grdName)

		nochgg = Con(mskg == 0, grdName)

		arcpy.MosaicToNewRaster_management([seag,landg,nochgg],arcpy.env.workspace,OutRaster,None, "32_BIT_SIGNED", None, 1, "FIRST") # mosaic and produce new raster
		
	except:
		e = sys.exc_info()[1]
		print(e.args[0])
		arcpy.AddError(e.args[0])

	return None
Esempio n. 2
0
def mosiacRasters():
    arcpy.env.workspace = 'C:\\Users\\Bougie\\Desktop\\Gibbs\\data\\usxp\\ancillary\\raster\\cdl.gdb\\'

    cdl_raster = Raster("cdl30_2015")

    elevSTDResult = arcpy.GetRasterProperties_management(cdl_raster, "TOP")
    YMax = elevSTDResult.getOutput(0)
    elevSTDResult = arcpy.GetRasterProperties_management(cdl_raster, "BOTTOM")
    YMin = elevSTDResult.getOutput(0)
    elevSTDResult = arcpy.GetRasterProperties_management(cdl_raster, "LEFT")
    XMin = elevSTDResult.getOutput(0)
    elevSTDResult = arcpy.GetRasterProperties_management(cdl_raster, "RIGHT")
    XMax = elevSTDResult.getOutput(0)

    arcpy.env.extent = arcpy.Extent(XMin, YMin, XMax, YMax)

    rasterlist = [
        'resampled_cdl30_2007_p1',
        'D:\\projects\\ksu\\v2\\attributes\\rasters\\cdl30_2007.img'
    ]

    ######mosiac tiles together into a new raster
    arcpy.MosaicToNewRaster_management(rasterlist, data['refine']['gdb'],
                                       data['refine']['mask_2007']['filename'],
                                       cdl_raster.spatialReference,
                                       "16_BIT_UNSIGNED", 30, "1", "LAST",
                                       "FIRST")

    #Overwrite the existing attribute table file
    arcpy.BuildRasterAttributeTable_management(
        data['refine']['mask_2007']['path'], "Overwrite")

    # Overwrite pyramids
    gen.buildPyramids(data['refine']['mask_2007']['path'])
Esempio n. 3
0
def mosaicRasters(map_project, tablename):
    ######Description: mosiac tiles together into a new raster
    tilelist = glob.glob(
        "D:/projects/usxp/deliverables/maps/{}/tiles/*.tif".format(
            map_project))
    print 'tilelist:', tilelist

    #### need to wrap these paths with Raster() fct or complains about the paths being a string
    inTraj = Raster(
        'C:\\Users\\Bougie\\Desktop\\Gibbs\\data\\usxp\\ancillary\\raster\\cdl.gdb\\cdl30_2017'
    )

    filename = 'gssurgo_{}_30m'.format(tablename)
    print 'filename:', filename

    gdb = 'D:\\projects\\usxp\\deliverables\\maps\\{0}\\{0}.gdb'.format(
        map_project)

    ####suboptimal need to detrmine the appropraite datatype with a function!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    datatype = "16_BIT_UNSIGNED"

    ######mosiac tiles together into a new raster
    arcpy.MosaicToNewRaster_management(tilelist, gdb, filename,
                                       inTraj.spatialReference, datatype, 30,
                                       "1", "LAST", "FIRST")

    #Overwrite the existing attribute table file
    arcpy.BuildRasterAttributeTable_management(
        '{0}\\{1}'.format(gdb, filename), "Overwrite")
Esempio n. 4
0
def mosiacRasters(covertype):
    ######Description: mosiac tiles together into a new raster
    tilelist = glob.glob("C:/Users/Bougie/Desktop/Gibbs/data/tiles/*.tif")
    print 'tilelist:', tilelist 

    #### need to wrap these paths with Raster() fct or complains about the paths being a string
    inTraj=Raster("C:\\Users\\Bougie\\Desktop\\Gibbs\\data\\usxp\\pre\\traj\\v4\\v4_traj.gdb\\v4_traj_cdl30_b_2008to2017")
    
    gdb='D:\\projects\\intact_land\\abandoned.gdb'

    def getFileName(covertype):
        if covertype=='noncrop':
            return "abandoned_nd"
        elif covertype=='crop':
            return "crop_nd"

    filename = getFileName(covertype)
    print 'filename:-----------------------------', filename
    
    ######mosiac tiles together into a new raster
    arcpy.MosaicToNewRaster_management(tilelist, gdb, filename, inTraj.spatialReference, "16_BIT_UNSIGNED", 30, "1", "LAST","FIRST")

    #######Overwrite the existing attribute table file
    arcpy.BuildRasterAttributeTable_management(gdb+'\\'+filename, "Overwrite")

    ########Overwrite pyramids
    gen.buildPyramids(gdb+'\\'+filename)
Esempio n. 5
0
def mosiacRasters():
    ######Description: mosiac tiles together into a new raster
    tilelist = glob.glob(
        "D:/projects/usxp/deliverables/maps/suitability/tiles/*.tif")
    print 'tilelist:', tilelist

    #### need to wrap these paths with Raster() fct or complains about the paths being a string
    inTraj = Raster(
        'C:\\Users\\Bougie\\Desktop\\Gibbs\\data\\usxp\\ancillary\\raster\\cdl.gdb\\cdl30_2017'
    )

    filename = 'gssurgo_nicc_30m'
    print 'filename:', filename

    gdb = 'D:\\projects\\usxp\\deliverables\\maps\\suitability\\suitability.gdb'

    ######mosiac tiles together into a new raster
    arcpy.MosaicToNewRaster_management(tilelist, gdb, filename,
                                       inTraj.spatialReference,
                                       "16_BIT_UNSIGNED", 30, "1", "LAST",
                                       "FIRST")

    #Overwrite the existing attribute table file
    arcpy.BuildRasterAttributeTable_management(
        '{0}\\{1}'.format(gdb, filename), "Overwrite")

    # Overwrite pyramids
    gen.buildPyramids('{0}\\{1}'.format(gdb, filename))
Esempio n. 6
0
def make_mosaic_from_tiles(dem_tiles_folder,
                           mosaic_name,
                           geodatabase,
                           coordinate_system,
                           make_gdb=True,
                           export_to_raster=False):

    if not arcpy.Exists(geodatabase) and make_gdb is True:
        folder, name = os.path.split(geodatabase)
        arcpy.CreateFileGDB_management(folder, name)

    print("Making Mosaic Dataset")
    arcpy.CreateMosaicDataset_management(geodatabase,
                                         mosaic_name,
                                         coordinate_system,
                                         num_bands=1)
    mosaic_dataset = os.path.join(geodatabase, mosaic_name)

    print("Adding Tiles to Dataset")
    arcpy.AddRastersToMosaicDataset_management(
        mosaic_dataset,
        "Raster Dataset",
        dem_tiles_folder,
        update_overviews="UPDATE_OVERVIEWS")

    if export_to_raster:
        arcpy.MosaicToNewRaster_management(mosaic_dataset,
                                           geodatabase,
                                           "{}_export".format(mosaic_name),
                                           pixel_type="32_BIT_FLOAT",
                                           number_of_bands=1)
Esempio n. 7
0
def createMilkweedRaster(schema, inraster):
    gdb = 'D:\\projects\\usxp\\deliverables\\maps\\{0}\\{0}.gdb'.format(schema)
    arcpy.env.workspace = gdb
    county_raster = Raster(
        'C:\\Users\\Bougie\\Desktop\\Gibbs\\data\\usxp\\ancillary\\raster\\misc.gdb\\county_30m'
    )

    #### need to wrap these paths with Raster() fct or complains about the paths being a string
    inTraj = Raster(
        'C:\\Users\\Bougie\\Desktop\\Gibbs\\data\\usxp\\ancillary\\raster\\cdl.gdb\\cdl30_2017'
    )

    #####raster 1 is concerned with county value so convert the value of the s35_traj_bfc_fc_rc to the county value where grouped
    raster_1 = SetNull(inraster, county_raster, "VALUE <> 1")
    county_raster = None

    ###reclass the pixels with the stems_acres coumn by county value from the rasster above
    reclassed_1 = Reclassify(raster_1, "Value",
                             RemapRange(createReclassifyList_v2()), "NODATA")
    raster_1 = None

    ########change ALL pixels where s35_traj_bfc_fc_rc = 2 to value 61.37.  Not concerned with county spatial info.
    raster_2 = SetNull(inraster, 61.37, "VALUE <> 2")

    filename = "s35_{}".format(schema)

    #### mosiac raster_1 and raster_2 to get the milkweed dataset
    arcpy.MosaicToNewRaster_management([reclassed_1, raster_2], gdb, filename,
                                       inTraj.spatialReference,
                                       "8_BIT_UNSIGNED", 30, "1", "LAST",
                                       "FIRST")
Esempio n. 8
0
def createRefinedTrajectory(data):
    # mask_fp_2007.run(data)
    # mask_fp_yfc_potential.run(data)
    # mask_fp_nlcd_yfc.run(data)
    # mask_fp_nlcd_ytc.run(data)
    # mask_fp_yfc.run(data)
    # mask_fp_ytc.run(data)

    ##### loop through each of the cdl rasters and make sure nlcd is last
    # filelist = [data['pre']['traj']['path'], data['refine']['masks_yfc']['path'], data['refine']['masks_ytc']['path'], data['refine']['mask_2007']['path'], data['refine']['mask_nlcd']['path']]
    # filelist = [data['pre']['traj_yfc']['path'], data['refine']['mask_fp_2007']['path'], data['refine']['mask_fp_yfc_potential']['path'], data['refine']['mask_fp_nlcd_yfc']['path'], data['refine']['mask_fp_nlcd_ytc']['path'], data['refine']['mask_fp_yfc']['path'], data['refine']['mask_fp_ytc']['path']]
    filelist = [
        data['pre']['traj_yfc']['path'],
        data['refine']['mask_fp_2007']['path'],
        data['refine']['mask_fp_nlcd_yfc']['path'],
        data['refine']['mask_fp_nlcd_ytc']['path'],
        data['refine']['mask_fp_yfc']['path'],
        data['refine']['mask_fp_ytc']['path']
    ]

    print 'filelist:', filelist

    ##### mosaicRasters():
    arcpy.MosaicToNewRaster_management(
        filelist, data['pre']['traj_rfnd']['gdb'],
        data['pre']['traj_rfnd']['filename'],
        Raster(data['pre']['traj']['path']).spatialReference,
        '16_BIT_UNSIGNED', data['global']['res'], "1", "LAST", "FIRST")

    #Overwrite the existing attribute table file
    arcpy.BuildRasterAttributeTable_management(
        data['pre']['traj_rfnd']['path'], "Overwrite")

    # Overwrite pyramids
    gen.buildPyramids(data['pre']['traj_rfnd']['path'])
Esempio n. 9
0
def week_mosaic(inpath, outpath):
    env.workspace = inpath

    f = os.listdir(inpath)
    infiles = ""
    first = f[0]
    end = first
    number = 0
    for i in range(len(f)):
        if f[i] == end and f[i].endswith('.tif'):
            #arcpy.SetRasterProperties_management(f[i], "#", "#", "#", "1 -1000")
            infiles += f[i]
            number += 1
            if number == 7:
                outfile = first.strip('.tif') + '-' + end
                arcpy.MosaicToNewRaster_management(infiles,
                                                   outpath,
                                                   outfile,
                                                   pixel_type="32_BIT_FLOAT",
                                                   number_of_bands="1",
                                                   mosaic_method="MEAN")

                infiles = ""
                number = 0
                if i + 1 >= len(f):
                    break
                else:
                    first = f[i + 1]
            else:
                infiles += ";"
            if end == '089.tif':
                break
            end = f[i + 1]
Esempio n. 10
0
def createRefinedTrajectory(data):

    ##### create a file list of all the masked datasets
    filelist = [
        data['pre']['traj_yfc']['path'],
        data['refine']['mask_fp_2007']['path'],
        data['refine']['mask_fp_nlcd_yfc']['path'],
        data['refine']['mask_fp_nlcd_ytc']['path'],
        data['refine']['mask_fp_yfc']['path'],
        data['refine']['mask_fp_ytc']['path']
    ]

    print 'filelist:', filelist

    ##### mosaicRasters():
    arcpy.MosaicToNewRaster_management(
        filelist, data['pre']['traj_rfnd']['gdb'],
        data['pre']['traj_rfnd']['filename'],
        Raster(data['pre']['traj']['path']).spatialReference,
        '16_BIT_UNSIGNED', data['global']['res'], "1", "LAST", "FIRST")

    #Overwrite the existing attribute table file
    arcpy.BuildRasterAttributeTable_management(
        data['pre']['traj_rfnd']['path'], "Overwrite")

    # Overwrite pyramids
    gen.buildPyramids(data['pre']['traj_rfnd']['path'])
def mosaic_alert_area(folder_data, mosaic_folder, gdb_folder):
    filing_data = set()
    sr = arcpy.SpatialReference(4326)
    temp_folder = os.path.join(mosaic_folder, 'temp')
    os.mkdir(temp_folder)
    for file in os.listdir(folder_data):
        if file.endswith(".tif"):
            parseString = file.split('_')
            data_date = parseString[1]
            filing_data.add(data_date)
    for i in filing_data:
        mosaic_files = []
        newfilename = "cli_chirps-v2.0.{0}.extremerainalert.tif".format(i)
        newfilename_gdb = "cli_chirps_v2_0_{0}_extremerainalert".format(i)
        for j in os.listdir(folder_data):
            if j.endswith(".tif"):
                JString = j.split('_')
                if JString[1] == i:
                    mosaic_files.append(os.path.join(folder_data, j))
        mosaic_files.sort()
        arcpy.CheckOutExtension("spatial")
        arcpy.MosaicToNewRaster_management(input_rasters=mosaic_files, output_location=temp_folder,
                                           raster_dataset_name_with_extension=newfilename,
                                           coordinate_system_for_the_raster=sr, pixel_type='4_BIT',
                                           mosaic_method='MAXIMUM',
                                           number_of_bands='1')
        mosaic_file_path = os.path.join(temp_folder, newfilename)
        gdb_mosaic_with_null = os.path.join(gdb_folder, newfilename_gdb)
        set_null_raster = SetNull(mosaic_file_path, mosaic_file_path, "VALUE < 1")
        set_null_raster.save(gdb_mosaic_with_null)
        print(newfilename + " is created")
        arcpy.CheckInExtension("spatial")
Esempio n. 12
0
def mosiacRasters(data, yxc, subtype):
    ######Description: mosiac tiles together into a new raster
    tilelist = glob.glob("C:/Users/Bougie/Desktop/Gibbs/data/tiles/*.tif")
    print 'tilelist:', tilelist

    # tilelist_complete=['C:\\Users\\Bougie\\Desktop\\Gibbs\\data\\usxp\\sa\\r2\\s35\\post\\yfc_s35.gdb\\s35_yfc30_2008to2017_mmu5_fnc_61'] + tilelist
    # print tilelist_complete

    #### need to wrap these paths with Raster() fct or complains about the paths being a string
    inTraj = Raster(data['pre']['traj']['path'])

    mask_61_filename = 'fnc_61_mask'
    mask_61_path = 'C:\\Users\\Bougie\\Desktop\\Gibbs\\data\\usxp\\sa\\r2\\s35\\post\\yfc_s35.gdb' + '\\' + mask_61_filename
    # path_yfc_fnc_61 = 'C:\\Users\\Bougie\\Desktop\\Gibbs\\data\\usxp\\sa\\r2\\s35\\post\\yfc_s35.gdb\\s35_yfc30_2008to2017_mmu5_fnc_61'

    ######mosiac tiles together into a new raster
    arcpy.MosaicToNewRaster_management(tilelist, data['post'][yxc]['gdb'],
                                       mask_61_filename,
                                       inTraj.spatialReference,
                                       "16_BIT_UNSIGNED", 30, "1", "LAST",
                                       "FIRST")

    #Overwrite the existing attribute table file
    arcpy.BuildRasterAttributeTable_management(mask_61_path, "Overwrite")

    # Overwrite pyramids
    gen.buildPyramids(mask_61_path)
Esempio n. 13
0
def mosiacRasters(schema):
    ######Description: mosiac tiles together into a new raster
    tilelist = glob.glob(
        "D:/projects/usxp/series/s35/maps/{}/tiles/*.tif".format(schema))
    print 'tilelist:', tilelist

    #### need to wrap these paths with Raster() fct or complains about the paths being a string
    inTraj = Raster(
        'E:\\data\\gSSURGO\\gSSURGO_CONUS_10m.gdb\\MapunitRaster_30m')

    filename = 'gssurgo_{}_30m'.format(schema)
    print 'filename:', filename

    gdb = 'D:\\projects\\usxp\\series\\s35\\maps\\{0}\\{0}.gdb'.format(schema)

    ######mosiac tiles together into a new raster
    arcpy.MosaicToNewRaster_management(tilelist, gdb, filename,
                                       inTraj.spatialReference,
                                       "16_BIT_UNSIGNED", 30, "1", "LAST",
                                       "FIRST")

    #Overwrite the existing attribute table file
    arcpy.BuildRasterAttributeTable_management(
        '{0}\\{1}'.format(gdb, filename), "Overwrite")

    # Overwrite pyramids
    gen.buildPyramids('{0}\\{1}'.format(gdb, filename))
Esempio n. 14
0
def merge_tcd_ras(tcd_cop_fold, OrdSurv_Grid, scratch, epsg_code):
    print("merging rasters in arcpy")

    tcd_3030_cop = os.path.join(tcd_cop_fold,
                                r"TCD_2015_020m_eu_03035_d05_E30N30",
                                r"TCD_2015_020m_eu_03035_d05_E30N30.TIF")
    tcd_3040_cop = os.path.join(tcd_cop_fold,
                                r"TCD_2015_020m_eu_03035_d05_E30N40",
                                r"TCD_2015_020m_eu_03035_d05_E30N40.TIF")
    # scratch_sub = os.path.join(scratch, "tcd_temp")
    tcd_name = "TCD_GB_merge.TIF"
    tcd_crop = os.path.join(tcd_cop_fold, tcd_name)

    spatial_ref = arcpy.Describe(tcd_3030_cop).spatialReference

    if arcpy.Exists(tcd_crop):
        print("merged raster exists - SKIPPING RASTER MERGE!")
        # tcd_merge = (scratch, tcd_name)
    else:
        tcd_merge = arcpy.MosaicToNewRaster_management(
            [tcd_3030_cop, tcd_3040_cop],
            scratch,
            tcd_name,
            spatial_ref,
            number_of_bands=1)

        os_a_copy = (os.path.join(scratch, "OS_Grid_copy.shp"))
        if arcpy.Exists(os_a_copy):
            arcpy.Delete_management(os_a_copy)

        os_area_copy = arcpy.Project_management(OrdSurv_Grid, os_a_copy,
                                                spatial_ref)

        extent = arcpy.Describe(os_area_copy).extent
        xmin = extent.XMin
        ymin = extent.YMin
        xmax = extent.XMax
        ymax = extent.YMax

        corners = (str(xmin) + " " + str(ymin) + " " + str(xmax) + " " +
                   str(ymax))

        if arcpy.Exists(tcd_crop):
            arcpy.Delete_management(tcd_crop)

        arcpy.Clip_management(tcd_merge, corners, tcd_crop)

        print("raster_clipped")

        # clear out scratch space
        print("clearing out scratch space")
        for the_file in os.listdir(scratch):
            file_path = os.path.join(scratch, the_file)
            try:
                if os.path.isfile(file_path):
                    os.unlink(file_path)
            except Exception as e:
                print(e)

    return tcd_crop
Esempio n. 15
0
def mosaic_rasters(raster_file_list, output_dir, output_file, mosaic_method):
    """ Mosaic the list of files using the specified method and save to output_file.

    Parameters
    ----------
    raster_file : str
        Filename of raster file
    polygon_file : str
        Filename of vector file
    zone_field : str
        Name of field labelling the zones within vector file
    output_table : str
        Filename of output table (.dbf or .csv)

    Returns
    -------
    None
        Returns None

    """
    arcpy.CheckOutExtension("Spatial")
    arcpy.MosaicToNewRaster_management(
        input_rasters=raster_file_list,
        output_location=output_dir,
        raster_dataset_name_with_extension=output_file,
        mosaic_method=mosaic_method,
        number_of_bands=1)
    return None
Esempio n. 16
0
def merge_rasts(path, data_type='ET', monthRange='', yearRange='', outpath=''):
    """Mosaics (merges) different MODIS cells into one layer.


    """
    if monthRange == '':
        monthRange = [1, 12]
    if yearRange == '':
        yearRange = [2000, 2015]
    if outpath == '':
        outpath = path

    arcpy.env.workspace = path
    outCS = arcpy.SpatialReference('NAD 1983 UTM Zone 12N')
    for y in range(yearRange[0],
                   yearRange[-1] + 1):  # set years converted here
        for m in range(monthRange[0],
                       monthRange[-1] + 1):  # set months converted here
            nm = data_type + str(y) + str(m).zfill(2)
            rlist = []
            for rast in arcpy.ListRasters(nm + '*'):
                rlist.append(rast)
            try:
                arcpy.MosaicToNewRaster_management(rlist, outpath, nm + 'c', outCS, \
                                                   "16_BIT_UNSIGNED", "1000", "1", "LAST", "LAST")

                print(path + nm + 'c')
            except:
                print(nm + ' failed!')
                pass
Esempio n. 17
0
def mosaicRaster(inRasters, outDir, outRaster):
    cat = lambda a1, a2: a1 + ';' + a2
    arcpy.MosaicToNewRaster_management(reduce(cat, inRasters),
                                       outDir,
                                       outRaster,
                                       pixel_type="32_BIT_FLOAT",
                                       number_of_bands="1")
Esempio n. 18
0
def createRefinedTrajectory():

    ##### Set environment settings
    arcpy.env.workspace = defineGDBpath(['refine', 'v2', 'masks'])

    ##### loop through each of the cdl rasters and make sure nlcd is last 
    condlist = ['36and61', refine.mask_dev, 'nlcd'+refine.nlcd_ven]

    ##### create a raster list to mosiac together make sure that the intial traj is first in list and nlcd mask is last in the list.
    filelist = [refine.traj_dataset_path]

    for cond in condlist:
        yo = '*'+refine.datarange+'*_'+cond
        print yo 
        for raster in arcpy.ListDatasets('*'+refine.datarange+'*'+cond, "Raster"): 

            print 'raster: ',raster

            filelist.append(raster)

    print 'filelist', filelist
    print 'lenght of list:', len(filelist)

    output = refine.traj_rfnd_dataset
    print "output:", output

    ##### mosaicRasters():
    arcpy.MosaicToNewRaster_management(filelist, defineGDBpath(['pre', 'v2', 'traj_refined']), output, Raster(refine.traj_dataset_path).spatialReference, '16_BIT_UNSIGNED', refine.res, "1", "LAST","FIRST")
Esempio n. 19
0
 def maxBarriers():
     randomerror()
     arcpy.MosaicToNewRaster_management(
         rasterString, mosaicDirPct,
         mosPctFN, "", "32_BIT_FLOAT",
         arcpy.env.cellSize, "1", "MAXIMUM",
         "MATCH")
Esempio n. 20
0
def main():
    try:
        print "Inputs being set"
        arcpy.env.workspace = "../orig/"
        input_list = arcpy.ListRasters("*.DEM")

        print "Outputs being set"
        output_dir = "../data/"
        output_tif = "elevation.tif"

        print "Processing..."
        arcpy.MosaicToNewRaster_management(input_list,
                                           output_dir,
                                           output_tif,
                                           pixel_type="16_BIT_SIGNED",
                                           number_of_bands="1")
        # The number_of_bands option is required.
        # The pixel_type option is optional, but should always be specified: the default is 8_BIT_UNSIGNED, which truncates the values greater than 255.
        # See http://desktop.arcgis.com/en/arcmap/10.4/tools/data-management-toolbox/mosaic-to-new-raster.htm for detail

        print "All geoprocessing successfully done."

    # Return geoprocessing specific errors
    except arcpy.ExecuteError:
        print arcpy.GetMessages()
    # Return any other type of error
    except:
        print "There is non-geoprocessing error."
    # Check in extensions
    finally:
        arcpy.CheckInExtension("spatial")
Esempio n. 21
0
def arcMosaic2NewRaster (inRasters=None,outPath=None,outName="NewMosaic",outExt = "",nbands=1):
	import arcpy
	if outPath is None: 
		os.mkdir("outMosaic")
		outPath = os.getcwd() + "\\outMosaic\\"
	#try: 
	arcpy.MosaicToNewRaster_management(inRasters,outPath,outName+outExt,number_of_bands=nbands,mosaic_method="FIRST",mosaic_colormap_mode="MATCH")
Esempio n. 22
0
def mosiacRasters(data, subtype, year):
    ######Description: mosiac tiles together into a new raster
    tilelist = glob.glob("C:/Users/Bougie/Desktop/Gibbs/tiles/*.tif")
    print 'tilelist:', tilelist

    #### need to wrap these paths with Raster() fct or complains about the paths being a string
    inTraj = Raster(data['pre']['traj']['path'])

    gdb = data['post']['ytc']['gdb']

    filename = '{}_{}'.format(data['post']['ytc'][subtype]['filename'], year)
    print 'filename:', filename

    ######mosiac tiles together into a new raster
    arcpy.MosaicToNewRaster_management(tilelist, gdb, filename,
                                       inTraj.spatialReference,
                                       "16_BIT_UNSIGNED", 30, "1", "LAST",
                                       "FIRST")

    #Overwrite the existing attribute table file
    arcpy.BuildRasterAttributeTable_management('{}//{}'.format(gdb, filename),
                                               "Overwrite")

    # Overwrite pyramids
    gen.buildPyramids('{}//{}'.format(gdb, filename))
Esempio n. 23
0
def mosaic_to_new_raster (inrasters):
# merges a list of raster files into one output raster 
#-----------------------
    nbands = arcpy.Raster.bandCount(inrasters[0])
    outname = "mosaic_ndvi2016_0p6m.tif"
    arcpy.MosaicToNewRaster_management(infiles, env.workspace, \
                                       outname, arcpy.SpatialReference(26918),\
                                       "32_BIT_FLOAT",number_of_bands=nbands)
Esempio n. 24
0
 def _mosaic_to_new_raster(self, file_paths, dest_dir, stitch_out_ras_name,
                           current_ref, pixel_type, mosaic_operator):
     """ Perform mosaicking """
     print('Mosaic raster..... {0}'.format(stitch_out_ras_name))
     arcpy.MosaicToNewRaster_management(file_paths, dest_dir,
                                        stitch_out_ras_name, current_ref,
                                        pixel_type, '', '1',
                                        mosaic_operator, 'FIRST')
Esempio n. 25
0
def main():
    global outWorkspace
    outWorkspace = flmc.SetupWorkspace(workspaceName)

    # Prepare input lines for multiprocessing
    numLines = flmc.SplitLines(Centerline_Feature_Class, outWorkspace, "CO",
                               ProcessSegments)

    pool = multiprocessing.Pool(processes=flmc.GetCores())
    flmc.log("Multiprocessing line corridors...")
    pool.map(workLines, range(1, numLines + 1))
    pool.close()
    pool.join()

    flmc.logStep("Corridor multiprocessing")

    nRasters = len(arcpy.ListRasters())

    if (nRasters == 1):
        arcpy.CopyRaster_management(arcpy.ListRasters()[0], Output_Corridor)
    else:
        mergeLoops = 0
        flmc.log("Merging corridor rasters...")
        while nRasters > 1:
            flmc.log("Multiprocessing line corridors... Round " +
                     str(mergeLoops + 1) + "; " + str(nRasters) +
                     " rasters in output folder to process...")
            # Multiprocessing merge, so that every process merges two files at a time
            pool = multiprocessing.Pool(processes=flmc.GetCores())

            # Create a number of workers equal to half the number of rasters, rounded up
            pool.map(workMerge, range(1, int(math.ceil(nRasters / 2.0) + 1)))
            pool.close()
            pool.join()

            renameMergedFiles(outWorkspace)
            nRasters = len(arcpy.ListRasters())

            # Log round execution time
            flmc.logStep("Merge Round " + str(mergeLoops + 1))

            # Prevent merging process from becoming an infinite loop
            mergeLoops += 1

            if (mergeLoops > 10 or nRasters < 5):
                corridorRasters = arcpy.ListRasters()
                flmc.log("Merging remaining " + str(nRasters) +
                         " files in a single process...")
                arcpy.MosaicToNewRaster_management(
                    corridorRasters, os.path.dirname(Output_Corridor),
                    os.path.basename(Output_Corridor), "", "32_BIT_FLOAT", "",
                    "1", "MINIMUM", "MATCH")
                flmc.log("Deleting temporary files...")
                for ras in corridorRasters:
                    arcpy.Delete_management(ras)
                # Log round execution time
                flmc.logStep("Merge Final Round")
                break
def createDynamicMap(andersonMapPaths, outputDirWorking, outputDirPathResult):
    print("Creating dynamic map...")

    # Turn filenames into Rasters
    andersonMaps = []
    for andersonMapPath in andersonMapPaths:
        andersonMaps.append(Raster(andersonMapPath))

    print("... running cell statistics")
    majorityRasterTempPath = os.path.join(outputDirWorking,
                                          "majorityRasterTemp.tif")
    majorityPath = os.path.join(outputDirWorking, "majorityRaster.tif")
    # Create MAJORITY Cell Statistic layer
    majorityRasterTemp = arcpy.gp.CellStatistics_sa(andersonMaps,
                                                    majorityRasterTempPath,
                                                    "MAJORITY", "DATA")

    # Returns largest YYYY in list of anthromeYYYYn.tif
    andersonPathCurrYearPath = sorted(andersonMapPaths, reverse=True)[0]

    # The MAJORITY function in Cell Statistics returns NoData if a tie for majority, so fill these with current year's value'
    majorityRaster = Con(IsNull(majorityRasterTempPath),
                         andersonPathCurrYearPath, majorityRasterTempPath)
    majorityRaster.save(majorityPath)

    varietyRaster = arcpy.gp.CellStatistics_sa(
        andersonMaps, os.path.join(outputDirWorking, "varietyRaster.tif"),
        "VARIETY", "DATA")

    varietyPath = os.path.join(outputDirWorking, "varietyRaster.tif")

    # Get cutoff value, should be greater than 50%
    #dynamicUnstableCuttoff = len(andersonMapPaths)/2
    dynamicUnstableCuttoff = int((len(andersonMapPaths) / 2) + 0.5)

    print("... generating stable, dynamic, and unstable rasters")
    stableRaster = Con(varietyPath, majorityPath, "", "Value = 1")
    #dynamicRaster = Con(varietyPath, Raster(majorityPath) + 100, "", "Value > 1 AND Value < " + str(dynamicUnstableCuttoff))
    #unstableRaster = Con(varietyPath, Raster(majorityPath) + 200, "", "Value >= " + str(dynamicUnstableCuttoff))
    dynamicRaster = Con(
        varietyPath,
        Raster(majorityPath) + 100, "",
        "Value > 1 AND Value <= " + str(dynamicUnstableCuttoff))
    unstableRaster = Con(varietyPath,
                         Raster(majorityPath) + 200, "",
                         "Value > " + str(dynamicUnstableCuttoff))

    stableRaster.save(os.path.join(outputDirPathResult, "andersonStable.tif"))
    dynamicRaster.save(os.path.join(outputDirPathResult,
                                    "andersonDynamic.tif"))
    unstableRaster.save(
        os.path.join(outputDirPathResult, "andersonUnstable.tif"))

    print("... generating mosaic")
    arcpy.MosaicToNewRaster_management(
        [stableRaster, dynamicRaster, unstableRaster], outputDirPathResult,
        "anderson-athrome-mandan.tif", "", "8_BIT_UNSIGNED", "", 1, "FIRST",
        "FIRST")
Esempio n. 27
0
def mosaicRasters(raster_list, year):
    year = str(year)
    outputLocation = "D:\\GISData_PostPhD\\MapBiomas_v23\\Year_Exports\\Processing\\"
    print "Mosaicking " + raster_list + " together..."
    arcpy.MosaicToNewRaster_management(raster_list, outputLocation,
                                       "BrazilLC_" + year + "_30m.img", "4326",
                                       "8_BIT_SIGNED", "", "1", "LAST",
                                       "FIRST")
    print "Mosaic raster created for year: " + year
Esempio n. 28
0
def mosaic():
    global nhdsubregion

    # Select the right HUC4 from WBD_HU4 and make it it's own layer.
    arcpy.MakeFeatureLayer_management("WBD_HU4", "HU4")
    field = "HUC_4"
    where = '"' + field + '" = ' + "'" + str(nhdsubregion) + "'"
    arcpy.SelectLayerByAttribute_management("HU4", "NEW_SELECTION", where)
    arcpy.CopyFeatures_management("HU4", "Subregion")

    # Apply a 5000 meter buffer around subregion
    arcpy.Buffer_analysis("Subregion", "Subregion_5000m_buffer", "5000 meters")
    arcpy.AddMessage("Buffered subregion.")

    # Naming conventions for mosaic output file
    subregion_number = os.path.basename(nhd)
    nhdsubregion = subregion_number[4:8]

    # Walk through the folder with NEDs to make a list of rasters
    mosaicrasters = []
    for dirpath, dirnames, filenames in arcpy.da.Walk(
            nedfolder, datatype="RasterDataset"):
        for filename in filenames:
            name = os.path.join(dirpath, filename)
            mosaicrasters.append(name)

    arcpy.AddMessage("Found NED ArcGrids.")

    # Mosaic, clip and then project to USGS Albers
    arcpy.MosaicToNewRaster_management(mosaicrasters, outfolder,
                                       "mosaicNAD.tif", nad83, "32_BIT_FLOAT",
                                       "", "1", "LAST")
    arcpy.Clip_management(
        outfolder + "\\" + "mosaicNAD.tif", '',
        outfolder + "\\" + "tempNED13_" + nhdsubregion + ".tif",
        "Subregion_5000m_buffer", "0", "ClippingGeometry")
    tempned13 = os.path.join(outfolder, "tempNED13_" + nhdsubregion + ".tif")
    arcpy.ProjectRaster_management(
        tempned13, os.path.join(mosaicfolder,
                                "NED13_" + nhdsubregion + ".tif"), albers,
        "BILINEAR", "10", "", "", nad83)
    arcpy.AddMessage("Mosaiced, clipped and projected NED tiles.")

    # Variables for intermediate data
    MosaicNAD = os.path.join(outfolder, "mosaicNAD.tif")
    MosaicClip = outfolder + "\\" + "tempNED13_" + nhdsubregion + ".tif"
    subregion_ned = outfolder + "\\" + "mosaic" + nhdsubregion + "\\" + "NED13_" + nhdsubregion + ".tif"
    global subregion_ned

    # Clean up
    arcpy.Delete_management(MosaicNAD)
    arcpy.Delete_management(MosaicClip)
    arcpy.Delete_management("Subregion")
    arcpy.Delete_management("Subregion_5000m_buffer")
    arcpy.AddMessage(
        "Cleaned up intermediate data from mosaic tool. Mosaic done.")
    return
Esempio n. 29
0
def combineMODData(folder, outputFolder, subset):
    processedDate = []
    for filename in os.listdir(folder):
        print(filename)
        if filename.endswith(".tif") or filename.endswith(".tiff"):
            split = filename.split('.')
            filedate = split[1]
            year = int(split[1][1:5])
            date = int(split[1][5:8])
            month, jd, y = JulianDate_to_MMDDYYY(year, date)
            twodigitmonth = str(month).zfill(2)
            twodigitday = str(jd).zfill(2)
            if filedate not in processedDate:
                processedDate.append(filedate)
                combinedData=[]
                combinedData.append(os.path.join(folder, filename))
                for SFilename in os.listdir(folder):
                    if SFilename.endswith(".tif") or SFilename.endswith(".tiff"):
                        if os.path.join(SFilename) not in combinedData:
                            split1 = SFilename.split('.')
                            Sfiledate = split1[1]
                            if Sfiledate == filedate:
                                combinedData.append(os.path.join(folder, SFilename))
                            else:
                                continue
                print(combinedData)
                sumofdata = len(combinedData)
                stringcombined = combinedData[0]
                x = 1
                while x > 0 and x < sumofdata:
                    stringcombined = stringcombined + ";" +combinedData[x]
                    x = x+1
                print(stringcombined)
                sr = arcpy.SpatialReference(4326)
                arcpy.env.workspace = folder
                newfilename = 'phy_MOD13A3.{0}.{1}.{2}_006.1_km_monthly_EVI.tif'.format(year, twodigitmonth, twodigitday )
                idnfilename = 'idn_phy_MOD13A3.{0}.{1}.{2}_006.1_km_monthly_EVI.tif'.format(year, twodigitmonth,
                                                                                        twodigitday)
                julianname = '{0}.{1}.006.250m_16_days_NDVI.tif'.format(split[0], filedate)
                arcpy.CheckOutExtension("spatial")
                arcpy.MosaicToNewRaster_management(input_rasters= combinedData, output_location = outputFolder, raster_dataset_name_with_extension=newfilename, coordinate_system_for_the_raster= sr, pixel_type='16_BIT_SIGNED', number_of_bands='1' )
                arcpy.DefineProjection_management(os.path.join(outputFolder,newfilename), sr)
                outExtractByMask = ExtractByMask(os.path.join(outputFolder,newfilename), subset)

                # ---- Uncomment code when result filename is in julian date---- #
                # if arcpy.Exists(os.path.join(outputFolder, julianname)):
                #     print(julianname + " exists")
                # else:
                #     outExtractByMask.save(os.path.join(outputFolder, julianname))

                if arcpy.Exists(os.path.join(outputFolder, idnfilename)):
                    print(idnfilename + " exists")
                else:
                    outExtractByMask.save(os.path.join(outputFolder, idnfilename))

                arcpy.CheckInExtension("spatial")
Esempio n. 30
0
def heightToSlope(heightInput1, heightInput2, heightInput3, heightInput4,
                  workspace, projectDataset):
    arcpy.Delete_management("C:/thesisData/ahn2RARaster.tif")
    arcpy.Delete_management("C:/thesisData/ahn2Slope.tif")
    arcpy.MosaicToNewRaster_management(
        (heightInput1, heightInput2, heightInput3, heightInput4), workspace,
        "/ahn2RARaster.tif", projectDataset, "8_BIT_UNSIGNED", 0.5, 1, "", "")
    ahn2Slope = Slope("C:/thesisData/ahn2RARaster.tif", "DEGREE", "")
    ahn2Slope.save("C:/thesisData/ahn2Slope.tif")
    return ahn2Slope