Changeset 3072


Ignore:
Timestamp:
Jun 5, 2006, 12:03:41 PM (18 years ago)
Author:
ole
Message:

Made boundary polygon return absolute UTM coordinates as per ticket:81

Location:
inundation/pyvolution
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • inundation/pyvolution/general_mesh.py

    r2866 r3072  
     1
     2from Numeric import concatenate, reshape, take
     3from Numeric import array, zeros, Int, Float, sqrt, sum
    14
    25from coordinate_transforms.geo_reference import Geo_reference
     
    6568
    6669        if verbose: print 'General_mesh: Building basic mesh structure'
    67 
    68         from Numeric import array, zeros, Int, Float, sqrt, sum
    6970
    7071        self.triangles = array(triangles,Int)
     
    192193
    193194
    194     def get_vertex_coordinates(self, obj = False):
     195    def get_vertex_coordinates(self, obj=False, absolute=False):
    195196        """Return all vertex coordinates.
    196197        Return all vertex coordinates for all triangles as an Nx6 array
     
    202203        FIXME - Maybe use something referring to unique vertices?
    203204
    204        
    205         """
     205        Boolean keyword argument absolute determines whether coordinates
     206        are to be made absolute by taking georeference into account       
     207        """
     208
     209        V = self.vertex_coordinates
     210        if absolute is True:
     211            V0 = self.geo_reference.get_absolute(V[:,0:2])
     212            V1 = self.geo_reference.get_absolute(V[:,2:4])
     213            V2 = self.geo_reference.get_absolute(V[:,4:6])           
     214           
     215            V = concatenate( (V0, V1, V2), axis=1 )
     216
    206217
    207218        if obj is True:
    208             from Numeric import concatenate, reshape
    209             V = self.vertex_coordinates
    210219            #return concatenate( (V[:,0:2], V[:,2:4], V[:,4:6]), axis=0)
    211220
     
    213222            return reshape(V, (3*N, 2))
    214223        else:   
    215             return self.vertex_coordinates
    216 
    217 
    218     def get_vertex_coordinate(self, i, j):
     224            return V
     225
     226
     227    def get_vertex_coordinate(self, i, j, absolute=False):
    219228        """Return coordinates for vertex j of the i'th triangle.
    220229        Return value is the numeric array slice [x, y]
    221230        """
    222         return self.vertex_coordinates[i, 2*j:2*j+2]
     231
     232        V = self.get_vertex_coordinates(absolute=absolute)
     233        return V[i, 2*j:2*j+2]
     234   
     235        ##return self.vertex_coordinates[i, 2*j:2*j+2]
    223236
    224237
     
    231244        #See quantity.get_vertex_values
    232245        #FIXME (Ole) - oh yes they should
    233 
    234         from Numeric import zeros, Float
    235246
    236247        N = self.number_of_elements
     
    251262        """
    252263
    253         from Numeric import take
    254 
    255264        if (indices ==  None):
    256265            indices = range(len(self))  #len(self)=number of elements
     
    259268
    260269    #FIXME - merge these two (get_vertices and get_triangles)
    261     def get_triangles(self, obj = False):
     270    def get_triangles(self, obj=False):
    262271        """Get connetivity
    263272        Return triangles (triplets of indices into point coordinates)
     
    269278
    270279        if obj is True:
    271             from Numeric import array, reshape, Int       
    272280            m = len(self)  #Number of triangles
    273281            M = 3*m        #Total number of unique vertices
     
    320328
    321329
    322     def get_extent(self):
     330    def get_extent(self, absolute=False):
    323331        """Return min and max of all x and y coordinates
    324         """
    325 
    326 
    327         C = self.get_vertex_coordinates()
     332
     333        Boolean keyword argument absolute determines whether coordinates
     334        are to be made absolute by taking georeference into account
     335        """
     336       
     337
     338
     339        C = self.get_vertex_coordinates(absolute=absolute)
    328340        X = C[:,0:6:2].copy()
    329341        Y = C[:,1:6:2].copy()
  • inundation/pyvolution/mesh.py

    r3062 r3072  
    426426
    427427
    428     def get_boundary_polygon(self, verbose = False):
     428    def get_boundary_polygon(self, verbose=False):
    429429        """Return bounding polygon for mesh (counter clockwise)
    430430
     
    432432        If multiple vertex values are present, the algorithm will select the
    433433        path that contains the mesh.
     434
     435        All points are in absolute UTM coordinates
    434436        """
    435437       
     
    438440
    439441
    440         # FIXME (Ole): Make sure all points are absolute UTM   
    441        
    442442        # Get mesh extent
    443         xmin, xmax, ymin, ymax = self.get_extent() # FIXME: Make Absolute
     443        xmin, xmax, ymin, ymax = self.get_extent(absolute=True)
    444444        pmin = ensure_numeric([xmin, ymin])
    445445        pmax = ensure_numeric([xmax, ymax])       
     
    456456            if edge_id == 2: a = 0; b = 1
    457457
    458             # FIXME: Make Absolute
    459             A = self.get_vertex_coordinate(i, a) # Start
    460             B = self.get_vertex_coordinate(i, b) # End
     458            A = self.get_vertex_coordinate(i, a, absolute=True) # Start
     459            B = self.get_vertex_coordinate(i, b, absolute=True) # End
     460
    461461
    462462            # Take the point closest to pmin as starting point
     
    488488
    489489
    490 
     490           
    491491        #Start with smallest point and follow boundary (counter clock wise)
    492492        polygon = [p0]      # Storage for final boundary polygon
    493         point_registry = {} # Keep track of storage to avoid multiple runs around boundary
    494                             # This will only be the case if there are more than one candidate
    495                             # FIXME (Ole): Perhaps we can do away with polygon and use
    496                             # only point_registry to save space.
     493        point_registry = {} # Keep track of storage to avoid multiple runs around
     494                            # boundary. This will only be the case if there are
     495                            # more than one candidate.
     496                            # FIXME (Ole): Perhaps we can do away with polygon
     497                            # and use only point_registry to save space.
    497498
    498499        point_registry[tuple(p0)] = 0                           
     
    509510
    510511                if verbose:
    511                     print 'Point %s has multiple candidates: %s' %(str(p0), candidate_list)
     512                    print 'Point %s has multiple candidates: %s'\
     513                          %(str(p0), candidate_list)
    512514
    513515
     
    516518                    v_prev = p0 - polygon[-2] # Vector that leads to p0
    517519                else:
    518                     # FIXME (Ole): What do we do if the first point has multiple candidates?
     520                    # FIXME (Ole): What do we do if the first point has multiple
     521                    # candidates?
    519522                    # Being the lower left corner, perhaps we can use the
    520523                    # vector [1, 0], but I really don't know if this is completely
     
    530533                    vc = pc-p0  # Candidate vector
    531534                   
    532                     # Angle between each candidate and the previous vector in [-pi, pi]
     535                    # Angle between each candidate and the previous vector
     536                    # in [-pi, pi]
    533537                    ac = angle(vc, v_prev)
    534538                    if ac > pi: ac = pi-ac
  • inundation/pyvolution/test_mesh.py

    r3057 r3072  
    944944                        'FAILED!')
    945945
    946     def FIXME_test_mesh_get_boundary_polygon_with_georeferencing(self):
     946    def test_mesh_get_boundary_polygon_with_georeferencing(self):
    947947     
    948948        # test
     
    957957
    958958        relative_points = geo.change_points_geo_ref(absolute_points)
    959         #relative_points = absolute_points #uncomment to make test pass!
     959
     960        #print 'Relative', relative_points
     961        #print 'Absolute', absolute_points       
     962
    960963        mesh = Mesh(relative_points, vertices, geo_reference=geo)
    961964        boundary_polygon = mesh.get_boundary_polygon()
     965
    962966        assert allclose(absolute_points, boundary_polygon)
     967       
    963968#-------------------------------------------------------------
    964969if __name__ == "__main__":
    965     #suite = unittest.makeSuite(Test_Mesh,'test_boundary_polygon')
     970    #suite = unittest.makeSuite(Test_Mesh,'test_mesh_get_boundary_polygon_with_georeferencing')
    966971    suite = unittest.makeSuite(Test_Mesh,'test')
    967972    runner = unittest.TextTestRunner()
Note: See TracChangeset for help on using the changeset viewer.