Skip to content

Commit

Permalink
Use the Extents.jl interface, rather than old GI (#95)
Browse files Browse the repository at this point in the history
* update to use Extents interface rather than old GI

* Add tests for extents where `bbox` does not exist
  • Loading branch information
asinghvi17 authored Feb 9, 2025
1 parent 5fa415e commit 556541a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/geointerface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,8 @@ GI.getfeature(::GI.FeatureCollectionTrait, fc::AbstractFeatureCollection, i::Int
GI.nfeature(::GI.FeatureCollectionTrait, fc::AbstractFeatureCollection) = length(fc)

# Any GeoJSON Object
GI.extent(::GI.FeatureTrait, x::GeoJSONT{2}) = _extent2(x)
GI.extent(::GI.FeatureCollectionTrait, x::GeoJSONT{2}) = _extent2(x)
GI.extent(::GI.AbstractGeometryTrait, x::GeoJSONT{2}) = _extent2(x)
GI.extent(::GI.FeatureTrait, x::GeoJSONT{3}) = _extent3(x)
GI.extent(::GI.FeatureCollectionTrait, x::GeoJSONT{3}) = _extent3(x)
GI.extent(::GI.AbstractGeometryTrait, x::GeoJSONT{3}) = _extent3(x)
GI.Extents.extent(x::GeoJSONT{2}) = _extent2(x)
GI.Extents.extent(x::GeoJSONT{3}) = _extent3(x)

function _extent3(x)
bb = bbox(x)
Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,14 @@ include("geojson_samples.jl")
end
end

@testset "Extents" begin
# First, test that `Extents.extent` returns nothing for a geometry with no bbox
feature = GeoJSON.read(Samples.b)
@test isnothing(GI.Extents.extent(feature))
# Next, test that `GI.extent` returns the correct extent for a geometry with a bbox
@test GI.extent(feature) == mapreduce(GI.extent, GI.Extents.union, GI.getpoint(feature.geometry))
end

@testset "GeoInterface tests" begin
@test all(GI.testgeometry, GeoJSON.read.(Samples.geometries))
@test all(GI.testfeature, GeoJSON.read.(Samples.features))
Expand Down

0 comments on commit 556541a

Please sign in to comment.