Exemple #1
0
 def create(self, DEM, WSEDEM):
     arcpy.CheckOutExtension("Spatial")
     arcpy.env.extent = arcpy.Describe(DEM).Extent
     arcpy.env.snapRaster = DEM
     rasterRawDepth = arcpy.sa.Minus(WSEDEM, DEM)
     rasterPositiveMaskBool = arcpy.sa.GreaterThan(rasterRawDepth, 0)
     rasterDepth = arcpy.sa.Abs(
         arcpy.sa.Times(rasterRawDepth, rasterPositiveMaskBool))
     rasterDepth.save(self.filename)
     arcpy.ClearEnvironment("extent")
     arcpy.ClearEnvironment("snapRaster")
Exemple #2
0
def execute_task(args):
	in_extentDict, prg = args

	fc_count = in_extentDict[0]
	# print fc_count
	procExt = in_extentDict[1]
	# print procExt
	XMin = procExt[0]
	YMin = procExt[1]
	XMax = procExt[2]
	YMax = procExt[3]

	#set environments
	 #The brilliant thing here is that using the extents with the full dataset!!!!!!   DONT EVEN NEED TO CLIP THE FULL RASTER TO THE FISHNET BECASUE 
	arcpy.env.snapRaster = prg.path_parent
	arcpy.env.cellsize = prg.path_parent
	arcpy.env.extent = arcpy.Extent(XMin, YMin, XMax, YMax)

	###  Execute Region Group  #####################
	
	ras_out = Reclassify(Raster(prg.path_parent), "Value", RemapRange(prg.reclasslist), "NODATA")

	#clear out the extent for next time
	arcpy.ClearEnvironment("extent")
    
    # print fc_count
	outname = "tile_" + str(fc_count) +'.tif'

	#create Directory

	outpath = os.path.join("C:/Users/Bougie/Desktop/Gibbs/", r"tiles", outname)

	ras_out.save(outpath)
Exemple #3
0
def execute_task(in_extentDict):
    #start the clock
    time1 = time.clock()
    #get extent count and extents
    fc_count = in_extentDict[0]
    procExt = in_extentDict[1]
    XMin = procExt[0]
    YMin = procExt[1]
    XMax = procExt[2]
    YMax = procExt[3]
    # set environments
    arcpy.env.snapRaster = in_raster_path
    arcpy.env.cellsize = in_raster_path
    arcpy.env.extent = arcpy.Extent(XMin, YMin, XMax, YMax)
    #send process info to logger
    logger.info("Running local math task: {} with PID {}".format(
        current_process().name, os.getpid()))
    #run the local task
    ras_out = arcpy.sa.SquareRoot(in_raster_path)
    #clear the extent environment
    arcpy.ClearEnvironment("extent")
    #specify output path and save it
    out_name = "out_sqrt_ras{}.tif".format(fc_count)
    out_path = os.path.join(os.getcwd(), r"local_rast_wspace", out_name)
    ras_out.save(out_path)
    #end the clock
    time2 = time.clock()
    logger.info("{} with PID {} finished in {}".format(current_process().name,
                                                       os.getpid(),
                                                       str(time2 - time1)))
Exemple #4
0
def create_fishnet(in_raster_path, out_fc_path):
    #create raster object from in_raster_path
    ras1 = arcpy.Raster(in_raster_path)
    #specify input parameters to fishnet tool
    XMin = ras1.extent.XMin
    XMax = ras1.extent.XMax
    YMin = ras1.extent.YMin
    YMax = ras1.extent.YMax
    origCord = "{} {}".format(XMin, YMin)
    YAxisCord = "{} {}".format(XMin, YMax)
    CornerCord = "{} {}".format(XMax, YMax)
    cellSizeW = '0'
    cellSizeH = '0'
    """modify the numRows and numCols to control how the input raster is chunked for parallel processing
	For example, if numRows = 4 & numCols = 4, total number of chunks = 4*4 = 16. 
	"""
    numRows = 4
    numCols = 4
    geo_type = "POLYGON"
    #Run fishnet tool
    logger.info("Running fishnet creator: {} with PID {}".format(
        current_process().name, os.getpid()))
    arcpy.env.outputCoordinateSystem = ras1.spatialReference
    arcpy.CreateFishnet_management(out_fc_path, origCord, YAxisCord, cellSizeW,
                                   cellSizeH, numRows, numCols, CornerCord,
                                   "NO_LABELS", "", geo_type)
    arcpy.ClearEnvironment("outputCoordinateSystem")
