Class: Contrek::Concurrent::GeoJsonStreamingMerger
Instance Attribute Summary
Attributes inherited from Merger
#tiles
Attributes included from Poolable
#number_of_threads
Attributes inherited from Finder
#maximum_width, #options
Instance Method Summary
collapse
#add_tile, #process_info
#add_tile, #process_info, #transpose?
Methods inherited from Merger
#add_tile, #process_info
Methods included from Poolable
#enqueue!, #wait!
Methods inherited from Finder
#process_info, #transpose?
Constructor Details
#initialize(stream_to:, pixel_val:, options: {}) ⇒ GeoJsonStreamingMerger
Returns a new instance of GeoJsonStreamingMerger.
6
7
8
9
|
# File 'lib/contrek/finder/concurrent/geo_json_streaming_merger.rb', line 6
def initialize(stream_to:, pixel_val:, options: {})
@pixel_val = pixel_val
super(stream_to:, options:)
end
|
Instance Method Details
#stream_raw_polygon(shape) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/contrek/finder/concurrent/geo_json_streaming_merger.rb', line 20
def stream_raw_polygon(shape)
if @first_feature
@first_feature = false
else
@stream.write(",")
end
outer_ring = shape.outer_polyline.raw.map { |p| [p[:y], p[:x]] }
outer_ring << outer_ring.first if outer_ring.first != outer_ring.last
polygon_coordinates = [outer_ring]
shape.inner_polylines.map(&:raw).each do |sequence|
inner_ring = sequence.map { |p| [p[:y], p[:x]] }
inner_ring << inner_ring.first if inner_ring.first != inner_ring.last
polygon_coordinates << inner_ring
end
feature_hash = {
type: "Feature",
properties: {PixelVal: @pixel_val},
geometry: {
type: "Polygon",
coordinates: polygon_coordinates
}
}
@stream.write(JSON.generate(feature_hash))
end
|
16
17
18
|
# File 'lib/contrek/finder/concurrent/geo_json_streaming_merger.rb', line 16
def
@stream.write("]}")
end
|
11
12
13
14
|
# File 'lib/contrek/finder/concurrent/geo_json_streaming_merger.rb', line 11
def
@first_feature = true
@stream.write("{\"type\":\"FeatureCollection\",\"features\":[")
end
|