22
33GeoInterface. isgeometry (:: Type{<:AbstractGeometry} ) = true
44GeoInterface. isgeometry (:: Type{<:AbstractFace} ) = true
5+
56GeoInterface. isgeometry (:: Type{<:Point} ) = true
6- GeoInterface. isgeometry (:: Type{<:AbstractVector{<:AbstractGeometry}} ) = true
7- GeoInterface. isgeometry (:: Type{<:AbstractVector{<:Point}} ) = true
8- GeoInterface. isgeometry (:: Type{<:AbstractVector{<:LineString}} ) = true
9- GeoInterface. isgeometry (:: Type{<:AbstractVector{<:AbstractPolygon}} ) = true
10- GeoInterface. isgeometry (:: Type{<:AbstractVector{<:AbstractFace}} ) = true
7+ GeoInterface. isgeometry (:: Type{<:AbstractMesh} ) = true
8+ GeoInterface. isgeometry (:: Type{<:AbstractPolygon} ) = true
9+ GeoInterface. isgeometry (:: Type{<:LineString} ) = true
10+ GeoInterface. isgeometry (:: Type{<:MultiPoint} ) = true
11+ GeoInterface. isgeometry (:: Type{<:MultiLineString} ) = true
12+ GeoInterface. isgeometry (:: Type{<:MultiPolygon} ) = true
1113GeoInterface. isgeometry (:: Type{<:Mesh} ) = true
1214
1315GeoInterface. geomtrait (:: Point ) = PointTrait ()
@@ -23,6 +25,7 @@ GeoInterface.geomtrait(::AbstractMesh) = PolyhedralSurfaceTrait()
2325# GeoInterface calls this method in `GeoInterface.convert(GeometryBasics, ...)`
2426geointerface_geomtype (:: GeoInterface.PointTrait ) = Point
2527geointerface_geomtype (:: GeoInterface.MultiPointTrait ) = MultiPoint
28+ geointerface_geomtype (:: GeoInterface.LineTrait ) = Line
2629geointerface_geomtype (:: GeoInterface.LineStringTrait ) = LineString
2730geointerface_geomtype (:: GeoInterface.MultiLineStringTrait ) = MultiLineString
2831geointerface_geomtype (:: GeoInterface.PolygonTrait ) = Polygon
@@ -59,8 +62,7 @@ GeoInterface.getgeom(::MultiPointTrait, g::MultiPoint, i::Int) = g[i]
5962function GeoInterface. ngeom (:: MultiLineStringTrait , g:: MultiLineString )
6063 return length (g)
6164end
62- function GeoInterface. getgeom (:: MultiLineStringTrait , g:: MultiLineString ,
63- i:: Int )
65+ function GeoInterface. getgeom (:: MultiLineStringTrait , g:: MultiLineString , i:: Int )
6466 return g[i]
6567end
6668GeoInterface. ncoord (:: MultiLineStringTrait , g:: MultiLineString{Dim} ) where {Dim} = Dim
@@ -91,13 +93,29 @@ GeoInterface.ngeom(::PolyhedralSurfaceTrait, g::AbstractMesh) = length(g)
9193GeoInterface. getgeom (:: PolyhedralSurfaceTrait , g:: AbstractMesh , i) = g[i]
9294
9395function GeoInterface. convert (:: Type{Point} , type:: PointTrait , geom)
94- dim = Int (ncoord (geom))
95- return Point {dim, Float64} (GeoInterface. coordinates (geom))
96+ x, y = GeoInterface. x (geom), GeoInterface. y (geom)
97+ if GeoInterface. is3d (geom)
98+ z = GeoInterface. z (geom)
99+ T = promote_type (typeof (x), typeof (y), typeof (z))
100+ return Point {3,T} (x, y, z)
101+ else
102+ GeoInterface. x (geom), GeoInterface. y (geom)
103+ T = promote_type (typeof (x), typeof (y))
104+ return Point {2,T} (x, y)
105+ end
96106end
97107
98108function GeoInterface. convert (:: Type{LineString} , type:: LineStringTrait , geom)
99- dim = Int (ncoord (geom))
100- return LineString ([Point {dim, Float64} (GeoInterface. coordinates (p)) for p in getgeom (geom)])
109+ g1 = getgeom (geom, 1 )
110+ x, y = GeoInterface. x (g1), GeoInterface. y (g1)
111+ if GeoInterface. is3d (geom)
112+ z = GeoInterface. z (g1)
113+ T = promote_type (typeof (x), typeof (y), typeof (z))
114+ return LineString ([Point {3,T} (GeoInterface. x (p), GeoInterface. y (p), GeoInterface. z (p)) for p in getgeom (geom)])
115+ else
116+ T = promote_type (typeof (x), typeof (y))
117+ return LineString ([Point {2,T} (GeoInterface. x (p), GeoInterface. y (p)) for p in getgeom (geom)])
118+ end
101119end
102120
103121function GeoInterface. convert (:: Type{Polygon} , type:: PolygonTrait , geom)
@@ -106,22 +124,35 @@ function GeoInterface.convert(::Type{Polygon}, type::PolygonTrait, geom)
106124 if GeoInterface. nhole (geom) == 0
107125 return Polygon (exterior)
108126 else
109- interiors = GeoInterface. convert . (LineString, Ref (t ), GeoInterface. gethole (geom))
127+ interiors = map (h -> GeoInterface. convert (LineString, t, h ), GeoInterface. gethole (geom))
110128 return Polygon (exterior, interiors)
111129 end
112130end
113131
114132function GeoInterface. convert (:: Type{MultiPoint} , type:: MultiPointTrait , geom)
115- dim = Int (ncoord (geom))
116- return MultiPoint ([Point {dim, Float64} (GeoInterface. coordinates (p)) for p in getgeom (geom)])
133+ g1 = getgeom (geom, 1 )
134+ x, y = GeoInterface. x (g1), GeoInterface. y (g1)
135+ if GeoInterface. is3d (geom)
136+ z = GeoInterface. z (g1)
137+ T = promote_type (typeof (x), typeof (y), typeof (z))
138+ return MultiPoint ([Point {3,T} (GeoInterface. x (p), GeoInterface. y (p), GeoInterface. z (p)) for p in getgeom (geom)])
139+ else
140+ T = promote_type (typeof (x), typeof (y))
141+ return MultiPoint ([Point {2,T} (GeoInterface. x (p), GeoInterface. y (p)) for p in getgeom (geom)])
142+ end
117143end
118144
119145function GeoInterface. convert (:: Type{MultiLineString} , type:: MultiLineStringTrait , geom)
120146 t = LineStringTrait ()
121- return MultiLineString ([ GeoInterface. convert (LineString, t, l) for l in getgeom (geom)] )
147+ return MultiLineString (map (l -> GeoInterface. convert (LineString, t, l), getgeom (geom)) )
122148end
123149
124150function GeoInterface. convert (:: Type{MultiPolygon} , type:: MultiPolygonTrait , geom)
125151 t = PolygonTrait ()
126- return MultiPolygon ([ GeoInterface. convert (Polygon, t, poly) for poly in getgeom (geom)] )
152+ return MultiPolygon (map (poly -> GeoInterface. convert (Polygon, t, poly), getgeom (geom)) )
127153end
154+
155+ function Extents. extent (rect:: Rect2 )
156+ (xmin, ymin), (xmax, ymax) = extrema (rect)
157+ return Extents. Extent (X= (xmin, xmax), Y= (ymin, ymax))
158+ end
0 commit comments