python 使用arcpy将栅格剪切到另一个栅格的范围,并将其转换为TIFF

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 使用arcpy将栅格剪切到另一个栅格的范围,并将其转换为TIFF相关的知识,希望对你有一定的参考价值。

# Load arcpy
import arcpy

# Set workspace
arcpy.env.workspace = "<some filepath for your working environment>"
scratch = "<some scratch location for intermediate files>"

# Specify the data you'll be clipping and the area you want to clip that data by
myClip = "<location of raster to be clipped>"
clipArea = "<location of raster to clip by>"

# Get the extent of the clip area
# http://help.arcgis.com/En/Arcgisdesktop/10.0/Help/index.html#//0017000000m7000000
# Values have to be converted to strings so they can be concatentated and used later
# https://docs.python.org/2/library/functions.html#str
clipAreaTop  = str(arcpy.GetRasterProperties_management(clipArea, "TOP"))
clipAreaLeft  = str(arcpy.GetRasterProperties_management(clipArea, "LEFT"))
clipAreaRight  = str(arcpy.GetRasterProperties_management(clipArea, "RIGHT"))
clipAreaBottom  = str(arcpy.GetRasterProperties_management(clipArea, "BOTTOM"))
# Concatentated stringified extent values
# http://www.pythonforbeginners.com/concatenation/string-concatenation-and-formatting-in-python
clipAreaExtent = clipAreaLeft + " " + clipAreaBottom + " " + clipAreaRight + " " + clipAreaTop

# Clip your raster by the extent of the clipAreaExtent derived from another raster
# http://resources.arcgis.com/EN/HELP/MAIN/10.1/index.html#//00170000009n000000
print("clipping")
myClipScratch = arcpy.Clip_management(myClip, clipAreaExtent, scratch + "<file name>", "#", "#", "NONE")

# arcpy saves the output to an ESRI Grid format.
# You may want to work with a more common format. Here we convert the previous output to a TIFF
# http://help.arcgis.com/EN/arcgisdesktop/10.0/help/index.html#//001200000032000000
print("converting")
arcpy.RasterToOtherFormat_conversion(aerialClipScratch, "<file path to folder wher you want to save output>", "TIFF")

以上是关于python 使用arcpy将栅格剪切到另一个栅格的范围,并将其转换为TIFF的主要内容,如果未能解决你的问题,请参考以下文章

Arcgis之栅格数据合并

Arcgis之栅格数据转换

Arcgis之栅格数据融合

arcpy-栅格转其他格式

使用arcpy遇到的那些坑

使用arcpy遇到的那些坑