3
3
GeoInterface. isgeometry (:: Type{<:AbstractGeometry} ) = true
4
4
GeoInterface. isgeometry (:: Type{<:AbstractFace} ) = true
5
5
GeoInterface. 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
11
12
GeoInterface. isgeometry (:: Type{<:Mesh} ) = true
12
13
13
14
GeoInterface. geomtrait (:: Point ) = PointTrait ()
@@ -23,6 +24,7 @@ GeoInterface.geomtrait(::AbstractMesh) = PolyhedralSurfaceTrait()
23
24
# GeoInterface calls this method in `GeoInterface.convert(GeometryBasics, ...)`
24
25
geointerface_geomtype (:: GeoInterface.PointTrait ) = Point
25
26
geointerface_geomtype (:: GeoInterface.MultiPointTrait ) = MultiPoint
27
+ geointerface_geomtype (:: GeoInterface.LineTrait ) = Line
26
28
geointerface_geomtype (:: GeoInterface.LineStringTrait ) = LineString
27
29
geointerface_geomtype (:: GeoInterface.MultiLineStringTrait ) = MultiLineString
28
30
geointerface_geomtype (:: GeoInterface.PolygonTrait ) = Polygon
@@ -58,8 +60,7 @@ GeoInterface.getgeom(::MultiPointTrait, g::MultiPoint, i::Int) = g[i]
58
60
function GeoInterface. ngeom (:: MultiLineStringTrait , g:: MultiLineString )
59
61
return length (g)
60
62
end
61
- function GeoInterface. getgeom (:: MultiLineStringTrait , g:: MultiLineString ,
62
- i:: Int )
63
+ function GeoInterface. getgeom (:: MultiLineStringTrait , g:: MultiLineString , i:: Int )
63
64
return g[i]
64
65
end
65
66
GeoInterface. ncoord (:: MultiLineStringTrait , g:: MultiLineString{Dim} ) where {Dim} = Dim
@@ -90,13 +91,29 @@ GeoInterface.ngeom(::PolyhedralSurfaceTrait, g::AbstractMesh) = length(g)
90
91
GeoInterface. getgeom (:: PolyhedralSurfaceTrait , g:: AbstractMesh , i) = g[i]
91
92
92
93
function 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
95
104
end
96
105
97
106
function 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
100
117
end
101
118
102
119
function GeoInterface. convert (:: Type{Polygon} , type:: PolygonTrait , geom)
@@ -105,22 +122,30 @@ function GeoInterface.convert(::Type{Polygon}, type::PolygonTrait, geom)
105
122
if GeoInterface. nhole (geom) == 0
106
123
return Polygon (exterior)
107
124
else
108
- interiors = GeoInterface. convert . (LineString, Ref (t ), GeoInterface. gethole (geom))
125
+ interiors = map (h -> GeoInterface. convert (LineString, t, h ), GeoInterface. gethole (geom))
109
126
return Polygon (exterior, interiors)
110
127
end
111
128
end
112
129
113
130
function 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
116
141
end
117
142
118
143
function GeoInterface. convert (:: Type{MultiLineString} , type:: MultiLineStringTrait , geom)
119
144
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)) )
121
146
end
122
147
123
148
function GeoInterface. convert (:: Type{MultiPolygon} , type:: MultiPolygonTrait , geom)
124
149
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)) )
126
151
end
0 commit comments