@@ -12,9 +12,17 @@ GI.geomtrait(g::MultiLineString) = GI.MultiLineStringTrait()
1212GI. geomtrait (g:: MultiPolygon ) = GI. MultiPolygonTrait ()
1313GI. geomtrait (g:: GeometryCollection ) = GI. GeometryCollectionTrait ()
1414
15+ GI. traittype (:: Val{:GeoJSON} , :: GI.PointTrait ) = Point
16+ GI. traittype (:: Val{:GeoJSON} , :: GI.LineStringTrait ) = LineString
17+ GI. traittype (:: Val{:GeoJSON} , :: GI.PolygonTrait ) = Polygon
18+ GI. traittype (:: Val{:GeoJSON} , :: GI.MultiLineStringTrait ) = MultiLineString
19+ GI. traittype (:: Val{:GeoJSON} , :: GI.MultiPolygonTrait ) = MultiPolygon
20+ GI. traittype (:: Val{:GeoJSON} , :: GI.GeometryCollectionTrait ) = GeometryCollection
21+
1522# we have to make use of the GI fallbacks that call geomtrait on the input
1623GI. ncoord (:: GI.PointTrait , g:: Point ) = length (g)
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. ncoord (:: GI.LineStringTrait , g:: LineString ) = length (first (g))
2028GI. ngeom (:: GI.LineStringTrait , g:: LineString ) = length (g)
@@ -23,42 +31,65 @@ GI.getpoint(::GI.LineStringTrait, g::LineString, i::Int) = Point(coordinates = g
2331# TODO what to return for length 0 and 1?
2432# TODO should this be an approximate equals for floating point?
2533GI. isclosed (:: GI.LineStringTrait , g:: LineString ) = first (g) == last (g)
34+ GI. convert (:: Type{<:LineString} , :: GI.LineStringTrait , geom) =
35+ LineString (; coordinates= coordinates (geom))
2636
2737GI. ngeom (:: GI.PolygonTrait , g:: Polygon ) = length (g)
2838GI. getgeom (:: GI.PolygonTrait , g:: Polygon , i:: Integer ) = LineString (coordinates = g[i])
2939GI. ncoord (:: GI.PolygonTrait , g:: Polygon ) = length (first (first (g)))
3040GI. getexterior (:: GI.PolygonTrait , g:: Polygon ) = LineString (coordinates = first (g))
3141GI. nhole (:: GI.PolygonTrait , g:: Polygon ) = length (g) - 1
3242GI. gethole (:: GI.PolygonTrait , g:: Polygon , i:: Int ) = LineString (coordinates = g[i+ 1 ])
43+ GI. convert (:: Type{<:Polygon} , :: GI.PolygonTrait , geom) =
44+ Polygon (; coordinates= coordinates (geom))
3345
3446GI. ncoord (:: GI.MultiPointTrait , g:: MultiPoint ) = length (first (g))
3547GI. ngeom (:: GI.MultiPointTrait , g:: MultiPoint ) = length (g)
3648GI. getgeom (:: GI.MultiPointTrait , g:: MultiPoint , i:: Int ) = Point (coordinates = g[i])
49+ GI. convert (:: Type{<:MultiPoint} , :: GI.MultiPointTrait , geom) =
50+ MultiPoint (; coordinates= coordinates (geom))
3751
3852GI. ncoord (:: GI.MultiLineStringTrait , g:: MultiLineString ) = length (first (first (g)))
3953GI. ngeom (:: GI.MultiLineStringTrait , g:: MultiLineString ) = length (g)
4054GI. getgeom (:: GI.MultiLineStringTrait , g:: MultiLineString , i:: Int ) =
4155 LineString (coordinates = g[i])
56+ GI. convert (:: Type{<:MultiLineString} , :: GI.MultiLineStringTrait , geom) =
57+ MultiLineString (; coordinates= coordinates (geom))
4258
4359GI. ncoord (:: GI.MultiPolygonTrait , g:: MultiPolygon ) = length (first (first (first (g))))
4460GI. ngeom (:: GI.MultiPolygonTrait , g:: MultiPolygon ) = length (g)
4561GI. getgeom (:: GI.MultiPolygonTrait , g:: MultiPolygon , i:: Int ) = Polygon (coordinates = g[i])
62+ GI. convert (:: Type{<:MultiPolygon} , :: GI.MultiPolygonTrait , geom) =
63+ MultiLineString (; coordinates= coordinates (geom))
4664
4765GI. ncoord (:: GI.GeometryCollectionTrait , g:: GeometryCollection ) = GI. ncoord (first (g))
4866GI. ngeom (:: GI.GeometryCollectionTrait , g:: GeometryCollection ) = length (g)
49- GI. getgeom (:: GI.GeometryCollectionTrait , g:: GeometryCollection , i:: Int ) = geometry (g[i])
67+ GI. getgeom (:: GI.GeometryCollectionTrait , g:: GeometryCollection , i:: Int ) =
68+ function GI. convert (:: Type{<:GeometryCollection} , :: GI.GeometryCollectionTrait , geom)
69+ geometries = [GI. convert (Val {:GeoJSON} (), g) for g in GI. getgeoms (geom)]
70+ GeometryCollection (; geometries)
71+ end
5072
5173# Feature
5274GI. isfeature (:: Type{<:Feature} ) = true
5375GI. trait (:: Feature ) = GI. FeatureTrait ()
5476GI. geometry (f:: Feature ) = geometry (f)
5577GI. properties (f:: Feature ) = properties (f)
78+ function GI. convert (:: Type{<:Feature} , :: GI.FeatureTrait , feature)
79+ Feature (;
80+ geometry= GI. convert (GeoJSON, GI. geometry (feature)),
81+ properties= GI. properties (feature),
82+ )
83+ end
5684
5785# FeatureCollection
5886GI. isfeaturecollection (:: Type{<:FeatureCollection} ) = true
5987GI. trait (:: FeatureCollection ) = GI. FeatureCollectionTrait ()
6088GI. getfeature (:: GI.FeatureCollectionTrait , fc:: FeatureCollection , i:: Integer ) = fc[i]
6189GI. nfeature (:: GI.FeatureCollectionTrait , fc:: FeatureCollection ) = length (fc)
90+ function GI. convert (:: Type{<:FeatureCollection} , :: GI.FeatureCollectionTrait , fc)
91+ FeatureCollection (GI. convert (Feature, GI. features (fc)))
92+ end
6293
6394# Any GeoJSON Object
6495function GI. extent (x:: GeoJSONObject )
0 commit comments