- Timestamp:
- Oct 11, 2006, 10:22:45 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/geospatial_data/test_geospatial_data.py
r3736 r3738 395 395 [[0.5, 0.5], [1, -0.5], [1.5, 0]]) 396 396 397 def no_test_clip1(self): 397 def test_clip0_with_attributes(self): 398 """test_clip0_with_attributes(self): 399 400 Test that point sets with attributes can be clipped by a polygon 401 """ 402 403 from anuga.coordinate_transforms.geo_reference import Geo_reference 404 405 points = [[-1, 4], [0.2, 0.5], [1.0, 2.1], [0.4, 0.3], [3.0, 5.3], 406 [0, 0], [2.4, 3.3]] 407 408 attributes = [2, -4, 5, 76, -2, 0.1, 3] 409 att_dict = {'att1': attributes, 410 'att2': array(attributes)+1} 411 412 G = Geospatial_data(points, att_dict) 413 414 # First try the unit square 415 U = [[0,0], [1,0], [1,1], [0,1]] 416 assert allclose(G.clip(U).get_data_points(), [[0.2, 0.5], [0.4, 0.3], [0, 0]]) 417 assert allclose(G.clip(U).get_attributes('att1'), [-4, 76, 0.1]) 418 assert allclose(G.clip(U).get_attributes('att2'), [-3, 77, 1.1]) 419 420 # Then a more complex polygon 421 polygon = [[0,0], [1,0], [0.5,-1], [2, -1], [2,1], [0,1]] 422 points = [ [0.5, 1.4], [0.5, 0.5], [1, -0.5], [1.5, 0], [0.5, 1.5], [0.5, -0.5]] 423 424 # This time just one attribute 425 attributes = [2, -4, 5, 76, -2, 0.1] 426 G = Geospatial_data(points, attributes) 427 428 assert allclose(G.clip(polygon).get_data_points(), 429 [[0.5, 0.5], [1, -0.5], [1.5, 0]]) 430 assert allclose(G.clip(polygon).get_attributes(), [-4, 5, 76]) 431 432 433 def test_clip1(self): 398 434 """test_clip1(self): 399 435 … … 408 444 attributes = [2, -4, 5, 76, -2, 0.1, 3] 409 445 att_dict = {'att1': attributes, 410 'att2': array(attributes) 446 'att2': array(attributes)+1} 411 447 G = Geospatial_data(points, att_dict) 412 448 … … 417 453 418 454 assert allclose(G.clip(U).get_attributes('att1'), [-4, 76, 0.1]) 419 #assert allclose(G.clip(U).get_attributes('att2'), ???)455 assert allclose(G.clip(U).get_attributes('att2'), [-3, 77, 1.1]) 420 456 421 457 # Then a more complex polygon 422 458 points = [ [0.5, 1.4], [0.5, 0.5], [1, -0.5], [1.5, 0], [0.5, 1.5], [0.5, -0.5]] 423 G = Geospatial_data(points) 459 attributes = [2, -4, 5, 76, -2, 0.1] 460 G = Geospatial_data(points, attributes) 424 461 polygon = Geospatial_data([[0,0], [1,0], [0.5,-1], [2, -1], [2,1], [0,1]]) 425 462 … … 427 464 assert allclose(G.clip(polygon).get_data_points(), 428 465 [[0.5, 0.5], [1, -0.5], [1.5, 0]]) 466 assert allclose(G.clip(polygon).get_attributes(), [-4, 5, 76]) 467 429 468 430 469 def test_clip0_outside(self): … … 438 477 points = [[-1, 4], [0.2, 0.5], [1.0, 2.1], [0.4, 0.3], [3.0, 5.3], 439 478 [0, 0], [2.4, 3.3]] 440 G = Geospatial_data(points) 479 attributes = [2, -4, 5, 76, -2, 0.1, 3] 480 G = Geospatial_data(points, attributes) 441 481 442 482 # First try the unit square … … 444 484 assert allclose(G.clip_outside(U).get_data_points(), 445 485 [[-1, 4], [1.0, 2.1], [3.0, 5.3], [2.4, 3.3]]) 486 #print G.clip_outside(U).get_attributes() 487 assert allclose(G.clip_outside(U).get_attributes(), [2, 5, -2, 3]) 488 446 489 447 490 # Then a more complex polygon 448 491 polygon = [[0,0], [1,0], [0.5,-1], [2, -1], [2,1], [0,1]] 449 492 points = [ [0.5, 1.4], [0.5, 0.5], [1, -0.5], [1.5, 0], [0.5, 1.5], [0.5, -0.5]] 450 G = Geospatial_data(points) 493 attributes = [2, -4, 5, 76, -2, 0.1] 494 G = Geospatial_data(points, attributes) 451 495 452 496 assert allclose(G.clip_outside(polygon).get_data_points(), 453 [[0.5, 1.4], [0.5, 1.5], [0.5, -0.5]]) 497 [[0.5, 1.4], [0.5, 1.5], [0.5, -0.5]]) 498 assert allclose(G.clip_outside(polygon).get_attributes(), [2, -2, 0.1]) 454 499 455 500 … … 465 510 points = [[-1, 4], [0.2, 0.5], [1.0, 2.1], [0.4, 0.3], [3.0, 5.3], 466 511 [0, 0], [2.4, 3.3]] 467 G = Geospatial_data(points) 512 attributes = [2, -4, 5, 76, -2, 0.1, 3] 513 G = Geospatial_data(points, attributes) 468 514 469 515 # First try the unit square … … 471 517 assert allclose(G.clip_outside(U).get_data_points(), 472 518 [[-1, 4], [1.0, 2.1], [3.0, 5.3], [2.4, 3.3]]) 519 assert allclose(G.clip(U).get_attributes(), [-4, 76, 0.1]) 473 520 474 521 # Then a more complex polygon 475 522 points = [ [0.5, 1.4], [0.5, 0.5], [1, -0.5], [1.5, 0], [0.5, 1.5], [0.5, -0.5]] 476 G = Geospatial_data(points) 523 attributes = [2, -4, 5, 76, -2, 0.1] 524 G = Geospatial_data(points, attributes) 525 477 526 polygon = Geospatial_data([[0,0], [1,0], [0.5,-1], [2, -1], [2,1], [0,1]]) 478 527 … … 480 529 assert allclose(G.clip_outside(polygon).get_data_points(), 481 530 [[0.5, 1.4], [0.5, 1.5], [0.5, -0.5]]) 531 assert allclose(G.clip_outside(polygon).get_attributes(), [2, -2, 0.1]) 532 482 533 483 534 … … 493 544 points = [[-1, 4], [0.2, 0.5], [1.0, 2.1], [0.4, 0.3], [3.0, 5.3], 494 545 [0, 0], [2.4, 3.3]] 495 496 G = Geospatial_data(points )546 attributes = [2, -4, 5, 76, -2, 0.1, 3] 547 G = Geospatial_data(points, attributes) 497 548 498 549 # First try the unit square … … 500 551 G1 = G.clip(U) 501 552 assert allclose(G1.get_data_points(),[[0.2, 0.5], [0.4, 0.3], [0, 0]]) 553 assert allclose(G.clip(U).get_attributes(), [-4, 76, 0.1]) 502 554 503 555 G2 = G.clip_outside(U) 504 556 assert allclose(G2.get_data_points(),[[-1, 4], [1.0, 2.1], 505 557 [3.0, 5.3], [2.4, 3.3]]) 558 assert allclose(G.clip_outside(U).get_attributes(), [2, 5, -2, 3]) 506 559 507 560 … … 510 563 [[-1, 4], [1.0, 2.1], [3.0, 5.3], [2.4, 3.3]] 511 564 565 new_attributes = [-4, 76, 0.1, 2, 5, -2, 3] 566 512 567 assert allclose((G1+G2).get_data_points(), new_points) 568 assert allclose((G1+G2).get_attributes(), new_attributes) 513 569 514 570 G = G1+G2 … … 523 579 # Check result 524 580 assert allclose(G3.get_data_points(), new_points) 525 581 assert allclose(G3.get_attributes(), new_attributes) 526 582 527 583 os.remove(FN)
Note: See TracChangeset
for help on using the changeset viewer.