Skip to content

Commit

Permalink
fix feature wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Feb 9, 2023
1 parent 94ccb9d commit ea9487f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/geometry_wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit ea9487f

Please sign in to comment.