@@ -13,48 +13,78 @@ GI.ncoord(::GI.AbstractTrait, ::AbstractGeometry{D,T}) where {D,T} = D
1313GI. coordinates (:: GI.AbstractGeometryTrait , g:: AbstractGeometry ) = coordinates (g)
1414GI. coordinates (:: GI.AbstractPointTrait , g:: AbstractGeometry ) = coordinates (g) # prevent ambiguity
1515
16+ GI. traittype (:: Val{:GeoJSON} , :: GI.PointTrait ) = Point
17+ GI. traittype (:: Val{:GeoJSON} , :: GI.LineStringTrait ) = LineString
18+ GI. traittype (:: Val{:GeoJSON} , :: GI.PolygonTrait ) = Polygon
19+ GI. traittype (:: Val{:GeoJSON} , :: GI.MultiLineStringTrait ) = MultiLineString
20+ GI. traittype (:: Val{:GeoJSON} , :: GI.MultiPolygonTrait ) = MultiPolygon
21+ GI. traittype (:: Val{:GeoJSON} , :: GI.GeometryCollectionTrait ) = GeometryCollection
22+
1623# we have to make use of the GI fallbacks that call geomtrait on the input
1724GI. getcoord (:: GI.PointTrait , g:: Point , i:: Int ) = g[i]
25+ GI. convert (:: Type{<:Point} , :: GI.PointTrait , geom) = Point (; coordinates= collect (GI. getcoord (geom)))
1826
1927GI. ngeom (:: GI.LineStringTrait , g:: LineString ) = length (g)
2028GI. getgeom (:: GI.LineStringTrait , g:: LineString{D,T} , i:: Integer ) where {D,T} = Point {D,T} (nothing , g[i])
2129GI. getpoint (:: GI.LineStringTrait , g:: LineString{D,T} , i:: Int ) where {D,T} = Point {D,T} (nothing , g[i])
2230# TODO what to return for length 0 and 1?
2331# TODO should this be an approximate equals for floating point?
2432GI. isclosed (:: GI.LineStringTrait , g:: LineString ) = first (g) == last (g)
33+ GI. convert (:: Type{<:LineString} , :: GI.LineStringTrait , geom) =
34+ LineString (; coordinates= GI. coordinates (geom))
2535
2636GI. ngeom (:: GI.PolygonTrait , g:: Polygon ) = length (g)
2737GI. getgeom (:: GI.PolygonTrait , g:: Polygon{D,T} , i:: Integer ) where {D,T} = LineString {D,T} (nothing , g[i])
2838GI. ncoord (:: GI.PolygonTrait , g:: Polygon ) = length (first (first (g)))
2939GI. getexterior (:: GI.PolygonTrait , g:: Polygon{D,T} ) where {D,T} = LineString {D,T} (nothing , first (g))
3040GI. nhole (:: GI.PolygonTrait , g:: Polygon ) = length (g) - 1
3141GI. gethole (:: GI.PolygonTrait , g:: Polygon{D,T} , i:: Int ) where {D,T} = LineString {D,T} (nothing , g[i+ 1 ])
42+ GI. convert (:: Type{<:Polygon} , :: GI.PolygonTrait , geom) =
43+ Polygon (; coordinates= GI. coordinates (geom))
3244
3345GI. ngeom (:: GI.MultiPointTrait , g:: MultiPoint ) = length (g)
3446GI. getgeom (:: GI.MultiPointTrait , g:: MultiPoint{D,T} , i:: Int ) where {D,T} = Point {D,T} (nothing , g[i])
47+ GI. convert (:: Type{<:MultiPoint} , :: GI.MultiPointTrait , geom) =
48+ MultiPoint (; coordinates= GI. coordinates (geom))
3549
3650GI. ngeom (:: GI.MultiLineStringTrait , g:: MultiLineString ) = length (g)
3751GI. getgeom (:: GI.MultiLineStringTrait , g:: MultiLineString{D,T} , i:: Int ) where {D,T} =
3852 LineString {D,T} (nothing , g[i])
53+ GI. convert (:: Type{<:MultiLineString} , :: GI.MultiLineStringTrait , geom) =
54+ MultiLineString (; coordinates= GI. coordinates (geom))
3955
4056GI. ngeom (:: GI.MultiPolygonTrait , g:: MultiPolygon ) = length (g)
4157GI. getgeom (:: GI.MultiPolygonTrait , g:: MultiPolygon{D,T} , i:: Int ) where {D,T} = Polygon {D,T} (nothing , g[i])
58+ GI. convert (:: Type{<:MultiPolygon} , :: GI.MultiPolygonTrait , geom) =
59+ MultiLineString (; coordinates= GI. coordinates (geom))
4260
4361GI. ngeom (:: GI.GeometryCollectionTrait , g:: GeometryCollection ) = length (g)
4462GI. getgeom (:: GI.GeometryCollectionTrait , g:: GeometryCollection , i:: Int ) = g[i]
4563GI. coordinates (:: GI.GeometryCollectionTrait , g:: GeometryCollection ) = coordinates .(geometry (g))
64+ function GI. convert (:: Type{<:GeometryCollection} , :: GI.GeometryCollectionTrait , geom)
65+ geometries = [GI. convert (Val {:GeoJSON} (), g) for g in GI. getgeoms (geom)]
66+ GeometryCollection (; geometries)
67+ end
4668
4769# Feature
4870GI. isfeature (:: Type{<:Feature} ) = true
4971GI. trait (:: Feature ) = GI. FeatureTrait ()
5072GI. geometry (f:: Feature ) = geometry (f)
5173GI. properties (f:: Feature ) = properties (f)
74+ function GI. convert (:: Type{<:Feature} , :: GI.FeatureTrait , feature)
75+ Feature (;
76+ geometry= GI. convert (GeoJSON, GI. geometry (feature)),
77+ properties= GI. properties (feature),
78+ )
79+ end
5280
5381# FeatureCollection
5482GI. isfeaturecollection (:: Type{<:AbstractFeatureCollection} ) = true
5583GI. trait (:: AbstractFeatureCollection ) = GI. FeatureCollectionTrait ()
5684GI. getfeature (:: GI.FeatureCollectionTrait , fc:: AbstractFeatureCollection , i:: Integer ) = fc[i]
5785GI. nfeature (:: GI.FeatureCollectionTrait , fc:: AbstractFeatureCollection ) = length (fc)
86+ GI. convert (:: Type{<:FeatureCollection} , :: GI.FeatureCollectionTrait , fc) =
87+ FeatureCollection (GI. convert (Feature, GI. features (fc)))
5888
5989# Any GeoJSON Object
6090GI. extent (:: GI.FeatureTrait , x:: GeoJSONT{2} ) = _extent2 (x)
0 commit comments