1

I have two raster datasets, the first an 800 meter digital elevation model, the second a corresponding set of temperatures at the same resolution and identical spatial reference.

I've extracted each into a smaller selection (elevation & temperature below):

Does a chunk of code exist that pulls the maximum and minimum values of one raster (in this case elevation), and extracts the values of the corresponding second raster (temperature)?

It's my goal to run this code for numerous smaller raster datasets.

My initial thought was to write code in ArcPy using the "Extract by Point" tool, however I discovered that this fell short of what I'm attempting to do.

enter image description here enter image description here

closed as off-topic by PolyGeo Jul 18 '17 at 21:46

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

4

First, you need to calculate the statistics on your raster, then you can use a tool in python GetRasterProperties to report the MIN/MAX values. Here is a bit of code that I use:

import os, sys, arcpy

ThisRas = sys.argv[1] # your input raster

d = arcpy.Describe(ThisRas)
if (d.bandCount == 1):
    try:
        arcpy.CalculateStatistics_management(ThisRas,1,1)
        MinValR = arcpy.GetRasterProperties_management(ThisRas,"MINIMUM")
        MaxValR = arcpy.GetRasterProperties_management(ThisRas,"MAXIMUM")
        MinVal = float(MinValR.getOutput(0))
        MaxVal = float(MaxValR.getOutput(0))
        arcpy.AddMessage('{} Min: {} Max: {}'.format(ThisRas,MinVal,MaxVal))
    except:
        arcpy.AddError("Failed to build on {}".format(ThisRas))
        failList.append(ThisRas)

From there you can Extract by Attributes from the elevation raster then use Sample tool to get the matching temperature from the other raster. Both of these tools require a spatial analyst license, if you don't have access to that license you could read both rasters as numpy arrays (assuming they're the same size: rows, columns, origin and cellsize) and locate the index of the min/max values in the elevation array and then get the corresponding value in the temperature array. I don't have any code for raster to numpy because I have access to spatial analyst - why bark if you've already got a dog?

  • Excellent code once again Michael, I appreciate the help! I fortunately do have the Spatial Analyst toolbox, so I can explore both Extract by Attributes and Sample tool. One additional question for you, any effective ways to write this to a .csv or .txt file, and append each instance of the script to said file? – E. Weglarz Jul 18 '17 at 22:55
  • The output of the sample tool is a table, I'm not sure what the format is but that should be readable by a cursor, not containing rows for the NoData pixels in the sample only the valid cells, as for getting that as CSV I'd use standard python writing to text files pythonforbeginners.com/files/… - writing text to a file is fairly easy in python but don't forget to write a \n at the end of each line. – Michael Stimson Jul 18 '17 at 23:14

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