Select to view content in your preferred language

Add spatial reference to a raster

8631
4
05-16-2011 11:55 AM
jili
by
New Contributor
Hi there,

After transforming the Numpy array back to raster data, the spatial reference lost. I want to add my original spatial reference information back on the new generated raster. But the spatialReference of raster data property is read-only, how can I do it?

Thanks,

Wei
Tags (2)
0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus
Start a new session of ArcMap and add the raster
Use the Define Projection Tool in ArcToolbox
Does this procedure work?
0 Kudos
AlessandroCinnirella
Regular Contributor
assuming you are using python & the arcpy module.
According to Dan you could use something like that:

desc = arcpy.Describe("original_raster")
SR = desc.spatialReference
arcpy.DefineProjection_management("numpy_raster", SR)

AC
0 Kudos
jili
by
New Contributor
Thanks guys, it works. I just want to try the import and export from Numpy array so that I can work on the image more. code is shown as below.

-------------------------------

import arcpy
import numpy
descData=arcpy.Describe('D:/arcpy test code/Geoprocessing/test.tif')
cellSize=descData.meanCellHeight
extent=descData.Extent
spatialReference=descData.spatialReference
pnt=arcpy.Point(extent.XMin,extent.YMin)
readRaster=arcpy.RasterToNumPyArray('D:/arcpy test code/Geoprocessing/test.tif')
newRaster = arcpy.NumPyArrayToRaster(readRaster,pnt, cellSize,cellSize)
arcpy.DefineProjection_management(newRaster,spatialReference)
newRaster.save("D:/arcpy test code/Geoprocessing/testRaster1")
0 Kudos
Atma_BharathiMani
Deactivated User
Thank you guys for this discussion and for the concluding script.. this helped me a lot.
0 Kudos