Changeset 2375 for inundation/utilities
- Timestamp:
- Feb 9, 2006, 2:37:57 PM (19 years ago)
- Location:
- inundation/utilities
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/utilities/polygon.py
r2351 r2375 333 333 Note: If two polygons overlap, the one last in the list takes precedence 334 334 335 FIXME? : Currently, coordinates specified here are assumed to be relative to the origin (georeference) used by domain. This function is more general than domain so perhaps it'd be an idea to allow the optional argument georeference??? 336 337 """ 338 339 def __init__(self, regions, default = 0.0): 335 Coordinates specified in the call are assumed to be relative to the origin (georeference) 336 e.g. used by domain. By specifying the optional argument georeference, all points are made relative. 337 338 FIXME: This should really work with geo_spatial point sets. 339 """ 340 341 def __init__(self, regions, default = 0.0, geo_reference = None): 340 342 341 343 try: … … 355 357 assert a == 2, 'Must have two component each: %s' %T 356 358 357 self.regions = regions 358 self.default = default 359 360 if geo_reference is None: 361 from coordinate_transforms.geo_reference import Geo_reference 362 geo_reference = Geo_reference() 363 364 365 self.default = default 366 367 #Make points in polygons relative to geo_reference 368 self.regions = [] 369 for polygon, value in regions: 370 P = geo_reference.change_points_geo_ref(polygon) 371 self.regions.append( (P, value) ) 372 373 359 374 360 375 … … 392 407 393 408 def read_polygon(filename): 394 """Read points assumed to form a polygon 395 There must be exactly two numbers in each line 409 """Read points assumed to form a polygon. 410 There must be exactly two numbers in each line separated by a comma. 411 No header. 396 412 """ 397 413 -
inundation/utilities/test_polygon.py
r2311 r2375 56 56 57 57 58 def test_polygon_function_georef(self): 59 """Check that georeferencing works 60 """ 61 62 from coordinate_transforms.geo_reference import Geo_reference 63 64 geo = Geo_reference(56, 200, 1000) 65 66 #Make points 'absolute' 67 p1 = [[200,1000], [210,1000], [210,1010], [200,1010]] 68 p2 = [[200,1000], [210,1010], [215,1005], [220, 1010], [225,1000], 69 [230,1010], [240,990]] 70 71 f = Polygon_function( [(p1, 1.0)], geo_reference = geo ) 72 z = f([5, 5, 27, 35], [5, 9, 8, -5]) #Two first inside p1 73 74 assert allclose(z, [1,1,0,0]) 75 76 77 f = Polygon_function( [(p2, 2.0)], geo_reference = geo ) 78 z = f([5, 5, 27, 35], [5, 9, 8, -5]) #First and last inside p2 79 assert allclose(z, [2,0,0,2]) 80 81 82 #Combined 83 f = Polygon_function( [(p1, 1.0), (p2, 2.0)], geo_reference = geo ) 84 z = f([5, 5, 27, 35], [5, 9, 8, -5]) 85 assert allclose(z, [2,1,0,2]) 86 87 88 #Check that it would fail without geo 89 f = Polygon_function( [(p1, 1.0), (p2, 2.0)]) 90 z = f([5, 5, 27, 35], [5, 9, 8, -5]) 91 assert not allclose(z, [2,1,0,2]) 92 93 94 58 95 def test_polygon_function_callable(self): 59 96 """Check that values passed into Polygon_function can be callable … … 84 121 z = f([5, 5, 27, 35], [5, 9, 8, -5]) 85 122 assert allclose(z, [2,14,35,2]) 123 86 124 87 125
Note: See TracChangeset
for help on using the changeset viewer.