python code to georeference image

12146
3
11-25-2010 11:49 PM
besmartbesmart
New Contributor
Can i get python code   to auto georeference image. The projection is known and the four coordinates x,y of the corners of the image are known.
Currently , i do georeference  manually by the gereference tool , but i want to automate these tasks for about 200+ image raster.
0 Kudos
3 Replies
NiklasNorrthon
Occasional Contributor III
I think it should be possible do automate this task. The steps you need to take is to first create a world file for each image. The world file is usually a text file with the same name as the image file, but a different extension (e.g. tfw for tif). The world file contains the coordinates of one of the corners, the rotation of the image, and the scale in the x and y directions. These numbers should be easy to calculate given that you have all for corners of you imaga.

When you have the world file you can add it to the map and it should end up in the correct spot, if they are in the same projection, but the projection information for the image is still missing. To add that just use the ArcToolbox tool Define projection.
V_StuartFoote
MVP Frequent Contributor
"besmart"

Niklas's suggestion, to use a World file would work, but could have issues in determining a correct rotation and scaling to apply and would have to be replicated for each image being processed.

I think your task can be done programmatically directly in Python with the Warp (Data Management) raster tool. Which actually is the same logic used for the interactive Georeference Tool in ArcMap.

Documentation and examples are here by release:
[INDENT]Warp_management in arcpy Python site package in ArcGIS 10

or

Warp_management in arcgisscripting Python module in ArcGIS 9.3[/INDENT]

Keep in mind that your images actually have two sets of coordinates, the 0,0 relative (x,y) of the raster and a corresponding (x',y') projected value--use the pairing as the from -- to as control for the warp (as in the Georeference Tool).

If you work in the same projection as corner points of the images, the POLYORDER1 "AFFINE" transform should work well using the corners as controls. Appropriate if your images are scans of existing maps sheets. But for images other than scanned maps (or if "reprojecting") you may need the more complex "fitting" of a higher order transformation to better register the input raster.  You probably don't want to resample so just accept the default NEAREST option.

Pick a raster output format and first try a couple from the Python IDLE command line. Then script a loop through a file list of images and associated control points/corners. You'll end up with two sets of rasters--the originals and the output of the Warp. Alternatively you can output directly as ESRI grid into a File Geodatabase Raster dataset ready to use in ArcGIS.

Stuart
0 Kudos
besmartbesmart
New Contributor
Thanks vsfoote and  Niklas for suggestions.
i found Warp  is what i need.
i used the script in the given link arcgis 9.3 , but the georeference was not valid when i add the raster to arcmap.
but , when i used the warp toolbox GUI directly and set the projection from within environment, the result was valid.
I think that i should  set the projection first , before starting warp.
0 Kudos