TransWikia.com

Reclassify rasters from raster dataset with ArcPy

Geographic Information Systems Asked by Michela Zanni on July 12, 2021

I have a raster dataset ("RDS_NFlows_3035") with several bands that I would like to reclassify to a single value and save in another raster dataset ("RDS_NFlows_reclass_3035").
When I run the script I get in the main workspace (daycentGDB) and not in the output raster dataset only one raster, called Reclass_RDS_1, correctly reclassified and I get also following error:

RuntimeError: ERROR 000732: Input Raster: Dataset E:projectsINMAPArcGISProjectDAYCENTDAYCENT.gdbRDS_NFlows_3035Reclass_RDS_1 does not exist or is not supported

I have no rasters in my input raster dataset with that name (Reclass_RDS_1), since this is the default name given to the output by the processing tool and I can’t understand why the script looks for such a raster and why it saves it outside the output raster dataset.

NFlows_in_rds = os.path.join(daycentGDB, "RDS_NFlows_3035")
NFlows_out_rds = os.path.join(daycentGDB, "RDS_NFlows_reclass_3035")
arcpy.env.workspace = NFlows_in_rds
nflow_rs  = arcpy.ListRasters()
outRsSuff = "_reclass"
for rs in nflow_rs:
    print("Working on {}".format(rs))
    inRaster = Raster(rs)
    minVal = arcpy.GetRasterProperties_management(inRaster, "MINIMUM")
    maxVal = arcpy.GetRasterProperties_management(inRaster, "MAXIMUM")
    print("min: {}, max: {}".format(minVal, maxVal))
    remap = RemapRange([[minVal, maxVal, 999]])
    outRsName = "{}{}".format(rs, outRsSuff)
    print(outRsName)
    outRs = Reclassify(inRaster, "VALUE", remap)
    outRs.save(os.path.join(NFlows_out_rds, outRsName))

This is the structure of my GDB:

DAYCENT.gdb (File geoDB)  
    RDS_NFlows_3035 (Raster dataset)  
        mineralFertilization (Band 1 of raster dataset)  
        organicFertilization (Band 2 of raster dataset)  
        N2O (Band 3 of raster dataset)  
        N2 (Band 4 of raster dataset)  

What I expect from script is a GDB like this:

DAYCENT.gdb
    RDS_NFlows_3035
        mineralFertilization
        organicFertilization
        N2O
        N2
    RDS_NFlows_reclass_3035
        mineralFertilization_reclass
        organicFertilization_reclass
        N2O_reclass
        N2_reclass      
    

But after the script returns error, the GDB structure is:

DAYCENT.gdb
    RDS_NFlows_3035
        mineralFertilization
        organicFertilization
        N2O
        N2
    Reclass_RDS_1
        Band_1  

One Answer

I think the issue is with your understanding of what a Raster Dataset is? I assume you have already created a Raster Dataset using the Create Raster dataset tool?

Read the first line of the usage section and it says:

When you create a raster dataset, you are creating an empty location to contain a single raster dataset. You can then mosaic or load raster datasets into this location.

The key word here is LOAD. Your code is not loading into an empty existing Raster Dataset you are saving a Raster Dataset which is the output of a reclassification.

I think the confusion is coming from ESRI calling an empty raster a raster dataset and it appears you are trying to replicate the functionality of a Feature dataset which is a kind of folder in a Geodatabase.

I would simply create the raster from the reclass and then save it to:

E:projectsINMAPArcGISProjectDAYCENTDAYCENT.gdbmyNewRaster

Answered by Hornbydd on July 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP