Skip to content

Commit

Permalink
fix .shx file header on write (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshday authored May 17, 2023
1 parent a6c898e commit 6fc19c8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/writer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ function write(path::AbstractString, o::Writer; force=false)
close(io)

# Write .shx file
index_handle = IndexHandle(header, shx_indices)
filesize = (100 + 8 * length(shx_indices)) ÷ 2 # Header: 100 bytes, IndexRecord: 8 bytes each
shx_header = Header(; filesize, shapecode, mbr, zrange, mrange)
index_handle = IndexHandle(shx_header, shx_indices)
Base.write(paths.shx, index_handle)

# Write .dbf file
Expand Down
26 changes: 23 additions & 3 deletions test/writer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,32 @@ for i in eachindex(test_tuples)[1:end-1] # We dont write 15 - multipatch
ih2 = read(Shapefile._shape_paths("testshape").shx, Shapefile.IndexHandle)
@test ih1.indices == ih2.indices
end
@testset "shx headers match" begin
h1 = read(Shapefile._shape_paths(path).shx, Shapefile.Header)
h2 = read(Shapefile._shape_paths("testshape").shx, Shapefile.Header)
if !haskey(test, :skip_check_mask)
@test h1 == h2
end
end
@testset "shx bytes match" begin
r1 = read("testshape.shx")
r2 = read(Shapefile._shape_paths(path).shx)
if haskey(test, :skip_check_mask)
inds = map(eachindex(r1)) do i
!(i in test.skip_check_mask)
end
@test r1[inds] == r2[inds]
else
findall(r1 .!= r2)
@test r1 == r2
end
end

@testset "shp headers match" begin
h1 = read("testshape.shp", Shapefile.Header)
h2 = read(path, Shapefile.Header)
h3 = read(Shapefile._shape_paths("testshape").shx, Shapefile.Header)
if !haskey(test, :skip_check_mask)
@test h1 == h2 == h3
@test h1 == h2
end
end
@testset "shp bytes match" begin
Expand All @@ -127,7 +147,7 @@ for i in eachindex(test_tuples)[1:end-1] # We dont write 15 - multipatch
inds = map(eachindex(r1)) do i
!(i in test.skip_check_mask)
end
r1[inds] == r2[inds]
@test r1[inds] == r2[inds]
else
findall(r1 .!= r2)
@test r1 == r2
Expand Down

0 comments on commit 6fc19c8

Please sign in to comment.