Changeset 3177


Ignore:
Timestamp:
Jun 19, 2006, 10:30:57 AM (18 years ago)
Author:
duncan
Message:

added function to pmesh.mesh for adding vertices by passing in a geospatial instance.

Location:
inundation
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • inundation/geospatial_data/geospatial_data.py

    r3154 r3177  
    175175        # represent the new geo-ref
    176176        if  self.geo_reference is not None:
    177             #print "self.geo_reference",self.geo_reference
    178             #print "geo_reference",geo_reference
    179177            #FIXME: Maybe put out a warning here...
    180178            self.data_points = self.get_data_points \
    181179                               (geo_reference=geo_reference)
    182             #self.data_points = geo_reference.change_points_geo_ref \
    183             #                   (self.data_points,
    184             #                    self.geo_reference)
    185180           
    186181        self.geo_reference = geo_reference
     
    205200        returned coordinates are relative to the internal georeference's
    206201        xll and yll corners.
     202
     203        If a geo_reference is passed the points are returned relative
     204        to that geo_reference.
    207205
    208206        Default: absolute is True.
  • inundation/geospatial_data/test_geospatial_data.py

    r3154 r3177  
    921921        '''
    922922
    923         #FIXME (Ole): I changed the georeference arbitrarily, but the test still passes.
    924        
    925923        # create files
    926924        att_dict1 = {}
     
    934932        att_dict2['elevation'] = array([1.0, 15.0, 1.4])
    935933        att_dict2['brightness'] = array([14.0, 1.0, -12.4])
    936         geo_reference2 = Geo_reference(56, 1.0, 2.0) #FIXME (Ole): I changed this, why does it still pass
    937         #OK - it fails now, after the fix revealed by test_create_from_pts_file_with_geo')
     934        geo_reference2 = Geo_reference(56, 1.0, 2.0)
    938935
    939936        G1 = Geospatial_data(pointlist1, att_dict1, geo_reference1)
  • inundation/pmesh/mesh.py

    r3100 r3177  
    1313   Geoscience Australia
    1414"""
    15 import load_mesh.loadASCII
    16 import alpha_shape.alpha_shape
    1715
    1816import sys
     
    2927from coordinate_transforms.geo_reference import Geo_reference,DEFAULT_ZONE
    3028from utilities.polygon import point_in_polygon
     29import load_mesh.loadASCII
     30import alpha_shape.alpha_shape
     31from geospatial_data.geospatial_data import Geospatial_data, ensure_geospatial
    3132
    3233SET_COLOUR='red'
     
    609610
    610611   
    611    
     612    def add_vertices(self, data):
     613        data = ensure_geospatial(data)
     614
     615        # get points relative to the mesh geo_ref
     616        points = data.get_data_points(geo_reference=self.geo_reference)
     617        #FIXME finish....
     618   
     619        for point in points:
     620            v=Vertex(point[0], point[1])
     621            self.userVertices.append(v)
     622           
    612623    def add_hole_from_polygon(self, polygon, tags=None, geo_reference=None):
    613624        """
     
    853864       
    854865    def getUserVertices(self):
     866        """
     867        Note: The x,y values will be relative to the mesh geo_reference
     868        This returns a list of vertex objects
     869        """
    855870        return self.userVertices
     871
     872    def get_user_vertices(self, absolute=True):
     873        """
     874        This returns a list of (x,y) values
     875        (maybe it should return a geospatical object?
     876        It makes it a bit confusing though.)
     877        """
     878        pointlist=[]
     879        for vertex in self.userVertices:
     880            pointlist.append([vertex.x,vertex.y])
     881        spat = Geospatial_data(pointlist, geo_reference=self.geo_reference)
     882        return spat.get_data_points(absolute=absolute)
    856883   
    857884    def getUserSegments(self):
  • inundation/pmesh/test_mesh.py

    r3100 r3177  
    1111from load_mesh.loadASCII import *
    1212from coordinate_transforms.geo_reference import Geo_reference
     13from geospatial_data.geospatial_data import Geospatial_data
    1314from utilities.polygon import  is_inside_polygon ### inside_polygon
    1415
     
    20522053        self.failUnless(4==len(vert),
    20532054                        'FAILED!')
     2055   
     2056    def test_add_vertices(self):
     2057        points_ab = [[0.1,1],[0.4,.2],[7,5],[10,5]]
     2058        geo =  Geo_reference(56,23,21)
     2059        points = geo.change_points_geo_ref(points_ab)
     2060        spat = Geospatial_data(points, geo_reference=geo)
     2061       
     2062        geo_mesh =  Geo_reference(56,100,200)
     2063        m = Mesh(geo_reference=geo_mesh)
     2064        m.add_vertices(spat)
     2065
     2066        vert = m.getUserVertices()
     2067        #print "vert",vert
     2068        self.failUnless(4==len(vert),
     2069                        'FAILED!')
     2070        vert= m.get_user_vertices(absolute=True)
     2071        self.failUnless(vert==points_ab,
     2072                        'FAILED!')
     2073       
     2074     
     2075    def test_get_user_vertices(self):
     2076        points_ab = [[0.1,1],[0.4,.2],[7,5],[10,5]]
     2077        geo =  Geo_reference(56,23,21)
     2078        points = geo.change_points_geo_ref(points_ab)
     2079        spat = Geospatial_data(points, geo_reference=geo)
     2080       
     2081        geo_mesh =  Geo_reference(56,100,200)
     2082        m = Mesh(geo_reference=geo_mesh)
     2083        m.add_vertices(spat)
     2084
     2085        vert = m.getUserVertices()
     2086        #print "vert",vert
     2087        self.failUnless(4==len(vert),
     2088                        'FAILED!')
     2089        vert= m.get_user_vertices(absolute=True)
     2090        self.failUnless(vert==points_ab,
     2091                        'FAILED!')
     2092        vert= m.get_user_vertices(absolute=False)
     2093        points_new = m.geo_reference.get_absolute(vert)
     2094       
     2095        self.failUnless(points_ab==points_new,
     2096                        'FAILED!')
     2097       
    20542098       
    20552099def list_comp(A,B):
Note: See TracChangeset for help on using the changeset viewer.