2

I'm writing this code to write the NDVI value and the date where picture was taken into my attribute table, later i'll export to excel. The code is downloading the images with no problem, but when it pass through the raster layer, it retrieves me an error! I don't understand what is going wrong...

import arcpy
import os
import datetime
from arcpy import env
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
NDVI_tempo = 'Z:\\04 - Temp\\Charles\\NDVI_tempo\\NAL_PL'
arcpy.env.workspace = 'Z:\\04 - Temp\\Charles\\NDVI_tempo\\NAL\\NAL.gdb'
arcpy.SplitByAttributes_analysis("Area_produtiva3", NDVI_tempo, ['ID_TALHAO'])
#Inicio do download das imagens

down = 'Z:\\04 - Temp\\Charles\\NDVI_tempo\\NAL_PL'
image_server = 'Y:\\E - IMAGEM SERVER\\IMAGEM_SERVER.gdb\\F01_PLANETLAB'

arcpy.env.workspace = r'Z:\\04 - Temp\\Charles\\NDVI_tempo\\NAL_PL'
fcs = arcpy.ListFeatureClasses()

for fc in fcs: 
    arcpy.DownloadRasters_management (image_server, down, "", fc, "CLIPPING", "CONVERT_AS_REQUIRED", "TIFF", "NONE", "", "NO_MAINTAIN_FOLDER")

    rasters = arcpy.ListRasters()
    for tiff in rasters:
            arcpy.MakeRasterLayer_management(tiff, "Z:\\04 - Temp\\Charles\\NDVI_tempo\\NAL\\temp_rast1.tif", "", "", "3")
            arcpy.MakeRasterLayer_management(tiff, "Z:\\04 - Temp\\Charles\\NDVI_tempo\\NAL\\temp_rast2.tif", "", "", "4")

            arcpy.CopyRaster_management("Z:\\04 - Temp\\Charles\\NDVI_tempo\\NAL\\temp_rast1.tif", "copy_rast1", "","", "", "", "", "", "", "", "", "")
            arcpy.CopyRaster_management("Z:\\04 - Temp\\Charles\\NDVI_tempo\\NAL\\temp_rast2.tif", "copy_rast2", "","", "", "", "", "", "", "", "", "")

            Property1Result = arcpy.GetRasterProperties_management ("copy_rast1", "MINIMUM")
            Property2Result = arcpy.GetRasterProperties_management ("copy_rast2", "MINIMUM")

            Property1 = Property1Result.getOutput
            Property2 = Property2Result.getOutput

            Correcao1 = Minus ("copy_rast1", "Property1")
            Correcao2 = Minus ("copy_rast2", "Property2")

            Rastdiv1 = Minus ("Correcao2", "Correcao1")
            Rastdiv2 = Plus  ("Correcao2", "Correcao1")

            NDVI_tiff = Divide (Rastdiv1, Rastdiv2)
            Zonaltif = arcpy.ZonalStatistics (fc, ['ID_TALHAO'], NDVI_tiff, "MEAN", "NODATA")
            Zonalper = Times (Zonaltif, 100)
            Zonalint = Int (Zonalper)
            arcpy.RasterToPolygon_conversion (Zonalint, Zonalpoly, "SIMPLIFY", "VALUE")
            arcpy.Intersect_analysis ([Zonalpoly, fc], "Z:\\04 - Temp\\Charles\\NDVI_tempo\\NAL_PL\\teste\\Intertif", "ALL", "", "")
            arcpy.AddField_management (Intertif, Data, "TEXT", "", "", "", "", "", "", "")
            tiff_name = arcpy.Describe(tiff).name
            field_name = "{}".format(tiff_name[5:13])
            field_value = datetime.datetime.strptime('field_value', '%Y%m%d').date()
            arcpy.CalculateField_management (Intertif, Data, field_value, "", "")
            arcpy.Delete_management (tiff, "")

Traceback (most recent call last): File "Z:\04 - Temp\Charles\NDVI_tempo\NAL\NAL.gdb\NDVI_RF#Script3_NDVIRF.py", line 40, in File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 6219, in MakeRasterLayer raise e File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 6216, in MakeRasterLayer retval = convertArcObjectToPythonObject(gp.MakeRasterLayer_management(*gp_fixargs((in_raster, out_rasterlayer, where_clause, envelope, band_index), True))) File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing_base.py", line 506, in return lambda *args: val(*gp_fixargs(args, True)) arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid. ERROR 000865: Input raster: 20170312_124653_0e1f_381_s65.tif does not exist. Failed to execute (MakeRasterLayer). Failed to execute (Script3).

1

You are using MakeRasterLayer incorrectly. The first parameter is the full path to the dataset on you computer, the second parameter is and I quote from the Help file "The name of the temporary output raster dataset". You have instead provided a full path to a file.

It should be a simple string like "temp_rast1". Then you have created an in memory LAYER called temp_rast1 which is pointing to your raster DATASET on your hard drive.

Your line should look like this:

arcpy.MakeRasterLayer_management(tiff, "temp_rast1", "", "", "3")
  • It keeps showing the same message... It's like it don't recognize the image like a valid input, but i did it before manually and it works – Charlera Sep 28 '17 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.