Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I use the numpy.ndarray output generated in one function as the input into another function?
    primarykey
    data
    text
    <p>Firstly, here is the script:</p> <pre><code>import numpy as np import osgeo.gdal import os ArbitraryXCoords = np.arange(435531.30622598,440020.30622598,400) ArbitraryYCoords = np.arange(5634955.28972479,5638945.28972479,400) os.chdir('/home/foo/GIS_Summer2013') dataset = osgeo.gdal.Open("Raster_DEM") gt = dataset.GetGeoTransform() def XAndYArrays(spacing): XPoints = np.arange(gt[0], gt[0] + dataset.RasterXSize * gt[1], spacing) YPoints = np.arange(gt[3] + dataset.RasterYSize * gt[5], gt[3], spacing) return (XPoints, YPoints) def RasterPoints(XCoords,YCoords): a=[] for row in YCoords: for col in XCoords: rasterx = int((col - gt[0]) / gt[1]) rastery = int((row - gt[3]) / gt[5]) band = int(dataset.GetRasterBand(1).ReadAsArray(rasterx,rastery, 1, 1)[0][0]) a[len(a):] = [band] foo = np.asarray(a) bar = foo.reshape(YCoords.size,XCoords.size) return bar </code></pre> <p>When I load the script that is presented above, I am unable to use the output from the function XAndYArrays as input in the function RasterPoints. But I am able to use the numpy.ndarray that I have defined manually as input in the function RasterPoints. But this is not good enough. I need to be able to use the output from XAndYArrays as input in RasterPoints. Here are the commands that I used at the PyDev interactive console:</p> <pre><code>&gt;&gt;&gt; Eastings,Northings = XAndYArrays(400) &gt;&gt;&gt; Eastings Out[1]: array([ 435530.30622598, 435930.30622598, 436330.30622598, 436730.30622598, 437130.30622598, 437530.30622598, 437930.30622598, 438330.30622598, 438730.30622598, 439130.30622598, 439530.30622598, 439930.30622598]) &gt;&gt;&gt; Northings Out[1]: array([ 5634954.28972479, 5635354.28972479, 5635754.28972479, 5636154.28972479, 5636554.28972479, 5636954.28972479, 5637354.28972479, 5637754.28972479, 5638154.28972479, 5638554.28972479, 5638954.28972479]) &gt;&gt;&gt; RasterPoints(Eastings, Northings) ERROR 5: MergedDEM_EPSG3159_Reduced, band 1: Access window out of range in RasterIO(). Requested (0,246) of size 1x1 on raster of 269x246. Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2538, in run_code exec code_obj in self.user_global_ns, self.user_ns File "&lt;ipython-input-1-326be9918188&gt;", line 1, in &lt;module&gt; RasterPoints(Eastings, Northings) File "/home/foo/GIS_Summer2013/src/22July_StackOverflowQuestion.py", line 23, in RasterPoints band = int(dataset.GetRasterBand(1).ReadAsArray(rasterx,rastery, 1, 1)[0][0]) TypeError: 'NoneType' object has no attribute '__getitem__' &gt;&gt;&gt; RasterPoints(ArbitraryXCoords, ArbitraryYCoords) Out[1]: array([[422, 422, 431, 439, 428, 399, 410, 395, 398, 413, 409, 386], [414, 428, 421, 430, 426, 403, 409, 410, 406, 408, 412, 406], [420, 428, 427, 424, 408, 406, 428, 420, 408, 410, 409, 420], [392, 418, 426, 430, 414, 428, 430, 418, 433, 414, 402, 399], [400, 411, 420, 406, 401, 405, 398, 420, 419, 400, 401, 414], [408, 421, 418, 428, 399, 398, 405, 412, 421, 406, 395, 397], [399, 404, 398, 401, 400, 399, 399, 398, 398, 419, 399, 395], [401, 410, 407, 407, 404, 400, 398, 397, 397, 399, 400, 398], [400, 410, 418, 405, 401, 400, 397, 398, 400, 398, 397, 396], [389, 387, 399, 408, 423, 400, 407, 398, 411, 408, 410, 420]]) &gt;&gt;&gt; print "partial success" partial success </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload