def test_populate_geo_coord_polygon(self): # Checks that the Y distance between points gets larger as the latitude # gets larger. randoms = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] polygon = [[0, 0], [50, 0], [50, 0.5], [0, 0.5]] points = populate_geo_coord_polygon(polygon, 9, None, None, randoms) prevDiff = 0.0 for i in xrange(len(points) - 1): if i <> 0: assert (points[i][0] - points[i - 1][0]) > prevDiff prevDiff = points[i][0] - points[i - 1][0] assert len(points) == 9 for point in points: assert is_inside_polygon(point, polygon) # Checks that the distance between points changes in proportion to the # the change in width of the polygon due to the curvature of the earth. randoms = [0.09, 0.1, 0.89, 0.9] points = populate_geo_coord_polygon(polygon, 4, None, None, randoms) midA_lat = abs(points[1][0] - points[0][0]) + points[0][0] length_X_A = calc_ll_dist(midA_lat, 0.0, midA_lat, 0.5) length_Y_A = calc_ll_dist(points[1][0], 0.25, points[0][0], 0.25) midB_lat = abs(points[3][0] - points[2][0]) + points[2][0] length_X_B = calc_ll_dist(midB_lat, 0.0, midB_lat, 0.5) length_Y_B = calc_ll_dist(points[3][0], 0.25, points[2][0], 0.25) ratioX = length_X_A / length_X_B ratioY = length_Y_B / length_Y_A assert abs(ratioX - ratioY) < 0.01 #Very convoluted polygon polygon = [[0, 0], [10, 10], [15, 5], [20, 10], [25, 0], [30, 10], [40, -10]] points = populate_geo_coord_polygon(polygon, 5) assert len(points) == 5 for point in points: assert is_inside_polygon(point, polygon)
def non_deterministic_test_populate_geo_coord_polygon(self): #Check that proportion of points in an area is roughly what it should be #given the latitude of the area polygon = [[0,0], [-50,0], [-50,10], [0,10]] points = populate_geo_coord_polygon(polygon, 100000) polygonA = [[0,0], [-2,0], [-2,10], [0,10]] polygonB = [[-48,0], [-50,0], [-50,10], [-48,10]] countA = 0.0 countB = 0.0 for point in points: if is_inside_polygon(point, polygonA): countA+=1 elif is_inside_polygon(point, polygonB): countB+=1 pointsRatio = countA/countB lengthA= calc_ll_dist(-1.0, 0.0, -1.0, 10.0) lengthB= calc_ll_dist(-49.0, 0.0, -49.0, 10.0) areaRatio= lengthA/lengthB assert abs(pointsRatio - areaRatio) < 0.2
def non_deterministic_test_populate_geo_coord_polygon(self): #Check that proportion of points in an area is roughly what it should be #given the latitude of the area polygon = [[0, 0], [-50, 0], [-50, 10], [0, 10]] points = populate_geo_coord_polygon(polygon, 100000) polygonA = [[0, 0], [-2, 0], [-2, 10], [0, 10]] polygonB = [[-48, 0], [-50, 0], [-50, 10], [-48, 10]] countA = 0.0 countB = 0.0 for point in points: if is_inside_polygon(point, polygonA): countA += 1 elif is_inside_polygon(point, polygonB): countB += 1 pointsRatio = countA / countB lengthA = calc_ll_dist(-1.0, 0.0, -1.0, 10.0) lengthB = calc_ll_dist(-49.0, 0.0, -49.0, 10.0) areaRatio = lengthA / lengthB assert abs(pointsRatio - areaRatio) < 0.2
def test_populate_geo_coord_polygon(self): # Checks that the Y distance between points gets larger as the latitude # gets larger. randoms=[0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9] polygon = [[0,0], [50,0], [50,0.5], [0,0.5]] points = populate_geo_coord_polygon(polygon, 9, None, None,randoms) prevDiff =0.0 for i in xrange(len(points)-1): if i <> 0: assert (points[i][0] -points[i-1][0])> prevDiff prevDiff = points[i][0] -points[i-1][0] assert len(points) == 9 for point in points: assert is_inside_polygon(point, polygon) # Checks that the distance between points changes in proportion to the # the change in width of the polygon due to the curvature of the earth. randoms = [0.09, 0.1, 0.89, 0.9] points = populate_geo_coord_polygon(polygon, 4, None, None,randoms) midA_lat = abs(points[1][0]-points[0][0]) + points[0][0] length_X_A= calc_ll_dist(midA_lat, 0.0, midA_lat, 0.5) length_Y_A= calc_ll_dist(points[1][0], 0.25, points[0][0], 0.25) midB_lat = abs(points[3][0]-points[2][0]) + points[2][0] length_X_B= calc_ll_dist(midB_lat, 0.0, midB_lat, 0.5) length_Y_B= calc_ll_dist(points[3][0], 0.25, points[2][0], 0.25) ratioX = length_X_A/length_X_B ratioY = length_Y_B/length_Y_A assert abs(ratioX - ratioY) < 0.01 #Very convoluted polygon polygon = [[0,0], [10,10], [15,5], [20, 10], [25,0], [30,10], [40,-10]] points = populate_geo_coord_polygon(polygon, 5) assert len(points) == 5 for point in points: assert is_inside_polygon(point, polygon)