Ignore:
Timestamp:
Sep 28, 2005, 6:00:46 PM (19 years ago)
Author:
ole
Message:

Better interface to meshing for karratha + some pypar work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • production/karratha_2005/create_mesh.py

    r1837 r1855  
    1111
    1212
    13 
    14 def create_mesh(polygon, tags, resolution, filename = None):
    15     """Create mesh from bounding polygon, tags for all segments and resolution.
    16 
    17     Polygon is a list of points in latitude and longitudes - decimal degrees
    18 
    19 
    20     Tags is a list of symbolic tags
    21 
    22     Resolution is the maximal area
    23    
    24 
    25     FIXME - FUTURE:
    26       Use class Point_set
    27       Take multiple polygons
    28 
    29       Accept deg, min, sec, e.g.
    30       [ [(-20,30,55), (116, 20, 00)], ...]
    31      
    32    
    33     """
    34 
    35     from pmesh.mesh import *
    36     from pyvolution.coordinate_transforms.redfearn import redfearn
    37    
    38 
    39     #Convert to UTM
    40     import project
    41     refzone = project.refzone  #FIXME
    42 
    43 
     13def convert_points_from_latlon_to_utm(polygon, refzone):
    4414    points = []
    4515    for point in polygon:
     
    4818        points.append([easting, northing])
    4919
    50     polygon = points   
     20    return points   
    5121
    52    
    53     mesh_origin = project.mesh_origin
    5422
    55     geo = Geo_reference(xllcorner = mesh_origin[1],  #From dem
    56                         yllcorner = mesh_origin[2],
    57                         zone = refzone)
    58    
     23
     24
     25
     26def create_region(polygon, tags, refzone):
     27    """Create dictionary representation of region bounded by given polygon for use with pmesh
     28    """
     29
    5930
    6031    #
     
    7748    #Create tags
    7849    #E.g. ['wall', 'wall', 'ocean', 'wall']
    79     segment_tags = [0]*N
    80     for key in tags:
    81         indices = tags[key]
    82         for i in indices:
    83             segment_tags[i] = key
     50
     51    if tags is not None:
     52        segment_tags = [0]*N
     53        for key in tags:
     54            indices = tags[key]
     55            for i in indices:
     56                segment_tags[i] = key
    8457   
    85     dict['segment_tags'] = segment_tags
     58        dict['segment_tags'] = segment_tags
    8659
     60
     61
     62    return dict
     63
     64
     65
     66def create_mesh(bounding_polygon, boundary_tags, resolution,
     67                filename = None, interior_regions = None):
     68    """Create mesh from bounding polygon, tags for all segments and resolution.
     69
     70    Polygon is a list of points in latitude and longitudes - decimal degrees
     71
     72
     73    Tags is a list of symbolic tags
     74
     75    Resolution is the maximal area
     76
     77    Interior_regions is a list of tuples consisting of (polygon, resolution)
     78
     79    This function does not allow segments to share points - use underlying
     80    pmesh functionality for that
     81
     82    FIXME - FUTURE:
     83      Use class Point_set
     84      Take multiple polygons
     85
     86      Accept deg, min, sec, e.g.
     87      [ [(-20,30,55), (116, 20, 00)], ...]
     88
     89
     90    FIXME: This whole thing needs to be completely rethought
     91   
     92    """
     93
     94    from pmesh.mesh import *
     95    from pyvolution.coordinate_transforms.redfearn import redfearn
     96    from pyvolution.util import populate_polygon
     97   
     98
     99    #Make georef
     100    #FIXME: Pass in geo or create automatically somehow
     101    import project
     102    refzone = project.refzone  #FIXME
     103    mesh_origin = project.mesh_origin
     104    geo = Geo_reference(xllcorner = mesh_origin[1],  #From dem
     105                        yllcorner = mesh_origin[2],
     106                        zone = refzone)
    87107
    88108
     
    92112   
    93113    m = Mesh(geo_reference=geo)
    94        
    95     m.addVertsSegs(dict)
    96114
    97115
    98     #FIXME: Find centroid automatically
    99     inner = m.addRegionEN(points[0][0]+1, points[0][1]+1)
     116
     117    #Convert to UTM
     118    bounding_polygon = convert_points_from_latlon_to_utm(bounding_polygon, refzone)   
     119   
     120   
     121    #Do bounding polygon
     122    region_dict = create_region(bounding_polygon, boundary_tags, refzone)   
     123    m.addVertsSegs(region_dict)
     124
     125
     126    #Find one point inside region automatically
     127    if interior_regions is not None:
     128        excluded_polygons = []       
     129        for P, res in interior_regions:
     130            polygon = convert_points_from_latlon_to_utm(P, refzone)           
     131            excluded_polygons.append( polygon )
     132    else:
     133        excluded_polygons = None
     134
     135    from Numeric import array
     136   
     137    [inner_point] = populate_polygon(bounding_polygon, 1, exclude = excluded_polygons)
     138    print 'I:', inner_point, resolution
     139    inner = m.addRegionEN(inner_point[0], inner_point[1])
    100140    inner.setMaxArea(resolution)
     141
     142
     143
     144    #Do interior regions
     145    if interior_regions is not None:   
     146        for P, res in interior_regions:
     147            polygon = convert_points_from_latlon_to_utm(P, refzone)                       
     148            region_dict = create_region(polygon, None, refzone)
     149
     150            m.addVertsSegs(region_dict)
     151
     152            [inner_point] = populate_polygon(polygon, 1)
     153            print 'I', inner_point, res
     154            X = m.addRegionEN(inner_point[0], inner_point[1])
     155            X.setMaxArea(res)
     156           
     157
    101158   
    102159    m.generateMesh('pzq28.0za1000000a')
Note: See TracChangeset for help on using the changeset viewer.