Exemple #5
0
def execute_task(args):
	in_extentDict, data = args

	# for count in masks_list:
	cond = "Count <> 3"


	fc_count = in_extentDict[0]
	# print fc_count
	procExt = in_extentDict[1]
	# print procExt
	XMin = procExt[0]
	YMin = procExt[1]
	XMax = procExt[2]
	YMax = procExt[3]

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

	in_raster = Raster(data['raster'])
	### set null the regions that are less than the mmu treshold
	raster_mask =  Con(IsNull(in_raster),0, in_raster)
	# raster_mask = SetNull(in_raster, in_raster, "VALUE = 3")

	#clear out the extent for next time
	arcpy.ClearEnvironment("extent")

	outname = "tile_" + str(fc_count) +'.tif'

	outpath = os.path.join("D:\\projects\\web\\tiles\\", r"mtr", outname)

	# raster_shrink.save(outpath)
	raster_mask.save(outpath)
	raster_mask=None
Exemple #6
0
def execute_task(args):
    in_extentDict, reclass_list, in_raster, schema = args

    fc_count = in_extentDict[0]
    # print fc_count
    procExt = in_extentDict[1]
    # print procExt
    XMin = procExt[0]
    YMin = procExt[1]
    XMax = procExt[2]
    YMax = procExt[3]

    #set environments
    cdl30_2017 = Raster(
        'E:\\data\\gSSURGO\\gSSURGO_CONUS_10m.gdb\\MapunitRaster_30m')
    arcpy.env.snapRaster = cdl30_2017
    # arcpy.env.cellsize = 30
    arcpy.env.extent = arcpy.Extent(XMin, YMin, XMax, YMax)

    #NOTE: need to reference mukey_ssurgo column in the raster and NOT value otherwise weird things occur with reclass function!
    raster_reclassed = Reclassify(Raster(in_raster), "Value",
                                  RemapRange(reclass_list), "NODATA")

    outname = "tile_" + str(fc_count) + '.tif'

    outpath = os.path.join(
        "D:/projects/usxp/series/s35/maps/{}/".format(schema), r"tiles",
        outname)

    arcpy.ClearEnvironment("extent")

    raster_reclassed.save(outpath)
    raster_reclassed = None

    outpath = None
Exemple #7
0
 def __exit__(self, exc_type, exc_value, traceback):
     #clean up
     self.Workspace = ""
     self.Regions = None
     shutil.rmtree(self._TempLocation, True)
     arcpy.ResetEnvironments()
     arcpy.ClearEnvironment("workspace")
Exemple #8
0
def execute_task(in_extentDict):
    fc_count = in_extentDict[0]
    # print fc_count
    procExt = in_extentDict[1]
    # print procExt
    XMin = procExt[0]
    YMin = procExt[1]
    XMax = procExt[2]
    YMax = procExt[3]

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

    #########  Execute Nibble  #####################
    ### Nibble (in_raster, in_mask_raster, {nibble_values})
    ras_out = arcpy.sa.Nibble(data['post']['ytc']['path_mmu'],
                              data['post']['ytc']['path_mask'], "DATA_ONLY")

    #clear out the extent for next time
    arcpy.ClearEnvironment("extent")

    # print fc_count
    outname = "tile_" + str(fc_count) + '.tif'

    #create Directory

    outpath = os.path.join("C:/Users/Bougie/Desktop/Gibbs/", r"tiles", outname)

    ras_out.save(outpath)
Exemple #9
0
def execute_task(args):
    in_extentDict, data, yxc, traj_list = args
    yxc_mtr = {'ytc': 3, 'yfc': 4}

    fc_count = in_extentDict[0]
    # print fc_count
    procExt = in_extentDict[1]
    # print procExt
    XMin = procExt[0]
    YMin = procExt[1]
    XMax = procExt[2]
    YMax = procExt[3]

    path_traj_rfnd = data['pre']['traj_rfnd']['path']
    print 'path_traj_rfnd:', path_traj_rfnd

    path_mtr = Raster(data['core']['path'])
    print path_mtr

    #set environments
    arcpy.env.snapRaster = path_mtr
    arcpy.env.cellsize = path_mtr
    arcpy.env.extent = arcpy.Extent(XMin, YMin, XMax, YMax)

    ##  Execute the three functions  #####################
    raster_yxc = Reclassify(Raster(path_traj_rfnd), "Value",
                            RemapRange(traj_list), "NODATA")
    raster_mask = Con((path_mtr == yxc_mtr[yxc]) & (raster_yxc >= 2008),
                      raster_yxc)
    raster_yxc = None
    filled_1 = Con(
        IsNull(raster_mask),
        FocalStatistics(raster_mask, NbrRectangle(3, 3, "CELL"), 'MAJORITY'),
        raster_mask)
    raster_mask = None
    filled_2 = Con(
        IsNull(filled_1),
        FocalStatistics(filled_1, NbrRectangle(10, 10, "CELL"), 'MAJORITY'),
        filled_1)
    filled_1 = None
    filled_3 = Con(
        IsNull(filled_2),
        FocalStatistics(filled_2, NbrRectangle(20, 20, "CELL"), 'MAJORITY'),
        filled_2)
    filled_2 = None
    final = SetNull(path_mtr, filled_3,
                    "VALUE <> {}".format(str(yxc_mtr[yxc])))
    filled_3 = None
    #clear out the extent for next time
    arcpy.ClearEnvironment("extent")

    # print fc_count
    outname = "tile_" + str(fc_count) + '.tif'

    outpath = os.path.join("C:/Users/Bougie/Desktop/Gibbs/data/", r"tiles",
                           outname)

    final.save(outpath)

    outpath = None
