-
Notifications
You must be signed in to change notification settings - Fork 26
/
geointerface.jl
79 lines (77 loc) · 2.58 KB
/
geointerface.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
let pointtypes = (wkbPoint, wkbPoint25D, wkbPointM, wkbPointZM),
multipointtypes =
(wkbMultiPoint, wkbMultiPoint25D, wkbMultiPointM, wkbMultiPointZM),
linetypes =
(wkbLineString, wkbLineString25D, wkbLineStringM, wkbLineStringZM),
multilinetypes = (
wkbMultiLineString,
wkbMultiLineString25D,
wkbMultiLineStringM,
wkbMultiLineStringZM,
),
polygontypes = (wkbPolygon, wkbPolygon25D, wkbPolygonM, wkbPolygonZM),
multipolygontypes = (
wkbMultiPolygon,
wkbMultiPolygon25D,
wkbMultiPolygonM,
wkbMultiPolygonZM,
),
collectiontypes = (
wkbGeometryCollection,
wkbGeometryCollection25D,
wkbGeometryCollectionM,
wkbGeometryCollectionZM,
)
function GeoInterface.geotype(g::AbstractGeometry)::Symbol
gtype = getgeomtype(g)
return if gtype in pointtypes
:Point
elseif gtype in multipointtypes
:MultiPoint
elseif gtype in linetypes
:LineString
elseif gtype == wkbLinearRing
:LinearRing
elseif gtype in multilinetypes
:MultiLineString
elseif gtype in polygontypes
:Polygon
elseif gtype in multipolygontypes
:MultiPolygon
elseif gtype in collectiontypes
:GeometryCollection
else
@warn "unknown geometry type" gtype
:Unknown
end
end
function GeoInterface.coordinates(g::AbstractGeometry)
gtype = getgeomtype(g)
ndim = getcoorddim(g)
return if gtype in pointtypes
if ndim == 2
Float64[getx(g, 0), gety(g, 0)]
elseif ndim == 3
Float64[getx(g, 0), gety(g, 0), getz(g, 0)]
else
error("getcoorddim($g) returned $ndim: expected 2 or 3")
end
elseif gtype in multipointtypes
Vector{Float64}[
GeoInterface.coordinates(getgeom(g, i - 1)) for i in 1:ngeom(g)
]
elseif gtype in linetypes || gtype == wkbLinearRing
Vector{Float64}[
collect(getpoint(g, i - 1)[1:ndim]) for i in 1:ngeom(g)
]
elseif gtype in multilinetypes || gtype in polygontypes
Vector{Vector{Float64}}[
GeoInterface.coordinates(getgeom(g, i - 1)) for i in 1:ngeom(g)
]
elseif gtype in multipolygontypes
Vector{Vector{Vector{Float64}}}[
GeoInterface.coordinates(getgeom(g, i - 1)) for i in 1:ngeom(g)
]
end
end
end