Skip to content

Commit e36009f

Browse files
committed
Add n points to MultiPoint with << operator
1 parent 82d3f21 commit e36009f

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

lib/geoscript/geom/multipoint.rb

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,30 @@ class MultiPoint < JTSMultiPoint
88
attr_accessor :bounds
99

1010
def initialize(*points)
11-
feature_points = []
11+
feature_points =
12+
if points.first.kind_of? JTSMultiPoint
13+
points.first.points
14+
else
15+
[].tap do |fp|
16+
points.each do |point|
17+
fp << (point.kind_of?(Point) ? point : Point.new(*point))
18+
end
19+
end
20+
end
1221

13-
if points.first.kind_of? JTSMultiPoint
14-
mp_geom = points.first
22+
super(feature_points.to_java(com.vividsolutions.jts.geom.Point), GEOM_FACTORY)
23+
end
1524

16-
for i in (0...mp_geom.num_geometries)
17-
feature_points << mp_geom.get_geometry_n(i)
18-
end
19-
else
20-
points.each do |point|
21-
if point.kind_of? Point
22-
feature_points << point
23-
else
24-
feature_points << Point.new(*point)
25-
end
25+
def points
26+
[].tap do |geometries|
27+
for i in 0...self.num_geometries do
28+
geometries << self.geometry_n(i)
2629
end
2730
end
31+
end
2832

29-
super(feature_points.to_java(com.vividsolutions.jts.geom.Point), GEOM_FACTORY)
33+
def <<(*new_points)
34+
MultiPoint.new *(points << new_points)
3035
end
3136

3237
def buffer(dist)

0 commit comments

Comments
 (0)