Changeset 6224
- Timestamp:
- Jan 21, 2009, 4:39:27 PM (16 years ago)
- Location:
- anuga_core/source/anuga/shallow_water
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/data_manager.py
r6215 r6224 988 988 989 989 990 def csv2building_polygons(file_name, floor_height=3): 990 def csv2building_polygons(file_name, 991 floor_height=3, 992 clipping_polygons=None): 991 993 """ 992 994 Convert CSV files of the form: … … 1009 1011 1010 1012 Optional parameter floor_height is the height of each building story. 1013 Optional parameter clipping_olygons is a list of polygons selecting 1014 buildings. Any building not in these polygons will be omitted. 1011 1015 1012 1016 See csv2polygons for more details 1013 1017 """ 1014 1018 1015 polygons, values = csv2polygons(file_name, value_name='floors') 1019 polygons, values = csv2polygons(file_name, 1020 value_name='floors', 1021 clipping_polygons=None) 1016 1022 1017 1023 … … 1027 1033 # @brief Convert CSV file into a dictionary of polygons and associated values. 1028 1034 # @param filename The path to the file to read, value_name name for the 4th column 1029 def csv2polygons(file_name, value_name='value'): 1035 def csv2polygons(file_name, 1036 value_name='value', 1037 clipping_polygons=None): 1030 1038 """ 1031 1039 Convert CSV files of the form: … … 1057 1065 Eastings and Northings will be returned as floating point values while 1058 1066 id and values will be returned as strings. 1067 1068 Optional argument: clipping_polygons will select only those polygons that are 1069 fully within one or more of the clipping_polygons. In other words any polygon from 1070 the csv file which has at least one point not inside one of the clipping polygons 1071 will be excluded 1059 1072 1060 1073 See underlying function csv2dict for more details. … … 1086 1099 1087 1100 # Loop through entries and compose polygons 1101 excluded_polygons={} 1088 1102 past_ids = {} 1089 1103 last_id = None … … 1107 1121 # Append this point to current polygon 1108 1122 point = [float(X['easting'][i]), float(X['northing'][i])] 1123 1124 if clipping_polygons is not None: 1125 exclude=True 1126 for clipping_polygon in clipping_polygons: 1127 if inside_polygon(point, clipping_polygon): 1128 exclude=False 1129 break 1130 1131 if exclude is True: 1132 excluded_polygons[id]=True 1133 1109 1134 polygons[id].append(point) 1110 1135 … … 1115 1140 1116 1141 last_id = id 1142 1143 # Weed out polygons that were not wholly inside clipping polygons 1144 for id in excluded_polygons: 1145 del polygons[id] 1117 1146 1118 1147 return polygons, values -
anuga_core/source/anuga/shallow_water/test_data_manager.py
r6215 r6224 11222 11222 11223 11223 11224 def test_csv2polygons_with_clipping(self): 11225 """test_csv2polygons with optional clipping 11226 """ 11227 #FIXME(Ole): Not Done!! 11228 11229 path = get_pathname_from_package('anuga.shallow_water') 11230 testfile = os.path.join(path, 'polygon_values_example.csv') 11231 11232 polygons, values = csv2polygons(testfile, 11233 value_name='floors', 11234 clipping_polygons=None) 11235 11236 assert len(polygons) == 7, 'Must have seven polygons' 11237 assert len(values) == 7, 'Must have seven values' 11238 11239 # Known floor values 11240 floors = {'1': 2, '2': 0, '3': 1, '4': 2, '5': 0, '8': 1, '9': 1} 11241 11242 # Known polygon values 11243 known_polys = {'1': [[422681.61,871117.55], 11244 [422691.02,871117.60], 11245 [422690.87,871084.23], 11246 [422649.36,871081.85], 11247 [422649.36,871080.39], 11248 [422631.86,871079.50], 11249 [422631.72,871086.75], 11250 [422636.75,871087.20], 11251 [422636.75,871091.50], 11252 [422649.66,871092.09], 11253 [422649.83,871084.91], 11254 [422652.94,871084.90], 11255 [422652.84,871092.39], 11256 [422681.83,871093.73], 11257 [422681.61,871117.55]], 11258 '2': [[422664.22,870785.46], 11259 [422672.48,870780.14], 11260 [422668.17,870772.62], 11261 [422660.35,870777.17], 11262 [422664.22,870785.46]], 11263 '3': [[422661.30,871215.06], 11264 [422667.50,871215.70], 11265 [422668.30,871204.86], 11266 [422662.21,871204.33], 11267 [422661.30,871215.06]], 11268 '4': [[422473.44,871191.22], 11269 [422478.33,871192.26], 11270 [422479.52,871186.03], 11271 [422474.78,871185.14], 11272 [422473.44,871191.22]], 11273 '5': [[422369.69,871049.29], 11274 [422378.63,871053.58], 11275 [422383.91,871044.51], 11276 [422374.97,871040.32], 11277 [422369.69,871049.29]], 11278 '8': [[422730.56,871203.13], 11279 [422734.10,871204.90], 11280 [422735.26,871202.18], 11281 [422731.87,871200.58], 11282 [422730.56,871203.13]], 11283 '9': [[422659.85,871213.80], 11284 [422660.91,871210.97], 11285 [422655.42,871208.85], 11286 [422654.36,871211.68], 11287 [422659.85,871213.80]] 11288 } 11289 11290 11291 11292 11293 for id in ['1', '2', '3', '4', '5' ,'8' ,'9']: 11294 assert id in polygons.keys() 11295 assert id in values.keys() 11296 11297 assert int(values[id]) == int(floors[id]) 11298 assert len(polygons[id]) == len(known_polys[id]) 11299 assert num.allclose(polygons[id], known_polys[id]) 11300 11301 11302 11303 11224 11304 11225 11305 def test_csv2building_polygons(self):
Note: See TracChangeset
for help on using the changeset viewer.