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
3 changes: 3 additions & 0 deletions src/crs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ end

function GFT.EPSG(crs::CRS)
str = proj_get_id_code(crs)
if isnothing(str)
error("Could not parse $crs to EPSG code; it probably does not correspond to one.")
end
code = parse(Int, str)
return GFT.EPSG(code)
end
Expand Down
4 changes: 4 additions & 0 deletions test/libproj.jl
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ end
@test GFT.EPSG(crs) == GFT.EPSG("EPSG:4326")

@test convert(GFT.EPSG, crs) == GFT.EPSG("EPSG:4326")

# Test error handling when CRS doesn't have an EPSG code
crs_without_epsg = Proj.CRS("+proj=merc +lat_ts=56.5 +ellps=GRS80 +type=crs")
@test_throws r"Could not parse.*EPSG code"is GFT.EPSG(crs_without_epsg)
@test convert(GFT.WellKnownText2, crs) == GFT.WellKnownText2(crs)
@test Proj.proj_get_id_code(convert(Proj.CRS, GFT.EPSG("EPSG:4326"))) ==
Proj.proj_get_id_code(crs)
Expand Down