-
Notifications
You must be signed in to change notification settings - Fork 4
/
segmentize.jl
69 lines (59 loc) · 3.04 KB
/
segmentize.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using Test
using Proj
import GeometryOps as GO
import GeoInterface as GI
using ..TestHelpers
@testset "Segmentation on multiple geometry levels" begin
ls = GI.LineString([(0, 0), (1, 1), (2, 2), (3, 3)])
lr = GI.LinearRing([(0, 0), (1, 1), (1, 0), (0, 1), (0, 0)])
p = GI.Polygon([lr])
mp = GI.MultiPolygon([p, p, p])
mls = GI.MultiLineString([ls, ls, ls])
@testset_implementations "LinearSegments" begin
@test GO.segmentize($ls; max_distance = 0.5) isa GI.LineString
if GI.trait($lr) isa GI.LinearRingTrait
@test GO.segmentize($lr; max_distance = 0.5) isa GI.LinearRing
end
# Test that linear rings are closed after segmentization
segmentized_ring = GO.segmentize($lr; max_distance = 0.5)
@test GI.getpoint(segmentized_ring, 1) ==
GI.getpoint(segmentized_ring, GI.npoint(segmentized_ring))
@test GO.segmentize($p; max_distance = 0.5) isa GI.Polygon
@test GO.segmentize($mp; max_distance = 0.5) isa GI.MultiPolygon
@test GI.ngeom(GO.segmentize($mp; max_distance = 0.5)) == 3
# Now test multilinestrings
@test GO.segmentize($mls; max_distance = 0.5) isa GI.MultiLineString
@test GI.ngeom(GO.segmentize($mls; max_distance = 0.5)) == 3
end
@testset_implementations "GeodesicSegments" begin
@test GO.segmentize(GO.GeodesicSegments(; max_distance = 0.5*900), $ls) isa GI.LineString
if GI.trait($lr) isa GI.LinearRingTrait
@test GO.segmentize(GO.GeodesicSegments(; max_distance = 0.5*900), $lr) isa GI.LinearRing
end
# Test that linear rings are closed after segmentization
segmentized_ring = GO.segmentize(GO.GeodesicSegments(; max_distance = 0.5*900), $lr)
@test GI.getpoint(segmentized_ring, 1) == GI.getpoint(segmentized_ring, GI.npoint(segmentized_ring))
@test GO.segmentize(GO.GeodesicSegments(; max_distance = 0.5*900), $p) isa GI.Polygon
@test GO.segmentize(GO.GeodesicSegments(; max_distance = 0.5*900), $mp) isa GI.MultiPolygon
@test GI.ngeom(GO.segmentize(GO.GeodesicSegments(; max_distance = 0.5*900), $mp)) == 3
# Now test multilinestrings
@test GO.segmentize(GO.GeodesicSegments(; max_distance = 0.5*900), $mls) isa GI.MultiLineString
@test GI.ngeom(GO.segmentize(GO.GeodesicSegments(; max_distance = 0.5*900), $mls)) == 3
end
end
lr = GI.LinearRing([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
@testset_implementations "LinearSegments" begin
ct = GO.centroid($lr)
ar = GO.area($lr)
for max_distance in exp10.(LinRange(log10(0.01), log10(1), 10))
segmentized = GO.segmentize(GO.LinearSegments(; max_distance), $lr)
@test all(GO.centroid(segmentized) .≈ ct)
@test GO.area(segmentized) ≈ ar
end
end
lr = GI.LinearRing([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
@testset_implementations "GeodesicSegments" begin
for max_distance in exp10.(LinRange(log10(0.01), log10(1), 10)) .* 900
@test_nowarn segmentized = GO.segmentize(GO.GeodesicSegments(; max_distance), $lr)
end
end