Exemple #10
0
def execute_task(args):
    in_extentDict, data, year, cdl_path = args
    yxc = 'ytc'

    oid = in_extentDict[0]
    # print oid
    procExt = in_extentDict[1]
    # print procExt
    XMin = procExt[0]
    YMin = procExt[1]
    XMax = procExt[2]
    YMax = procExt[3]

    yxc_path = Raster(data['post'][yxc]['path'])

    #set environments
    arcpy.env.snapRaster = yxc_path
    arcpy.env.cellsize = yxc_path
    arcpy.env.extent = arcpy.Extent(XMin, YMin, XMax, YMax)

    output = SetNull(yxc_path, cdl_path, "VALUE <> {}".format(str(year)))

    outname = "tile_" + str(oid) + '.tif'

    outpath = os.path.join("C:/Users/Bougie/Desktop/Gibbs/", r"tiles", outname)

    arcpy.ClearEnvironment("extent")

    output.save(outpath)
Exemple #11
0
def execute_task(args):
    in_extentDict = args

    fc_count = in_extentDict[0]
    # print fc_count
    procExt = in_extentDict[1]
    # print procExt
    XMin = procExt[0]
    YMin = procExt[1]
    XMax = procExt[2]
    YMax = procExt[3]

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

    raster_rg = RegionGroup(Raster(fvdcvcvcv), "EIGHT", "WITHIN", "NO_LINK")

    #clear out the extent for next time
    arcpy.ClearEnvironment("extent")

    outname = "tile_" + str(fc_count) + '.tif'

    outpath = os.path.join("C:/Users/Bougie/Desktop/Gibbs/", r"tiles", outname)

    # raster_shrink.save(outpath)
    raster_rg.save(outpath)
Exemple #12
0
def execute_task(in_extentDict):
    fc_count = in_extentDict[0]
    print fc_count
    procExt = in_extentDict[1]
    print procExt
    XMin = procExt[0]
    YMin = procExt[1]
    XMax = procExt[2]
    YMax = procExt[3]

    #set environments
    #The brilliant thing here is that using the extents with the full dataset!!!!!!   DONT EVEN NEED TO CLIP THE FULL RASTER TO THE FISHNET BECASUE
    # arcpy.env.snapRaster = prg.clu
    # arcpy.env.cellsize = prg.clu
    # arcpy.env.extent = arcpy.Extent(XMin, YMin, XMax, YMax)

    ###  Execute Nibble  #####################

    # import arcpy
    # from arcpy import env

    print 'hi'

    # env.workspace = "C:/data"
    outname = "tile_" + str(fc_count) + ".shp"

    outpath = os.path.join("D:/projects/ksu/v2/", r"tiles", outname)

    arcpy.Clip_analysis(prg.clu, prg.out_fishnet, outpath)

    arcpy.ClearEnvironment("extent")
Exemple #13
0
def execute_task(in_extentDict):
    fc_count = in_extentDict[0]
    # print fc_count
    procExt = in_extentDict[1]
    # print procExt
    XMin = procExt[0]
    YMin = procExt[1]
    XMax = procExt[2]
    YMax = procExt[3]

    #set environments
    # arcpy.env.snapRaster = Raster(raster_in)
    # arcpy.env.cellsize = Raster(raster_in)
    arcpy.env.extent = arcpy.Extent(XMin, YMin, XMax, YMax)

    ###  Execute Region Group  #####################

    filter_combos = {'8w': ["EIGHT", "WITHIN"]}

    for k, v in filter_combos.iteritems():
        print k, v
        # Execute RegionGroup
        ras_out = RegionGroup(Raster(data['core']['path']['mtr']), v[0], v[1],
                              "NO_LINK")

    #clear out the extent for next time
    arcpy.ClearEnvironment("extent")

    # print fc_count
    outname = "tile_" + str(fc_count) + '.tif'

    #create Directory
    outpath = os.path.join("C:/Users/Bougie/Desktop/Gibbs/", r"tiles", outname)

    ras_out.save(outpath)
