1

I want to linear stretch my raster grid formate having column/rows 3128, 3503 with 30 meter resolution by using the following syntax in raster calculator of arcmap 10.1.

("raster" - FocalStatistics("raster", NbrRectangle, 30, 30, "Minimum") / 
(FocalStatistics("raster", NbrRectangle, 30, 30, "Maximum") - 
FocalStatistics("raster", NbrRectangle, 30, 30, "Minimum"))

But this gives me the error while executing. I have also tried the simple equation but did not work.

("raster" - min("raster")) * 1.0 / (max("raster") - min("raster")) + 0.0

Error displayed:

000539 : Error message from Python. ArcGIS 10.1 Locate topic Description The calculation used by the Calculate Field or Calculate Value tool is invalid. This error message provided will list the specific Python error. Solution This error code covers a number of Python errors: Example error 1: exceptions.TypeError: cannot concatenate 'str' and 'int' objects.The above is a Python-specific error. The calculation is attempting to add or concatenate a string and a number. Example error 2: Invalid field shape@distance The above is an error using the geometry object. The distance method is not a valid method of the geometry object.For specific Python issues, consult the external Python help for more information, or consult the Calculate Field or Calculate Value help for more information on these tools.

What is the right syntax.

2

The expression of the rectangle is incorrect, your neighbourhood should be specified like this:

FocalStatistics("raster",NbrRectangle(30,30),"MINIMUM")

As the NbrRectangle is an object... to specify your first calculation use:

("raster" - FocalStatistics("raster",NbrRectangle(30,30),"MINIMUM"))  
/ ((FocalStatistics("raster",NbrRectangle(30,30),"MAXIMUM")) 
- (FocalStatistics("raster",NbrRectangle(30,30),"MINIMUM")))

The 'simple' equation is anything but... minimum and maximum can only be obtained when statistics have been built, if they are not you will receive an error saying 'value unobtainable' or something along those lines. Using the whole raster min and max:

Con(IsNull("raster"),-9999,("raster"
/ (float(arcpy.GetRasterProperties_management("raster","MAXIMUM").getOutput(0)) 
- float(arcpy.GetRasterProperties_management("raster","MINIMUM").getOutput(0))) * 100))
  • @MichaelMS. I have already tried the same syntax you mentioned first but received the error while executing. Please see I have edited my syntax in main post. I want to rescale it into 0-1 range. I don't get your second option or not explained well to understand. Is this syntax for use in python or? Add you had missed some expression in numerator part. – Waseem Ali Nov 3 '14 at 0:15
  • I've broken them up into three lines to make it easier to read. In order to get a numeric minimum and maximum you need to use getOutput(0), which is a string, and then use float to make it a floating point number. Both of these worked for me with no error messages. – Michael Stimson Nov 3 '14 at 0:22
  • @MichaelMS. Your first syntax by using raster calculator works for me successfully. I had missed one bracket in it. I am a new to use python this is why I might be panic to ask such a basic questions. As my understanding, you did not subtract the minimum value from the main raster before division (in numerator part) as I need to subtract first from the main raster and then divide it with dynamic range. Thanks anyway – Waseem Ali Nov 3 '14 at 10:02

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.