Skip to content

Commit af4cb4a

Browse files
authored
convert to string rather than CRS in reproject (#95)
* convert to string rather than CRS * allow Proj.CRS
1 parent 73f64df commit af4cb4a

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

ext/GeometryOpsProjExt/reproject.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,16 @@ end
2525
function reproject(geom, source_crs, target_crs;
2626
time=Inf,
2727
always_xy=true,
28-
transform=Proj.Transformation(Proj.CRS(source_crs), Proj.CRS(target_crs); always_xy),
28+
transform=nothing,
2929
kw...
3030
)
31+
transform = if isnothing(transform)
32+
s = source_crs isa Proj.CRS ? source_crs : convert(String, source_crs)
33+
t = target_crs isa Proj.CRS ? target_crs : convert(String, target_crs)
34+
Proj.Transformation(s, t; always_xy)
35+
else
36+
transform
37+
end
3138
reproject(geom, transform; time, target_crs, kw...)
3239
end
3340
function reproject(geom, transform::Proj.Transformation; time=Inf, target_crs=nothing, kw...)
@@ -40,4 +47,4 @@ function reproject(geom, transform::Proj.Transformation; time=Inf, target_crs=no
4047
transform(GI.x(p), GI.y(p))
4148
end
4249
end
43-
end
50+
end

test/transformations/reproject.jl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,39 @@ import Proj
4141

4242
# Run it threaded over 100 replicates
4343
GO.reproject([multipolygon3857 for _ in 1:100]; target_crs=EPSG(4326), threaded=true, calc_extent=true)
44+
45+
utm32_wkt = """
46+
PROJCS["WGS 84 / UTM zone 32N",
47+
GEOGCS["WGS 84",
48+
DATUM["WGS_1984",
49+
SPHEROID["WGS 84",6378137,298.257223563,
50+
AUTHORITY["EPSG","7030"]],
51+
AUTHORITY["EPSG","6326"]],
52+
PRIMEM["Greenwich",0,
53+
AUTHORITY["EPSG","8901"]],
54+
UNIT["degree",0.0174532925199433,
55+
AUTHORITY["EPSG","9122"]],
56+
AUTHORITY["EPSG","4326"]],
57+
PROJECTION["Transverse_Mercator"],
58+
PARAMETER["latitude_of_origin",0],
59+
PARAMETER["central_meridian",9],
60+
PARAMETER["scale_factor",0.9996],
61+
PARAMETER["false_easting",500000],
62+
PARAMETER["false_northing",0],
63+
UNIT["metre",1,
64+
AUTHORITY["EPSG","9001"]],
65+
AXIS["Easting",EAST],
66+
AXIS["Northing",NORTH],
67+
AUTHORITY["EPSG","32632"]]
68+
"""
69+
70+
@test GO.reproject(multipolygon4326; source_crs="epsg:4326", target_crs="+proj=utm +zone=32 +datum=WGS84") ==
71+
GO.reproject(multipolygon4326; source_crs=EPSG(4326), target_crs=ProjString("+proj=utm +zone=32 +datum=WGS84")) ==
72+
GO.reproject(multipolygon4326; target_crs=EPSG(32632)) ==
73+
GO.reproject(multipolygon4326; target_crs="epsg:32632") ==
74+
GO.reproject(multipolygon4326; target_crs=utm32_wkt)
75+
76+
GO.reproject(multipolygon4326; target_crs=ProjString("+proj=moll"))
77+
4478
end
4579

0 commit comments

Comments
 (0)