Class: Contrek::Concurrent::GeoJsonStreamingMerger
- Inherits:
-
StreamingMerger
- Object
- Finder
- Merger
- VerticalMerger
- StreamingMerger
- Contrek::Concurrent::GeoJsonStreamingMerger
- Defined in:
- lib/contrek/finder/concurrent/geo_json_streaming_merger.rb
Instance Attribute Summary
Attributes inherited from Merger
Attributes included from Poolable
Attributes inherited from Finder
Instance Method Summary collapse
-
#initialize(stream_to:, pixel_val:, options: {}) ⇒ GeoJsonStreamingMerger
constructor
A new instance of GeoJsonStreamingMerger.
- #stream_raw_polygon(polygon) ⇒ Object
- #write_footer ⇒ Object
- #write_header ⇒ Object
Methods inherited from StreamingMerger
Methods inherited from VerticalMerger
#add_tile, #process_info, #transpose?
Methods inherited from Merger
#add_tile, #process_info, #safe?
Methods included from Poolable
Methods inherited from Finder
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(polygon) ⇒ 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(polygon) if @first_feature @first_feature = false else @stream.write(",") end outer_ring = polygon[:outer].map { |p| [p[:y], p[:x]] } outer_ring << outer_ring.first if outer_ring.first != outer_ring.last polygon_coordinates = [outer_ring] polygon[:inner].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 |
#write_footer ⇒ Object
16 17 18 |
# File 'lib/contrek/finder/concurrent/geo_json_streaming_merger.rb', line 16 def @stream.write("]}") end |
#write_header ⇒ Object
11 12 13 14 |
# File 'lib/contrek/finder/concurrent/geo_json_streaming_merger.rb', line 11 def write_header @first_feature = true @stream.write("{\"type\":\"FeatureCollection\",\"features\":[") end |