diff --git a/src/geometry_wrappers.jl b/src/geometry_wrappers.jl index c50ed683..422b922e 100644 --- a/src/geometry_wrappers.jl +++ b/src/geometry_wrappers.jl @@ -22,6 +22,8 @@ module Wrappers import Extents +import ..GeoInterface + import ..GeoInterface: AbstractGeometryTrait, PointTrait, LineTrait, LineStringTrait, LinearRingTrait, TriangleTrait, QuadTrait, PentagonTrait, HexagonTrait, RectangleTrait, MultiPointTrait, PolygonTrait, MultiLineStringTrait, MultiCurveTrait, MultiPolygonTrait, TINTrait, GeometryCollectionTrait, PolyhedralSurfaceTrait, @@ -352,7 +354,7 @@ Feature(geometry=nothing; properties=nothing, crs=nothing, extent=nothing) = isfeature(::Type{<:Feature}) = true trait(feature::Feature) = FeatureTrait() -geometry(f::Feature) = f.geometry +GeoInterface.geometry(f::Feature) = f.geometry properties(f::Feature) = f.properties extent(f::Feature) = f.extent crs(f::Feature) = f.crs @@ -377,15 +379,17 @@ struct FeatureCollection{P,C,E} extent::E end function FeatureCollection(parent; crs=nothing, extent=nothing) - if GI.isfeaturecollection(parent) + if isfeaturecollection(parent) FeatureCollection(parent, crs, extent) else features = !(parent isa AbstractArray) ? collect(parent) : parent - all(f -> isfeature(f) in features) || _child_feature_error() + all(f -> isfeature(f), features) || _child_feature_error() FeatureCollection(parent, crs, extent) end end +Base.parent(fc::FeatureCollection) = fc.parent + _child_feature_error() = throw(ArgumentError("child objects must be features, but the return `GeoInterface.isfeature(obj) == false`")) isfeaturecollection(fc::Type{<:FeatureCollection}) = true @@ -394,9 +398,9 @@ trait(fc::FeatureCollection) = FeatureCollectionTrait() function nfeature(::FeatureCollectionTrait, fc::FeatureCollection) isfeaturecollection(parent(fc)) ? nfeature(t, parent(fc)) : length(fc.geoms) end -getfeature(::FeatureCollectionTrait, fc::FeatureCollection) = fc.features +getfeature(::FeatureCollectionTrait, fc::FeatureCollection) = fc.parent function getfeature(t::FeatureCollectionTrait, fc::FeatureCollection, i::Integer) - isfeaturecollection(parent(fc)) ? getfeature(t, parent(fc), i) : fc.features[i] + isfeaturecollection(parent(fc)) ? getfeature(t, parent(fc), i) : fc.parent[i] end function extent(fc::FeatureCollection) if isfeaturecollection(parent(fc)) && isnothing(fc.extent)