diff --git a/Project.toml b/Project.toml index f6787b264..ad2d4f956 100644 --- a/Project.toml +++ b/Project.toml @@ -21,9 +21,10 @@ ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3" Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" GeoFormatTypes = "68eda718-8dee-11e9-39e7-89f7f65f511f" GeoJSON = "61d90e0f-e114-555e-ac52-39dfb47a3ef9" +JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" LibGEOS = "a90b1aa1-3769-5649-ba7e-abc5a9d163eb" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["ArchGDAL", "Distributions", "GeoFormatTypes", "GeoJSON", "LibGEOS", "Random", "Test"] +test = ["ArchGDAL", "Distributions", "GeoFormatTypes", "GeoJSON", "JLD2", "LibGEOS", "Random", "Test"] diff --git a/test/data/complex_polygons.jld2 b/test/data/complex_polygons.jld2 index d472d8658..d530e0e21 100644 Binary files a/test/data/complex_polygons.jld2 and b/test/data/complex_polygons.jld2 differ diff --git a/test/transformations/simplify.jl b/test/transformations/simplify.jl index 284250639..eebc13cd0 100644 --- a/test/transformations/simplify.jl +++ b/test/transformations/simplify.jl @@ -1,20 +1,35 @@ using Test - -import GeoInterface as GI -import GeometryOps as GO +# import GeoInterface as GI +# import GeometryOps as GO import GeoJSON +import JLD2 @testset "simplify" begin datadir = realpath(joinpath(dirname(pathof(GO)), "../test/data")) fc = GeoJSON.read(joinpath(datadir, "simplify.geojson")) fc2 = GeoJSON.read(joinpath(datadir, "simplify2.geojson")) - T = GO.RadialDistance fcs = [fc for i in 1:100] - for T in (GO.RadialDistance, GO.VisvalingamWhyatt, GO.DouglasPeucker) + for T in (GO.RadialDistance, GO.VisvalingamWhyatt) @test length(collect(GO.flatten(GI.PointTrait, GO.simplify(T(number=10), fc)))) == 10 @test length(collect(GO.flatten(GI.PointTrait, GO.simplify(T(ratio=0.5), fc)))) == 39 # Half of 78 GO.simplify(T(tol=0.001), fc; threaded=true, calc_extent=true) GO.simplify(T(tol=0.001), fcs; threaded=true, calc_extent=true) end + + poly_coords = JLD2.jldopen(joinpath(datadir, "complex_polygons.jld2"))["verts"][1:3] + for c in poly_coords + npoints = length(c[1]) + third = (npoints == 50) # only the third is failing + third && @show c + poly = LG.Polygon(c) + lg_vals = GI.coordinates(LG.simplify(poly, 100.0))[1] + reduced_npoints = length(lg_vals) + third && @show reduced_npoints + tol_vals = GI.coordinates(GO.simplify(poly; tol = 100.0))[1] + @test all(tol_vals .== lg_vals) + @test all(GI.coordinates(GO.simplify(poly; number = reduced_npoints))[1] .== lg_vals) + @test all(GI.coordinates(GO.simplify(poly; ratio = (reduced_npoints/npoints)))[1] .== lg_vals) + end + end