Ignore:
Timestamp:
Feb 14, 2006, 3:29:10 PM (19 years ago)
Author:
duncan
Message:

added auto geo-reffing in create_mesh_from_regions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/pmesh/mesh_interface.py

    r2401 r2402  
    44#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    55
    6 from coordinate_transforms.geo_reference import Geo_reference
     6from coordinate_transforms.geo_reference import Geo_reference,DEFAULT_ZONE
    77from utilities.polygon import populate_polygon
     8from utilities.numerical_tools import ensure_numeric
     9from Numeric import Float
    810
    911# This is due to pmesh being a package and a module and
     
    1315except ImportError: 
    1416    from mesh import Mesh
    15    
     17
     18
    1619def create_mesh_from_regions(bounding_polygon,
    1720                             boundary_tags,
     
    2427    """Create mesh from bounding polygons, and resolutions.
    2528
    26     Polygon is a list of points in Eastings and Northings, absolute
     29    bounding_polygon is a list of points in Eastings and Northings,
     30    relative to the poly_geo_reference.
    2731
    2832    Boundary tags is a dictionary of symbolic tags. For every tag there
     
    3943
    4044    poly_geo_reference is the geo_reference of the polygons.
    41     If none, assume absolute.
     45    If none, assume absolute.  Please pass one though, since absolute
     46    references have a zone.
    4247   
    4348    mesh_geo_reference is the geo_reference of the mesh to be created.
    44     If none, assume absolute.
     49    If none is given one will be automatically generated.  It was use
     50    the lower left hand corner of  bounding_polygon (absolute)
     51    as the x and y values for the geo_ref.
    4552   
    4653    Returns the mesh instance if no finename is given
    4754   
    4855    """
     56    #FIXME (OLE-DSG)
    4957    # To do make maximum_triangle_area optional?
    5058    # check the segment indexes - throw an error if they are out of bounds
    51 
    52     #IDEA (Ole): Let us work out what the mesh_geo_reference is automatically:
    53     #If bounding_polygon is absolute it would look as follows:
    54     #
    55     #from utilities.numerical_tools import ensure_numeric   
    56     #bounding_polygon = ensure_numeric(bounding_polygon) #Make it Numeric
    57     #xllcorner = min(bounding_polygon[:,0])
    58     #yllcorner = min(bounding_polygon[:,1])   
    59     #
    60     #mesh_geo_reference = Geo_reference(xllcorner = xllcorner,
    61     #                                   yllcorner = yllcorner,
    62     #                                   zone = "zone from bounding polygon")
    6359    #
    6460    #In addition I reckon the polygons could be of class Geospatial_data
     61
     62    if mesh_geo_reference is None:
     63        bounding_polygon = ensure_numeric(bounding_polygon, Float)
     64        xllcorner = min(bounding_polygon[:,0])
     65        yllcorner = min(bounding_polygon[:,1])   
     66        #
     67        if poly_geo_reference is None:
     68            zone = DEFAULT_ZONE
     69        else:
     70            zone = poly_geo_reference.get_zone()
     71            [(xllcorner,yllcorner)] = poly_geo_reference.get_absolute( \
     72            [(xllcorner,yllcorner)])
     73        # create a geo_ref, based on the llc of the bounding_polygon
     74        mesh_geo_reference = Geo_reference(xllcorner = xllcorner,
     75                                       yllcorner = yllcorner,
     76                                       zone = zone)
    6577
    6678    m = Mesh(geo_reference=mesh_geo_reference)
     
    118130    else:
    119131        m.export_mesh_file(filename)
     132
     133
Note: See TracChangeset for help on using the changeset viewer.