diff --git a/src/crs.jl b/src/crs.jl index f3c8c18..d0a271e 100644 --- a/src/crs.jl +++ b/src/crs.jl @@ -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 diff --git a/test/libproj.jl b/test/libproj.jl index ab6b6a3..d910993 100644 --- a/test/libproj.jl +++ b/test/libproj.jl @@ -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)