Changeset 3051


Ignore:
Timestamp:
Jun 2, 2006, 12:33:16 PM (18 years ago)
Author:
duncan
Message:

checking in changes half way thru, so Ole can help

Location:
inundation
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • inundation/geospatial_data/geospatial_data.py

    r2955 r3051  
    692692    else:
    693693        points = ensure_numeric(points, Float)
    694    
    695694    if geo_reference is None:
    696695        geo = None #Geo_reference()
  • inundation/pmesh/mesh_interface.py

    r3042 r3051  
    88from utilities.numerical_tools import ensure_numeric
    99from Numeric import Float
     10from utilities.polygon import inside_polygon
    1011
    1112# This is due to pmesh being a package and a module and
     
    6970    # converted to relative coordinates (I think). How can we simplify this?
    7071    #
     72    #FIXME (DSG-DSG) this code does not take into account geo-referencing
    7173    #if interior_regions is not None:       
    72     #    from utilities.polygon import inside_polygon
    73     #
    74     #    for interior_polygon, res in interior_regions:
    75     #        indices = inside_polygon(interior_polygon, bounding_polygon,
    76     #                                 closed = True, verbose = False)
    77     #
    78     #        if len(indices) <> len(interior_polygon):
    79     #            msg = 'Interior polygon %s is outside bounding polygon: %s'\
    80     #                  %(str(interior_polygon), str(bounding_polygon))
    81     #            raise msg
     74     
     75     #   for interior_polygon, res in interior_regions:
     76      #      indices = inside_polygon(interior_polygon, bounding_polygon,
     77       #                              closed = True, verbose = False)
     78   
     79       #     if len(indices) <> len(interior_polygon):
     80        #        msg = 'Interior polygon %s is outside bounding polygon: %s'\
     81         #             %(str(interior_polygon), str(bounding_polygon))
     82          #      raise msg
    8283
    8384
  • inundation/utilities/polygon.py

    r2955 r3051  
    1414from math import sqrt
    1515from utilities.numerical_tools import ensure_numeric
    16 
     16from geospatial_data.geospatial_data import ensure_absolute
    1717
    1818def point_on_line(x, y, x0, y0, x1, y1):
     
    4343
    4444
    45 def inside_polygon(points, polygon, closed = True, verbose = False):
     45def inside_polygon(points, polygon, closed = True, verbose = False,
     46                   points_geo_ref=None, polygon_geo_ref=None):
    4647    """Determine points inside a polygon
    4748
     
    5657
    5758    try:
    58         points = ensure_numeric(points, Float)
     59        points = ensure_absolute(points, geo_reference=points_geo_ref)
    5960    except NameError, e:
    6061        raise NameError, e
     
    6465
    6566    try:
    66         polygon = ensure_numeric(polygon, Float)
     67        polygon = ensure_absolute(polygon, geo_reference=polygon_geo_ref)
    6768    except NameError, e:
    6869        raise NameError, e
     
    7071        msg = 'Polygon %s could not be converted to Numeric array' %(str(polygon))
    7172        raise msg
    72 
    73 
    7473
    7574    if len(points.shape) == 1:
  • inundation/utilities/test_polygon.py

    r2912 r3051  
    77
    88from polygon import *
    9 
     9from coordinate_transforms.geo_reference import Geo_reference
    1010
    1111def test_function(x, y):
     
    624624        os.remove('test1.png')
    625625        os.remove('test2.png')
     626
    626627       
     628    def test_inside_polygon_geo_ref(self):
     629
     630
     631        #Simplest case: Polygon is the unit square
     632        polygon_absolute = [[0,0], [1,0], [1,1], [0,1]]
     633        poly_geo_ref = Geo_reference(57,100,100)
     634        polygon = poly_geo_ref.change_points_geo_ref(polygon_absolute)
     635
     636        points_absolute = (0.5, 0.5)
     637        points_geo_ref = Geo_reference(57,78,-56)
     638        points = points_geo_ref.change_points_geo_ref(points_absolute)
     639
     640        assert inside_polygon( points_absolute, polygon_absolute)
     641       
     642        points_inside = inside_polygon( points, polygon,
     643                               polygon_geo_ref=poly_geo_ref,
     644                               points_geo_ref=points_geo_ref)
     645        #print "points_inside",points_inside
     646        #assert 1 == len(inside_polygon( points, polygon,
     647        #                       polygon_geo_ref=poly_geo_ref,
     648        #                       points_geo_ref=points_geo_ref))
     649        assert not inside_polygon( (0.5, 1.5), polygon,
     650                               polygon_geo_ref= poly_geo_ref )
     651        assert not inside_polygon( (0.5, -0.5), polygon,
     652                               polygon_geo_ref= poly_geo_ref )
     653        assert not inside_polygon( (-0.5, 0.5), polygon,
     654                               polygon_geo_ref= poly_geo_ref )
     655        assert not inside_polygon( (1.5, 0.5), polygon,
     656                               polygon_geo_ref= poly_geo_ref )
    627657#-------------------------------------------------------------
    628658if __name__ == "__main__":
    629659    suite = unittest.makeSuite(Test_Polygon,'test')
     660    #suite = unittest.makeSuite(Test_Polygon,'test_inside_polygon_geo_ref')
    630661    runner = unittest.TextTestRunner()
    631662    runner.run(suite)
Note: See TracChangeset for help on using the changeset viewer.