コード例 #1
0
ファイル: PRISM (2).py プロジェクト: vicmansep/ArcPy
arcpy.AddMessage("Finished Downsampling Data!")

# convert from mm to inches of ppt
ischecked4 = arcpy.GetParameterAsText(11)
if str(ischecked4) == 'true':
    env.workspace = outplace
    calcFileList = arcpy.ListRasters()
    for calcFile in calcFileList:
        if int(calcFile[1:-1]) >= (int(arcpy.GetParameterAsText(8)) * 100 +
                                   int(arcpy.GetParameterAsText(9))):
            # Overwrite pre-existing files
            arcpy.env.overwriteOutput = True
            calcFileName = os.path.splitext(calcFile)[0]
            calcFile1 = outplace + '/' + 'a' + calcFileName[1:-1]
            arcpy.Times_3d(calcFile, 0.0393701, calcFile1)
            arcpy.AddMessage("Converted " + calcFileName + ' to inches')

# Add Metadata Input
ischecked5 = arcpy.GetParameterAsText(12)

if str(ischecked5) == 'true':
    env.workspace = outplace
    metaFileList = arcpy.ListRasters('a*')
    for metafile in metaFileList:
        if int(metafile[1:-1]) >= (int(arcpy.GetParameterAsText(8)) * 100 +
                                   int(arcpy.GetParameterAsText(9))):
            metaplace = outplace + '/' + metafile
            metadata = md.MetadataEditor(metaplace)
            metadata.title.set('PRISM precipitation data (inches) ' +
                               metafile[-3:-1] + ' ' + metafile[1:-3])  #
コード例 #2
0
                                           "IMG_Mosaic.tif",
                                           pixel_type="32_BIT_FLOAT",
                                           cellsize="",
                                           number_of_bands="1")
    else:
        print "Maybe Reconsider the Source that you got your data"

print "Mosaic All Done"

# Now lets use the times tool to put the DEM into feet if its not already

print "Now we are changing the DEM from Meters to Feet"
arcpy.CheckOutExtension(
    "3D"
)  #This will check out the 3d-Analyst extension so that we can run the times tool
arcpy.Times_3d("IMG_Mosaic.tif", "0.3048", "..\Final_Proj\IMG_Times.tif"
               )  #This is how to convert the DEM which comes in meters to feet

# Now lets make a hillshade out of the DEM
#We are going to try to make a swiss hillshade
Divide_By = "5"  #This is the amount that we will divide the original dem by in order to combine it and make something cool
DEM_div_5 = "Divide_DEM"  #This is going to be the DEM we create when we divide by 5
Default_Hillshade = "HillSha_1"  #This is creating a variable for our Hillshade we are about to create
arcpy.CheckOutExtension("Spatial")  #Check out the Spatial Analyst Tools

arcpy.gp.Divide_sa(
    "..\Final_Proj\IMG_Times.tif", Divide_By,
    DEM_div_5)  #This is giving us the Original DEM divided by a factor of 5
print "DEM Division Done"

arcpy.gp.Hillshade_sa("..\Final_Proj\IMG_Times.tif", Default_Hillshade, "315",
                      "45", "NO_SHADOWS",
コード例 #3
0
ファイル: tttttttt.py プロジェクト: mikewang01/GIS-tool
dirYmj = "F:\shuju\ymj"#叶面积文件夹路径
arcpy.CheckOutExtension("Spatial")#使用 CheckInExtension 函数将许可归还给许可管理器,以便其他应用程序使用
files = os.listdir(dirJsl)#获取降水量文件夹下所有的文件
for file in files:#遍历文件
    if file.endswith('tif'):#判断是否为tif文件
        if not(os.path.exists('F:/temp')):#判断'F:/temp'零时文件夹路径是否存在
            os.makedirs('F:/temp')#不存在则创建零时文件夹
        if not(os.path.exists('F:/out')):#判断输出文件夹是否存在
            os.makedirs('F:/out')#不存在则创建输出文件夹
        name = file.decode("gbk").encode("utf-8")#吧文件名转成UTF-8编码
        jslFullName = dirJsl+"\\" + name#降水量的tif文件
        ymjFullName = dirYmj+"\\"+name[:6]+"_clip_001.tif"#叶面积的tif文件
        rasterJsl = arcpy.RasterToFloat_conversion(jslFullName)#叶面积的tif文件转成float以便计算
        rasterYmj = arcpy.RasterToFloat_conversion(ymjFullName)
        print "开始计算"
        arcpy.Times_3d(0.17,rasterJsl,"F:/temp/1.tif")
        raster1 = arcpy.RasterToFloat_conversion("F:/temp/1.tif")
        arcpy.Times_3d(0.35,rasterYmj,"F:/temp/2.tif")
        raster2 = arcpy.RasterToFloat_conversion("F:/temp/2.tif")
        arcpy.Times_3d(0.35,rasterYmj,"F:/temp/3.tif")
        raster3 = arcpy.RasterToFloat_conversion("F:/temp/3.tif")
        arcpy.Divide_3d(rasterJsl,raster3,"F:/temp/4.tif")
        raster4 = arcpy.RasterToFloat_conversion("F:/temp/4.tif")
        arcpy.Times_3d(-1,raster4,"F:/temp/5.tif")
        raster5 = arcpy.RasterToFloat_conversion("F:/temp/5.tif")
        expData = arcpy.sa.Exp(raster5)
        expData.save("F:/temp/6.tif")
        raster6 = arcpy.RasterToFloat_conversion("F:/temp/6.tif")
        arcpy.Minus_3d(1,raster6,"F:/temp/7.tif")
        raster7 = arcpy.RasterToFloat_conversion("F:/temp/7.tif")
        arcpy.Times_3d(raster2,raster7,"F:/temp/8.tif")
コード例 #4
0
    stage_name_for_table)
