Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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, and have about 48 hours left before I need to deliver results. Therefore a programmatic solution is OK, but I will need specific insctructions 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)

Thanks.

share|improve this question
1  
Are programmatic solutions acceptable? –  Kirk Kuykendall Sep 27 '11 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 '11 at 15:27
add comment

2 Answers 2

Corrected two mistakes in the original code. I tested this and it works now.

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)
    center = arcpy.Point(raster.extent.XMin + (raster.extent.XMax - raster.extent.XMin)/2, raster.extent.YMin + (raster.extent.YMax - raster.extent.YMin)/2)
    gcenter = arcpy.PointGeometry(center, raster.spatialReference)
    featureclass = arcpy.CreateFeatureclass_management("in_memory", os.path.basename(str(raster)) + "_center", "POINT", "" , "", "", raster.spatialReference)
    cursor = arcpy.InsertCursor(featureclass)
    feature = cursor.newRow()
    feature.shape = gcenter
    cursor.insertRow(feature)
    del cursor

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">)
share|improve this answer
add comment

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

share|improve this answer
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 '11 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 '11 at 15:30
    
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 –  blord-castillo Sep 28 '11 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 '11 at 6:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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