Exemple #14
0
def execute_task(in_extentDict):
	fc_count = in_extentDict[0]
	# print fc_count
	procExt = in_extentDict[1]
	# print procExt
	XMin = procExt[0]
	YMin = procExt[1]
	XMax = procExt[2]
	YMax = procExt[3]

	#set environments
	 #The brilliant thing here is that using the extents with the full dataset!!!!!!   DONT EVEN NEED TO CLIP THE FULL RASTER TO THE FISHNET BECASUE 
	# arcpy.env.snapRaster = nibble.path_parent
	# arcpy.env.cellsize = nibble.path_parent
	arcpy.env.extent = arcpy.Extent(XMin, YMin, XMax, YMax)

	###  Execute Nibble  #####################
	ras_out = arcpy.sa.Nibble(data['core']['function']['parallel_mtr']['input'], data['core']['function']['parallel_mtr']['mask'], "DATA_ONLY")

	#clear out the extent for next time
	arcpy.ClearEnvironment("extent")
    
    # print fc_count
	outname = "tile_" + str(fc_count) +'.tif'

	#create Directory

	outpath = os.path.join("C:/Users/Bougie/Desktop/Gibbs/", r"tiles", outname)

	ras_out.save(outpath)
Exemple #15
0
def execute_task(in_extentDict):
    fc_count = in_extentDict[0]
    # print fc_count
    procExt = in_extentDict[1]
    # print procExt
    XMin = procExt[0]
    YMin = procExt[1]
    XMax = procExt[2]
    YMax = procExt[3]

    raster_in = data['core']['function']['parallel_mtr']['input']
    print 'raster_in:', raster_in

    #set environments
    arcpy.env.snapRaster = Raster(raster_in)
    arcpy.env.cellsize = Raster(raster_in)
    arcpy.env.extent = arcpy.Extent(XMin, YMin, XMax, YMax)

    ###  Execute Nibble  #####################
    ras_out = Reclassify(Raster(raster_in), "Value", RemapRange(reclassArray),
                         "NODATA")

    #clear out the extent for next time
    arcpy.ClearEnvironment("extent")

    # print fc_count
    outname = "tile_" + str(fc_count) + '.tif'

    #create Directory

    outpath = os.path.join("C:/Users/Bougie/Desktop/Gibbs/", r"tiles", outname)

    ras_out.save(outpath)
Exemple #16
0
def execute_task(in_extentDict):
    fc_count = in_extentDict[0]
    print fc_count
    procExt = in_extentDict[1]
    print procExt
    XMin = procExt[0]
    YMin = procExt[1]
    XMax = procExt[2]
    YMax = procExt[3]

    #set environments
    #The brilliant thing here is that using the extents with the full dataset!!!!!!   DONT EVEN NEED TO CLIP THE FULL RASTER TO THE FISHNET BECASUE
    arcpy.env.snapRaster = yxc.in_raster
    arcpy.env.cellsize = yxc.in_raster
    arcpy.env.extent = arcpy.Extent(XMin, YMin, XMax, YMax)

    ###  Execute Nibble  #####################
    ras_out = arcpy.sa.Nibble(yxc.in_raster, yxc.in_mask_raster, "DATA_ONLY")

    #clear out the extent for next time
    arcpy.ClearEnvironment("extent")

    # print fc_count
    outname = "tile_" + str(fc_count) + '.tif'

    outpath = os.path.join("C:/Users/Bougie/Desktop/Gibbs/", r"tiles", outname)

    ras_out.save(outpath)
