Skip to content

Commit b1f6567

Browse files
authored
Merge branch 'master' into sd/simple-mesh
2 parents 785d940 + 3ec16b8 commit b1f6567

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "GeometryBasics"
22
uuid = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
33
authors = ["SimonDanisch <[email protected]>"]
4-
version = "0.4.3"
4+
version = "0.4.5"
55

66
[deps]
77
EarCut_jll = "5ae413db-bbd1-5e63-b57d-d24a61df00f5"

src/geointerface.jl

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ GeoInterface.geomtrait(::MultiPolygon) = MultiPolygonTrait()
2020
GeoInterface.geomtrait(::Ngon) = PolygonTrait()
2121
GeoInterface.geomtrait(::AbstractMesh) = PolyhedralSurfaceTrait()
2222

23+
# GeoInterface calls this method in `GeoInterface.convert(GeometryBasics, ...)`
24+
geointerface_geomtype(::GeoInterface.PointTrait) = Point
25+
geointerface_geomtype(::GeoInterface.MultiPointTrait) = MultiPoint
26+
geointerface_geomtype(::GeoInterface.LineStringTrait) = LineString
27+
geointerface_geomtype(::GeoInterface.MultiLineStringTrait) = MultiLineString
28+
geointerface_geomtype(::GeoInterface.PolygonTrait) = Polygon
29+
geointerface_geomtype(::GeoInterface.MultiPolygonTrait) = MultiPolygon
30+
geointerface_geomtype(::GeoInterface.PolyhedralSurfaceTrait) = Mesh
31+
2332
GeoInterface.geomtrait(::Simplex{Dim,T,1}) where {Dim,T} = PointTrait()
2433
GeoInterface.geomtrait(::Simplex{Dim,T,2}) where {Dim,T} = LineStringTrait()
2534
GeoInterface.geomtrait(::Simplex{Dim,T,3}) where {Dim,T} = PolygonTrait()
@@ -30,7 +39,9 @@ GeoInterface.getcoord(::PointTrait, g::Point, i::Int) = g[i]
3039
GeoInterface.ngeom(::LineTrait, g::Line) = length(g)
3140
GeoInterface.getgeom(::LineTrait, g::Line, i::Int) = g[i]
3241

33-
GeoInterface.ngeom(::LineStringTrait, g::LineString) = length(g) # n line segments + 1
42+
43+
GeoInterface.ngeom(::LineStringTrait, g::LineString) = length(g) + 1 # n line segments + 1
44+
GeoInterface.ncoord(::LineStringTrait, g::LineString{Dim}) where {Dim} = Dim
3445
function GeoInterface.getgeom(::LineStringTrait, g::LineString, i::Int)
3546
return GeometryBasics.coordinates(g)[i]
3647
end
@@ -52,6 +63,7 @@ function GeoInterface.getgeom(::MultiLineStringTrait, g::MultiLineString,
5263
i::Int)
5364
return g[i]
5465
end
66+
GeoInterface.ncoord(::MultiLineStringTrait, g::MultiLineString{Dim}) where {Dim} = Dim
5567

5668
GeoInterface.ngeom(::MultiPolygonTrait, g::MultiPolygon) = length(g)
5769
GeoInterface.getgeom(::MultiPolygonTrait, g::MultiPolygon, i::Int) = g[i]
@@ -80,12 +92,12 @@ GeoInterface.getgeom(::PolyhedralSurfaceTrait, g::AbstractMesh, i) = g[i]
8092

8193
function GeoInterface.convert(::Type{Point}, type::PointTrait, geom)
8294
dim = Int(ncoord(geom))
83-
return Point{dim}(GeoInterface.coordinates(geom))
95+
return Point{dim, Float64}(GeoInterface.coordinates(geom))
8496
end
8597

