diff --git a/src/writer.jl b/src/writer.jl index fb4a2a2..ba67a5f 100644 --- a/src/writer.jl +++ b/src/writer.jl @@ -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 diff --git a/test/writer.jl b/test/writer.jl index 79d50e0..3523ac0 100644 --- a/test/writer.jl +++ b/test/writer.jl @@ -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 @@ -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