def main():

    # change directory to the parent folder path
    os.chdir(pf_path)

    # list all folders in parent folder path - note this is not recursive
    dir_list = filter(lambda x: os.path.isdir(x), os.listdir('.'))

    # remove folders in the list that start with '00_' since these aren't our huc8 folders
    for dir in dir_list[:]:
        if dir.startswith('00_'):
            dir_list.remove(dir)

    # set arcpy environment settings
    arcpy.env.overwriteOutput = 'TRUE'  # overwrite output
    arcpy.env.resamplingMethod = 'CUBIC'  # set resampling method to cubic in case arc does any behind the scenes dem re-sampling

    # run dem_clip function for each huc8 folder
    for dir in dir_list:
        #if not os.path.exists(os.path.join(pf_path, dir, 'PRISM')):
            try:
                prism_clip(dir)
            except Exception as err:
                print "Clipping PRISM failed for " + dir + ". The exception thrown was:"
                print err

    # clear environment settings
    arcpy.ResetEnvironments()
    arcpy.ClearEnvironment("workspace")
Exemple #18
0
def execute_task(args):
    in_extentDict, covertype = args

    fc_count = in_extentDict[0]
    
    procExt = in_extentDict[1]
    # print procExt
    XMin = procExt[0]
    YMin = procExt[1]
    XMax = procExt[2]
    YMax = procExt[3]

    #set environments
    #The brilliant thing here is that using the extents with the full dataset!!!!!!   DONT EVEN NEED TO CLIP THE FULL RASTER TO THE FISHNET BECASUE 
    arcpy.env.snapRaster = "C:\\Users\\Bougie\\Desktop\\Gibbs\\data\\usxp\\pre\\traj\\v4\\v4_traj.gdb\\v4_traj_cdl30_b_2008to2017"
    arcpy.env.cellsize = "C:\\Users\\Bougie\\Desktop\\Gibbs\\data\\usxp\\pre\\traj\\v4\\v4_traj.gdb\\v4_traj_cdl30_b_2008to2017"
    arcpy.env.outputCoordinateSystem = "C:\\Users\\Bougie\\Desktop\\Gibbs\\data\\usxp\\pre\\traj\\v4\\v4_traj.gdb\\v4_traj_cdl30_b_2008to2017"
    arcpy.env.extent = arcpy.Extent(XMin, YMin, XMax, YMax)

    cls = 21973
    rws = 13789

    outData = np.zeros((13789, 21973), dtype=np.int)
    
    cdl_2016 = 'C:\\Users\\Bougie\\Desktop\\Gibbs\\data\\usxp\\ancillary\\raster\\cdl.gdb\\cdl30_2016'
    cdl_2017 = 'C:\\Users\\Bougie\\Desktop\\Gibbs\\data\\usxp\\ancillary\\raster\\cdl.gdb\\cdl30_2017'
    InRas1=Raster('D:\\projects\\intact_land\\years\\2015.gdb\\clu_2015_crop_c_raster_rc1')


    def getReclassedRasters(covertype):
        #####NOTE &/OR compliment each other---exhuastive!!
        if covertype=='noncrop':
            reclass_2016 = Reclassify(Raster(cdl_2016), "Value", RemapValue([[176,1],[152,1],[195,1]]), "NODATA")
            reclass_2017 = Reclassify(Raster(cdl_2017), "Value", RemapValue([[176,1],[152,1],[195,1]]), "NODATA")
            #####  AND Operator  ###########################
            outCon = Con(IsNull(InRas1), InRas1, Con((reclass_2016==1) & (reclass_2017==1),1))
            return outCon
        elif covertype=='crop':
            ####NOTE: Need to reclass NULL to zero or else will ignore pixel !!!!!!!!!
            reclass_2016 = Reclassify(Raster(cdl_2016), "Value", RemapRange(createReclassifyList()), "NODATA")
            reclass_2016_0 =  Con(IsNull(reclass_2016),0,reclass_2016)
            reclass_2017 = Reclassify(Raster(cdl_2017), "Value", RemapRange(createReclassifyList()), "NODATA")
            reclass_2017_0 =  Con(IsNull(reclass_2017),0,reclass_2017)
            #####  OR Operator  ###########################
            outCon = Con(IsNull(InRas1), InRas1, Con((reclass_2016_0==1) | (reclass_2017_0==1),1))
            return outCon

    outCon=getReclassedRasters(covertype)

    #clear out the extent for next time
    arcpy.ClearEnvironment("extent")

    outname = "tile_" + str(fc_count) +'.tif'

    outpath = os.path.join("C:/Users/Bougie/Desktop/Gibbs/data/", r"tiles", outname)

    ###Save the output 
    outCon.save(outpath)
def Iter_ListRaster(workspaces, wildcard):
    outlist = []
    for ws in workspaces:
        arcpy.env.workspace = ws
        rlist = arcpy.ListRasters(wildcard)
        if rlist is not None:
            outlist.extend([os.path.join(ws, r) for r in rlist if os.path.join(ws, r) not in outlist])
    arcpy.ClearEnvironment('Workspace')
    return outlist
