Skip to content

Instantly share code, notes, and snippets.

@chadcooper
Created April 2, 2013 00:32
Show Gist options
  • Save chadcooper/5288996 to your computer and use it in GitHub Desktop.
Save chadcooper/5288996 to your computer and use it in GitHub Desktop.
def raster_center(in_raster, gdb=""):
""" For given input raster, calculate center of bounding box and create a
point featureclass of the center
"""
raster = arcpy.Raster(in_raster)
center = arcpy.Point(raster.extent.XMin + (raster.extent.XMax - raster.extent.XMin)/2,
raster.extent.YMin + (raster.extent.YMax - raster.extent.YMin)/2)
if gdb:
gcenter = arcpy.PointGeometry(center, raster.spatialReference)
featureclass = arcpy.CreateFeatureclass_management(gdb,
os.path.basename(str(raster)) + "_center", "POINT", "" , "",
"", raster.spatialReference)
cursor = arcpy.InsertCursor(featureclass)
feature = cursor.newRow()
feature.shape = gcenter
cursor.insertRow(feature)
del cursor
return center
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment