2

There is a part in my Python script where I convert a Feature to a Raster (arcpy.FeatureToRaster_conversion). The output is a raster with a certain value (based on a field of the Feature). The rest of the extent of the resulting raster has "NoData" values.

However, I want that "NoData" to be 0. Here is the code.

arcpy.env.overwriteOutput = True

raster = arcpy.Raster(export_path)
arcpy.sa.Reclassify(raster, "Value", arcpy.sa.RemapValue([["NoData", 0]]), "").save(export_path)

But this has no effect. I still have "NoData".

How do you reclassify "NoData" values to a numerical value using arcpy?

1 Answer 1

4

You could use a conditional instead:

reclassify = arcpy.sa.Con(arcpy.sa.IsNull(raster), 0, raster, "Value = 1")
reclassify.save(export_path)

This will evaluate a version of your raster where all NoData cells are changed to value 1 (the IsNull part). The Con part will then assign 0 if Value = 1 and the original raster values if false.

2
  • Just to you know, you can't append ".save(export_path)" at the end of the first line. Aug 14, 2018 at 17:52
  • I was going to edit my post with the exact changes you proposed. Perfect!
    – Gabriel
    Aug 14, 2018 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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