def convert_to_features(raster, features=None, extent_features=None):
    """
    Convert raster to features, clipping it if an extent feature class
    is provided
    """
    arcpy.env.extent = extent_features
    feature_class = arcpy.RasterToPolygon_conversion(raster,
                                                     features,
                                                     raster_field='Class_name')
    arcpy.ClearEnvironment('extent')

    return feature_class[0]
def getwkspfiles(dir, repattern=None):
    arcpy.env.workspace = dir
    filenames_list = (arcpy.ListDatasets() or []) +\
                     (arcpy.ListTables() or []) +\
                     (arcpy.ListFeatureClasses() or []) # Either LisDatsets or ListTables may return None so need to create empty list alternative
    if not repattern == None:
        filenames_list = [
            os.path.join(dir, filen) for filen in filenames_list
            if re.search(repattern, filen)
        ]
    return (filenames_list)
    arcpy.ClearEnvironment('workspace')
Exemple #22
0
def execute_task(args):
    in_extentDict = args

    rg_combos = {
        '4w': ["FOUR", "WITHIN"],
        '8w': ["EIGHT", "WITHIN"],
        '4c': ["FOUR", "CROSS"],
        '8c': ["EIGHT", "CROSS"]
    }
    rg_instance = rg_combos['8w']

    fc_count = in_extentDict[0]
    # print fc_count
    procExt = in_extentDict[1]
    # print procExt
    XMin = procExt[0]
    YMin = procExt[1]
    XMax = procExt[2]
    YMax = procExt[3]

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

    cond = "LINK <> 3"
    print 'cond: ', cond

    raster_in = Raster(
        'C:\\Users\\Bougie\\Desktop\\Gibbs\\data\\usxp\\sa\\r2\\s18\\core\\core_s18.gdb\\s18_v4_traj_cdl30_b_2008to2017_rfnd_v2_n8h_mtr_8w_mmu5'
    )
    raster_rg = RegionGroup(raster_in, rg_instance[0], rg_instance[1],
                            "ADD_LINK")
    # raster_oid = Lookup(raster_rg, "OID")
    # raster_mask = SetNull(raster_rg, raster_rg, cond)

    #clear out the extent for next time
    arcpy.ClearEnvironment("extent")

    outname = "tile_" + str(fc_count) + '.tif'

    outpath = os.path.join("C:/Users/Bougie/Desktop/Gibbs/", r"tiles", outname)

    # outname2 = "tile_rg2_" + str(fc_count) +'.tif'
    # outpath2 = os.path.join("C:/Users/Bougie/Desktop/Gibbs/", r"tiles", outname2)

    # raster_shrink.save(outpath)
    raster_rg.save(outpath)

    arcpy.AddField_management(Raster(outpath),
                              field_name='tile',
                              field_type='TEXT')
    expression = "{}".format(str(fc_count))
    arcpy.CalculateField_management(outpath, "tile", expression, "PYTHON_9.3")
Exemple #23
0
def execute_task(in_extentDict):
    #########  Execute Nibble  #####################
    filter_combos = {
        'n4h': ["FOUR", "HALF"],
        'n4m': ["FOUR", "MAJORITY"],
        'n8h': ["EIGHT", "HALF"],
        'n8m': ["EIGHT", "MAJORITY"]
    }
    filter_key = data['core']['filter']

    rg_combos = {'8w': ["EIGHT", "WITHIN"]}
    rg_instance = rg_combos['8w']

    # for count in masks_list:
    cond = "Count < " + str(
        gen.getPixelCount(str(data['global']['res']), int(
            data['core']['mmu'])))
    print 'cond: ', cond

    fc_count = in_extentDict[0]
    # print fc_count
    procExt = in_extentDict[1]
    # print procExt
    XMin = procExt[0]
    YMin = procExt[1]
    XMax = procExt[2]
    YMax = procExt[3]

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

    if data['core']['route'] == 'r2':
        raster_filter = MajorityFilter(
            Raster(data['pre']['traj_rfnd']['path']),
            filter_combos[filter_key][0], filter_combos[filter_key][1])
        raster_mtr = Reclassify(raster_filter, "Value",
                                RemapRange(reclassArray), "NODATA")
        raster_rg = RegionGroup(raster_mtr, rg_instance[0], rg_instance[1],
                                "NO_LINK")
        raster_mask = SetNull(raster_rg, 1, cond)
        raster_nbl = arcpy.sa.Nibble(raster_mtr, raster_mask, "DATA_ONLY")

        #clear out the extent for next time
        arcpy.ClearEnvironment("extent")

        outname = "tile_" + str(fc_count) + '.tif'

        outpath = os.path.join("C:/Users/Bougie/Desktop/Gibbs/", r"tiles",
                               outname)

        raster_nbl.save(outpath)
