From 75a012218c5ab0c78a9b92b1a0e54b48cf73c8be Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 8 Aug 2024 12:11:08 -0400 Subject: [PATCH 1/9] Remove method ambiguity for `scatter(::Table)` convert arguments. This commit significantly narrows the types available for the first argument in `convert_arguments(::T1, ::Table)`. This removes a method ambiguity I ran into when testing Shapefile.jl on my machine. --- ext/ShapefileMakieExt.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ShapefileMakieExt.jl b/ext/ShapefileMakieExt.jl index 1ff486b..27e9b79 100644 --- a/ext/ShapefileMakieExt.jl +++ b/ext/ShapefileMakieExt.jl @@ -10,7 +10,7 @@ GeoInterfaceMakie.@enable Shapefile.LinearRing Makie.plottype(tbl::Shapefile.Table) = Makie.plottype(Shapefile.shapes(tbl)) Makie.plottype(shp::Shapefile.Handle) = Makie.plottype(Shapefile.shapes(shp)) -for T in (Any, Union{Type{Any}, Type{<:Makie.AbstractPlot}}, Type{<:Makie.Poly}, Type{<:Makie.Lines}, Makie.PointBased) +for T in (Makie.ConversionTrait, Type{<:Makie.AbstractPlot}, Type{<:Makie.Poly}, Type{<:Makie.Lines}, Makie.PointBased) @eval begin Makie.convert_arguments(t::$T, tbl::Shapefile.Table) = Makie.convert_arguments(t, Shapefile.shapes(tbl)) From 8855be2d573e4b6faec2a3fb14d5d1215d27e8c9 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 8 Aug 2024 22:00:03 -0400 Subject: [PATCH 2/9] Add Aqua testing --- Project.toml | 5 +++-- test/runtests.jl | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 2d240c3..7740c6d 100644 --- a/Project.toml +++ b/Project.toml @@ -38,12 +38,13 @@ julia = "1.9" [extras] ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3" +Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" RemoteFiles = "cbe49d4c-5af1-5b60-bb70-0a60aa018e1b" -ZipFile = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +ZipFile = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea" [targets] -test = ["ArchGDAL", "DataFrames", "Makie", "Plots", "RemoteFiles", "ZipFile", "Test"] +test = ["ArchGDAL", "Aqua", "DataFrames", "Makie", "Plots", "RemoteFiles", "ZipFile", "Test"] diff --git a/test/runtests.jl b/test/runtests.jl index 165afe3..7e88bdb 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,6 +3,8 @@ using Shapefile using GeoFormatTypes using Test +import Aqua + const GI = GeoInterface @@ -255,3 +257,19 @@ include("table.jl") include("writer.jl") cleanup() + +import GeoInterfaceRecipes # for ambiguity ignore list only + +Aqua.test_all( + Shapefile; + # Exclude ambiguities from imported packages as well as GeoInterfaceRecipes, + # since the ambiguities there are not the kind that would actually cause problems. + ambiguities = (; recursive = false, exclude = [GeoInterfaceRecipes.apply_recipe,]), + # GeoInterfaceRecipes and GeoInterfaceMakie are considered stale dependencies + # but are actually used in extensions on Plots and Makie respectively, so we need them! + stale_deps = (; ignore = [:GeoInterfaceRecipes, :GeoInterfaceMakie]), + # too much headache for now - will go through this again if I'm sure + # CompatHelper is working, but the tests are good flags for new versions with + # suspicious behaviour. + deps_compat = false, +) From 46ee46cc76b024c924bf654805a07baf95bbd6a4 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 8 Aug 2024 22:00:17 -0400 Subject: [PATCH 3/9] Remove GI dimchecks on Subpolygon that cause ambiguities --- src/polygons.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/polygons.jl b/src/polygons.jl index 04292e8..1a1ee1e 100644 --- a/src/polygons.jl +++ b/src/polygons.jl @@ -35,10 +35,9 @@ struct SubPolygon{L<:LinearRing} <: AbstractVector{L} end GI.isgeometry(::Type{<:SubPolygon}) = true GI.geomtrait(::SubPolygon) = GI.PolygonTrait() -GI.is3d(::GI.PolygonTrait, p::SubPolygon) = GI.is3d(first(p)) -GI.ismeasured(::GI.PolygonTrait, p::SubPolygon) = GI.measures(first(p)) GI.ncoord(::GI.PolygonTrait, ::SubPolygon{<:LinearRing{P}}) where {P} = _ncoord(P) GI.ngeom(::GI.PolygonTrait, sp::SubPolygon) = length(sp) +# `is3d` and `ismeasured` are defined in `extents.jl` Base.@propagate_inbounds GI.getgeom(::GI.PolygonTrait, sp::SubPolygon, i::Integer) = getindex(sp, i) From 325a068d976e2f671b732b10f7f775f65d6f1039 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 8 Aug 2024 22:01:33 -0400 Subject: [PATCH 4/9] Fix reference to `apply_recipe` --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 7e88bdb..376b56e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -264,7 +264,7 @@ Aqua.test_all( Shapefile; # Exclude ambiguities from imported packages as well as GeoInterfaceRecipes, # since the ambiguities there are not the kind that would actually cause problems. - ambiguities = (; recursive = false, exclude = [GeoInterfaceRecipes.apply_recipe,]), + ambiguities = (; recursive = false, exclude = [GeoInterfaceRecipes.RecipesBase.apply_recipe,]), # GeoInterfaceRecipes and GeoInterfaceMakie are considered stale dependencies # but are actually used in extensions on Plots and Makie respectively, so we need them! stale_deps = (; ignore = [:GeoInterfaceRecipes, :GeoInterfaceMakie]), From 558834dc57dd1ed79ceca8924a5b7e8be80e4fd2 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 8 Aug 2024 22:02:39 -0400 Subject: [PATCH 5/9] Test string equality by `==` not `===` --- test/table.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/table.jl b/test/table.jl index 1750b55..98f7c3d 100644 --- a/test/table.jl +++ b/test/table.jl @@ -105,7 +105,7 @@ wkt = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",637813 ) for r in ne_land @test Shapefile.shape(r) isa Shapefile.Polygon - @test r.featurecla === "Land" + @test r.featurecla == "Land" end df_land = DataFrames.DataFrame(ne_land) @test size(df_land) == (127, 4) From b78c933a3100e898e8a9dbecc748dc4404e588e8 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 8 Aug 2024 22:44:38 -0400 Subject: [PATCH 6/9] Make tests pass! --- test/table.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/table.jl b/test/table.jl index 98f7c3d..1b4909e 100644 --- a/test/table.jl +++ b/test/table.jl @@ -52,7 +52,7 @@ ne_cities = Shapefile.Table(path(natural_earth, "ne_cities_shp")) if eltype(a) <: Union{Missing, String} # ne_cities has non-ascii characters @test all(isequal.( - replace.(skipmissing(a), !isascii => x -> '_' ^ textwidth(x)), + skipmissing(a),#replace.(skipmissing(a), !isascii => x -> '_' ^ textwidth(x)), skipmissing(b) )) else From 3a9c1d5a8aefc994131b47910b7c8350c31d8adb Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 8 Aug 2024 22:45:02 -0400 Subject: [PATCH 7/9] Unify all tests into one toplevel testset This is mainly so that the overview is better looking. --- test/runtests.jl | 464 ++++++++++++++++++++++++----------------------- 1 file changed, 234 insertions(+), 230 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 376b56e..7652aed 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,269 +7,273 @@ import Aqua const GI = GeoInterface +import GeoInterfaceRecipes # for ambiguity ignore list only using Shapefile: Point, PointM, PointZ, Polygon, PolygonM, PolygonZ, Polyline, PolylineM, PolylineZ, MultiPoint, MultiPointM, MultiPointZ, MultiPatch, LineString, LinearRing, SubPolygon, Rect, Interval -shp = Shapefile.Handle(joinpath("shapelib_testcases", "test.shp")) + shp = Shapefile.Handle(joinpath("shapelib_testcases", "test.shp")) -function cleanup() - files = filter(readdir(@__DIR__)) do file - any(ext -> endswith(file, ext), [".shp", ".shx", ".dbf", ".prj"]) + function cleanup() + files = filter(readdir(@__DIR__)) do file + any(ext -> endswith(file, ext), [".shp", ".shx", ".dbf", ".prj"]) + end + rm.(files) end - rm.(files) -end -cleanup() + cleanup() -test_tuples = [ - ( - path=joinpath("shapelib_testcases", "test.shp"), - geomtype=Polygon, - coordinates=[[[[[20.0,20.0],[20.0,30.0],[30.0,30.0],[20.0,20.0]]],[[[0.0,0.0],[100.0,0.0],[100.0,100.0],[0.0,100.0],[0.0,0.0]]]],[[[[150.0,150.0],[160.0,150.0],[180.0,170.0],[150.0,150.0]]]],[[[[150.0,150.0],[160.0,150.0],[180.0,170.0],[150.0,150.0]]]]], - extent=Extent(X=(0.0, 180.0), Y=(0.0, 170.0), Z=(0.0, 0.0)), - ),( - path=joinpath("shapelib_testcases", "test0.shp"), - geomtype=Missing, - coordinates=nothing, - extent=Extent(X=(0.0, 10.0), Y=(0.0, 20.0), Z=(0.0, 0.0)), - # This data has no shape, the correct bbox should be all zeros. - # However the data contain some non-zero box values - skip_check_mask = [43:44..., 51:52..., 59:60..., 67:68...], - ),( - path=joinpath("shapelib_testcases", "test1.shp"), - geomtype=Point, - coordinates=[[1.0,2.0],[10.0,20.0]], - extent=Extent(X=(1.0, 10.0), Y=(2.0, 20.0), Z=(0.0, 0.0)), - ),( - path=joinpath("shapelib_testcases", "test2.shp"), - geomtype=PointZ, - coordinates=[[1.0,2.0,3.0,4.0],[10.0,20.0,30.0,40.0]], - extent=Extent(X=(1.0, 10.0), Y=(2.0, 20.0), Z=(3.0, 30.0)), - ),( - path=joinpath("shapelib_testcases", "test3.shp"), - geomtype=PointM, - coordinates=[[1.0,2.0,4.0],[10.0,20.0,40.0]], - extent=Extent(X=(1.0, 10.0), Y=(2.0, 20.0), Z=(0.0, 0.0)), - ),( - path=joinpath("shapelib_testcases", "test4.shp"), - geomtype=MultiPoint, - coordinates=[[[1.15,2.25],[2.15,3.25],[3.15,4.25],[4.15,5.25]],[[11.15,12.25],[12.15,13.25],[13.15,14.25],[14.15,15.25]],[[21.15,22.25],[22.15,23.25],[23.15,24.25],[24.15,25.25]]], - extent=Extent(X=(1.15, 24.15), Y=(2.25, 25.25), Z=(0.0, 0.0)), - ),( - path=joinpath("shapelib_testcases", "test5.shp"), - geomtype=MultiPointZ, - coordinates=[[[1.15,2.25,3.35,4.45],[2.15,3.25,4.35,5.45],[3.15,4.25,5.35,6.45],[4.15,5.25,6.35,7.45]],[[11.15,12.25,13.35,14.45],[12.15,13.25,14.35,15.45],[13.15,14.25,15.35,16.45],[14.15,15.25,16.35,17.45]],[[21.15,22.25,23.35,24.45],[22.15,23.25,24.35,25.45],[23.15,24.25,25.35,26.45],[24.15,25.25,26.35,27.45]]], - extent=Extent(X=(1.15, 24.15), Y=(2.25, 25.25), Z=(3.35, 26.35)), - ),( - path=joinpath("shapelib_testcases", "test6.shp"), - geomtype=MultiPointM, - coordinates=[[[1.15,2.25,4.45],[2.15,3.25,5.45],[3.15,4.25,6.45],[4.15,5.25,7.45]],[[11.15,12.25,14.45],[12.15,13.25,15.45],[13.15,14.25,16.45],[14.15,15.25,17.45]],[[21.15,22.25,24.45],[22.15,23.25,25.45],[23.15,24.25,26.45],[24.15,25.25,27.45]]], - extent=Extent(X=(1.15, 24.15), Y=(2.25, 25.25), Z=(0.0, 0.0)), - ),( - path=joinpath("shapelib_testcases", "test7.shp"), - geomtype=Polyline, - coordinates=[[[[1.0,1.0],[2.0,1.0],[2.0,2.0],[1.0,2.0],[1.0,1.0]]],[[[1.0,4.0],[2.0,4.0],[2.0,5.0],[1.0,5.0],[1.0,4.0]]],[[[1.0,7.0],[2.0,7.0],[2.0,8.0],[1.0,8.0],[1.0,7.0]]],[[[0.0,0.0],[0.0,100.0],[100.0,100.0],[100.0,0.0],[0.0,0.0]],Array{Float64,1}[[10.0,20.0],[30.0,20.0],[30.0,40.0],[10.0,40.0],[10.0,20.0]],Array{Float64,1}[[60.0,20.0],[90.0,20.0],[90.0,40.0],[60.0,40.0],[60.0,20.0]]]], - extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 0.0)), - ),( - path=joinpath("shapelib_testcases", "test8.shp"), - geomtype=PolylineZ, - coordinates=[[[[1.0,1.0,3.35,4.45],[2.0,1.0,4.35,5.45],[2.0,2.0,5.35,6.45],[1.0,2.0,6.35,7.45],[1.0,1.0,7.35,8.45]]],[[[1.0,4.0,13.35,14.45],[2.0,4.0,14.35,15.45],[2.0,5.0,15.35,16.45],[1.0,5.0,16.35,17.45],[1.0,4.0,17.35,18.45]]],[[[1.0,7.0,23.35,24.45],[2.0,7.0,24.35,25.45],[2.0,8.0,25.35,26.45],[1.0,8.0,26.35,27.45],[1.0,7.0,27.35,28.45]]],[[[0.0,0.0,0.0,0.0],[0.0,100.0,1.0,2.0],[100.0,100.0,2.0,4.0],[100.0,0.0,3.0,6.0],[0.0,0.0,4.0,8.0]],[[10.0,20.0,5.0,10.0],[30.0,20.0,6.0,12.0],[30.0,40.0,7.0,14.0],[10.0,40.0,8.0,16.0],[10.0,20.0,9.0,18.0]],[[60.0,20.0,10.0,20.0],[90.0,20.0,11.0,22.0],[90.0,40.0,12.0,24.0],[60.0,40.0,13.0,26.0],[60.0,20.0,14.0,28.0]]]], - extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 27.35)), - ),( - path=joinpath("shapelib_testcases", "test9.shp"), - geomtype=PolylineM, - coordinates=[[[[1.0,1.0,4.45],[2.0,1.0,5.45],[2.0,2.0,6.45],[1.0,2.0,7.45],[1.0,1.0,8.45]]],[[[1.0,4.0,14.45],[2.0,4.0,15.45],[2.0,5.0,16.45],[1.0,5.0,17.45],[1.0,4.0,18.45]]],[[[1.0,7.0,24.45],[2.0,7.0,25.45],[2.0,8.0,26.45],[1.0,8.0,27.45],[1.0,7.0,28.45]]],[[[0.0,0.0,0.0],[0.0,100.0,2.0],[100.0,100.0,4.0],[100.0,0.0,6.0],[0.0,0.0,8.0]],[[10.0,20.0,10.0],[30.0,20.0,12.0],[30.0,40.0,14.0],[10.0,40.0,16.0],[10.0,20.0,18.0]],[[60.0,20.0,20.0],[90.0,20.0,22.0],[90.0,40.0,24.0],[60.0,40.0,26.0],[60.0,20.0,28.0]]]], - extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 0.0)), - ),( - path=joinpath("shapelib_testcases", "test10.shp"), - geomtype=Polygon, - coordinates=[[[[[1.0,1.0],[2.0,1.0],[2.0,2.0],[1.0,2.0],[1.0,1.0]]]],[[[[1.0,4.0],[2.0,4.0],[2.0,5.0],[1.0,5.0],[1.0,4.0]]]],[[[[1.0,7.0],[2.0,7.0],[2.0,8.0],[1.0,8.0],[1.0,7.0]]]],[[[[0.0,0.0],[0.0,100.0],[100.0,100.0],[100.0,0.0],[0.0,0.0]],[[10.0,20.0],[30.0,20.0],[30.0,40.0],[10.0,40.0],[10.0,20.0]],[[60.0,20.0],[90.0,20.0],[90.0,40.0],[60.0,40.0],[60.0,20.0]]]]], - extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 0.0)), - ),( - path=joinpath("shapelib_testcases", "test11.shp"), - geomtype=PolygonZ, - coordinates=[[[[[1.0,1.0,3.35,4.45],[2.0,1.0,4.35,5.45],[2.0,2.0,5.35,6.45],[1.0,2.0,6.35,7.45],[1.0,1.0,7.35,8.45]]]],[[[[1.0,4.0,13.35,14.45],[2.0,4.0,14.35,15.45],[2.0,5.0,15.35,16.45],[1.0,5.0,16.35,17.45],[1.0,4.0,17.35,18.45]]]],[[[[1.0,7.0,23.35,24.45],[2.0,7.0,24.35,25.45],[2.0,8.0,25.35,26.45],[1.0,8.0,26.35,27.45],[1.0,7.0,27.35,28.45]]]],[[[[0.0,0.0,0.0,0.0],[0.0,100.0,1.0,2.0],[100.0,100.0,2.0,4.0],[100.0,0.0,3.0,6.0],[0.0,0.0,4.0,8.0]],[[10.0,20.0,5.0,10.0],[30.0,20.0,6.0,12.0],[30.0,40.0,7.0,14.0],[10.0,40.0,8.0,16.0],[10.0,20.0,9.0,18.0]],[[60.0,20.0,10.0,20.0],[90.0,20.0,11.0,22.0],[90.0,40.0,12.0,24.0],[60.0,40.0,13.0,26.0],[60.0,20.0,14.0,28.0]]]]], - extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 27.35)), - ),( - path=joinpath("shapelib_testcases", "test12.shp"), - geomtype=PolygonM, - coordinates=[[[[[1.0,1.0,4.45],[2.0,1.0,5.45],[2.0,2.0,6.45],[1.0,2.0,7.45],[1.0,1.0,8.45]]]],[[[[1.0,4.0,14.45],[2.0,4.0,15.45],[2.0,5.0,16.45],[1.0,5.0,17.45],[1.0,4.0,18.45]]]],[[[[1.0,7.0,24.45],[2.0,7.0,25.45],[2.0,8.0,26.45],[1.0,8.0,27.45],[1.0,7.0,28.45]]]],[[[[0.0,0.0,0.0],[0.0,100.0,2.0],[100.0,100.0,4.0],[100.0,0.0,6.0],[0.0,0.0,8.0]],[[10.0,20.0,10.0],[30.0,20.0,12.0],[30.0,40.0,14.0],[10.0,40.0,16.0],[10.0,20.0,18.0]],[[60.0,20.0,20.0],[90.0,20.0,22.0],[90.0,40.0,24.0],[60.0,40.0,26.0],[60.0,20.0,28.0]]]]],extent=Extent(X=(0.0,100.0),Y=(0.0,100.0),Z=(0.0,0.0)), - ),( - path=joinpath("shapelib_testcases/test13.shp"), - geomtype=MultiPatch, - coordinates=nothing, - extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 27.35)), - skip_check_mask = 93:100, - ) -] + test_tuples = [ + ( + path=joinpath("shapelib_testcases", "test.shp"), + geomtype=Polygon, + coordinates=[[[[[20.0,20.0],[20.0,30.0],[30.0,30.0],[20.0,20.0]]],[[[0.0,0.0],[100.0,0.0],[100.0,100.0],[0.0,100.0],[0.0,0.0]]]],[[[[150.0,150.0],[160.0,150.0],[180.0,170.0],[150.0,150.0]]]],[[[[150.0,150.0],[160.0,150.0],[180.0,170.0],[150.0,150.0]]]]], + extent=Extent(X=(0.0, 180.0), Y=(0.0, 170.0), Z=(0.0, 0.0)), + ),( + path=joinpath("shapelib_testcases", "test0.shp"), + geomtype=Missing, + coordinates=nothing, + extent=Extent(X=(0.0, 10.0), Y=(0.0, 20.0), Z=(0.0, 0.0)), + # This data has no shape, the correct bbox should be all zeros. + # However the data contain some non-zero box values + skip_check_mask = [43:44..., 51:52..., 59:60..., 67:68...], + ),( + path=joinpath("shapelib_testcases", "test1.shp"), + geomtype=Point, + coordinates=[[1.0,2.0],[10.0,20.0]], + extent=Extent(X=(1.0, 10.0), Y=(2.0, 20.0), Z=(0.0, 0.0)), + ),( + path=joinpath("shapelib_testcases", "test2.shp"), + geomtype=PointZ, + coordinates=[[1.0,2.0,3.0,4.0],[10.0,20.0,30.0,40.0]], + extent=Extent(X=(1.0, 10.0), Y=(2.0, 20.0), Z=(3.0, 30.0)), + ),( + path=joinpath("shapelib_testcases", "test3.shp"), + geomtype=PointM, + coordinates=[[1.0,2.0,4.0],[10.0,20.0,40.0]], + extent=Extent(X=(1.0, 10.0), Y=(2.0, 20.0), Z=(0.0, 0.0)), + ),( + path=joinpath("shapelib_testcases", "test4.shp"), + geomtype=MultiPoint, + coordinates=[[[1.15,2.25],[2.15,3.25],[3.15,4.25],[4.15,5.25]],[[11.15,12.25],[12.15,13.25],[13.15,14.25],[14.15,15.25]],[[21.15,22.25],[22.15,23.25],[23.15,24.25],[24.15,25.25]]], + extent=Extent(X=(1.15, 24.15), Y=(2.25, 25.25), Z=(0.0, 0.0)), + ),( + path=joinpath("shapelib_testcases", "test5.shp"), + geomtype=MultiPointZ, + coordinates=[[[1.15,2.25,3.35,4.45],[2.15,3.25,4.35,5.45],[3.15,4.25,5.35,6.45],[4.15,5.25,6.35,7.45]],[[11.15,12.25,13.35,14.45],[12.15,13.25,14.35,15.45],[13.15,14.25,15.35,16.45],[14.15,15.25,16.35,17.45]],[[21.15,22.25,23.35,24.45],[22.15,23.25,24.35,25.45],[23.15,24.25,25.35,26.45],[24.15,25.25,26.35,27.45]]], + extent=Extent(X=(1.15, 24.15), Y=(2.25, 25.25), Z=(3.35, 26.35)), + ),( + path=joinpath("shapelib_testcases", "test6.shp"), + geomtype=MultiPointM, + coordinates=[[[1.15,2.25,4.45],[2.15,3.25,5.45],[3.15,4.25,6.45],[4.15,5.25,7.45]],[[11.15,12.25,14.45],[12.15,13.25,15.45],[13.15,14.25,16.45],[14.15,15.25,17.45]],[[21.15,22.25,24.45],[22.15,23.25,25.45],[23.15,24.25,26.45],[24.15,25.25,27.45]]], + extent=Extent(X=(1.15, 24.15), Y=(2.25, 25.25), Z=(0.0, 0.0)), + ),( + path=joinpath("shapelib_testcases", "test7.shp"), + geomtype=Polyline, + coordinates=[[[[1.0,1.0],[2.0,1.0],[2.0,2.0],[1.0,2.0],[1.0,1.0]]],[[[1.0,4.0],[2.0,4.0],[2.0,5.0],[1.0,5.0],[1.0,4.0]]],[[[1.0,7.0],[2.0,7.0],[2.0,8.0],[1.0,8.0],[1.0,7.0]]],[[[0.0,0.0],[0.0,100.0],[100.0,100.0],[100.0,0.0],[0.0,0.0]],Array{Float64,1}[[10.0,20.0],[30.0,20.0],[30.0,40.0],[10.0,40.0],[10.0,20.0]],Array{Float64,1}[[60.0,20.0],[90.0,20.0],[90.0,40.0],[60.0,40.0],[60.0,20.0]]]], + extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 0.0)), + ),( + path=joinpath("shapelib_testcases", "test8.shp"), + geomtype=PolylineZ, + coordinates=[[[[1.0,1.0,3.35,4.45],[2.0,1.0,4.35,5.45],[2.0,2.0,5.35,6.45],[1.0,2.0,6.35,7.45],[1.0,1.0,7.35,8.45]]],[[[1.0,4.0,13.35,14.45],[2.0,4.0,14.35,15.45],[2.0,5.0,15.35,16.45],[1.0,5.0,16.35,17.45],[1.0,4.0,17.35,18.45]]],[[[1.0,7.0,23.35,24.45],[2.0,7.0,24.35,25.45],[2.0,8.0,25.35,26.45],[1.0,8.0,26.35,27.45],[1.0,7.0,27.35,28.45]]],[[[0.0,0.0,0.0,0.0],[0.0,100.0,1.0,2.0],[100.0,100.0,2.0,4.0],[100.0,0.0,3.0,6.0],[0.0,0.0,4.0,8.0]],[[10.0,20.0,5.0,10.0],[30.0,20.0,6.0,12.0],[30.0,40.0,7.0,14.0],[10.0,40.0,8.0,16.0],[10.0,20.0,9.0,18.0]],[[60.0,20.0,10.0,20.0],[90.0,20.0,11.0,22.0],[90.0,40.0,12.0,24.0],[60.0,40.0,13.0,26.0],[60.0,20.0,14.0,28.0]]]], + extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 27.35)), + ),( + path=joinpath("shapelib_testcases", "test9.shp"), + geomtype=PolylineM, + coordinates=[[[[1.0,1.0,4.45],[2.0,1.0,5.45],[2.0,2.0,6.45],[1.0,2.0,7.45],[1.0,1.0,8.45]]],[[[1.0,4.0,14.45],[2.0,4.0,15.45],[2.0,5.0,16.45],[1.0,5.0,17.45],[1.0,4.0,18.45]]],[[[1.0,7.0,24.45],[2.0,7.0,25.45],[2.0,8.0,26.45],[1.0,8.0,27.45],[1.0,7.0,28.45]]],[[[0.0,0.0,0.0],[0.0,100.0,2.0],[100.0,100.0,4.0],[100.0,0.0,6.0],[0.0,0.0,8.0]],[[10.0,20.0,10.0],[30.0,20.0,12.0],[30.0,40.0,14.0],[10.0,40.0,16.0],[10.0,20.0,18.0]],[[60.0,20.0,20.0],[90.0,20.0,22.0],[90.0,40.0,24.0],[60.0,40.0,26.0],[60.0,20.0,28.0]]]], + extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 0.0)), + ),( + path=joinpath("shapelib_testcases", "test10.shp"), + geomtype=Polygon, + coordinates=[[[[[1.0,1.0],[2.0,1.0],[2.0,2.0],[1.0,2.0],[1.0,1.0]]]],[[[[1.0,4.0],[2.0,4.0],[2.0,5.0],[1.0,5.0],[1.0,4.0]]]],[[[[1.0,7.0],[2.0,7.0],[2.0,8.0],[1.0,8.0],[1.0,7.0]]]],[[[[0.0,0.0],[0.0,100.0],[100.0,100.0],[100.0,0.0],[0.0,0.0]],[[10.0,20.0],[30.0,20.0],[30.0,40.0],[10.0,40.0],[10.0,20.0]],[[60.0,20.0],[90.0,20.0],[90.0,40.0],[60.0,40.0],[60.0,20.0]]]]], + extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 0.0)), + ),( + path=joinpath("shapelib_testcases", "test11.shp"), + geomtype=PolygonZ, + coordinates=[[[[[1.0,1.0,3.35,4.45],[2.0,1.0,4.35,5.45],[2.0,2.0,5.35,6.45],[1.0,2.0,6.35,7.45],[1.0,1.0,7.35,8.45]]]],[[[[1.0,4.0,13.35,14.45],[2.0,4.0,14.35,15.45],[2.0,5.0,15.35,16.45],[1.0,5.0,16.35,17.45],[1.0,4.0,17.35,18.45]]]],[[[[1.0,7.0,23.35,24.45],[2.0,7.0,24.35,25.45],[2.0,8.0,25.35,26.45],[1.0,8.0,26.35,27.45],[1.0,7.0,27.35,28.45]]]],[[[[0.0,0.0,0.0,0.0],[0.0,100.0,1.0,2.0],[100.0,100.0,2.0,4.0],[100.0,0.0,3.0,6.0],[0.0,0.0,4.0,8.0]],[[10.0,20.0,5.0,10.0],[30.0,20.0,6.0,12.0],[30.0,40.0,7.0,14.0],[10.0,40.0,8.0,16.0],[10.0,20.0,9.0,18.0]],[[60.0,20.0,10.0,20.0],[90.0,20.0,11.0,22.0],[90.0,40.0,12.0,24.0],[60.0,40.0,13.0,26.0],[60.0,20.0,14.0,28.0]]]]], + extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 27.35)), + ),( + path=joinpath("shapelib_testcases", "test12.shp"), + geomtype=PolygonM, + coordinates=[[[[[1.0,1.0,4.45],[2.0,1.0,5.45],[2.0,2.0,6.45],[1.0,2.0,7.45],[1.0,1.0,8.45]]]],[[[[1.0,4.0,14.45],[2.0,4.0,15.45],[2.0,5.0,16.45],[1.0,5.0,17.45],[1.0,4.0,18.45]]]],[[[[1.0,7.0,24.45],[2.0,7.0,25.45],[2.0,8.0,26.45],[1.0,8.0,27.45],[1.0,7.0,28.45]]]],[[[[0.0,0.0,0.0],[0.0,100.0,2.0],[100.0,100.0,4.0],[100.0,0.0,6.0],[0.0,0.0,8.0]],[[10.0,20.0,10.0],[30.0,20.0,12.0],[30.0,40.0,14.0],[10.0,40.0,16.0],[10.0,20.0,18.0]],[[60.0,20.0,20.0],[90.0,20.0,22.0],[90.0,40.0,24.0],[60.0,40.0,26.0],[60.0,20.0,28.0]]]]],extent=Extent(X=(0.0,100.0),Y=(0.0,100.0),Z=(0.0,0.0)), + ),( + path=joinpath("shapelib_testcases/test13.shp"), + geomtype=MultiPatch, + coordinates=nothing, + extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 27.35)), + skip_check_mask = 93:100, + ) + ] -# Visual plot check -# for t in test_tuples -# if !(t.geomtype <: Union{Missing,MultiPatch}) -# @show t.path t.geomtype -# sh = Shapefile.Handle(t.path) -# p = sh.shapes -# display(plot(p; opacity=.5)) -# sleep(1) -# end -# end + # Visual plot check + # for t in test_tuples + # if !(t.geomtype <: Union{Missing,MultiPatch}) + # @show t.path t.geomtype + # sh = Shapefile.Handle(t.path) + # p = sh.shapes + # display(plot(p; opacity=.5)) + # sleep(1) + # end + # end -points = [Point(1, 3), Point(2, 3), Point(2, 4), Point(1, 4)] -test_shapes = Dict( - Point => Point(1, 2), - PointM => PointM(1, 2, 3), - PointZ => PointZ(1, 2, 3, 4), - MultiPoint => MultiPoint(Rect(1, 3, 2, 4), points), - MultiPointM => MultiPointM(Rect(1, 3, 2, 4), points, Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), - MultiPointZ => MultiPointZ(Rect(1, 3, 2, 4), points, Interval(1, 4), [1, 2, 3, 4], Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), - Polygon => Polygon(Rect(1, 3, 2, 4), [0], points), - PolygonM => PolygonM(Rect(1, 3, 2, 4), [0], points, Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), - PolygonZ => PolygonZ(Rect(1, 3, 2, 4), [0], points, Interval(1, 4), [1, 2, 3, 4], Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), - Polyline => Polyline(Rect(1, 3, 2, 4), [0], points), - PolylineM => PolylineM(Rect(1, 3, 2, 4), [0], points, Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), - PolylineZ => PolylineZ(Rect(1, 3, 2, 4), [0], points, Interval(1, 4), [1, 2, 3, 4], Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), - LineString => LineString{Point}(view(points, 1:4)), - LinearRing => LinearRing{Point}(view(points, 1:4)), - SubPolygon => SubPolygon([LinearRing{Point}(view(points, 1:4))]), -) + points = [Point(1, 3), Point(2, 3), Point(2, 4), Point(1, 4)] + test_shapes = Dict( + Point => Point(1, 2), + PointM => PointM(1, 2, 3), + PointZ => PointZ(1, 2, 3, 4), + MultiPoint => MultiPoint(Rect(1, 3, 2, 4), points), + MultiPointM => MultiPointM(Rect(1, 3, 2, 4), points, Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), + MultiPointZ => MultiPointZ(Rect(1, 3, 2, 4), points, Interval(1, 4), [1, 2, 3, 4], Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), + Polygon => Polygon(Rect(1, 3, 2, 4), [0], points), + PolygonM => PolygonM(Rect(1, 3, 2, 4), [0], points, Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), + PolygonZ => PolygonZ(Rect(1, 3, 2, 4), [0], points, Interval(1, 4), [1, 2, 3, 4], Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), + Polyline => Polyline(Rect(1, 3, 2, 4), [0], points), + PolylineM => PolylineM(Rect(1, 3, 2, 4), [0], points, Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), + PolylineZ => PolylineZ(Rect(1, 3, 2, 4), [0], points, Interval(1, 4), [1, 2, 3, 4], Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), + LineString => LineString{Point}(view(points, 1:4)), + LinearRing => LinearRing{Point}(view(points, 1:4)), + SubPolygon => SubPolygon([LinearRing{Point}(view(points, 1:4))]), + ) -@testset "GeoInterface compatibility" begin - foreach(test_shapes) do (k, s) - @test GeoInterface.testgeometry(s) - @test GeoInterface.extent(s) isa GeoInterface.Extent - # This test should be moved to GeoInterface `testgeometry` - @test GeoInterface.ncoord(s) == - (2 + GeoInterface.is3d(s) + GeoInterface.ismeasured(s)) == - length(GeoInterface.coordnames(s)) - # TODO Plotting a single measured point fails, needs fixing in GeoInterfaceRecipes.jl - GeoInterface.ismeasured(s) && GeoInterface.trait(s) isa GeoInterface.PointTrait || plot(s) - end - @test_broken GeoInterface.testgeometry(MultiPatch(Rect(1, 3, 2, 4), [0], [1], points, Interval(1, 4), [1, 2, 3, 4])) +@testset "Shapefile.jl" begin - @test GeoInterface.extent(Shapefile.Point(1.0, 2.0)) == Extents.Extent(X=(1.0, 1.0), Y=(2.0, 2.0)) - @test GeoInterface.extent(Shapefile.PointM(1.0, 2.0, 4.0)) == Extents.Extent(X=(1.0, 1.0), Y=(2.0, 2.0)) - @test GeoInterface.extent(Shapefile.PointZ(1.0, 2.0, 3.0, 4.0)) == Extents.Extent(X=(1.0, 1.0), Y=(2.0, 2.0), Z=(3.0, 3.0)) - @test GeoInterface.extent(test_shapes[Polygon]) == Extents.Extent(X=(1.0, 2.0), Y=(3.0, 4.0)) - @test GeoInterface.extent(test_shapes[PolygonM]) == Extents.Extent(X=(1.0, 2.0), Y=(3.0, 4.0)) - @test GeoInterface.extent(test_shapes[PolygonZ]) == Extents.Extent(X=(1.0, 2.0), Y=(3.0, 4.0), Z=(1.0, 4.0)) + @testset "GeoInterface compatibility" begin + foreach(test_shapes) do (k, s) + @test GeoInterface.testgeometry(s) + @test GeoInterface.extent(s) isa GeoInterface.Extent + # This test should be moved to GeoInterface `testgeometry` + @test GeoInterface.ncoord(s) == + (2 + GeoInterface.is3d(s) + GeoInterface.ismeasured(s)) == + length(GeoInterface.coordnames(s)) + # TODO Plotting a single measured point fails, needs fixing in GeoInterfaceRecipes.jl + GeoInterface.ismeasured(s) && GeoInterface.trait(s) isa GeoInterface.PointTrait || plot(s) + end + @test_broken GeoInterface.testgeometry(MultiPatch(Rect(1, 3, 2, 4), [0], [1], points, Interval(1, 4), [1, 2, 3, 4])) + + @test GeoInterface.extent(Shapefile.Point(1.0, 2.0)) == Extents.Extent(X=(1.0, 1.0), Y=(2.0, 2.0)) + @test GeoInterface.extent(Shapefile.PointM(1.0, 2.0, 4.0)) == Extents.Extent(X=(1.0, 1.0), Y=(2.0, 2.0)) + @test GeoInterface.extent(Shapefile.PointZ(1.0, 2.0, 3.0, 4.0)) == Extents.Extent(X=(1.0, 1.0), Y=(2.0, 2.0), Z=(3.0, 3.0)) + @test GeoInterface.extent(test_shapes[Polygon]) == Extents.Extent(X=(1.0, 2.0), Y=(3.0, 4.0)) + @test GeoInterface.extent(test_shapes[PolygonM]) == Extents.Extent(X=(1.0, 2.0), Y=(3.0, 4.0)) + @test GeoInterface.extent(test_shapes[PolygonZ]) == Extents.Extent(X=(1.0, 2.0), Y=(3.0, 4.0), Z=(1.0, 4.0)) - subpolygon = getgeom(test_shapes[Polygon], 1) - @test GeoInterface.testgeometry(subpolygon) - linearring = getgeom(subpolygon, 1) - @test GeoInterface.testgeometry(linearring) - @test GeoInterface.extent(subpolygon) == Extents.Extent(X=(1.0, 2.0), Y=(3.0, 4.0)) + subpolygon = getgeom(test_shapes[Polygon], 1) + @test GeoInterface.testgeometry(subpolygon) + linearring = getgeom(subpolygon, 1) + @test GeoInterface.testgeometry(linearring) + @test GeoInterface.extent(subpolygon) == Extents.Extent(X=(1.0, 2.0), Y=(3.0, 4.0)) - @test GeoInterface.trait(shp) isa GeoInterface.GeometryCollectionTrait - @test GeoInterface.testgeometry(shp) -end + @test GeoInterface.trait(shp) isa GeoInterface.GeometryCollectionTrait + @test GeoInterface.testgeometry(shp) + end -@testset "Loading Shapefiles" begin + @testset "Loading Shapefiles" begin -for test in test_tuples - for shx in (:manual, :auto, :none) - shp = if shx == :manual - # this accesses .shp based on offsets in .shx - stempath, ext = splitext(test.path) - shxname = string(stempath, ".shx") - Shapefile.Handle(joinpath(@__DIR__, test.path), joinpath(@__DIR__, shxname)) - elseif shx == :auto - Shapefile.Handle(joinpath(@__DIR__, test.path)) - else - # use .shp only - open(joinpath(@__DIR__, test.path)) do fd - read(fd, Shapefile.Handle) + for test in test_tuples + for shx in (:manual, :auto, :none) + shp = if shx == :manual + # this accesses .shp based on offsets in .shx + stempath, ext = splitext(test.path) + shxname = string(stempath, ".shx") + Shapefile.Handle(joinpath(@__DIR__, test.path), joinpath(@__DIR__, shxname)) + elseif shx == :auto + Shapefile.Handle(joinpath(@__DIR__, test.path)) + else + # use .shp only + open(joinpath(@__DIR__, test.path)) do fd + read(fd, Shapefile.Handle) + end end + shapes = unique(map(typeof, shp.shapes)) + @test GeoInterface.crs(shp) == nothing + @test length(shapes) == 1 + @test length(shapes) == 1 + @test shapes[1] == test.geomtype + @test eltype(shp.shapes) == Union{test.geomtype,Missing} + # missing and MultiPatch are not covered by the GeoInterface + if !(test.geomtype <: Union{Missing,Shapefile.MultiPatch}) + @test GeoInterface.coordinates.(shp.shapes) == test.coordinates + # Run this a second time to test caching + @test GeoInterface.coordinates.(shp.shapes) == test.coordinates + end + ext = test.extent + @test shp.header.MBR == Shapefile.Rect(ext.X[1], ext.Y[1], ext.X[2], ext.Y[2]) + @test GeoInterface.extent(shp) == test.extent + # Multipatch can't be plotted, but it's obscure anyway + test.geomtype == Shapefile.MultiPatch && continue + # Plots has no fallback recipe for a Vector{Missing} + length(collect(skipmissing(shp.shapes))) > 0 || continue + # Plots cant plot measures + GeoInterface.ismeasured(first(skipmissing(shp.shapes))) && continue + # plot(shp) # Just test that geometries actually plot end - shapes = unique(map(typeof, shp.shapes)) - @test GeoInterface.crs(shp) == nothing - @test length(shapes) == 1 - @test length(shapes) == 1 - @test shapes[1] == test.geomtype - @test eltype(shp.shapes) == Union{test.geomtype,Missing} - # missing and MultiPatch are not covered by the GeoInterface - if !(test.geomtype <: Union{Missing,Shapefile.MultiPatch}) - @test GeoInterface.coordinates.(shp.shapes) == test.coordinates - # Run this a second time to test caching - @test GeoInterface.coordinates.(shp.shapes) == test.coordinates - end - ext = test.extent - @test shp.header.MBR == Shapefile.Rect(ext.X[1], ext.Y[1], ext.X[2], ext.Y[2]) - @test GeoInterface.extent(shp) == test.extent - # Multipatch can't be plotted, but it's obscure anyway - test.geomtype == Shapefile.MultiPatch && continue - # Plots has no fallback recipe for a Vector{Missing} - length(collect(skipmissing(shp.shapes))) > 0 || continue - # Plots cant plot measures - GeoInterface.ismeasured(first(skipmissing(shp.shapes))) && continue - # plot(shp) # Just test that geometries actually plot end -end -# Test all .shx files; the values in .shx must match the .shp offsets -test = test_tuples[1] -for test in test_tuples + # Test all .shx files; the values in .shx must match the .shp offsets + test = test_tuples[1] + for test in test_tuples - offsets = Int32[] - contentlens = Int32[] + offsets = Int32[] + contentlens = Int32[] - # Get the shapefile's record offsets and contentlens - shp = open(joinpath(@__DIR__, test.path)) do fd - seek(fd, 32) - shapeType = read(fd, Int32) - seek(fd, 100) - jltype = Shapefile.SHAPETYPE[shapeType] - - push!(offsets, position(fd)) - while (!eof(fd)) - - num = bswap(read(fd, Int32)) - rlength = bswap(read(fd, Int32)) + # Get the shapefile's record offsets and contentlens + shp = open(joinpath(@__DIR__, test.path)) do fd + seek(fd, 32) shapeType = read(fd, Int32) - if shapeType !== Int32(0) - read(fd, jltype) - end + seek(fd, 100) + jltype = Shapefile.SHAPETYPE[shapeType] - # records the offset after this geometry record push!(offsets, position(fd)) - end - end - contentlens = diff(offsets) - offsets = offsets[1:end-1] + while (!eof(fd)) - # Match the Index values to Shapefile offsets - shx = - open(joinpath(@__DIR__, replace(test.path, r".shp$" => ".shx"))) do fd - shx = read(fd, Shapefile.IndexHandle) - for sIdx = 1:lastindex(shx.indices) - @test shx.indices[sIdx].offset * 2 == offsets[sIdx] - @test shx.indices[sIdx].contentlen * 2 + 8 == contentlens[sIdx] + num = bswap(read(fd, Int32)) + rlength = bswap(read(fd, Int32)) + shapeType = read(fd, Int32) + if shapeType !== Int32(0) + read(fd, jltype) + end + + # records the offset after this geometry record + push!(offsets, position(fd)) end end + contentlens = diff(offsets) + offsets = offsets[1:end-1] -end + # Match the Index values to Shapefile offsets + shx = + open(joinpath(@__DIR__, replace(test.path, r".shp$" => ".shx"))) do fd + shx = read(fd, Shapefile.IndexHandle) + for sIdx = 1:lastindex(shx.indices) + @test shx.indices[sIdx].offset * 2 == offsets[sIdx] + @test shx.indices[sIdx].contentlen * 2 + 8 == contentlens[sIdx] + end + end -end # @testset "Loading Shapefiles" + end -include("table.jl") -include("writer.jl") + end # @testset "Loading Shapefiles" -cleanup() + include("table.jl") + include("writer.jl") -import GeoInterfaceRecipes # for ambiguity ignore list only + cleanup() -Aqua.test_all( - Shapefile; - # Exclude ambiguities from imported packages as well as GeoInterfaceRecipes, - # since the ambiguities there are not the kind that would actually cause problems. - ambiguities = (; recursive = false, exclude = [GeoInterfaceRecipes.RecipesBase.apply_recipe,]), - # GeoInterfaceRecipes and GeoInterfaceMakie are considered stale dependencies - # but are actually used in extensions on Plots and Makie respectively, so we need them! - stale_deps = (; ignore = [:GeoInterfaceRecipes, :GeoInterfaceMakie]), - # too much headache for now - will go through this again if I'm sure - # CompatHelper is working, but the tests are good flags for new versions with - # suspicious behaviour. - deps_compat = false, -) + @testset "Aqua.jl" begin + Aqua.test_all( + Shapefile; + # Exclude ambiguities from imported packages as well as GeoInterfaceRecipes, + # since the ambiguities there are not the kind that would actually cause problems. + ambiguities = (; recursive = false, exclude = [GeoInterfaceRecipes.RecipesBase.apply_recipe,]), + # GeoInterfaceRecipes and GeoInterfaceMakie are considered stale dependencies + # but are actually used in extensions on Plots and Makie respectively, so we need them! + stale_deps = (; ignore = [:GeoInterfaceRecipes, :GeoInterfaceMakie]), + # too much headache for now - will go through this again if I'm sure + # CompatHelper is working, but the tests are good flags for new versions with + # suspicious behaviour. + deps_compat = false, + ) + end +end \ No newline at end of file From 1df9a0400b6e745e772ac87300642b5d7e4384c2 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Fri, 9 Aug 2024 06:38:39 -0400 Subject: [PATCH 8/9] Remove extra tab --- test/runtests.jl | 232 +++++++++++++++++++++++------------------------ 1 file changed, 116 insertions(+), 116 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 7652aed..c513134 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -13,128 +13,128 @@ using Shapefile: Point, PointM, PointZ, Polygon, PolygonM, PolygonZ, Polyline, PolylineM, PolylineZ, MultiPoint, MultiPointM, MultiPointZ, MultiPatch, LineString, LinearRing, SubPolygon, Rect, Interval - shp = Shapefile.Handle(joinpath("shapelib_testcases", "test.shp")) +shp = Shapefile.Handle(joinpath("shapelib_testcases", "test.shp")) - function cleanup() - files = filter(readdir(@__DIR__)) do file - any(ext -> endswith(file, ext), [".shp", ".shx", ".dbf", ".prj"]) - end - rm.(files) +function cleanup() + files = filter(readdir(@__DIR__)) do file + any(ext -> endswith(file, ext), [".shp", ".shx", ".dbf", ".prj"]) end + rm.(files) +end - cleanup() +cleanup() - test_tuples = [ - ( - path=joinpath("shapelib_testcases", "test.shp"), - geomtype=Polygon, - coordinates=[[[[[20.0,20.0],[20.0,30.0],[30.0,30.0],[20.0,20.0]]],[[[0.0,0.0],[100.0,0.0],[100.0,100.0],[0.0,100.0],[0.0,0.0]]]],[[[[150.0,150.0],[160.0,150.0],[180.0,170.0],[150.0,150.0]]]],[[[[150.0,150.0],[160.0,150.0],[180.0,170.0],[150.0,150.0]]]]], - extent=Extent(X=(0.0, 180.0), Y=(0.0, 170.0), Z=(0.0, 0.0)), - ),( - path=joinpath("shapelib_testcases", "test0.shp"), - geomtype=Missing, - coordinates=nothing, - extent=Extent(X=(0.0, 10.0), Y=(0.0, 20.0), Z=(0.0, 0.0)), - # This data has no shape, the correct bbox should be all zeros. - # However the data contain some non-zero box values - skip_check_mask = [43:44..., 51:52..., 59:60..., 67:68...], - ),( - path=joinpath("shapelib_testcases", "test1.shp"), - geomtype=Point, - coordinates=[[1.0,2.0],[10.0,20.0]], - extent=Extent(X=(1.0, 10.0), Y=(2.0, 20.0), Z=(0.0, 0.0)), - ),( - path=joinpath("shapelib_testcases", "test2.shp"), - geomtype=PointZ, - coordinates=[[1.0,2.0,3.0,4.0],[10.0,20.0,30.0,40.0]], - extent=Extent(X=(1.0, 10.0), Y=(2.0, 20.0), Z=(3.0, 30.0)), - ),( - path=joinpath("shapelib_testcases", "test3.shp"), - geomtype=PointM, - coordinates=[[1.0,2.0,4.0],[10.0,20.0,40.0]], - extent=Extent(X=(1.0, 10.0), Y=(2.0, 20.0), Z=(0.0, 0.0)), - ),( - path=joinpath("shapelib_testcases", "test4.shp"), - geomtype=MultiPoint, - coordinates=[[[1.15,2.25],[2.15,3.25],[3.15,4.25],[4.15,5.25]],[[11.15,12.25],[12.15,13.25],[13.15,14.25],[14.15,15.25]],[[21.15,22.25],[22.15,23.25],[23.15,24.25],[24.15,25.25]]], - extent=Extent(X=(1.15, 24.15), Y=(2.25, 25.25), Z=(0.0, 0.0)), - ),( - path=joinpath("shapelib_testcases", "test5.shp"), - geomtype=MultiPointZ, - coordinates=[[[1.15,2.25,3.35,4.45],[2.15,3.25,4.35,5.45],[3.15,4.25,5.35,6.45],[4.15,5.25,6.35,7.45]],[[11.15,12.25,13.35,14.45],[12.15,13.25,14.35,15.45],[13.15,14.25,15.35,16.45],[14.15,15.25,16.35,17.45]],[[21.15,22.25,23.35,24.45],[22.15,23.25,24.35,25.45],[23.15,24.25,25.35,26.45],[24.15,25.25,26.35,27.45]]], - extent=Extent(X=(1.15, 24.15), Y=(2.25, 25.25), Z=(3.35, 26.35)), - ),( - path=joinpath("shapelib_testcases", "test6.shp"), - geomtype=MultiPointM, - coordinates=[[[1.15,2.25,4.45],[2.15,3.25,5.45],[3.15,4.25,6.45],[4.15,5.25,7.45]],[[11.15,12.25,14.45],[12.15,13.25,15.45],[13.15,14.25,16.45],[14.15,15.25,17.45]],[[21.15,22.25,24.45],[22.15,23.25,25.45],[23.15,24.25,26.45],[24.15,25.25,27.45]]], - extent=Extent(X=(1.15, 24.15), Y=(2.25, 25.25), Z=(0.0, 0.0)), - ),( - path=joinpath("shapelib_testcases", "test7.shp"), - geomtype=Polyline, - coordinates=[[[[1.0,1.0],[2.0,1.0],[2.0,2.0],[1.0,2.0],[1.0,1.0]]],[[[1.0,4.0],[2.0,4.0],[2.0,5.0],[1.0,5.0],[1.0,4.0]]],[[[1.0,7.0],[2.0,7.0],[2.0,8.0],[1.0,8.0],[1.0,7.0]]],[[[0.0,0.0],[0.0,100.0],[100.0,100.0],[100.0,0.0],[0.0,0.0]],Array{Float64,1}[[10.0,20.0],[30.0,20.0],[30.0,40.0],[10.0,40.0],[10.0,20.0]],Array{Float64,1}[[60.0,20.0],[90.0,20.0],[90.0,40.0],[60.0,40.0],[60.0,20.0]]]], - extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 0.0)), - ),( - path=joinpath("shapelib_testcases", "test8.shp"), - geomtype=PolylineZ, - coordinates=[[[[1.0,1.0,3.35,4.45],[2.0,1.0,4.35,5.45],[2.0,2.0,5.35,6.45],[1.0,2.0,6.35,7.45],[1.0,1.0,7.35,8.45]]],[[[1.0,4.0,13.35,14.45],[2.0,4.0,14.35,15.45],[2.0,5.0,15.35,16.45],[1.0,5.0,16.35,17.45],[1.0,4.0,17.35,18.45]]],[[[1.0,7.0,23.35,24.45],[2.0,7.0,24.35,25.45],[2.0,8.0,25.35,26.45],[1.0,8.0,26.35,27.45],[1.0,7.0,27.35,28.45]]],[[[0.0,0.0,0.0,0.0],[0.0,100.0,1.0,2.0],[100.0,100.0,2.0,4.0],[100.0,0.0,3.0,6.0],[0.0,0.0,4.0,8.0]],[[10.0,20.0,5.0,10.0],[30.0,20.0,6.0,12.0],[30.0,40.0,7.0,14.0],[10.0,40.0,8.0,16.0],[10.0,20.0,9.0,18.0]],[[60.0,20.0,10.0,20.0],[90.0,20.0,11.0,22.0],[90.0,40.0,12.0,24.0],[60.0,40.0,13.0,26.0],[60.0,20.0,14.0,28.0]]]], - extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 27.35)), - ),( - path=joinpath("shapelib_testcases", "test9.shp"), - geomtype=PolylineM, - coordinates=[[[[1.0,1.0,4.45],[2.0,1.0,5.45],[2.0,2.0,6.45],[1.0,2.0,7.45],[1.0,1.0,8.45]]],[[[1.0,4.0,14.45],[2.0,4.0,15.45],[2.0,5.0,16.45],[1.0,5.0,17.45],[1.0,4.0,18.45]]],[[[1.0,7.0,24.45],[2.0,7.0,25.45],[2.0,8.0,26.45],[1.0,8.0,27.45],[1.0,7.0,28.45]]],[[[0.0,0.0,0.0],[0.0,100.0,2.0],[100.0,100.0,4.0],[100.0,0.0,6.0],[0.0,0.0,8.0]],[[10.0,20.0,10.0],[30.0,20.0,12.0],[30.0,40.0,14.0],[10.0,40.0,16.0],[10.0,20.0,18.0]],[[60.0,20.0,20.0],[90.0,20.0,22.0],[90.0,40.0,24.0],[60.0,40.0,26.0],[60.0,20.0,28.0]]]], - extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 0.0)), - ),( - path=joinpath("shapelib_testcases", "test10.shp"), - geomtype=Polygon, - coordinates=[[[[[1.0,1.0],[2.0,1.0],[2.0,2.0],[1.0,2.0],[1.0,1.0]]]],[[[[1.0,4.0],[2.0,4.0],[2.0,5.0],[1.0,5.0],[1.0,4.0]]]],[[[[1.0,7.0],[2.0,7.0],[2.0,8.0],[1.0,8.0],[1.0,7.0]]]],[[[[0.0,0.0],[0.0,100.0],[100.0,100.0],[100.0,0.0],[0.0,0.0]],[[10.0,20.0],[30.0,20.0],[30.0,40.0],[10.0,40.0],[10.0,20.0]],[[60.0,20.0],[90.0,20.0],[90.0,40.0],[60.0,40.0],[60.0,20.0]]]]], - extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 0.0)), - ),( - path=joinpath("shapelib_testcases", "test11.shp"), - geomtype=PolygonZ, - coordinates=[[[[[1.0,1.0,3.35,4.45],[2.0,1.0,4.35,5.45],[2.0,2.0,5.35,6.45],[1.0,2.0,6.35,7.45],[1.0,1.0,7.35,8.45]]]],[[[[1.0,4.0,13.35,14.45],[2.0,4.0,14.35,15.45],[2.0,5.0,15.35,16.45],[1.0,5.0,16.35,17.45],[1.0,4.0,17.35,18.45]]]],[[[[1.0,7.0,23.35,24.45],[2.0,7.0,24.35,25.45],[2.0,8.0,25.35,26.45],[1.0,8.0,26.35,27.45],[1.0,7.0,27.35,28.45]]]],[[[[0.0,0.0,0.0,0.0],[0.0,100.0,1.0,2.0],[100.0,100.0,2.0,4.0],[100.0,0.0,3.0,6.0],[0.0,0.0,4.0,8.0]],[[10.0,20.0,5.0,10.0],[30.0,20.0,6.0,12.0],[30.0,40.0,7.0,14.0],[10.0,40.0,8.0,16.0],[10.0,20.0,9.0,18.0]],[[60.0,20.0,10.0,20.0],[90.0,20.0,11.0,22.0],[90.0,40.0,12.0,24.0],[60.0,40.0,13.0,26.0],[60.0,20.0,14.0,28.0]]]]], - extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 27.35)), - ),( - path=joinpath("shapelib_testcases", "test12.shp"), - geomtype=PolygonM, - coordinates=[[[[[1.0,1.0,4.45],[2.0,1.0,5.45],[2.0,2.0,6.45],[1.0,2.0,7.45],[1.0,1.0,8.45]]]],[[[[1.0,4.0,14.45],[2.0,4.0,15.45],[2.0,5.0,16.45],[1.0,5.0,17.45],[1.0,4.0,18.45]]]],[[[[1.0,7.0,24.45],[2.0,7.0,25.45],[2.0,8.0,26.45],[1.0,8.0,27.45],[1.0,7.0,28.45]]]],[[[[0.0,0.0,0.0],[0.0,100.0,2.0],[100.0,100.0,4.0],[100.0,0.0,6.0],[0.0,0.0,8.0]],[[10.0,20.0,10.0],[30.0,20.0,12.0],[30.0,40.0,14.0],[10.0,40.0,16.0],[10.0,20.0,18.0]],[[60.0,20.0,20.0],[90.0,20.0,22.0],[90.0,40.0,24.0],[60.0,40.0,26.0],[60.0,20.0,28.0]]]]],extent=Extent(X=(0.0,100.0),Y=(0.0,100.0),Z=(0.0,0.0)), - ),( - path=joinpath("shapelib_testcases/test13.shp"), - geomtype=MultiPatch, - coordinates=nothing, - extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 27.35)), - skip_check_mask = 93:100, - ) - ] +test_tuples = [ + ( + path=joinpath("shapelib_testcases", "test.shp"), + geomtype=Polygon, + coordinates=[[[[[20.0,20.0],[20.0,30.0],[30.0,30.0],[20.0,20.0]]],[[[0.0,0.0],[100.0,0.0],[100.0,100.0],[0.0,100.0],[0.0,0.0]]]],[[[[150.0,150.0],[160.0,150.0],[180.0,170.0],[150.0,150.0]]]],[[[[150.0,150.0],[160.0,150.0],[180.0,170.0],[150.0,150.0]]]]], + extent=Extent(X=(0.0, 180.0), Y=(0.0, 170.0), Z=(0.0, 0.0)), + ),( + path=joinpath("shapelib_testcases", "test0.shp"), + geomtype=Missing, + coordinates=nothing, + extent=Extent(X=(0.0, 10.0), Y=(0.0, 20.0), Z=(0.0, 0.0)), + # This data has no shape, the correct bbox should be all zeros. + # However the data contain some non-zero box values + skip_check_mask = [43:44..., 51:52..., 59:60..., 67:68...], + ),( + path=joinpath("shapelib_testcases", "test1.shp"), + geomtype=Point, + coordinates=[[1.0,2.0],[10.0,20.0]], + extent=Extent(X=(1.0, 10.0), Y=(2.0, 20.0), Z=(0.0, 0.0)), + ),( + path=joinpath("shapelib_testcases", "test2.shp"), + geomtype=PointZ, + coordinates=[[1.0,2.0,3.0,4.0],[10.0,20.0,30.0,40.0]], + extent=Extent(X=(1.0, 10.0), Y=(2.0, 20.0), Z=(3.0, 30.0)), + ),( + path=joinpath("shapelib_testcases", "test3.shp"), + geomtype=PointM, + coordinates=[[1.0,2.0,4.0],[10.0,20.0,40.0]], + extent=Extent(X=(1.0, 10.0), Y=(2.0, 20.0), Z=(0.0, 0.0)), + ),( + path=joinpath("shapelib_testcases", "test4.shp"), + geomtype=MultiPoint, + coordinates=[[[1.15,2.25],[2.15,3.25],[3.15,4.25],[4.15,5.25]],[[11.15,12.25],[12.15,13.25],[13.15,14.25],[14.15,15.25]],[[21.15,22.25],[22.15,23.25],[23.15,24.25],[24.15,25.25]]], + extent=Extent(X=(1.15, 24.15), Y=(2.25, 25.25), Z=(0.0, 0.0)), + ),( + path=joinpath("shapelib_testcases", "test5.shp"), + geomtype=MultiPointZ, + coordinates=[[[1.15,2.25,3.35,4.45],[2.15,3.25,4.35,5.45],[3.15,4.25,5.35,6.45],[4.15,5.25,6.35,7.45]],[[11.15,12.25,13.35,14.45],[12.15,13.25,14.35,15.45],[13.15,14.25,15.35,16.45],[14.15,15.25,16.35,17.45]],[[21.15,22.25,23.35,24.45],[22.15,23.25,24.35,25.45],[23.15,24.25,25.35,26.45],[24.15,25.25,26.35,27.45]]], + extent=Extent(X=(1.15, 24.15), Y=(2.25, 25.25), Z=(3.35, 26.35)), + ),( + path=joinpath("shapelib_testcases", "test6.shp"), + geomtype=MultiPointM, + coordinates=[[[1.15,2.25,4.45],[2.15,3.25,5.45],[3.15,4.25,6.45],[4.15,5.25,7.45]],[[11.15,12.25,14.45],[12.15,13.25,15.45],[13.15,14.25,16.45],[14.15,15.25,17.45]],[[21.15,22.25,24.45],[22.15,23.25,25.45],[23.15,24.25,26.45],[24.15,25.25,27.45]]], + extent=Extent(X=(1.15, 24.15), Y=(2.25, 25.25), Z=(0.0, 0.0)), + ),( + path=joinpath("shapelib_testcases", "test7.shp"), + geomtype=Polyline, + coordinates=[[[[1.0,1.0],[2.0,1.0],[2.0,2.0],[1.0,2.0],[1.0,1.0]]],[[[1.0,4.0],[2.0,4.0],[2.0,5.0],[1.0,5.0],[1.0,4.0]]],[[[1.0,7.0],[2.0,7.0],[2.0,8.0],[1.0,8.0],[1.0,7.0]]],[[[0.0,0.0],[0.0,100.0],[100.0,100.0],[100.0,0.0],[0.0,0.0]],Array{Float64,1}[[10.0,20.0],[30.0,20.0],[30.0,40.0],[10.0,40.0],[10.0,20.0]],Array{Float64,1}[[60.0,20.0],[90.0,20.0],[90.0,40.0],[60.0,40.0],[60.0,20.0]]]], + extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 0.0)), + ),( + path=joinpath("shapelib_testcases", "test8.shp"), + geomtype=PolylineZ, + coordinates=[[[[1.0,1.0,3.35,4.45],[2.0,1.0,4.35,5.45],[2.0,2.0,5.35,6.45],[1.0,2.0,6.35,7.45],[1.0,1.0,7.35,8.45]]],[[[1.0,4.0,13.35,14.45],[2.0,4.0,14.35,15.45],[2.0,5.0,15.35,16.45],[1.0,5.0,16.35,17.45],[1.0,4.0,17.35,18.45]]],[[[1.0,7.0,23.35,24.45],[2.0,7.0,24.35,25.45],[2.0,8.0,25.35,26.45],[1.0,8.0,26.35,27.45],[1.0,7.0,27.35,28.45]]],[[[0.0,0.0,0.0,0.0],[0.0,100.0,1.0,2.0],[100.0,100.0,2.0,4.0],[100.0,0.0,3.0,6.0],[0.0,0.0,4.0,8.0]],[[10.0,20.0,5.0,10.0],[30.0,20.0,6.0,12.0],[30.0,40.0,7.0,14.0],[10.0,40.0,8.0,16.0],[10.0,20.0,9.0,18.0]],[[60.0,20.0,10.0,20.0],[90.0,20.0,11.0,22.0],[90.0,40.0,12.0,24.0],[60.0,40.0,13.0,26.0],[60.0,20.0,14.0,28.0]]]], + extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 27.35)), + ),( + path=joinpath("shapelib_testcases", "test9.shp"), + geomtype=PolylineM, + coordinates=[[[[1.0,1.0,4.45],[2.0,1.0,5.45],[2.0,2.0,6.45],[1.0,2.0,7.45],[1.0,1.0,8.45]]],[[[1.0,4.0,14.45],[2.0,4.0,15.45],[2.0,5.0,16.45],[1.0,5.0,17.45],[1.0,4.0,18.45]]],[[[1.0,7.0,24.45],[2.0,7.0,25.45],[2.0,8.0,26.45],[1.0,8.0,27.45],[1.0,7.0,28.45]]],[[[0.0,0.0,0.0],[0.0,100.0,2.0],[100.0,100.0,4.0],[100.0,0.0,6.0],[0.0,0.0,8.0]],[[10.0,20.0,10.0],[30.0,20.0,12.0],[30.0,40.0,14.0],[10.0,40.0,16.0],[10.0,20.0,18.0]],[[60.0,20.0,20.0],[90.0,20.0,22.0],[90.0,40.0,24.0],[60.0,40.0,26.0],[60.0,20.0,28.0]]]], + extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 0.0)), + ),( + path=joinpath("shapelib_testcases", "test10.shp"), + geomtype=Polygon, + coordinates=[[[[[1.0,1.0],[2.0,1.0],[2.0,2.0],[1.0,2.0],[1.0,1.0]]]],[[[[1.0,4.0],[2.0,4.0],[2.0,5.0],[1.0,5.0],[1.0,4.0]]]],[[[[1.0,7.0],[2.0,7.0],[2.0,8.0],[1.0,8.0],[1.0,7.0]]]],[[[[0.0,0.0],[0.0,100.0],[100.0,100.0],[100.0,0.0],[0.0,0.0]],[[10.0,20.0],[30.0,20.0],[30.0,40.0],[10.0,40.0],[10.0,20.0]],[[60.0,20.0],[90.0,20.0],[90.0,40.0],[60.0,40.0],[60.0,20.0]]]]], + extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 0.0)), + ),( + path=joinpath("shapelib_testcases", "test11.shp"), + geomtype=PolygonZ, + coordinates=[[[[[1.0,1.0,3.35,4.45],[2.0,1.0,4.35,5.45],[2.0,2.0,5.35,6.45],[1.0,2.0,6.35,7.45],[1.0,1.0,7.35,8.45]]]],[[[[1.0,4.0,13.35,14.45],[2.0,4.0,14.35,15.45],[2.0,5.0,15.35,16.45],[1.0,5.0,16.35,17.45],[1.0,4.0,17.35,18.45]]]],[[[[1.0,7.0,23.35,24.45],[2.0,7.0,24.35,25.45],[2.0,8.0,25.35,26.45],[1.0,8.0,26.35,27.45],[1.0,7.0,27.35,28.45]]]],[[[[0.0,0.0,0.0,0.0],[0.0,100.0,1.0,2.0],[100.0,100.0,2.0,4.0],[100.0,0.0,3.0,6.0],[0.0,0.0,4.0,8.0]],[[10.0,20.0,5.0,10.0],[30.0,20.0,6.0,12.0],[30.0,40.0,7.0,14.0],[10.0,40.0,8.0,16.0],[10.0,20.0,9.0,18.0]],[[60.0,20.0,10.0,20.0],[90.0,20.0,11.0,22.0],[90.0,40.0,12.0,24.0],[60.0,40.0,13.0,26.0],[60.0,20.0,14.0,28.0]]]]], + extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 27.35)), + ),( + path=joinpath("shapelib_testcases", "test12.shp"), + geomtype=PolygonM, + coordinates=[[[[[1.0,1.0,4.45],[2.0,1.0,5.45],[2.0,2.0,6.45],[1.0,2.0,7.45],[1.0,1.0,8.45]]]],[[[[1.0,4.0,14.45],[2.0,4.0,15.45],[2.0,5.0,16.45],[1.0,5.0,17.45],[1.0,4.0,18.45]]]],[[[[1.0,7.0,24.45],[2.0,7.0,25.45],[2.0,8.0,26.45],[1.0,8.0,27.45],[1.0,7.0,28.45]]]],[[[[0.0,0.0,0.0],[0.0,100.0,2.0],[100.0,100.0,4.0],[100.0,0.0,6.0],[0.0,0.0,8.0]],[[10.0,20.0,10.0],[30.0,20.0,12.0],[30.0,40.0,14.0],[10.0,40.0,16.0],[10.0,20.0,18.0]],[[60.0,20.0,20.0],[90.0,20.0,22.0],[90.0,40.0,24.0],[60.0,40.0,26.0],[60.0,20.0,28.0]]]]],extent=Extent(X=(0.0,100.0),Y=(0.0,100.0),Z=(0.0,0.0)), + ),( + path=joinpath("shapelib_testcases/test13.shp"), + geomtype=MultiPatch, + coordinates=nothing, + extent=Extent(X=(0.0, 100.0), Y=(0.0, 100.0), Z=(0.0, 27.35)), + skip_check_mask = 93:100, + ) +] - # Visual plot check - # for t in test_tuples - # if !(t.geomtype <: Union{Missing,MultiPatch}) - # @show t.path t.geomtype - # sh = Shapefile.Handle(t.path) - # p = sh.shapes - # display(plot(p; opacity=.5)) - # sleep(1) - # end - # end +# Visual plot check +# for t in test_tuples +# if !(t.geomtype <: Union{Missing,MultiPatch}) +# @show t.path t.geomtype +# sh = Shapefile.Handle(t.path) +# p = sh.shapes +# display(plot(p; opacity=.5)) +# sleep(1) +# end +# end - points = [Point(1, 3), Point(2, 3), Point(2, 4), Point(1, 4)] - test_shapes = Dict( - Point => Point(1, 2), - PointM => PointM(1, 2, 3), - PointZ => PointZ(1, 2, 3, 4), - MultiPoint => MultiPoint(Rect(1, 3, 2, 4), points), - MultiPointM => MultiPointM(Rect(1, 3, 2, 4), points, Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), - MultiPointZ => MultiPointZ(Rect(1, 3, 2, 4), points, Interval(1, 4), [1, 2, 3, 4], Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), - Polygon => Polygon(Rect(1, 3, 2, 4), [0], points), - PolygonM => PolygonM(Rect(1, 3, 2, 4), [0], points, Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), - PolygonZ => PolygonZ(Rect(1, 3, 2, 4), [0], points, Interval(1, 4), [1, 2, 3, 4], Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), - Polyline => Polyline(Rect(1, 3, 2, 4), [0], points), - PolylineM => PolylineM(Rect(1, 3, 2, 4), [0], points, Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), - PolylineZ => PolylineZ(Rect(1, 3, 2, 4), [0], points, Interval(1, 4), [1, 2, 3, 4], Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), - LineString => LineString{Point}(view(points, 1:4)), - LinearRing => LinearRing{Point}(view(points, 1:4)), - SubPolygon => SubPolygon([LinearRing{Point}(view(points, 1:4))]), - ) +points = [Point(1, 3), Point(2, 3), Point(2, 4), Point(1, 4)] +test_shapes = Dict( + Point => Point(1, 2), + PointM => PointM(1, 2, 3), + PointZ => PointZ(1, 2, 3, 4), + MultiPoint => MultiPoint(Rect(1, 3, 2, 4), points), + MultiPointM => MultiPointM(Rect(1, 3, 2, 4), points, Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), + MultiPointZ => MultiPointZ(Rect(1, 3, 2, 4), points, Interval(1, 4), [1, 2, 3, 4], Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), + Polygon => Polygon(Rect(1, 3, 2, 4), [0], points), + PolygonM => PolygonM(Rect(1, 3, 2, 4), [0], points, Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), + PolygonZ => PolygonZ(Rect(1, 3, 2, 4), [0], points, Interval(1, 4), [1, 2, 3, 4], Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), + Polyline => Polyline(Rect(1, 3, 2, 4), [0], points), + PolylineM => PolylineM(Rect(1, 3, 2, 4), [0], points, Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), + PolylineZ => PolylineZ(Rect(1, 3, 2, 4), [0], points, Interval(1, 4), [1, 2, 3, 4], Interval(10.0, 40.0), [10.0, 20.0, 30.0, 40.0]), + LineString => LineString{Point}(view(points, 1:4)), + LinearRing => LinearRing{Point}(view(points, 1:4)), + SubPolygon => SubPolygon([LinearRing{Point}(view(points, 1:4))]), +) @testset "Shapefile.jl" begin From d7b7b848951036b28973485c1bc4c38246f6af5c Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Fri, 9 Aug 2024 16:15:53 -0400 Subject: [PATCH 9/9] Untab all things --- test/runtests.jl | 230 +++++++++++++++++++++++------------------------ 1 file changed, 115 insertions(+), 115 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index c513134..b7426db 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -138,142 +138,142 @@ test_shapes = Dict( @testset "Shapefile.jl" begin - @testset "GeoInterface compatibility" begin - foreach(test_shapes) do (k, s) - @test GeoInterface.testgeometry(s) - @test GeoInterface.extent(s) isa GeoInterface.Extent - # This test should be moved to GeoInterface `testgeometry` - @test GeoInterface.ncoord(s) == - (2 + GeoInterface.is3d(s) + GeoInterface.ismeasured(s)) == - length(GeoInterface.coordnames(s)) - # TODO Plotting a single measured point fails, needs fixing in GeoInterfaceRecipes.jl - GeoInterface.ismeasured(s) && GeoInterface.trait(s) isa GeoInterface.PointTrait || plot(s) - end - @test_broken GeoInterface.testgeometry(MultiPatch(Rect(1, 3, 2, 4), [0], [1], points, Interval(1, 4), [1, 2, 3, 4])) +@testset "GeoInterface compatibility" begin + foreach(test_shapes) do (k, s) + @test GeoInterface.testgeometry(s) + @test GeoInterface.extent(s) isa GeoInterface.Extent + # This test should be moved to GeoInterface `testgeometry` + @test GeoInterface.ncoord(s) == + (2 + GeoInterface.is3d(s) + GeoInterface.ismeasured(s)) == + length(GeoInterface.coordnames(s)) + # TODO Plotting a single measured point fails, needs fixing in GeoInterfaceRecipes.jl + GeoInterface.ismeasured(s) && GeoInterface.trait(s) isa GeoInterface.PointTrait || plot(s) + end + @test_broken GeoInterface.testgeometry(MultiPatch(Rect(1, 3, 2, 4), [0], [1], points, Interval(1, 4), [1, 2, 3, 4])) - @test GeoInterface.extent(Shapefile.Point(1.0, 2.0)) == Extents.Extent(X=(1.0, 1.0), Y=(2.0, 2.0)) - @test GeoInterface.extent(Shapefile.PointM(1.0, 2.0, 4.0)) == Extents.Extent(X=(1.0, 1.0), Y=(2.0, 2.0)) - @test GeoInterface.extent(Shapefile.PointZ(1.0, 2.0, 3.0, 4.0)) == Extents.Extent(X=(1.0, 1.0), Y=(2.0, 2.0), Z=(3.0, 3.0)) - @test GeoInterface.extent(test_shapes[Polygon]) == Extents.Extent(X=(1.0, 2.0), Y=(3.0, 4.0)) - @test GeoInterface.extent(test_shapes[PolygonM]) == Extents.Extent(X=(1.0, 2.0), Y=(3.0, 4.0)) - @test GeoInterface.extent(test_shapes[PolygonZ]) == Extents.Extent(X=(1.0, 2.0), Y=(3.0, 4.0), Z=(1.0, 4.0)) + @test GeoInterface.extent(Shapefile.Point(1.0, 2.0)) == Extents.Extent(X=(1.0, 1.0), Y=(2.0, 2.0)) + @test GeoInterface.extent(Shapefile.PointM(1.0, 2.0, 4.0)) == Extents.Extent(X=(1.0, 1.0), Y=(2.0, 2.0)) + @test GeoInterface.extent(Shapefile.PointZ(1.0, 2.0, 3.0, 4.0)) == Extents.Extent(X=(1.0, 1.0), Y=(2.0, 2.0), Z=(3.0, 3.0)) + @test GeoInterface.extent(test_shapes[Polygon]) == Extents.Extent(X=(1.0, 2.0), Y=(3.0, 4.0)) + @test GeoInterface.extent(test_shapes[PolygonM]) == Extents.Extent(X=(1.0, 2.0), Y=(3.0, 4.0)) + @test GeoInterface.extent(test_shapes[PolygonZ]) == Extents.Extent(X=(1.0, 2.0), Y=(3.0, 4.0), Z=(1.0, 4.0)) - subpolygon = getgeom(test_shapes[Polygon], 1) - @test GeoInterface.testgeometry(subpolygon) - linearring = getgeom(subpolygon, 1) - @test GeoInterface.testgeometry(linearring) - @test GeoInterface.extent(subpolygon) == Extents.Extent(X=(1.0, 2.0), Y=(3.0, 4.0)) + subpolygon = getgeom(test_shapes[Polygon], 1) + @test GeoInterface.testgeometry(subpolygon) + linearring = getgeom(subpolygon, 1) + @test GeoInterface.testgeometry(linearring) + @test GeoInterface.extent(subpolygon) == Extents.Extent(X=(1.0, 2.0), Y=(3.0, 4.0)) - @test GeoInterface.trait(shp) isa GeoInterface.GeometryCollectionTrait - @test GeoInterface.testgeometry(shp) - end + @test GeoInterface.trait(shp) isa GeoInterface.GeometryCollectionTrait + @test GeoInterface.testgeometry(shp) +end - @testset "Loading Shapefiles" begin +@testset "Loading Shapefiles" begin - for test in test_tuples - for shx in (:manual, :auto, :none) - shp = if shx == :manual - # this accesses .shp based on offsets in .shx - stempath, ext = splitext(test.path) - shxname = string(stempath, ".shx") - Shapefile.Handle(joinpath(@__DIR__, test.path), joinpath(@__DIR__, shxname)) - elseif shx == :auto - Shapefile.Handle(joinpath(@__DIR__, test.path)) - else - # use .shp only - open(joinpath(@__DIR__, test.path)) do fd - read(fd, Shapefile.Handle) - end - end - shapes = unique(map(typeof, shp.shapes)) - @test GeoInterface.crs(shp) == nothing - @test length(shapes) == 1 - @test length(shapes) == 1 - @test shapes[1] == test.geomtype - @test eltype(shp.shapes) == Union{test.geomtype,Missing} - # missing and MultiPatch are not covered by the GeoInterface - if !(test.geomtype <: Union{Missing,Shapefile.MultiPatch}) - @test GeoInterface.coordinates.(shp.shapes) == test.coordinates - # Run this a second time to test caching - @test GeoInterface.coordinates.(shp.shapes) == test.coordinates +for test in test_tuples + for shx in (:manual, :auto, :none) + shp = if shx == :manual + # this accesses .shp based on offsets in .shx + stempath, ext = splitext(test.path) + shxname = string(stempath, ".shx") + Shapefile.Handle(joinpath(@__DIR__, test.path), joinpath(@__DIR__, shxname)) + elseif shx == :auto + Shapefile.Handle(joinpath(@__DIR__, test.path)) + else + # use .shp only + open(joinpath(@__DIR__, test.path)) do fd + read(fd, Shapefile.Handle) end - ext = test.extent - @test shp.header.MBR == Shapefile.Rect(ext.X[1], ext.Y[1], ext.X[2], ext.Y[2]) - @test GeoInterface.extent(shp) == test.extent - # Multipatch can't be plotted, but it's obscure anyway - test.geomtype == Shapefile.MultiPatch && continue - # Plots has no fallback recipe for a Vector{Missing} - length(collect(skipmissing(shp.shapes))) > 0 || continue - # Plots cant plot measures - GeoInterface.ismeasured(first(skipmissing(shp.shapes))) && continue - # plot(shp) # Just test that geometries actually plot end + shapes = unique(map(typeof, shp.shapes)) + @test GeoInterface.crs(shp) == nothing + @test length(shapes) == 1 + @test length(shapes) == 1 + @test shapes[1] == test.geomtype + @test eltype(shp.shapes) == Union{test.geomtype,Missing} + # missing and MultiPatch are not covered by the GeoInterface + if !(test.geomtype <: Union{Missing,Shapefile.MultiPatch}) + @test GeoInterface.coordinates.(shp.shapes) == test.coordinates + # Run this a second time to test caching + @test GeoInterface.coordinates.(shp.shapes) == test.coordinates + end + ext = test.extent + @test shp.header.MBR == Shapefile.Rect(ext.X[1], ext.Y[1], ext.X[2], ext.Y[2]) + @test GeoInterface.extent(shp) == test.extent + # Multipatch can't be plotted, but it's obscure anyway + test.geomtype == Shapefile.MultiPatch && continue + # Plots has no fallback recipe for a Vector{Missing} + length(collect(skipmissing(shp.shapes))) > 0 || continue + # Plots cant plot measures + GeoInterface.ismeasured(first(skipmissing(shp.shapes))) && continue + # plot(shp) # Just test that geometries actually plot end +end - # Test all .shx files; the values in .shx must match the .shp offsets - test = test_tuples[1] - for test in test_tuples +# Test all .shx files; the values in .shx must match the .shp offsets +test = test_tuples[1] +for test in test_tuples - offsets = Int32[] - contentlens = Int32[] + offsets = Int32[] + contentlens = Int32[] - # Get the shapefile's record offsets and contentlens - shp = open(joinpath(@__DIR__, test.path)) do fd - seek(fd, 32) - shapeType = read(fd, Int32) - seek(fd, 100) - jltype = Shapefile.SHAPETYPE[shapeType] + # Get the shapefile's record offsets and contentlens + shp = open(joinpath(@__DIR__, test.path)) do fd + seek(fd, 32) + shapeType = read(fd, Int32) + seek(fd, 100) + jltype = Shapefile.SHAPETYPE[shapeType] - push!(offsets, position(fd)) - while (!eof(fd)) + push!(offsets, position(fd)) + while (!eof(fd)) - num = bswap(read(fd, Int32)) - rlength = bswap(read(fd, Int32)) - shapeType = read(fd, Int32) - if shapeType !== Int32(0) - read(fd, jltype) - end - - # records the offset after this geometry record - push!(offsets, position(fd)) + num = bswap(read(fd, Int32)) + rlength = bswap(read(fd, Int32)) + shapeType = read(fd, Int32) + if shapeType !== Int32(0) + read(fd, jltype) end + + # records the offset after this geometry record + push!(offsets, position(fd)) end - contentlens = diff(offsets) - offsets = offsets[1:end-1] + end + contentlens = diff(offsets) + offsets = offsets[1:end-1] - # Match the Index values to Shapefile offsets - shx = - open(joinpath(@__DIR__, replace(test.path, r".shp$" => ".shx"))) do fd - shx = read(fd, Shapefile.IndexHandle) - for sIdx = 1:lastindex(shx.indices) - @test shx.indices[sIdx].offset * 2 == offsets[sIdx] - @test shx.indices[sIdx].contentlen * 2 + 8 == contentlens[sIdx] - end + # Match the Index values to Shapefile offsets + shx = + open(joinpath(@__DIR__, replace(test.path, r".shp$" => ".shx"))) do fd + shx = read(fd, Shapefile.IndexHandle) + for sIdx = 1:lastindex(shx.indices) + @test shx.indices[sIdx].offset * 2 == offsets[sIdx] + @test shx.indices[sIdx].contentlen * 2 + 8 == contentlens[sIdx] end + end - end +end - end # @testset "Loading Shapefiles" +end # @testset "Loading Shapefiles" - include("table.jl") - include("writer.jl") +include("table.jl") +include("writer.jl") - cleanup() +cleanup() - @testset "Aqua.jl" begin - Aqua.test_all( - Shapefile; - # Exclude ambiguities from imported packages as well as GeoInterfaceRecipes, - # since the ambiguities there are not the kind that would actually cause problems. - ambiguities = (; recursive = false, exclude = [GeoInterfaceRecipes.RecipesBase.apply_recipe,]), - # GeoInterfaceRecipes and GeoInterfaceMakie are considered stale dependencies - # but are actually used in extensions on Plots and Makie respectively, so we need them! - stale_deps = (; ignore = [:GeoInterfaceRecipes, :GeoInterfaceMakie]), - # too much headache for now - will go through this again if I'm sure - # CompatHelper is working, but the tests are good flags for new versions with - # suspicious behaviour. - deps_compat = false, - ) - end +@testset "Aqua.jl" begin + Aqua.test_all( + Shapefile; + # Exclude ambiguities from imported packages as well as GeoInterfaceRecipes, + # since the ambiguities there are not the kind that would actually cause problems. + ambiguities = (; recursive = false, exclude = [GeoInterfaceRecipes.RecipesBase.apply_recipe,]), + # GeoInterfaceRecipes and GeoInterfaceMakie are considered stale dependencies + # but are actually used in extensions on Plots and Makie respectively, so we need them! + stale_deps = (; ignore = [:GeoInterfaceRecipes, :GeoInterfaceMakie]), + # too much headache for now - will go through this again if I'm sure + # CompatHelper is working, but the tests are good flags for new versions with + # suspicious behaviour. + deps_compat = false, + ) +end end \ No newline at end of file