arcpy.CreateTin_3d(TIN, spatial_ref, expression, "CONSTRAINED_DELAUNAY")

# TIN to Raster
arcpy.AddMessage("Converting TIN to raster for {0}".format(stage))
input_cell_size = "CELLSIZE {0}".format(Cell_Size)
arcpy.TinRaster_3d(TIN, RasterFromTIN, "FLOAT", "LINEAR", input_cell_size, "1")

# Raster subtraction
arcpy.AddMessage(
    "Subtracting the raster from TIN with the input DEM for {0}".format(stage))
arcpy.Minus_3d(RasterFromTIN, DEM, Subtracted)

# Reverse values
depth_grid_name = "{0}_Normalized".format(stage)
arcpy.Times_3d(Subtracted, -1, depth_grid_name)

# Slice DEM
arcpy.Slice_3d(depth_grid_name, "Hypsometry", 100, "EQUAL_INTERVAL", 1)

# Percent of elevation
arcpy.AddField_management("Hypsometry", "Percent_Elevation", "FLOAT", 2, "",
                          "", "Percent_Elevation")
arcpy.CalculateField_management("Hypsometry", "Percent_Elevation",
                                "!Value! * 0.01", "PYTHON_9.3")

# Cummulative Area
arcpy.AddField_management("Hypsometry", "Cumulative", "LONG", 9, "", "",
                          "Cumulative")
freq = 0
with arcpy.da.UpdateCursor("Hypsometry", ("COUNT", "CUMULATIVE")) as cursor:
コード例 #5
0
    "shp")  #subwatershed map created by Hydrotel_Raven code
arcpy.env.scratchWorkspace = workspace

###############################################################################################################
print('section 1')
arcpy.CheckOutExtension("Spatial")  #activating spetial analyst module

# Transforming altitude, soil type, landuse and slope raster maps to polygon
#cellsize = arcpy.GetRasterProperties_management("altitude.tif","CELLSIZEX")  #Extracting the raster cell size
#cellsize1 = float(cellsize.getOutput(0))
#cellarea = cellsize1*cellsize1/1000000.0

slope1 = Slope("altitude.tif", 'DEGREE')  # SLOPE IN DEGREE
slope1.save("slope_in_deg.tif")
const = 100.0
arcpy.Times_3d("slope_in_deg.tif", "100.0", "times.tif")
intslope = Int("times.tif")
#
aspect1 = Aspect(
    "altitude.tif"
)  # ATTENTION: Aspect in Arcgis is calculated clockwise so East is 90. in Raven's manual Aspect is assumed to be counterclockwise i.e., west 90
aspect1.save("aspect")

#############################################################################################################
print('section 2')
# converting landuse, slope, and soil rasters to feature class and overlaying the created feature classes

arcpy.RasterToPolygon_conversion("type_sol.tif", 'soil_poly', "NO_SIMPLIFY",
                                 "VALUE")
arcpy.RasterToPolygon_conversion("occupation_sol.tif", 'LU_poly',
                                 "NO_SIMPLIFY", "VALUE")