Skip to content

Instantly share code, notes, and snippets.

@chadcooper
Created April 2, 2013 00:33
Show Gist options
  • Save chadcooper/5289004 to your computer and use it in GitHub Desktop.
Save chadcooper/5289004 to your computer and use it in GitHub Desktop.
def get_raster_corners(in_raster):
"""Get XY coordinates of four corners of a raster as dictionary"""
r = arcpy.Raster(in_raster)
corners = ["lowerLeft", "lowerRight", "upperLeft", "upperRight"]
corner_dict = {}
for corner in corners:
x = getattr(r.extent, "%s" % corner).X
y = getattr(r.extent, "%s" % corner).Y
corner_dict[corner] = [x, y]
return corner_dict
def get_raster_props(in_raster):
"""Get properties of a raster, return as dict"""
r = arcpy.Raster(in_raster)
raster_props = {}
x_center = r.extent.XMin + (r.extent.XMax - r.extent.XMin)/2
y_center = r.extent.YMin + (r.extent.YMax - r.extent.YMin)/2
raster_props["x_center"] = x_center
raster_props["y_center"] = y_center
raster_props["max_elev"] = r.maximum
raster_props["min_elev"] = r.minimum
raster_props["no_data"] = r.noDataValue
raster_props["terr_width"] = r.width
raster_props["terr_height"] = r.height
raster_props["terr_cell_res"] = r.meanCellHeight
return raster_props
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment