Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Catch errors when reading single features #54

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
25 changes: 16 additions & 9 deletions src/Shapefile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -343,16 +343,23 @@ function Base.read(io::IO, ::Type{Handle}, index = nothing)
Interval(mmin, mmax),
shapes,
)
num = Int32(0)
ii = 0
while (!eof(io))
seeknext(io, num, index)
num = bswap(read(io, Int32))
rlength = bswap(read(io, Int32))
shapeType = read(io, Int32)
if shapeType === Int32(0)
try
ii = ii + 1
seeknext(io, ii, index)
num = bswap(read(io, Int32))
@assert num == ii
rlength = bswap(read(io, Int32))
shapeType = read(io, Int32)
if shapeType === Int32(0)
push!(shapes, missing)
else
push!(shapes, read(io, jltype))
end
catch e
println("An error occured when trying to read corrupt entry $(ii) in Shapefile: $e")
push!(shapes, missing)
else
push!(shapes, read(io, jltype))
end
end
file
Expand All @@ -366,7 +373,7 @@ include("plotrecipes.jl")
seeknext(io, num, ::Nothing) = nothing

function seeknext(io, num, index::IndexHandle)
seek(io, index.indices[num+1].offset * 2)
seek(io, index.indices[num].offset * 2)
end

function Handle(path::AbstractString, indexpath::AbstractString)
Expand Down