Changeset 2590
- Timestamp:
- Mar 24, 2006, 2:43:10 PM (19 years ago)
- Location:
- inundation/geospatial_data
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/geospatial_data/geospatial_data.py
r2584 r2590 169 169 170 170 def get_data_points(self, absolute = True): 171 """Get coordinates for all data points as an Nx2 array 172 173 If absolute is True absolute UTM coordinates are returned otherwise 174 returned coordinates are relative to the internal georeference's 175 xll and yll corners. 176 177 Default: absolute is True. 178 """ 171 179 if absolute is True: 172 180 xll = self.geo_reference.xllcorner 173 181 yll = self.geo_reference.yllcorner 174 182 return self.data_points + [xll, yll] 175 176 183 else: 177 184 return self.data_points … … 224 231 225 232 if zone1 == zone2: 226 a_rel_points = self.get_data_points() 227 b_rel_points = other.get_data_points() 228 229 # subtracts xll and yll from self's and other's 230 # reletive data point and concatenates 231 c_points = concatenate((a_rel_points-[xll, yll], 232 b_rel_points-[xll, yll]), axis = 0) 233 a_absolute_points = self.get_data_points(absolute=True) 234 b_absolute_points = other.get_data_points(absolute=True) 235 236 # subtract xll and yll from self's and other's 237 # absolute data points and concatenate 238 c_points = concatenate((a_absolute_points-[xll, yll], 239 b_absolute_points-[xll, yll]), 240 axis = 0) 233 241 234 242 new_attributes = {} … … 388 396 line = fd.readline() 389 397 numbers = clean_line(line,delimiter) 390 print 'read xya numbers', numbers398 #print 'read xya numbers', numbers 391 399 while len(numbers) > 1: 392 400 if numbers != []: … … 588 596 that are shared. This will require some work and maybe __subtract__ function 589 597 ''' 590 # print 'load %s' %add_file1591 # if access(add_file1,F_OK) == 1 :592 # print'file1', add_file1593 594 # print'file1 again', add_file1595 # print'file2 again', add_file2596 print 'create G1'597 598 G1 = Geospatial_data(file_name = add_file1) 598 599 # print 'G1 dict'600 # G1_points_dict = geospatial_data2points_dictionary(G1)601 602 # print 'G1 xya file'603 # export_points_file("v:\inundation\onslow_tsunami_scenario_2006\\topographies\onshore.xya", G1_points_dict)604 605 print 'create G2'606 # print 'load %s' %add_file2607 # if access(add_file2,F_OK) == 1 :608 # print'file2', add_file2609 599 G2 = Geospatial_data(file_name = add_file2) 610 print 'G2 dict'611 # G2_points_dict = geospatial_data2points_dictionary(G2)612 613 600 new_add_file2 = add_file2[:-4] + '.pts' 614 print 'G2 pts file', new_add_file2 615 616 # export_points_file(new_add_file2, G2_points_dict) 617 print 'G1+g2' 601 618 602 G = G1 + G2 603 619 604 #FIXME remove dependance on points to dict in export only! 620 605 G_points_dict = geospatial_data2points_dictionary(G) 621 622 606 export_points_file(results_file, G_points_dict) 623 607 -
inundation/geospatial_data/test_geospatial_data.py
r2589 r2590 202 202 [1.0, 2.1], [3.0, 5.3]]) 203 203 204 def test_add 1(self):204 def test_add_with_geo (self): 205 205 """ 206 206 Difference in Geo_reference resolved … … 208 208 points1 = [[1.0, 2.1], [3.0, 5.3]] 209 209 points2 = [[5.0, 6.1], [6.0, 3.3]] 210 attributes1 = [2, 4]210 attributes1 = [2, 4] 211 211 attributes2 = [5, 76] 212 212 geo_ref1= Geo_reference(55, 1.0, 2.0) 213 geo_ref2 = Geo_reference(zone = 55, xllcorner = 0.1, 214 yllcorner = 3.0, datum = 'wgs84', 215 projection = 'UTM', units = 'm') 213 geo_ref2 = Geo_reference(zone=55, 214 xllcorner=0.1, 215 yllcorner=3.0, 216 datum='wgs84', 217 projection='UTM', 218 units='m') 216 219 217 220 G1 = Geospatial_data(points1, attributes1, geo_ref1) 218 221 G2 = Geospatial_data(points2, attributes2, geo_ref2) 219 222 223 #Check that absolute values are as expected 224 P1 = G1.get_data_points(absolute=True) 225 assert allclose(P1, [[2.0, 4.1], [4.0, 7.3]]) 226 227 P2 = G2.get_data_points(absolute=True) 228 assert allclose(P2, [[5.1, 9.1], [6.1, 6.3]]) 229 220 230 G = G1 + G2 221 231 222 232 assert allclose(G.get_geo_reference().get_xllcorner(), 0.1) 223 233 assert allclose(G.get_geo_reference().get_yllcorner(), 2.0) 224 # print 'G data points=', G.get_data_points() 225 assert allclose(G.get_data_points(), [[2.0, 4.1], [4.0, 7.3], [5.1, 9.1], [6.1, 6.3]]) 226 234 235 P = G.get_data_points(absolute=True) 236 assert allclose(P, concatenate( (P1,P2) )) 237 238 P_relative = G.get_data_points(absolute=False) 239 assert allclose(P_relative, P - [0.1, 2.0]) 240 assert allclose(P, [[2.0, 4.1], [4.0, 7.3], 241 [5.1, 9.1], [6.1, 6.3]]) 227 242 228 243
Note: See TracChangeset
for help on using the changeset viewer.