Class: Satellite::Sentinel2::CoordinateConverterService
- Inherits:
-
Object
- Object
- Satellite::Sentinel2::CoordinateConverterService
- Defined in:
- lib/satellite/sentinel2/coordinate_converter_service.rb
Constant Summary collapse
- KML_FILE =
Arquivo baixado em sentinel.esa.int/web/sentinel/missions/sentinel-2/data-products
'S2A_OPER_GIP_TILPAR_MPC__20151209T095117_V20150622T000000_21000101T000000_B00.kml'- KML_FILE_URL =
"https://sentinel.esa.int/documents/247904/1955685/#{KML_FILE}"- FILE_SIZE =
108817408
Instance Attribute Summary collapse
-
#lat ⇒ Object
Returns the value of attribute lat.
-
#lon ⇒ Object
Returns the value of attribute lon.
Instance Method Summary collapse
- #convert ⇒ Object
-
#initialize(lat, lon) ⇒ CoordinateConverterService
constructor
A new instance of CoordinateConverterService.
Constructor Details
#initialize(lat, lon) ⇒ CoordinateConverterService
Returns a new instance of CoordinateConverterService.
15 16 17 18 |
# File 'lib/satellite/sentinel2/coordinate_converter_service.rb', line 15 def initialize(lat, lon) self.lat = lat self.lon = lon end |
Instance Attribute Details
#lat ⇒ Object
Returns the value of attribute lat.
13 14 15 |
# File 'lib/satellite/sentinel2/coordinate_converter_service.rb', line 13 def lat @lat end |
#lon ⇒ Object
Returns the value of attribute lon.
13 14 15 |
# File 'lib/satellite/sentinel2/coordinate_converter_service.rb', line 13 def lon @lon end |
Instance Method Details
#convert ⇒ 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 44 45 46 47 48 |
# File 'lib/satellite/sentinel2/coordinate_converter_service.rb', line 20 def convert cache_key = "Sentinel2KML-#{FILE_SIZE}" cached = Redis.current.get(cache_key) if cached cached = JSON.parse(cached) else cached = parsed_kml Redis.current.set(cache_key, cached.to_json, ex: 86400) end found = cached.find do |polygon| Map::PolygonService.new.inside_polygons?({latitude: lat, longitude: lon}, polygon['coordinates']) end return unless found creator = Map::KmlCreatorService.new found['coordinates'].each { |c| creator.add_polygon(c) } kml_service = Map::KmlService.new(creator.to_xml) bounds = { point_more_south_west: kml_service.point_more_south_west, point_more_north_east: kml_service.point_more_north_east } { name: found['name'], bounds: bounds } end |