Skip to content

Commit

Permalink
Added simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skygering committed Jan 10, 2024
1 parent 8767974 commit dc445f8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Binary file modified test/data/complex_polygons.jld2
Binary file not shown.
25 changes: 20 additions & 5 deletions test/transformations/simplify.jl
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit dc445f8

Please sign in to comment.