-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
52 additions
and
39 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Test | ||
|
||
import GeoInterface as GI | ||
import GeometryOps as GO | ||
using GeoFormatTypes | ||
import Proj | ||
|
||
@testset "reproject" begin | ||
ring1 = GI.LinearRing([(1, 2), (7, 4), (5, 6), (1, 2)]) | ||
ring2 = GI.LinearRing([(11, 2), (20, 4), (15, 6), (11, 2)]) | ||
hole2 = GI.LinearRing([(14, 4), (16, 4), (17, 5), (14, 4)]) | ||
|
||
# Set up a regular tranformation of the points for reference | ||
source_crs = convert(Proj.CRS, EPSG(4326)) | ||
target_crs = convert(Proj.CRS, EPSG(3857)) | ||
trans = Proj.Transformation(source_crs, target_crs; always_xy=true) | ||
|
||
polygon1 = GI.Polygon([ring1]) | ||
polygon2 = GI.Polygon([ring2, hole2]) | ||
multipolygon = GI.MultiPolygon([polygon1, polygon2]) | ||
|
||
ref_points3857 = map(GI.getpoint(multipolygon)) do p | ||
trans([GI.x(p), GI.y(p)]) | ||
end | ||
|
||
multipolygon3857 = GO.reproject(multipolygon, EPSG(4326), EPSG(3857)) | ||
multipolygon4326 = GO.reproject(multipolygon3857; target_crs=EPSG(4326)) | ||
points4326_1 = collect(GI.getpoint(multipolygon)) | ||
points4326_2 = GI.getcoord.(GI.getpoint(multipolygon4326)) | ||
points3857 = GI.getcoord.(GI.getpoint(multipolygon3857)) | ||
|
||
# Comparison to regular `trans` on points | ||
@test all(map((p1, p2) -> all(map(isapprox, p1, p2)), ref_points3857, points3857)) | ||
|
||
# Round trip comparison | ||
@test all(map((p1, p2) -> all(map(isapprox, p1, p2)), points4326_1, points4326_2)) | ||
|
||
# Embedded crs check | ||
@test GI.crs(multipolygon3857) == EPSG(3857) | ||
@test GI.crs(multipolygon4326) == EPSG(4326) | ||
end | ||
|
||
|
||
|
||
@testset "flip" begin | ||
geom = GI.Polygon([GI.LinearRing([(1, 2), (3, 4), (5, 6), (1, 2)]), | ||
GI.LinearRing([(3, 4), (5, 6), (6, 7), (3, 4)])]) | ||
|
||
|
||
@test GO.flip(geom) == GI.Polygon([GI.LinearRing([(2, 1), (4, 3), (6, 5), (2, 1)]), | ||
GI.LinearRing([(4, 3), (6, 5), (7, 6), (4, 3)])]) | ||
end |