def test_wkt_polygons_contains_original_not_changed(self): """Point cloud in should not change by filtering.""" pc_in = read_las.read("testdata/AHN2.las") len_x_before = len(pc_in[point]['x']['data']) _pc_out = points_in_polygon_wkt(pc_in, self.polygon_around_1_point_ahn2) len_x_after = len(pc_in[point]['x']['data']) assert_equal(len_x_after, len_x_before)
def test_wkt_polygons_containsEmpty(): """ Selecting all points within a Polygon. """ pc_in = read_las.read("testdata/AHN2.las") pc_out = points_in_polygon_wkt(pc_in, "POLYGON(( 253590.0 582110.0, 253640.0 582160.0, 253700.0 582110.0, 253640.0 582060.0, 253590.0 582110.0 ))") x = pc_out[point]['x']['data'] y = pc_out[point]['y']['data'] assert (len(x) == 0) assert (len(y) == 0)
def test_wkt_polygons_contains(): """ Selecting all points within a Polygon using artificial data. """ test_data = ComplexTestData() pc_in = test_data.get_point_cloud() expected_point = np.array(pc_in[point]['x']['data'][0], pc_in[point]['y']['data'][0]) pc_out = points_in_polygon_wkt(pc_in, test_data.get_wkt_polygon_around_first_point_only()) assert_equal(len(pc_out[point]['x']['data']), 1) selected_point = np.array(pc_out[point]['x']['data'][0], pc_out[point]['y']['data'][0]) np.testing.assert_allclose(selected_point, expected_point)
def test_wkt_polygons_contains_single_point(self): """Selecting a single point with a tiny polygon. Test for https://github.com/eEcoLiDAR/eEcoLiDAR/issues/64. """ pc_in = read_las.read("testdata/AHN2.las") pc_out = points_in_polygon_wkt(pc_in, self.polygon_around_1_point_ahn2) x = pc_out[point]['x']['data'] y = pc_out[point]['y']['data'] expected_x = 243627.841248 expected_y = 572073.440002 assert_equal(len(x), 1) assert_almost_equal(x[0], expected_x, 4) assert_almost_equal(y[0], expected_y, 4)
from laserchicken import read_las from laserchicken.spatial_selections import points_in_polygon_wkt from laserchicken import write_ply pc = read_las.read("D:/GitHub/eEcoLiDAR/eEcoLiDAR/testdata/AHN2.las") pc_out = points_in_polygon_wkt( pc, "POLYGON(( 243590.0 572110.0, 243640.0 572160.0, 243700.0 572110.0, 243640.0 572060.0, 243590.0 572110.0 ))" ) write_ply.write( pc, "D:/GitHub/komazsofi/myPhD_escience_analysis/test_data/testply_orig1.ply") write_ply.write( pc_out, "D:/GitHub/komazsofi/myPhD_escience_analysis/test_data/withinplygonply1.ply" )
## Import libraries from laserchicken import read_las from laserchicken.spatial_selections import points_in_polygon_wkt from laserchicken.keys import point from laserchicken.compute_neighbors import compute_neighbourhoods, compute_cylinder_neighborhood_indices, compute_sphere_neighborhood_indices from laserchicken.feature_extractor.height_statistics_feature_extractor import HeightStatisticsFeatureExtractor from laserchicken import write_ply ## Read-Write pc = read_las.read("D:/NAEM/Data/ALS_AHN2/SelStudyArea2_v2.las") pc_sub = points_in_polygon_wkt( pc, "POLYGON((196550 446510,196550 446540,196580 446540,196580 446510,196550 446510))" ) #write_ply.write(pc_sub, "D:/NAEM/Data/ALS_AHN2/SelStudyArea2_v3.ply") ## Compute neighborhood #indices_cyl=compute_cylinder_neighborhood_indices(pc_sub, pc_sub,1) indices_sph = compute_sphere_neighborhood_indices(pc_sub, pc_sub, 1) output_text = "" for i in range(len(indices_sph)): extractor = HeightStatisticsFeatureExtractor() max_z, min_z, mean_z, median_z, std_z, var_z, range_z, coeff_var_z, skew_z, kurto_z = extractor.extract( pc_sub, indices_sph[i], None, None, None)
def test_points_in_polygon_wkt_invalidPolygon(): """Polygon is not closed so should raise error.""" pc_in = read_las.read("testdata/AHN2.las") with pytest.raises(ValueError): points_in_polygon_wkt(pc_in, "POLYGON(( 243590.0 572110.0, 243640.0 572160.0, 243700.0 572110.0, 243640.0 572060.0 ))")
def test_points_in_polygon_wkt_Collection(): pc_in = read_las.read("testdata/AHN2.las") with pytest.raises(ValueError): points_in_polygon_wkt(pc_in, "GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(4 6,7 10))")
def test_points_in_polygon_wkt_MultiPolygon(): pc_in = read_las.read("testdata/AHN2.las") with pytest.raises(ValueError): points_in_polygon_wkt(pc_in, "MULTIPOLYGON(((1 1,5 1,5 5,1 5,1 1),(2 2, 3 2, 3 3, 2 3,2 2)),((3 3,6 2,6 4,3 3)))")
def test_points_in_polygon_wkt_MultiLine(): pc_in = read_las.read("testdata/AHN2.las") with pytest.raises(ValueError): points_in_polygon_wkt(pc_in, "MULTILINESTRING((3 4,10 50,20 25),(-5 -8,-10 -8,-15 -4))")
def test_points_in_polygon_wkt_MultiPoint(): pc_in = read_las.read("testdata/AHN2.las") with pytest.raises(ValueError): points_in_polygon_wkt(pc_in, "MULTIPOINT(3.5 5.6, 4.8 10.5)")
def test_points_in_polygon_wkt_Line(): pc_in = read_las.read("testdata/AHN2.las") with pytest.raises(ValueError): points_in_polygon_wkt(pc_in, "LINESTRING(3 4,10 50,20 25)")
def test_points_in_polygon_wkt_Point(): pc_in = read_las.read("testdata/AHN2.las") with pytest.raises(ValueError): points_in_polygon_wkt(pc_in, "POINT(6 10)")