Problem with NumPyArrayToRaster

3149
3
04-13-2012 05:20 AM
FabianBlau
Occasional Contributor II
NumPyArrayToRaster ignores the lower_left_corner if an extent ist set. The result is stupid.
I did following to check the problem:

New mxd.
Create Random Raster with defaults.
Python window:
>>> LL = arcpy.Raster('CreateRandom1').extent.lowerLeft
>>> LL.X += 100
>>> LL.Y += 100
>>> numras = arcpy.RasterToNumPyArray('CreateRandom1', LL, 100, 100, arcpy.Raster('CreateRandom1').noDataValue)
>>> numras.shape
(100, 100)
>>> LL
<Point (100.0, 100.0, #, #)>
>>> outras = arcpy.NumPyArrayToRaster(numras, LL, 1, 1, arcpy.Raster('CreateRandom1').noDataValue)
>>> arcpy.env.extent
>>> arcpy.env.extent = arcpy.Raster('CreateRandom1').extent
>>> outras1 = arcpy.NumPyArrayToRaster(numras, LL, 1, 1, arcpy.Raster('CreateRandom1').noDataValue)


Results:
CreateRandom1 and outras (without extent):
[ATTACH=CONFIG]13488[/ATTACH]
CreateRandom1 and outras1 (with extent, yellow:NoData)
[ATTACH=CONFIG]13489[/ATTACH]

The LL-Parameter is unused in outras1. The extent is not the extent of the NumPyArray. outras2 is set to the upperleft-corner of the extent.
In my opinion this is wrong.
Solution: Setting the extent before calling NumPyArrayToRaster. Maybe it is necessary to buffer the extent for other reasons before changing it.
0 Kudos
3 Replies
PhilMorefield
Occasional Contributor III
I don't get the same results as you. When I follow your steps exactly, LL is not unused for outras1. It lines up in exactly the same place as outras. I'm using AGD 10.0, service pack 4.

Also, I'm not sure what you're trying to show by changing the extent. That won't change where the rasters line up. By default, the extent window is set to the maximum of your inputs ('CreateRandom1' in this case). Setting the extent to 'CreateRandom1.extent' doesn't change anything at all, since that is the input with the maximum extent.
0 Kudos
by Anonymous User
Not applicable
Original User: fabl

I dont use service pack 4. Maybe the problem is solved there. I will check this.

By default there is no extent set:
>>> print arcpy.env.extent
None

It is possible to set one on the environments Application-level, of course. But I did not so.
0 Kudos
PhilMorefield
Occasional Contributor III

By default there is no extent set:


Ah yes, you're right. I must have set this a while ago.
0 Kudos