1+ module GeometryBasicsGeoInterfaceExt
2+
3+ using GeoInterface, GeometryBasics
4+
5+ import GeometryBasics: geointerface_geomtype
6+ using GeometryBasics: Ngon
7+
18# Implementation of trait based interface from https://github.com/JuliaGeo/GeoInterface.jl/
29
310GeoInterface. isgeometry (:: Type{<:AbstractGeometry} ) = true
@@ -104,12 +111,6 @@ function GeoInterface.convert(::Type{Point}, type::PointTrait, geom)
104111 return Point {2,T} (x, y)
105112 end
106113end
107-
108- # without a function barrier you get a lot of allocations from runtime types
109- function _collect_with_type (:: Type{PT} , geom) where {PT <: Point{2} }
110- return [PT (GeoInterface. x (p), GeoInterface. y (p)) for p in getgeom (geom)]
111- end
112-
113114function GeoInterface. convert (:: Type{LineString} , type:: LineStringTrait , geom)
114115 g1 = getgeom (geom, 1 )
115116 x, y = GeoInterface. x (g1), GeoInterface. y (g1)
@@ -122,7 +123,6 @@ function GeoInterface.convert(::Type{LineString}, type::LineStringTrait, geom)
122123 return LineString (_collect_with_type (Point{2 , T}, geom))
123124 end
124125end
125-
126126function GeoInterface. convert (:: Type{Polygon} , type:: PolygonTrait , geom)
127127 t = LineStringTrait ()
128128 exterior = GeoInterface. convert (LineString, t, GeoInterface. getexterior (geom))
@@ -133,7 +133,6 @@ function GeoInterface.convert(::Type{Polygon}, type::PolygonTrait, geom)
133133 return Polygon (exterior, interiors)
134134 end
135135end
136-
137136function GeoInterface. convert (:: Type{MultiPoint} , type:: MultiPointTrait , geom)
138137 g1 = getgeom (geom, 1 )
139138 x, y = GeoInterface. x (g1), GeoInterface. y (g1)
@@ -146,18 +145,18 @@ function GeoInterface.convert(::Type{MultiPoint}, type::MultiPointTrait, geom)
146145 return MultiPoint ([Point {2,T} (GeoInterface. x (p), GeoInterface. y (p)) for p in getgeom (geom)])
147146 end
148147end
149-
150148function GeoInterface. convert (:: Type{MultiLineString} , type:: MultiLineStringTrait , geom)
151149 t = LineStringTrait ()
152150 return MultiLineString (map (l -> GeoInterface. convert (LineString, t, l), getgeom (geom)))
153151end
154-
155152function GeoInterface. convert (:: Type{MultiPolygon} , type:: MultiPolygonTrait , geom)
156153 t = PolygonTrait ()
157154 return MultiPolygon (map (poly -> GeoInterface. convert (Polygon, t, poly), getgeom (geom)))
158155end
159156
160- function Extents. extent (rect:: Rect2 )
161- (xmin, ymin), (xmax, ymax) = extrema (rect)
162- return Extents. Extent (X= (xmin, xmax), Y= (ymin, ymax))
163- end
157+ # without a function barrier you get a lot of allocations from runtime types
158+ function _collect_with_type (:: Type{PT} , geom) where {PT <: Point{2} }
159+ return [PT (GeoInterface. x (p), GeoInterface. y (p)) for p in getgeom (geom)]
160+ end
161+
162+ end
0 commit comments