Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/crs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@ function CRS(
crs::Union{GFT.CoordinateReferenceSystemFormat,GFT.MixedFormat{<:MaybeGFTCRS}},
ctx::Ptr{PJ_CONTEXT} = C_NULL,
)
crs = proj_create(convert(String, crs), ctx)
return CRS(crs)
crs_str = convert(String, crs)
# For ProjString format, ensure +type=crs is present if it's a proj-string definition
# This is needed because proj_create() creates a projection (not a CRS) without it
if crs isa GFT.ProjString && startswith(crs_str, "+proj=") && !contains(crs_str, "+type=crs")
crs_str = crs_str * " +type=crs"
end
pj = proj_create(crs_str, ctx)
@assert Bool(proj_is_crs(pj)) "Not a CRS:\n$pj"
return CRS(pj)
end

function Base.show(io::IO, crs::CRS)
Expand Down
43 changes: 43 additions & 0 deletions test/libproj.jl
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,49 @@ end
@test description2 == description_true
end

@testset "ProjString Transformation (issue #102)" begin
# Test that ProjString works the same as String for Transformation
# Issue: https://github.com/JuliaGeo/Proj.jl/issues/102

# Test case 1: Original issue example
equi7_eu_projstring = "+proj=aeqd +lat_0=53 +lon_0=24 +x_0=5837287.81977 +y_0=2121415.69617 +datum=WGS84 +units=m +no_defs"

# Both String and ProjString should work
trans_string = Proj.Transformation(equi7_eu_projstring, "EPSG:3857", always_xy=true)
trans_projstring = Proj.Transformation(GFT.ProjString(equi7_eu_projstring), GFT.EPSG(3857), always_xy=true)

# They should produce the same transformation
@test unsafe_string(Proj.proj_pj_info(trans_string.pj).definition) ==
unsafe_string(Proj.proj_pj_info(trans_projstring.pj).definition)

# Test case 2: Simple longlat case
longlat_projstring = "+proj=longlat +datum=WGS84"

trans_string2 = Proj.Transformation(longlat_projstring, "EPSG:3857", always_xy=true)
trans_projstring2 = Proj.Transformation(GFT.ProjString(longlat_projstring), GFT.EPSG(3857), always_xy=true)

@test unsafe_string(Proj.proj_pj_info(trans_string2.pj).definition) ==
unsafe_string(Proj.proj_pj_info(trans_projstring2.pj).definition)

# Test case 3: ProjString already containing +type=crs should work
longlat_with_type = "+proj=longlat +datum=WGS84 +type=crs"
trans_with_type = Proj.Transformation(GFT.ProjString(longlat_with_type), GFT.EPSG(3857), always_xy=true)

@test unsafe_string(Proj.proj_pj_info(trans_with_type.pj).definition) ==
unsafe_string(Proj.proj_pj_info(trans_string2.pj).definition)

# Test case 4: Both source and target as ProjString
target_projstring = "+proj=utm +zone=32 +datum=WGS84"
trans_both = Proj.Transformation(
GFT.ProjString(longlat_projstring),
GFT.ProjString(target_projstring),
always_xy=true
)

# Should not throw an error and should create a valid transformation
@test trans_both isa Proj.Transformation
end

@testset "bounds" begin
trans = Proj.Transformation("EPSG:4326", "+proj=utm +zone=32 +datum=WGS84")
x, y = 52, 11
Expand Down
Loading