def test_tri_grid_polygon_on_inner_boundary(rtree=True): gr = get_tri_grid() if gr == -1: return ix = GridIntersect(gr, rtree=rtree) result = ix.intersect( Polygon([(5., 10.0), (15., 10.0), (15., 5.), (5., 5.)])) assert len(result) == 4 assert result.areas.sum() == 50. return result
def test_rect_grid_point_outside(): # avoid test fail when shapely not available try: import shapely except: return gr = get_rect_grid() ix = GridIntersect(gr, method="structured") result = ix.intersect(Point(25., 25.)) assert len(result) == 0 return result
def test_rect_grid_point_outside_shapely(rtree=True): # avoid test fail when shapely not available try: import shapely except: return gr = get_rect_grid() ix = GridIntersect(gr, method="vertex", rtree=rtree) result = ix.intersect(Point(25.0, 25.0)) assert len(result) == 0 return result
def test_rect_grid_polygon_outside(): # avoid test fail when shapely not available try: import shapely except: return gr = get_rect_grid() ix = GridIntersect(gr, method="structured") result = ix.intersect(Polygon([(21.0, 11.0), (23.0, 17.0), (25.0, 11.0)])) assert len(result) == 0 return result
def test_rect_grid_linestring_outside_shapely(rtree=True): # avoid test fail when shapely not available try: import shapely except: return gr = get_rect_grid() ix = GridIntersect(gr, method='vertex', rtree=rtree) result = ix.intersect(LineString([(25., 25.), (21., 5.)])) assert len(result) == 0 return result
def test_rect_grid_linestring_outside(): # avoid test fail when shapely not available try: import shapely except: return gr = get_rect_grid() ix = GridIntersect(gr, method="structured") result = ix.intersect(LineString([(25.0, 25.0), (21.0, 5.0)])) assert len(result) == 0 return result
def test_rect_grid_polygon_outside_shapely(rtree=True): # avoid test fail when shapely not available try: import shapely except: return gr = get_rect_grid() ix = GridIntersect(gr, method='vertex', rtree=rtree) result = ix.intersect(Polygon([(21., 11.), (23., 17.), (25., 11.)])) assert len(result) == 0 return result
def test_linestring_offset_rot_structured_grid_shapely(rtree=True): # avoid test fail when shapely not available try: import shapely except: return sgr = get_rect_grid(angrot=45., xyoffset=10.) ls = LineString([(5, 10. + np.sqrt(200.)), (15, 10. + np.sqrt(200.))]) ix = GridIntersect(sgr, method="vertex", rtree=rtree) result = ix.intersect(ls) # assert len(result) == 2. return result
def test_point_offset_rot_structured_grid_shapely(rtree=True): # avoid test fail when shapely not available try: import shapely except: return sgr = get_rect_grid(angrot=45., xyoffset=10.) p = Point(10., 10 + np.sqrt(200.)) ix = GridIntersect(sgr, method="vertex", rtree=rtree) result = ix.intersect(p) # assert len(result) == 1. return result
def test_rect_grid_3d_point_above(): # avoid test fail when shapely not available try: import shapely except: return botm = np.concatenate([np.ones(4), np.zeros(4)]).reshape(2, 2, 2) gr = get_rect_grid(top=np.ones(4), botm=botm) ix = GridIntersect(gr, method="structured") result = ix.intersect(Point(2., 2., 2)) assert len(result) == 0 return result
def test_rect_grid_multipoint_in_one_cell_shapely(rtree=True): # avoid test fail when shapely not available try: import shapely except: return gr = get_rect_grid() ix = GridIntersect(gr, method='vertex', rtree=rtree) result = ix.intersect(MultiPoint([Point(1., 1.), Point(2., 2.)])) assert len(result) == 1 assert result.cellids[0] == (1, 0) return result
def test_rect_vertex_grid_point_in_one_cell_shapely(rtree=True): # avoid test fail when shapely not available try: import shapely except: return gr = get_rect_vertex_grid() ix = GridIntersect(gr, method='vertex', rtree=rtree) result = ix.intersect(Point(4., 4.)) assert len(result) == 1 assert result.cellids[0] == 0 result = ix.intersect(Point(4., 6.)) assert len(result) == 1 assert result.cellids[0] == 0 result = ix.intersect(Point(6., 6.)) assert len(result) == 1 assert result.cellids[0] == 0 result = ix.intersect(Point(6., 4.)) assert len(result) == 1 assert result.cellids[0] == 0 return result
def test_rect_grid_point_on_inner_boundary_shapely(rtree=True): # avoid test fail when shapely not available try: import shapely except: return gr = get_rect_grid() ix = GridIntersect(gr, method='vertex', rtree=rtree) result = ix.intersect(Point(10., 10.)) assert len(result) == 1 assert np.all(result.cellids[0] == (0, 0)) return result
def test_rect_grid_point_on_outer_boundary(): # avoid test fail when shapely not available try: import shapely except: return gr = get_rect_grid() ix = GridIntersect(gr, method="structured") result = ix.intersect(Point(20., 10.)) assert len(result) == 1 assert np.all(result.cellids[0] == (0, 1)) return result
def test_rect_grid_multipoint_in_one_cell(): # avoid test fail when shapely not available try: import shapely except: return gr = get_rect_grid() ix = GridIntersect(gr, method="structured") result = ix.intersect(MultiPoint([Point(1.0, 1.0), Point(2.0, 2.0)])) assert len(result) == 1 assert result.cellids[0] == (1, 0) return result
def test_tri_grid_point_outside(rtree=True): # avoid test fail when shapely not available try: import shapely except: return gr = get_tri_grid() if gr == -1: return ix = GridIntersect(gr, rtree=rtree) result = ix.intersect(Point(25., 25.)) assert len(result) == 0 return result
def test_rect_grid_polygon_on_outer_boundary_shapely(rtree=True): # avoid test fail when shapely not available try: import shapely except: return gr = get_rect_grid() ix = GridIntersect(gr, method="vertex", rtree=rtree) result = ix.intersect( Polygon([(20.0, 5.0), (25.0, 5.0), (25.0, 15.0), (20.0, 15.0)]) ) assert len(result) == 0 return result
def test_tri_grid_linestring_outside(rtree=True): # avoid test fail when shapely not available try: import shapely except: return gr = get_tri_grid() if gr == -1: return ix = GridIntersect(gr, rtree=rtree) result = ix.intersect(LineString([(25.0, 25.0), (21.0, 5.0)])) assert len(result) == 0 return result
def test_rect_grid_3d_point_inside(): # avoid test fail when shapely not available try: import shapely except: return botm = np.concatenate([np.ones(4), .5 * np.ones(4), np.zeros(4)]).reshape(3, 2, 2) gr = get_rect_grid(top=np.ones(4), botm=botm) ix = GridIntersect(gr, method="structured") result = ix.intersect(Point(2., 2., .2)) assert result.cellids[0] == (1, 1, 0) return result
def test_rect_grid_polygon_on_inner_boundary_shapely(rtree=True): # avoid test fail when shapely not available try: import shapely except: return gr = get_rect_grid() ix = GridIntersect(gr, method='vertex', rtree=rtree) result = ix.intersect( Polygon([(5., 10.0), (15., 10.0), (15., 5.), (5., 5.)])) assert len(result) == 2 assert result.areas.sum() == 50. return result
def test_rect_grid_polygon_in_2cells(): # avoid test fail when shapely not available try: import shapely except: return gr = get_rect_grid() ix = GridIntersect(gr, method="structured") result = ix.intersect( Polygon([(2.5, 5.0), (7.5, 5.0), (7.5, 15.), (2.5, 15.)])) assert len(result) == 2 assert result.areas.sum() == 50. return result
def test_rect_grid_multipoint_in_multiple_cells_shapely(rtree=True): # avoid test fail when shapely not available try: import shapely except: return gr = get_rect_grid() ix = GridIntersect(gr, method="vertex", rtree=rtree) result = ix.intersect(MultiPoint([Point(1.0, 1.0), Point(12.0, 12.0)])) assert len(result) == 2 assert result.cellids[0] == (0, 1) assert result.cellids[1] == (1, 0) return result
def test_tri_grid_polygon_on_outer_boundary(rtree=True): # avoid test fail when shapely not available try: import shapely except: return gr = get_tri_grid() if gr == -1: return ix = GridIntersect(gr, rtree=rtree) result = ix.intersect( Polygon([(20., 5.0), (25., 5.0), (25., 15.), (20., 15.)])) assert len(result) == 0 return result
def test_rect_grid_polygon_in_edge_in_cell(rtree=True): # avoid test fail when shapely not available try: import shapely except: return gr = get_rect_grid() ix = GridIntersect(gr, method='vertex', rtree=rtree) p = Polygon([(0., 5.), (3., 0.), (7., 0.), (10., 5.), (10., -1.), (0., -1.)]) result = ix.intersect(p) assert len(result) == 1 assert result.areas.sum() == 15. return result
def test_rect_grid_polygon_with_hole_shapely(rtree=True): # avoid test fail when shapely not available try: import shapely except: return gr = get_rect_grid() ix = GridIntersect(gr, method='vertex', rtree=rtree) p = Polygon([(5., 5.), (5., 15.), (25., 15.), (25., -5.), (5., -5.)], holes=[[(9., -1), (9, 11), (21, 11), (21, -1)]]) result = ix.intersect(p) assert len(result) == 3 assert result.areas.sum() == 104. return result
def test_rect_grid_linestring_in_and_out_of_cell_shapely(rtree=True): # avoid test fail when shapely not available try: import shapely except: return gr = get_rect_grid() ix = GridIntersect(gr, method='vertex', rtree=rtree) result = ix.intersect(LineString([(5., 9), (15., 5.), (5., 1.)])) assert len(result) == 2 assert result.cellids[0] == (1, 0) assert result.cellids[1] == (1, 1) assert np.allclose(result.lengths.sum(), 21.540659228538015) return result
def test_rect_grid_linestring_on_inner_boundary_shapely(rtree=True): # avoid test fail when shapely not available try: import shapely except: return gr = get_rect_grid() ix = GridIntersect(gr, method='vertex', rtree=rtree) result = ix.intersect(LineString([(5., 10.), (15., 10.)])) assert len(result) == 2 assert result.lengths.sum() == 10. assert result.cellids[0] == (0, 0) assert result.cellids[1] == (0, 1) return result
def test_tri_grid_point_on_inner_boundary(rtree=True): # avoid test fail when shapely not available try: import shapely except: return gr = get_tri_grid() if gr == -1: return ix = GridIntersect(gr, rtree=rtree) result = ix.intersect(Point(10., 10.)) assert len(result) == 1 assert np.all(result.cellids[0] == 0) return result
def test_rect_grid_linestring_on_outer_boundary(): # avoid test fail when shapely not available try: import shapely except: return gr = get_rect_grid() ix = GridIntersect(gr, method="structured") result = ix.intersect(LineString([(15., 20.), (5., 20.)])) assert len(result) == 2 assert result.lengths.sum() == 10. assert result.cellids[1] == (0, 0) assert result.cellids[0] == (0, 1) return result
def test_tri_grid_multipoint_in_one_cell(rtree=True): # avoid test fail when shapely not available try: import shapely except: return gr = get_tri_grid() if gr == -1: return ix = GridIntersect(gr, rtree=rtree) result = ix.intersect(MultiPoint([Point(1., 1.), Point(2., 2.)])) assert len(result) == 1 assert result.cellids[0] == 1 return result