Changeset 3052 for inundation/utilities/polygon.py
- Timestamp:
- Jun 2, 2006, 1:12:20 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/utilities/polygon.py
r3051 r3052 43 43 44 44 45 def inside_polygon(points, polygon, closed = True, verbose = False, 45 def is_inside_polygon(point, polygon, closed=True, verbose=False, 46 points_geo_ref=None, polygon_geo_ref=None): 47 """Determine if one point is inside a polygon 48 49 See inside_polygon for more details 50 """ 51 52 indices = inside_polygon(point, polygon, closed, verbose, 53 points_geo_ref, polygon_geo_ref) 54 55 if indices.shape[0] == 1: 56 return True 57 elif indices.shape[0] == 0: 58 return False 59 else: 60 msg = 'is_inside_polygon must be invoked with one point only' 61 raise msg 62 63 64 def inside_polygon(points, polygon, closed=True, verbose=False, 46 65 points_geo_ref=None, polygon_geo_ref=None): 47 66 """Determine points inside a polygon … … 73 92 74 93 if len(points.shape) == 1: 75 one_point = True 76 points = reshape(points, (1,2)) 77 else: 78 one_point = False 94 # Only one point was passed in. Convert to array of points 95 points = reshape(points, (1,2)) 79 96 80 97 indices, count = separate_points_by_polygon(points, polygon, … … 82 99 verbose=verbose) 83 100 84 if one_point: 85 return count == 1 101 # Return indices of points inside polygon 102 return indices[:count] 103 104 105 106 def is_outside_polygon(point, polygon, closed=True, verbose=False, 107 points_geo_ref=None, polygon_geo_ref=None): 108 """Determine if one point is outside a polygon 109 110 See outside_polygon for more details 111 """ 112 113 indices = outside_polygon(point, polygon, closed, verbose) 114 #points_geo_ref, polygon_geo_ref) 115 116 if indices.shape[0] == 1: 117 return True 118 elif indices.shape[0] == 0: 119 return False 86 120 else: 87 return indices[:count] 121 msg = 'is_outside_polygon must be invoked with one point only' 122 raise msg 123 88 124 89 125 def outside_polygon(points, polygon, closed = True, verbose = False): … … 115 151 116 152 117 118 153 if len(points.shape) == 1: 119 one_point = True 120 points = reshape(points, (1,2)) 121 else: 122 one_point = False 154 # Only one point was passed in. Convert to array of points 155 points = reshape(points, (1,2)) 123 156 124 157 indices, count = separate_points_by_polygon(points, polygon, … … 126 159 verbose=verbose) 127 160 128 129 if one_point: 130 return count != 1 161 # Return indices of points outside polygon 162 if count == len(indices): 163 # No points are outside 164 return array([]) 131 165 else: 132 if count == len(indices): 133 # No points are outside 134 return [] 135 else: 136 return indices[count:][::-1] #return reversed 166 return indices[count:][::-1] #return reversed 137 167 138 168 … … 162 192 raise msg 163 193 164 165 166 194 if len(points.shape) == 1: 167 one_point = True 168 points = reshape(points, (1,2)) 169 else: 170 one_point = False 195 # Only one point was passed in. Convert to array of points 196 points = reshape(points, (1,2)) 197 171 198 172 199 indices, count = separate_points_by_polygon(points, polygon, 173 200 closed=closed, 174 201 verbose=verbose) 175 # Returns an array of points inside and an array of points outside 202 203 # Returns indices of points inside and indices of points outside 176 204 # the polygon 177 205 178 206 if count == len(indices): 179 207 # No points are outside … … 637 665 638 666 append = False 639 if i nside_polygon( [x,y], polygon):667 if is_inside_polygon([x,y], polygon): 640 668 641 669 append = True … … 644 672 if exclude is not None: 645 673 for ex_poly in exclude: 646 if i nside_polygon( [x,y], ex_poly):674 if is_inside_polygon([x,y], ex_poly): 647 675 append = False 648 676 … … 689 717 point = [x_delta, y_delta] 690 718 #print "point",point 691 if i nside_polygon( point, polygon, closed = False):719 if is_inside_polygon(point, polygon, closed=False): 692 720 raise Found 693 721 except Found:
Note: See TracChangeset
for help on using the changeset viewer.