Exemple #24
0
def execute_task_v2(args):
    in_extentDict, reclass_list, in_raster, schema, cls, rws = args

    fc_count = in_extentDict[0]
    # print fc_count
    procExt = in_extentDict[1]
    # print procExt
    XMin = procExt[0]
    YMin = procExt[1]
    XMax = procExt[2]
    YMax = procExt[3]

    #set environments
    # cdl30_2017=Raster('E:\\data\\usxp\\ancillary\\raster\\cdl.gdb\\cdl30_2017')
    cdl30_2017 = Raster(in_raster)

    #set environments
    arcpy.env.snapRaster = cdl30_2017
    arcpy.env.cellsize = cdl30_2017
    arcpy.env.outputCoordinateSystem = cdl30_2017
    arcpy.env.extent = arcpy.Extent(XMin, YMin, XMax, YMax)

    a = arcpy.RasterToNumPyArray(in_raster=Raster(in_raster),
                                 lower_left_corner=arcpy.Point(XMin, YMin),
                                 nrows=rws,
                                 ncols=cls)

    outData = np.vectorize(reclass_list.get)(a)

    outname = "tile_" + str(fc_count) + '.tif'

    outpath = os.path.join(
        "D:/projects/usxp/series/s35/maps/{}/".format(schema), r"tiles",
        outname)

    arcpy.ClearEnvironment("extent")

    myRaster = arcpy.NumPyArrayToRaster(outData,
                                        lower_left_corner=arcpy.Point(
                                            XMin, YMin),
                                        x_cell_size=30,
                                        y_cell_size=30,
                                        value_to_nodata=255)

    outData = None

    myRaster.save(outpath)

    myRaster = None
Exemple #25
0
def execute_task(args):
	in_extentDict, data = args



	fc_count = in_extentDict[0]
	# print fc_count
	procExt = in_extentDict[1]
	# print procExt
	XMin = procExt[0]
	YMin = procExt[1]
	XMax = procExt[2]
	YMax = procExt[3]

	path_traj_rfnd = data['pre']['traj_rfnd']['path']
	print 'path_traj_rfnd:', path_traj_rfnd

	path_mtr = Raster(data['core']['path'])
	print path_mtr

	#set environments
	arcpy.env.snapRaster = path_mtr
	arcpy.env.cellsize = path_mtr
	arcpy.env.extent = arcpy.Extent(XMin, YMin, XMax, YMax)

	##  Execute the three functions  #####################
    # Set local variables
	inRaster = Raster("C:\\Users\\Bougie\\Desktop\\Gibbs\\data\\usxp\\sa\\r2\\s22\\post\\ytc_s22.gdb\\s22_ytc30_2008to2017_mmu5")
	nbr = NbrAnnulus(3000, 3000, "CELL")

	# Execute BlockStatistics
	outBlockStat = BlockStatistics(inRaster, nbr, "SUM", "DATA")

	#clear out the extent for next time
	arcpy.ClearEnvironment("extent")

	# print fc_count
	outname = "tile_" + str(fc_count) +'.tif'

	outpath = os.path.join("C:/Users/Bougie/Desktop/Gibbs/data/", r"tiles", outname)
    
	outBlockStat.save(outpath)

	outpath = None

	outBlockStat = None
def execute_task(args):
    in_extentDict, data = args

    rg_combos = {
        '4w': ["FOUR", "WITHIN"],
        '8w': ["EIGHT", "WITHIN"],
        '4c': ["FOUR", "CROSS"],
        '8c': ["EIGHT", "CROSS"]
    }
    rg_instance = rg_combos['8w']

    fc_count = in_extentDict[0]
    # print fc_count
    procExt = in_extentDict[1]
    # print procExt
    XMin = procExt[0]
    YMin = procExt[1]
    XMax = procExt[2]
    YMax = procExt[3]

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

    cond = "LINK <> 3"
    print 'cond: ', cond

    raster_in = Raster(data['core']['path'])
    raster_rg = RegionGroup(raster_in, rg_instance[0], rg_instance[1],
                            "ADD_LINK")

    #clear out the extent for next time
    arcpy.ClearEnvironment("extent")

    outname = "tile_" + str(fc_count) + '.tif'

    outpath = os.path.join("C:/Users/Bougie/Desktop/Gibbs/data/", r"tiles",
                           outname)

    raster_rg.save(outpath)

    arcpy.AddField_management(Raster(outpath),
                              field_name='tile',
                              field_type='TEXT')
    expression = "{}".format(str(fc_count))
    arcpy.CalculateField_management(outpath, "tile", expression, "PYTHON_9.3")
