Skip to content

Commit 6e9615a

Browse files
asinghvi17claude
andauthored
Implement error handling for EPSG code parsing (#123)
Co-authored-by: Claude <[email protected]>
1 parent 317c8df commit 6e9615a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/crs.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ end
133133

134134
function GFT.EPSG(crs::CRS)
135135
str = proj_get_id_code(crs)
136+
if isnothing(str)
137+
error("Could not parse $crs to EPSG code; it probably does not correspond to one.")
138+
end
136139
code = parse(Int, str)
137140
return GFT.EPSG(code)
138141
end

test/libproj.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,10 @@ end
489489
@test GFT.EPSG(crs) == GFT.EPSG("EPSG:4326")
490490

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

0 commit comments

Comments
 (0)