If I have, say, a rectangular and georeferenced raster file loaded in an ArcMap 10 document (.tiff w/ associated tfw), how do I easily find its centre point and store that point in a points vector layer?

Also, if I have multiple such rasters in my ArcMap document, how do I apply the process to all of them?

Unfortunately, I have zero Python experience. Therefore a programmatic solution is OK, but I will need specific instructions on how to load an existing script into ArcGIS 10, and run it on the rasters in questions. (BTW, the rasters are all in their separate layers).

  • 1
    Are programmatic solutions acceptable? Sep 27, 2011 at 1:22
  • I would like to accept a programmatic solution, but have zero python experience. I will need instructions on how to load the script into ArcGIS, and run it on the rasters in question.
    – hpy
    Sep 27, 2011 at 15:27

2 Answers 2


Though the original question was for 10.0, I have updated the code below for 10.3.1.

Copy paste this into the python window in arcmap to create the RasterCenter function:

import arcpy, os
def RasterCenter(raster):
    #raster: string reference to raster
    raster = arcpy.Raster(raster)
    fcname = "{}_center".format(os.path.basename(str(raster)))
    x = raster.extent.XMin + (raster.extent.XMax - raster.extent.XMin)/2
    y = raster.extent.YMin + (raster.extent.YMax - raster.extent.YMin)/2
    featureclass = arcpy.CreateFeatureclass_management("in_memory", fcname, "POINT",spatial_reference = raster.spatialReference)
    with arcpy.da.InsertCursor(featureclass, ['SHAPE@XY']) as cursor:
        cursor.insertRow(((x, y),))
    mxd = arcpy.mapping.MapDocument("CURRENT")
    df = arcpy.mapping.ListDataFrames(mxd)[0]
    arcpy.MakeFeatureLayer_management(featureclass, fcname)
    layer = arcpy.mapping.Layer(fcname)
    arcpy.mapping.AddLayer(df, layer)

Then, you can use the python window to create your feature class by calling

RasterCenter("<reference to raster">)

So, for example, if you have a raster named DEM, you call RasterCenter("dem") in the python window, and it will add a layer named "dem_center" with a single point at the center of the raster. The layer is stored in memory, so if you want to keep it, export it.

To go one step farther, you can save the script to a .py file and place the .py file in the search path for python. e.g. save it as RasterCenter.py and place it in PYTHONPATH (normally the spot for this is C:\Python26\ArcGIS10.0\Lib)

Then you could do:

import RasterCenter
RasterCenter.RasterCenter("<reference to raster">)

Very easy, simple get the rasters properties and work out the centre point from min, max x and y

MinX = arcpy.GetRasterProperties_management("raster", "LEFT")
MinY = arcpy.GetRasterProperties_management("raster", "BOTTOM")
MaxX = arcpy.GetRasterProperties_management("raster", "RIGHT")
MaxY = arcpy.GetRasterProperties_management("raster", "TOP")

centreX = (MaxX + MinX) / 2
centreY = (MaxY + MinY) / 2

And the usual error checking etc....

Then add to your point table with an updateCursor

  • 2
    Nice approach. I think you want to improve your formulas for the center coordinates: they are the means of the endpoints, not their differences.
    – whuber
    Sep 27, 2011 at 14:37
  • This looks like what I am looking for, but since I have no scripting experience in ArcGIS, can you tell me how to load and run such a script? (I've updated the original question to reflect this...) thanks!
    – hpy
    Sep 27, 2011 at 15:30
  • 1
    You can also access the values using the raster extent properties, e.g. raster = arcpy.Raster("raster"), then centreX = raster.extent.XMax - raster.extent.XMin Sep 28, 2011 at 12:38
  • 1
    @Whuber I can see the error now, I was thinking of something else I was doing! Thanks Whuber
    – Hairy
    Sep 29, 2011 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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