Changeset 2297
- Timestamp:
- Jan 27, 2006, 1:41:52 PM (19 years ago)
- Location:
- inundation/pmesh
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/pmesh/mesh.py
r2276 r2297 598 598 return h 599 599 600 def add_hole(self, x,y, geo_reference=None): 601 """ 602 adds a point, which represents a hole. 603 604 The point data can have it's own geo_refernece. 605 If geo_reference is None the data is asumed to be absolute 606 """ 607 [[x,y]] = self.geo_reference.change_points_geo_ref([x,y], 608 points_geo_ref=geo_reference) 609 return self._addHole(x, y) 610 600 611 def _addRegion(self, x,y): 601 612 h=Region(x, y) … … 618 629 print "depreciated, use add_region" 619 630 return self.add_region(x,y) 620 621 def add_region_from_polygon(self, polygon, tags=None, 622 max_triangle_area=None, geo_reference=None): 631 632 633 634 def add_hole_from_polygon(self, polygon, tags=None, geo_reference=None): 623 635 """ 624 636 Add a polygon with tags to the current mesh, as a region. … … 635 647 636 648 This returns the region instance, so if the user whats to modify 649 it they can. 650 """ 651 return self._add_area_from_polygon(polygon, tags=tags, 652 hole=True, 653 geo_reference=geo_reference 654 ) 655 656 657 def add_region_from_polygon(self, polygon, tags=None, 658 max_triangle_area=None, geo_reference=None): 659 """ 660 Add a polygon with tags to the current mesh, as a region. 661 The maxArea of the region can be specified. 662 663 If a geo_reference of the polygon points is given, this is used. 664 If not; 665 The x,y info is assumed to be Easting and Northing, absolute, 666 for the meshes zone. 667 668 polygon a list of points, in meters that describe the polygon 669 (e.g. [[x1,y1],[x2,y2],...] 670 tags (e.g.{'wall':[0,1,3],'ocean':[2]}) 671 672 This returns the region instance (if a max_triangle_area is given), 673 so if the user whats to modify it they can. 674 """ 675 return self._add_area_from_polygon(polygon, tags=tags, 676 max_triangle_area=max_triangle_area, 677 geo_reference=geo_reference) 678 679 def _add_area_from_polygon(self, polygon, tags=None, 680 max_triangle_area=None, 681 geo_reference=None, 682 hole=False): 683 """ 684 Add a polygon with tags to the current mesh, as a region. 685 The maxArea of the region can be specified. 686 687 If a geo_reference of the polygon points is given, this is used. 688 If not; 689 The x,y info is assumed to be Easting and Northing, absolute, 690 for the meshes zone. 691 692 polygon a list of points, in meters that describe the polygon 693 (e.g. [[x1,y1],[x2,y2],...] 694 tags (e.g.{'wall':[0,1,3],'ocean':[2]}) 695 696 This returns the region instance, so if the user whats to modify 637 697 it they can. 638 698 639 699 """ 640 #take into account georef on mesh side641 #polygon = self.geo_reference.change_points_geo_ref(polygon,642 # points_geo_ref=geo_reference)643 #print "polygon - should be relative to poly geo_ref",polygon644 645 700 #get absolute values 646 701 if geo_reference is not None: 647 702 polygon = geo_reference.get_absolute(polygon) 648 703 # polygon is now absolute 649 #print "polygon should be absolute",polygon 704 #print "polygon should be absolute",polygon 705 650 706 #create points, segs and tags 651 707 region_dict = {} … … 681 737 inner = None 682 738 683 if max_triangle_area is not None :739 if max_triangle_area is not None and hole is False: 684 740 #get inner point - absolute values 685 741 inner_point = point_in_polygon(polygon) … … 687 743 geo_reference=None) 688 744 inner.setMaxArea(max_triangle_area) 745 746 if hole is True: 747 #get inner point - absolute values 748 inner_point = point_in_polygon(polygon) 749 inner = self.add_hole(inner_point[0], inner_point[1], 750 geo_reference=None) 689 751 690 752 return inner … … 744 806 def generate_mesh(self, 745 807 maximum_triangle_area=None, 746 minimum_triangle_angle= None,808 minimum_triangle_angle=28.0, 747 809 verbose=False): 748 810 if verbose is True: -
inundation/pmesh/test_mesh.py
r2282 r2297 1793 1793 1794 1794 1795 def test_add_hole_from_polygon(self): 1796 x=-500 1797 y=-1000 1798 m=Mesh(geo_reference=Geo_reference(56,x,y)) 1799 1800 # These are the absolute values 1801 polygon_absolute = [[0,0],[1,0],[1,1],[0,1]] 1802 1803 x_p = -10 1804 y_p = -40 1805 geo_ref_poly = Geo_reference(56, x_p, y_p) 1806 polygon = geo_ref_poly.change_points_geo_ref(polygon_absolute) 1807 1808 poly_point = m.add_hole_from_polygon(polygon, 1809 {'tagin':[0,1],'bom':[2]}, 1810 geo_reference=geo_ref_poly) 1811 # poly_point values are relative to the mesh geo-ref 1812 # make them absolute 1813 #print "poly_point.x+x",poly_point.x+x 1814 #print "polygon_absolute", polygon_absolute 1815 self.failUnless(inside_polygon([poly_point.x+x,poly_point.y+y], 1816 polygon_absolute, closed = False), 1817 'FAILED!') 1818 1819 self.failUnless(len(m.holes)==1, 1820 'FAILED!') 1821 segs = m.getUserSegments() 1822 self.failUnless(len(segs)==4, 1823 'FAILED!') 1824 self.failUnless(len(m.userVertices)==4, 1825 'FAILED!') 1826 self.failUnless(segs[0].tag=='tagin', 1827 'FAILED!') 1828 self.failUnless(segs[1].tag=='tagin', 1829 'FAILED!') 1830 1831 self.failUnless(segs[2].tag=='bom', 1832 'FAILED!') 1833 self.failUnless(segs[3].tag=='', 1834 'FAILED!') 1835 verts = m.getUserVertices() 1836 #print "User verts",verts 1837 #print 'polygon',polygon 1838 #vert values are relative 1839 for point,new_point in map(None,polygon,verts): 1840 point_x = point[0] + geo_ref_poly.get_xllcorner() 1841 new_point_x = new_point.x + m.geo_reference.get_xllcorner() 1842 point_y = point[1] + geo_ref_poly.get_yllcorner() 1843 #print "new_point.y",new_point.y 1844 #print "m.geo_ref.get_yllcorner()",m.geo_reference.get_yllcorner() 1845 new_point_y = new_point.y + m.geo_reference.get_yllcorner() 1846 #print "point_y",point_y 1847 #print "new_point_y",new_point_y 1848 1849 self.failUnless(point_x == new_point_x, ' failed') 1850 self.failUnless(point_y == new_point_y, ' failed') 1851 1852 1795 1853 1796 1854 def list_comp(A,B):
Note: See TracChangeset
for help on using the changeset viewer.