Created
April 2, 2013 00:32
-
-
Save chadcooper/5288996 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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