Module: Charta::Coordinates
- Defined in:
- lib/charta/coordinates.rb
Class Method Summary collapse
-
.flatten(hash) ⇒ Object
Force coordinates to 2D.
- .map_coordinates(hash, &block) ⇒ Object
- .normalize_4326_geometry(json) ⇒ Object
Class Method Details
.flatten(hash) ⇒ Object
Force coordinates to 2D
6 7 8 |
# File 'lib/charta/coordinates.rb', line 6 def flatten(hash) map_coordinates(hash) { |position| position[0..1] } end |
.map_coordinates(hash, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/charta/coordinates.rb', line 10 def map_coordinates(hash, &block) case hash['type'] when 'FeatureCollection' map_feature_collection_coordinates hash, &block when 'Feature' map_feature_coordinates hash, &block else map_geometry_coordinates hash, &block end end |
.normalize_4326_geometry(json) ⇒ Object
21 22 23 24 25 |
# File 'lib/charta/coordinates.rb', line 21 def normalize_4326_geometry(json) map_coordinates json do |(x, y)| [((x + 180.to_d) % 360.to_d) - 180.to_d, ((y + 90.to_d) % 180.to_d) - 90.to_d] end end |