numpy array to raster

873
2
03-14-2013 08:51 PM
MatthewBrown1
Occasional Contributor
Hi,

I am iterating through a series of rasters and would like to mosaic the results, but don't have access to any tools that I would normally use because this is a Runtime SDK for WPF project using local server only. (Available tools: http://resources.arcgis.com/en/help/runtime-wpf/concepts/index.html#//01700000006r000000)

One option I have tried is numpy.concatenate but this is only partially successful:

[ATTACH=CONFIG]22625[/ATTACH]

r2 is in the correct location, but r1 has shifted. No idea where the backwards 'F' came from.

Here's the code I'm using:

import arcpy
import numpy
from arcpy.sa import *

r1 = Raster("ras1")
r2 = Raster("ras2")

arcpy.env.outputCoordinateSystem = r2.spatialReference

x = r2.extent.XMin
y = r2.extent.YMin

point = arcpy.Point(x,y)

a1 = arcpy.RasterToNumPyArray(r1)
a2 = arcpy.RasterToNumPyArray(r2)

b = numpy.concatenate((a1,a2))

c = arcpy.NumPyArrayToRaster(b,point,15)


Any ideas what I am missing?
Tags (2)
0 Kudos
2 Replies
MelanieMaguire
New Contributor III
Do both of your rasters use the same projections?
Do they both have the same cell sizes?
Should r1 be south or north of r2?


  • If so, you might want to try explicitly specifying the axis to concatenate your numpy array on. Here are examples for axis 0 and 1 (at the bottom of the linked page in green).  You would want to use axis=0.


  • If that doesn't work, you may need to look at how your environment settings are being applied.

0 Kudos
MatthewBrown1
Occasional Contributor
Hi Melanie,

Yes, both rasters are in the same projection/cell size as they have been extracted from the same raster. I had a go at changing the axis, and even thought axis=0 is correct, changing it to 1 made me realise that the raster extents are the problem. For some reason, the extract by mask tool did not update the raster extents and the original extents are still being used.

While I can fix this, I'm now wondering if the NoData cells are going to cause a problem with the alignment of the extracted rasters.

Update: seems like I'm also blocked by the differences in array dimension for each raster.
0 Kudos