8698
function GeoInterface.convert(::Type{LineString}, type::LineStringTrait, geom)
8799
dim = Int(ncoord(geom))
88-
return LineString([Point{dim}(GeoInterface.coordinates(p)) for p in getgeom(geom)])
100+
return LineString([Point{dim, Float64}(GeoInterface.coordinates(p)) for p in getgeom(geom)])
89101
end
90102

91103
function GeoInterface.convert(::Type{Polygon}, type::PolygonTrait, geom)
@@ -101,7 +113,7 @@ end
101113

102114
function GeoInterface.convert(::Type{MultiPoint}, type::MultiPointTrait, geom)
103115
dim = Int(ncoord(geom))
104-
return MultiPoint([Point{dim}(GeoInterface.coordinates(p)) for p in getgeom(geom)])
116+
return MultiPoint([Point{dim, Float64}(GeoInterface.coordinates(p)) for p in getgeom(geom)])
105117
end
106118

107119
function GeoInterface.convert(::Type{MultiLineString}, type::MultiLineStringTrait, geom)

test/geointerface.jl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
linestring = LineString(Point{2,Int}[(10, 10), (20, 20), (10, 40)])
1515
@test testgeometry(linestring)
1616
@test ngeom(linestring) == 3
17+
@test ncoord(linestring) == 2
1718
@test getgeom(linestring, 1) == Point(10, 10)
1819
@test getgeom(linestring, 2) == Point(20, 20)
1920
@test getgeom(linestring, 3) == Point(10, 40)
@@ -23,6 +24,7 @@
2324
@test testgeometry(multilinestring)
2425
@test GeoInterface.coordinates(multilinestring) ==
2526
[[[10, 10], [20, 20], [10, 40]], [[10, 10], [20, 20], [10, 40]]]
27+
@test ncoord(multilinestring) == 2
2628

2729
poly = Polygon(rand(Point{2,Float32}, 5), [rand(Point{2,Float32}, 5)])
2830
@test testgeometry(poly)
@@ -68,15 +70,15 @@ end
6870
multipolygon_json = GeoJSON.read(multipolygon_str)
6971
multipolygon_hole_json = GeoJSON.read(multipolygon_hole_str)
7072

71-
point_gb = GeoInterface.convert(Point, point_json)
72-
point_3d_gb = GeoInterface.convert(Point, point_3d_json)
73-
linestring_gb = GeoInterface.convert(LineString, linestring_json)
74-
polygon_gb = GeoInterface.convert(Polygon, polygon_json)
75-
polygon_hole_gb = GeoInterface.convert(Polygon, polygon_hole_json)
76-
multipoint_gb = GeoInterface.convert(MultiPoint, multipoint_json)
77-
multilinestring_gb = GeoInterface.convert(MultiLineString, multilinestring_json)
78-
multipolygon_gb = GeoInterface.convert(MultiPolygon, multipolygon_json)
79-
multipolygon_hole_gb = GeoInterface.convert(MultiPolygon, multipolygon_hole_json)
73+
point_gb = GeoInterface.convert(GeometryBasics, point_json)
74+
point_3d_gb = GeoInterface.convert(GeometryBasics, point_3d_json)
75+
linestring_gb = GeoInterface.convert(GeometryBasics, linestring_json)
76+
polygon_gb = GeoInterface.convert(GeometryBasics, polygon_json)
77+
polygon_hole_gb = GeoInterface.convert(GeometryBasics, polygon_hole_json)
78+
multipoint_gb = GeoInterface.convert(GeometryBasics, multipoint_json)
79+
multilinestring_gb = GeoInterface.convert(GeometryBasics, multilinestring_json)
80+
multipolygon_gb = GeoInterface.convert(GeometryBasics, multipolygon_json)
81+
multipolygon_hole_gb = GeoInterface.convert(GeometryBasics, multipolygon_hole_json)
8082

8183
@test point_gb === Point{2, Float64}(30.1, 10.1)
8284
@test point_3d_gb === Point{3, Float64}(30.1, 10.1, 5.1)

0 commit comments

Comments
 (0)