Я пытаюсь создать инструмент в ArcGIS, который вычисляет полосы Landsat8 (b8-b4) / (b8 + b4). Я построил модель в arcmap, а затем экспортировал ее как скрипт. Он запускает модель, но как инструмент. Я получаю ошибку в последней строке, где вычисляю полосы.
# Import arcpy module
import arcpy
# Script arguments
band8_input = arcpy.GetParameterAsText(0)
if band8_input == '#' or not band8_input:
band8_input = "band8_input" # provide a default value if unspecified
band4_input = arcpy.GetParameterAsText(1)
if band4_input == '#' or not band4_input:
band4_input = "band4_input" # provide a default value if unspecified
RGB_input = arcpy.GetParameterAsText(2)
if RGB_input == '#' or not RGB_input:
RGB_input = "RGB_input" # provide a default value if unspecified
clip_polygon = arcpy.GetParameterAsText(3)
if clip_polygon == '#' or not clip_polygon:
clip_polygon = "clip_polygon" # provide a default value if unspecified
# Local variables:
RGB_clp = "C:\\egm722\\RGB_clp"
RGB_clp_prj = RGB_clp
b8_clp = "C:\\egm722\\b8_clp"
b8_clp_prj = b8_clp
b4_clp = "C:\\egm722\\b4_clp"
b4_clp_prj = b4_clp
NVDI = "C:\\egm722\\NVDI.img"
NVDI_prj = NVDI
# Process: Clip_RGB
arcpy.Clip_management(RGB_input, "321255.095287406 5732480.81845376 327031.683798733 5736711.6778568", RGB_clp, clip_polygon, "256", "NONE", "NO_MAINTAIN_EXTENT")
# Process: Prj_RGB
arcpy.DefineProjection_management(RGB_clp, "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]")
# Process: Clip_b8
arcpy.Clip_management(band8_input, "321255.095287406 5732480.81845376 327031.683798733 5736711.6778568", b8_clp, clip_polygon, "-32768", "NONE", "NO_MAINTAIN_EXTENT")
# Process: Prj_b8
arcpy.DefineProjection_management(b8_clp, "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]")
# Process: Clip_b4
arcpy.Clip_management(band4_input, "321255.095287406 5732480.81845376 327031.683798733 5736711.6778568", b4_clp, clip_polygon, "-32768", "NONE", "NO_MAINTAIN_EXTENT")
# Process: Prj_b4
arcpy.DefineProjection_management(b4_clp, "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]")
# Process: Calc_NVDI
arcpy.gp.RasterCalculator_sa("Float(\"%b8_clp_prj%\" - \"%b4_clp_prj%\") / (\"%b8_clp_prj%\" + \"%b4_clp_prj%\")", NVDI)
# Process: Prj_NVDI
arcpy.DefineProjection_management(NVDI, "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]")
И я получаю следующую ошибку:
Traceback (most recent call last):
File "C:\egm722\NVDI_arcpy.py", line 59, in <module>
arcpy.gp.RasterCalculator_sa("Float(\"%b8_clp_prj%\" - \"%b4_clp_prj%\") / (\"%b8_clp_prj%\" + \"%b4_clp_prj%\")", NVDI)
File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\geoprocessing\_base.py", line 510, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
ExecuteError: ERROR 000539: Error running expression: rcexec()
Traceback (most recent call last):
File "<expression>", line 1, in <module>
File "<string>", line 5, in rcexec
TypeError: unsupported operand type(s) for -: 'str' and 'str'
Failed to execute (RasterCalculator).
Failed to execute (NVDI)
Спасибо за помощь. Судя по тому, что я прочитал, это синтаксическая ошибка, но я не могу ее понять. Большое спасибо за ваше время и помощь.