Changeset 2062
- Timestamp:
- Nov 24, 2005, 1:05:20 PM (19 years ago)
- Location:
- inundation
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/pyvolution/data_manager.py
r2061 r2062 1480 1480 from Numeric import array2string 1481 1481 1482 from utilities.polygon import inside_polygon 1482 from utilities.polygon import inside_polygon, outside_polygon, separate_points_by_polygon 1483 1483 from util import apply_expression_to_dictionary 1484 1484 … … 1676 1676 1677 1677 1678 #Assign NODATA_value to all points outside bounding polygon (from interpolation mesh)1679 P = interp.mesh.get_boundary_polygon()1680 inside_indices = inside_polygon(grid_points, P)1681 1682 #FIXME: Remove when new interpolation takes care of this1683 for i in range(nrows):1684 if verbose and i%((nrows+10)/10)==0:1685 print 'Doing row %d of %d' %(i, nrows)1686 1687 base_index = (nrows-i-1)*ncols1688 for j in range(ncols):1689 index = base_index+j1690 1691 if not sometrue(inside_indices == index):1692 grid_values[index] = NODATA_value1693 1694 #############1695 1696 1697 1698 1678 if verbose: 1699 1679 print 'Interpolated values are in [%f, %f]' %(min(grid_values), 1700 1680 max(grid_values)) 1681 1682 #Assign NODATA_value to all points outside bounding polygon (from interpolation mesh) 1683 P = interp.mesh.get_boundary_polygon() 1684 outside_indices = outside_polygon(grid_points, P, closed=True) 1685 1686 for i in outside_indices: 1687 grid_values[i] = NODATA_value 1688 1689 1690 1701 1691 1702 1692 if format.lower() == 'ers': -
inundation/pyvolution/test_data_manager.py
r2061 r2062 3590 3590 suite = unittest.makeSuite(Test_Data_Manager,'test') 3591 3591 #suite = unittest.makeSuite(Test_Data_Manager,'test_sww2dem_asc_missing_points') 3592 #suite = unittest.makeSuite(Test_Data_Manager,'test_sww2dem_ boundingbox')3592 #suite = unittest.makeSuite(Test_Data_Manager,'test_sww2dem_asc_elevation') 3593 3593 #suite = unittest.makeSuite(Test_Data_Manager,'test_dem2pts_bounding_box') 3594 3594 #suite = unittest.makeSuite(Test_Data_Manager,'test_decimate_dem') -
inundation/utilities/polygon.py
r1911 r2062 116 116 return count != 1 117 117 else: 118 return indices[count:][::-1] #return reversed 118 if count == len(indices): 119 # No points are outside 120 return [] 121 else: 122 return indices[count:][::-1] #return reversed 119 123 120 124 -
inundation/utilities/test_polygon.py
r1910 r2062 247 247 #evaluate to True as the point 0.5, 1.0 is outside the unit square 248 248 249 def test_all_outside_polygon(self): 250 """Test case where all points are outside poly 251 """ 252 253 U = [[0,0], [1,0], [1,1], [0,1]] #Unit square 254 255 points = [[2,2], [1,3], [-1,1], [0,2]] #All outside 256 257 258 indices, count = separate_points_by_polygon(points, U) 259 #print indices, count 260 assert count == 0 #None inside 261 assert allclose(indices, [3,2,1,0]) 262 263 indices = outside_polygon(points, U, closed = True) 264 assert allclose(indices, [0,1,2,3]) 265 266 indices = inside_polygon(points, U, closed = True) 267 assert allclose(indices, []) 268 269 270 def test_all_inside_polygon(self): 271 """Test case where all points are inside poly 272 """ 273 274 U = [[0,0], [1,0], [1,1], [0,1]] #Unit square 275 276 points = [[0.5,0.5], [0.2,0.3], [0,0.5]] #All inside (or on edge) 277 278 279 indices, count = separate_points_by_polygon(points, U) 280 assert count == 3 #All inside 281 assert allclose(indices, [0,1,2]) 282 283 indices = outside_polygon(points, U, closed = True) 284 assert allclose(indices, []) 285 286 indices = inside_polygon(points, U, closed = True) 287 assert allclose(indices, [0,1,2]) 288 289 249 290 def test_separate_points_by_polygon(self): 250 291 U = [[0,0], [1,0], [1,1], [0,1]] #Unit square
Note: See TracChangeset
for help on using the changeset viewer.