Changeset 664 for inundation/ga/storm_surge/pyvolution/util.py
- Timestamp:
- Dec 2, 2004, 3:28:33 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/util.py
r659 r664 57 57 """ 58 58 59 #FIXME: Could do with some optimisation59 #FIXME: Could do with some C-optimisation 60 60 61 61 from Numeric import array, dot, allclose … … 94 94 point - Tuple of (x, y) coordinates, or list of tuples 95 95 polygon - list of vertices of polygon 96 closed - (optional) determine whether points on boundary should be 97 regarded as belonging to the polygon (closed = True) 98 or not (closed = False) 96 99 97 100 Output: … … 109 112 110 113 Remarks: 111 <Copy from source Franklins code > 114 The vertices may be listed clockwise or counterclockwise and 115 the first point may optionally be repeated. 116 Polygons do not need to be convex. 117 Polygons can have holes in them and points inside a hole is 118 regarded as being outside the polygon. 112 119 113 114 points at a vertex are considered to be inside115 120 116 Algorithm due to Darel Finley, http://www.alienryderflex.com/polygon/ 117 118 119 FIXME: More comments about algoritm 120 FIXME: Deal with case where point on border of polygon (closed) 121 121 Algorithm is based on work by Darel Finley, 122 http://www.alienryderflex.com/polygon/ 123 122 124 """ 123 125 … … 166 168 y = points[k, 1] 167 169 168 169 170 inside = False 170 171 for i in range(N): … … 187 188 if inside: indices.append(k) 188 189 189 #print x, y, polygon, inside190 191 192 190 if one_point: 193 191 return inside … … 222 220 Note: If two polygons overlap, the one last in the list takes precedence 223 221 224 Note: default can only be a constant.225 222 """ 226 223 … … 253 250 x = array(x).astype(Float) 254 251 y = array(y).astype(Float) 255 x = reshape(x, (len(x), 1)) 256 y = reshape(y, (len(y), 1)) 257 258 points = concatenate( (x,y), axis=1 ) 259 260 z = ones(x.shape[0], Float) * self.default 252 253 N = len(x) 254 assert len(y) == N 255 256 points = concatenate( (reshape(x, (N, 1)), 257 reshape(y, (N, 1))), axis=1 ) 258 259 if callable(self.default): 260 z = self.default(x,y) 261 else: 262 z = ones(N, Float) * self.default 263 261 264 for polygon, value in self.regions: 262 265 indices = inside_polygon(points, polygon) 263 for i in indices: 264 z[i] = value 265 266 #from sys import exit; exit() 266 267 #FIXME: This needs to be vectorised 268 if callable(value): 269 for i in indices: 270 xx = array([x[i]]) 271 yy = array([y[i]]) 272 z[i] = value(xx, yy)[0] 273 else: 274 for i in indices: 275 z[i] = value 276 267 277 return z 268 278
Note: See TracChangeset
for help on using the changeset viewer.