33GeoInterface. isgeometry (:: Type{<:AbstractGeometry} ) = true
44GeoInterface. isgeometry (:: Type{<:AbstractFace} ) = true
55GeoInterface. isgeometry (:: Type{<:AbstractPoint} ) = true
6- GeoInterface. isgeometry (:: Type{<:AbstractVector{<:AbstractGeometry}} ) = true
7- GeoInterface. isgeometry (:: Type{<:AbstractVector{<:AbstractPoint}} ) = true
8- GeoInterface. isgeometry (:: Type{<:AbstractVector{<:LineString}} ) = true
9- GeoInterface. isgeometry (:: Type{<:AbstractVector{<:AbstractPolygon}} ) = true
10- GeoInterface. isgeometry (:: Type{<:AbstractVector{<:AbstractFace}} ) = true
6+ GeoInterface. isgeometry (:: Type{<:AbstractMesh} ) = true
7+ GeoInterface. isgeometry (:: Type{<:AbstractPolygon} ) = true
8+ GeoInterface. isgeometry (:: Type{<:LineString} ) = true
9+ GeoInterface. isgeometry (:: Type{<:MultiPoint} ) = true
10+ GeoInterface. isgeometry (:: Type{<:MultiLineString} ) = true
11+ GeoInterface. isgeometry (:: Type{<:MultiPolygon} ) = true
1112GeoInterface. isgeometry (:: Type{<:Mesh} ) = true
1213
1314GeoInterface. geomtrait (:: Point ) = PointTrait ()
@@ -23,6 +24,7 @@ GeoInterface.geomtrait(::AbstractMesh) = PolyhedralSurfaceTrait()
2324# GeoInterface calls this method in `GeoInterface.convert(GeometryBasics, ...)`
2425geointerface_geomtype (:: GeoInterface.PointTrait ) = Point
2526geointerface_geomtype (:: GeoInterface.MultiPointTrait ) = MultiPoint
27+ geointerface_geomtype (:: GeoInterface.LineTrait ) = Line
2628geointerface_geomtype (:: GeoInterface.LineStringTrait ) = LineString
2729geointerface_geomtype (:: GeoInterface.MultiLineStringTrait ) = MultiLineString
2830geointerface_geomtype (:: GeoInterface.PolygonTrait ) = Polygon
@@ -58,8 +60,7 @@ GeoInterface.getgeom(::MultiPointTrait, g::MultiPoint, i::Int) = g[i]
5860function GeoInterface. ngeom (:: MultiLineStringTrait , g:: MultiLineString )
5961 return length (g)
6062end
61- function GeoInterface. getgeom (:: MultiLineStringTrait , g:: MultiLineString ,
62- i:: Int )
63+ function GeoInterface. getgeom (:: MultiLineStringTrait , g:: MultiLineString , i:: Int )
6364 return g[i]
6465end
6566GeoInterface. ncoord (:: MultiLineStringTrait , g:: MultiLineString{Dim} ) where {Dim} = Dim
@@ -90,13 +91,29 @@ GeoInterface.ngeom(::PolyhedralSurfaceTrait, g::AbstractMesh) = length(g)
9091GeoInterface. getgeom (:: PolyhedralSurfaceTrait , g:: AbstractMesh , i) = g[i]
9192
9293function GeoInterface. convert (:: Type{Point} , type:: PointTrait , geom)
93- dim = Int (ncoord (geom))
94- return Point {dim, Float64} (GeoInterface. coordinates (geom))
94+ x, y = GeoInterface. x (geom), GeoInterface. y (geom)
95+ if GeoInterface. is3d (geom)
96+ z = GeoInterface. z (geom)
97+ T = promote_type (typeof (x), typeof (y), typeof (z))
98+ return Point {3,T} (x, y, z)
99+ else
100+ GeoInterface. x (geom), GeoInterface. y (geom)
101+ T = promote_type (typeof (x), typeof (y))
102+ return Point {2,T} (x, y)
103+ end
95104end
96105
97106function GeoInterface. convert (:: Type{LineString} , type:: LineStringTrait , geom)
98- dim = Int (ncoord (geom))
99- return LineString ([Point {dim, Float64} (GeoInterface. coordinates (p)) for p in getgeom (geom)])
107+ g1 = getgeom (geom, 1 )
108+ x, y = GeoInterface. x (g1), GeoInterface. y (g1)
109+ if GeoInterface. is3d (geom)
110+ z = GeoInterface. z (g1)
111+ T = promote_type (typeof (x), typeof (y), typeof (z))
112+ return LineString ([Point {3,T} (GeoInterface. x (p), GeoInterface. y (p), GeoInterface. z (p)) for p in getgeom (geom)])
113+ else
114+ T = promote_type (typeof (x), typeof (y))
115+ return LineString ([Point {2,T} (GeoInterface. x (p), GeoInterface. y (p)) for p in getgeom (geom)])
116+ end
100117end
101118
102119function GeoInterface. convert (:: Type{Polygon} , type:: PolygonTrait , geom)
@@ -105,22 +122,30 @@ function GeoInterface.convert(::Type{Polygon}, type::PolygonTrait, geom)
105122 if GeoInterface. nhole (geom) == 0
106123 return Polygon (exterior)
107124 else
108- interiors = GeoInterface. convert . (LineString, Ref (t ), GeoInterface. gethole (geom))
125+ interiors = map (h -> GeoInterface. convert (LineString, t, h ), GeoInterface. gethole (geom))
109126 return Polygon (exterior, interiors)
110127 end
111128end
112129
113130function GeoInterface. convert (:: Type{MultiPoint} , type:: MultiPointTrait , geom)
114- dim = Int (ncoord (geom))
115- return MultiPoint ([Point {dim, Float64} (GeoInterface. coordinates (p)) for p in getgeom (geom)])
131+ g1 = getgeom (geom, 1 )
132+ x, y = GeoInterface. x (g1), GeoInterface. y (g1)
133+ if GeoInterface. is3d (geom)
134+ z = GeoInterface. z (g1)
135+ T = promote_type (typeof (x), typeof (y), typeof (z))
136+ return MultiPoint ([Point {3,T} (GeoInterface. x (p), GeoInterface. y (p), GeoInterface. z (p)) for p in getgeom (geom)])
137+ else
138+ T = promote_type (typeof (x), typeof (y))
139+ return MultiPoint ([Point {2,T} (GeoInterface. x (p), GeoInterface. y (p)) for p in getgeom (geom)])
140+ end
116141end
117142
118143function GeoInterface. convert (:: Type{MultiLineString} , type:: MultiLineStringTrait , geom)
119144 t = LineStringTrait ()
120- return MultiLineString ([ GeoInterface. convert (LineString, t, l) for l in getgeom (geom)] )
145+ return MultiLineString (map (l -> GeoInterface. convert (LineString, t, l), getgeom (geom)) )
121146end
122147
123148function GeoInterface. convert (:: Type{MultiPolygon} , type:: MultiPolygonTrait , geom)
124149 t = PolygonTrait ()
125- return MultiPolygon ([ GeoInterface. convert (Polygon, t, poly) for poly in getgeom (geom)] )
150+ return MultiPolygon (map (poly -> GeoInterface. convert (Polygon, t, poly), getgeom (geom)) )
126151end
0 commit comments