Exemple #27
0
    def get_file_path_with_wildcard_from_gdb(self, wildcard=None):
        arcpy.env.workspace = self.env_0
        fc = arcpy.ListFeatureClasses(wildcard)
        fc_list_path = []

        if fc is None:
            print("did not find fc, skipping")
            return fc_list_path
        else:

            for x in fc:
                fc_list_path.append(
                    os.path.join(self.env_0,
                                 os.path.splitext(x)[0]))

            arcpy.ClearEnvironment("workspace")
            print("I found {} many file(s)".format(len(fc_list_path)))
            return fc_list_path
Exemple #28
0
def execute_task(args):
    in_extentDict, nibble = args

    fc_count = in_extentDict[0]
    # print fc_count
    procExt = in_extentDict[1]
    # print procExt
    XMin = procExt[0]
    YMin = procExt[1]
    XMax = procExt[2]
    YMax = procExt[3]

    #set environments
    #The brilliant thing here is that using the extents with the full dataset!!!!!!   DONT EVEN NEED TO CLIP THE FULL RASTER TO THE FISHNET BECASUE
    arcpy.env.snapRaster = nibble.in_raster
    arcpy.env.cellsize = nibble.in_raster
    arcpy.env.extent = arcpy.Extent(XMin, YMin, XMax, YMax)

    ###  Execute Nibble  #####################
    # ras_out = arcpy.sa.Nibble(nibble.in_raster, nibble.in_mask_raster, "DATA_ONLY")
    # Local variables:
    # tile_5_tif = "tile_5.tif"
    # EucAllo_tif2 = "C:\\Users\\Bougie\\Documents\\ArcGIS\\Default.gdb\\EucAllo_tif2"
    Output_distance_raster = ""
    Output_direction_raster = ""

    # # Process: Euclidean Allocation
    # arcpy.gp.EucAllocation_sa(tile_5_tif, EucAllo_tif2, "", "", "30", "Value", Output_distance_raster, Output_direction_raster)

    # print fc_count
    outname = "tile_" + str(fc_count) + '.tif'
    #create Directory

    outpath = os.path.join("C:/Users/Bougie/Desktop/Gibbs/", r"tiles", outname)
    # EucAllo_tif2 = "C:\\Users\\Bougie\\Desktop\\Gibbs\\data\\usxp\\temp\\temp.gdb\\"+try_yo
    ras_out = arcpy.sa.EucAllocation(nibble.in_raster, "", "", "30", "Value",
                                     "", "")

    # arcpy.sa.EucAllocation(nibble.in_raster, outpath, "", "", "30", "Value", Output_distance_raster, Output_direction_raster)

    ras_out.save(outpath)

    #clear out the extent for next time
    arcpy.ClearEnvironment("extent")
Exemple #29
0
    def get_file_path_with_wildcard_from_gdb(self, wildcard=None):
        arcpy.env.workspace = self.env_0
        fc = arcpy.ListFeatureClasses(wildcard)

        if fc is None:
            print("did not find fc, skipping")
        else:

            fc_list_path = []
            for x in fc:
                fc_list_path.append(
                    os.path.join(self.env_0,
                                 os.path.splitext(x)[0]))

            arcpy.ClearEnvironment("workspace")
            print("I found {} many file(s)".format(len(fc_list_path)))

            if list(fc) == 'NoneType':
                raise Warning("Did not find path, check your wild card")
            else:
                return fc_list_path
Exemple #30
0
def init(logger):
    '''
    make sure forklift is ready to run. create the hashing gdb and clear out the scratch geodatabase
    logger is passed in from cli.py (rather than just setting it via `log = logging.getLogger('forklift')`)
    to enable other projects to use this module without colliding with the same logger'''
    global log
    log = logger

    #: create gdb if needed
    if arcpy.Exists(scratch_gdb_path):
        log.info('%s exists, deleting', scratch_gdb_path)
        try:
            arcpy.Delete_management(scratch_gdb_path)
        except ExecuteError:
            #: swallow error thrown by Pro 2.0
            pass

    log.info('creating: %s', scratch_gdb_path)
    arcpy.CreateFileGDB_management(garage, _scratch_gdb)

    arcpy.ClearEnvironment('workspace')