Skip to content

Commit

Permalink
move to transformations
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed May 5, 2023
1 parent 914ee84 commit 077aa7b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 39 deletions.
39 changes: 0 additions & 39 deletions test/methods/reproject.jl

This file was deleted.

52 changes: 52 additions & 0 deletions test/transformations.jl
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

0 comments on commit 077aa7b

Please sign in to comment.