diff --git a/Project.toml b/Project.toml index 783b2bf8..3529392d 100644 --- a/Project.toml +++ b/Project.toml @@ -19,6 +19,14 @@ GeoInterfaceRecipes = "0329782f-3d07-4b52-b9f6-d3137cf03c7a" ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534" Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" +[weakdeps] +JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" +Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" + +[extensions] +ArchGDALMakieExt = "Makie" +ArchGDALJLD2Ext = "JLD2" + [compat] CEnum = "0.4, 0.5" ColorTypes = "0.10, 0.11, 0.12" @@ -33,13 +41,9 @@ GeoInterfaceRecipes = "1.0" ImageCore = "0.8, 0.9, 0.10" Makie = "0.20, 0.21" Tables = "1" +JLD2 = "0.4, 0.5" julia = "1.6" -[extensions] -ArchGDALMakieExt = "Makie" - [extras] Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" - -[weakdeps] -Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" +JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" diff --git a/ext/ArchGDALJLD2Ext.jl b/ext/ArchGDALJLD2Ext.jl new file mode 100644 index 00000000..0ddf2b75 --- /dev/null +++ b/ext/ArchGDALJLD2Ext.jl @@ -0,0 +1,23 @@ +module ArchGDALJLD2Ext + +import ArchGDAL as AG +import GeoInterface as GI +import JLD2 + +struct ArchGDALSerializedGeometry + # TODO: add spatial reference + wkb::Vector{UInt8} +end + + +JLD2.writeas(::Type{<: AG.AbstractGeometry}) = ArchGDALSerializedGeometry + +function JLD2.wconvert(::Type{<: ArchGDALSerializedGeometry}, x::AG.AbstractGeometry) + return ArchGDALSerializedGeometry(AG.toWKB(x)) +end + +function JLD2.rconvert(::Type{<: AG.AbstractGeometry}, x::ArchGDALSerializedGeometry) + return AG.fromWKB(x.wkb) +end + +end \ No newline at end of file diff --git a/test/Project.toml b/test/Project.toml index aeef832e..b23afeb8 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -10,6 +10,7 @@ GDAL = "add2ef01-049f-52c4-9ee2-e494f65e021a" GeoFormatTypes = "68eda718-8dee-11e9-39e7-89f7f65f511f" GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f" ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534" +JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" diff --git a/test/test_geometry.jl b/test/test_geometry.jl index 1544c4ba..6561677e 100644 --- a/test/test_geometry.jl +++ b/test/test_geometry.jl @@ -2,6 +2,7 @@ using Test import GeoInterface as GI import ArchGDAL as AG import GeoFormatTypes as GFT +import JLD2 @testset "test_geometry.jl" begin @testset "GeoInterface" begin @@ -1028,4 +1029,17 @@ import GeoFormatTypes as GFT GI.coordinates(ag_geom) == [[1, 2], [1, 2]] end + + @testset "JLD2 serialization" begin + filepath = joinpath(tempdir(), "test_geometry.jld2") + geom = AG.fromWKT("MULTIPOLYGON (" * + "((0 4 8,4 4 8,4 0 8,0 0 8,0 4 8)," * + "(3 1 8,3 3 8,1 3 8,1 1 8,3 1 8))," * + "((10 4 8,14 4 8,14 0 8,10 0 8,10 4 8)," * + "(13 1 8,13 3 8,11 3 8,11 1 8,13 1 8)))") + + JLD2.save_object(filepath, geom) + geom2 = JLD2.load_object(filepath) + @test AG.toWKT(geom2) == AG.toWKT(geom) + end end