Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Extracting a subset of points efficiently depends on the exact format you are using. Assuming you store your raster as a numpy array of integers, you can extract points like this:</p> <pre><code>from numpy import * def points_in_circle(circle, arr): "A generator to return all points whose indices are within given circle." i0,j0,r = circle def intceil(x): return int(ceil(x)) for i in xrange(intceil(i0-r),intceil(i0+r)): ri = sqrt(r**2-(i-i0)**2) for j in xrange(intceil(j0-ri),intceil(j0+ri)): yield arr[i][j] </code></pre> <p><code>points_in_circle</code> will create a generator returning all points. Please note that I used <code>yield</code> instead of <code>return</code>. This function does not actually return point values, but describes how to find all of them. It creates a sequential iterator over values of points within circle. See <a href="http://docs.python.org/reference/expressions.html#yieldexpr" rel="nofollow noreferrer">Python documentation</a> for more details how <code>yield</code> works.</p> <p>I used the fact that for circle we can explicitly loop only over inner points. For more complex shapes you may loop over the points of the extent of a shape, and then check if a point belongs to it. The trick is not to check <em>every</em> point, only a narrow subset of them.</p> <p>Now an example of how to use <code>points_in_circle</code>:</p> <pre><code># raster dimensions, 10 million points N, M = 3200, 3200 # circle center and its radius in index space i0, j0, r = 70, 20, 12.3 raster = fromfunction(lambda i,j: 100+10*i+j, (N, M), dtype=int) print "raster is ready" print raster pts_iterator = points_in_circle((i0,j0,r), raster) # very quick, do not extract points yet pts = array(list(pts_iterator)) # actually extract all points print pts.size, "points extracted, sum = ", sum(pts) </code></pre> <p>On a raster of 10 million integers it is pretty quick.</p> <p>Please describe file format or put a sample somewhere if you need more specific answer.</p>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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