Skip to content

Commit a3772ed

Browse files
authored
Merge pull request #184 from jw3126/geominterface
add missing ncoord methods for (Multi)LineString
2 parents 4e99eae + c780949 commit a3772ed

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/geointerface.jl

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ GeoInterface.ngeom(::LineTrait, g::Line) = length(g)
3131
GeoInterface.getgeom(::LineTrait, g::Line, i::Int) = g[i]
3232

3333
GeoInterface.ngeom(::LineStringTrait, g::LineString) = length(g) + 1 # n line segments + 1
34+
GeoInterface.ncoord(::LineStringTrait, g::LineString{Dim}) where {Dim} = Dim
3435
function GeoInterface.getgeom(::LineStringTrait, g::LineString, i::Int)
3536
return GeometryBasics.coordinates(g)[i]
3637
end
@@ -52,6 +53,7 @@ function GeoInterface.getgeom(::MultiLineStringTrait, g::MultiLineString,
5253
i::Int)
5354
return g[i]
5455
end
56+
GeoInterface.ncoord(::MultiLineStringTrait, g::MultiLineString{Dim}) where {Dim} = Dim
5557

5658
GeoInterface.ngeom(::MultiPolygonTrait, g::MultiPolygon) = length(g)
5759
GeoInterface.getgeom(::MultiPolygonTrait, g::MultiPolygon, i::Int) = g[i]

test/geointerface.jl

+2
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)

0 commit comments

Comments
 (0)