Module: CollectingEvent::Georeference
- Extended by:
- ActiveSupport::Concern
- Included in:
- CollectingEvent
- Defined in:
- app/models/collecting_event/georeference.rb
Instance Method Summary collapse
-
#dwc_georeference_source ⇒ Symbol?
Prioritizes and identifies the source of the latitude/longitude values that will be calculated for DWCA and primary display.
-
#generate_verbatim_data_georeference(reference_self = false, no_cached: false) ⇒ Georeference::VerbatimData, false
CollectingEvent.select {|d| !(d.verbatim_latitude.nil? || d.verbatim_longitude.nil?)} .select {|ce| ce.georeferences.empty?}.
-
#georeference_latitude ⇒ Object
TODO: refactor to nil on no georeference.
-
#georeference_longitude ⇒ Object
TODO: refactor to nil on no georeference.
-
#get_error_radius ⇒ Integer
@TODO: See Utilities::Geo.distance_in_meters(String).
- #latitude ⇒ Object
- #longitude ⇒ Object
- #map_center ⇒ Rgeo::Geographic::ProjectedPointImpl?
-
#map_center_method ⇒ Symbol?
The name of the method that will return an Rgeo object that represent the “preferred” centroid for this collecing event.
-
#next_without_georeference ⇒ CollectingEvent
TODO: Helper method.
-
#verbatim_center_coordinates ⇒ String
Coordinates for centering a Google map.
-
#verbatim_map_center(delta_z = 0.0) ⇒ RGeo::Geographic::ProjectedPointImpl?
For the verbatim latitude/longitude only.
Instance Method Details
#dwc_georeference_source ⇒ Symbol?
Returns Prioritizes and identifies the source of the latitude/longitude values that will be calculated for DWCA and primary display.
154 155 156 157 158 159 160 161 162 163 164 |
# File 'app/models/collecting_event/georeference.rb', line 154 def dwc_georeference_source if !preferred_georeference.nil? :georeference elsif verbatim_latitude && verbatim_longitude :verbatim elsif geographic_area && geographic_area.has_shape? :geographic_area else nil end end |
#generate_verbatim_data_georeference(reference_self = false, no_cached: false) ⇒ Georeference::VerbatimData, false
CollectingEvent.select {|d| !(d.verbatim_latitude.nil? || d.verbatim_longitude.nil?)} .select {|ce| ce.georeferences.empty?}
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'app/models/collecting_event/georeference.rb', line 133 def generate_verbatim_data_georeference(reference_self = false, no_cached: false) return false if (verbatim_latitude.nil? || verbatim_longitude.nil?) begin CollectingEvent.transaction do vg_attributes = {collecting_event_id: id.to_s, no_cached: no_cached} vg_attributes.merge!(by: self.creator.id, project_id: self.project_id) if reference_self a = Georeference::VerbatimData.new(vg_attributes) if a.valid? a.save end return a end rescue raise end false end |
#georeference_latitude ⇒ Object
TODO: refactor to nil on no georeference
67 68 69 70 71 72 73 |
# File 'app/models/collecting_event/georeference.rb', line 67 def georeference_latitude retval = 0.0 if georeferences.count > 0 retval = Georeference.where(collecting_event_id: self.id).order(:position).limit(1)[0].latitude.to_f end retval.round(6) end |
#georeference_longitude ⇒ Object
TODO: refactor to nil on no georeference
76 77 78 79 80 81 82 |
# File 'app/models/collecting_event/georeference.rb', line 76 def georeference_longitude retval = 0.0 if georeferences.count > 0 retval = Georeference.where(collecting_event_id: self.id).order(:position).limit(1)[0].longitude.to_f end retval.round(6) end |
#get_error_radius ⇒ Integer
@TODO: See Utilities::Geo.distance_in_meters(String)
121 122 123 124 125 |
# File 'app/models/collecting_event/georeference.rb', line 121 def get_error_radius return nil if verbatim_geolocation_uncertainty.blank? return verbatim_geolocation_uncertainty.to_i if is.number?(verbatim_geolocation_uncertainty) nil end |
#latitude ⇒ Object
42 43 44 |
# File 'app/models/collecting_event/georeference.rb', line 42 def latitude verbatim_map_center.try(:y) end |
#longitude ⇒ Object
46 47 48 |
# File 'app/models/collecting_event/georeference.rb', line 46 def longitude verbatim_map_center.try(:x) end |
#map_center ⇒ Rgeo::Geographic::ProjectedPointImpl?
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/models/collecting_event/georeference.rb', line 105 def map_center case map_center_method when :preferred_georeference preferred_georeference.geographic_item.centroid when :verbatim_map_center verbatim_map_center when :geographic_area geographic_area.default_geographic_item.centroid else nil end end |
#map_center_method ⇒ Symbol?
Returns the name of the method that will return an Rgeo object that represent the “preferred” centroid for this collecing event.
97 98 99 100 101 102 |
# File 'app/models/collecting_event/georeference.rb', line 97 def map_center_method return :preferred_georeference if preferred_georeference # => { georeferenceProtocol => ? } return :verbatim_map_center if verbatim_map_center # => { } return :geographic_area if geographic_area.try(:has_shape?) nil end |
#next_without_georeference ⇒ CollectingEvent
TODO: Helper method
58 59 60 61 62 63 64 |
# File 'app/models/collecting_event/georeference.rb', line 58 def next_without_georeference CollectingEvent.not_including(self). includes(:georeferences). where(project_id: project_id, georeferences: {collecting_event_id: nil}). order(:verbatim_locality, :geographic_area_id, :start_date_year, :updated_at, :id). first end |
#verbatim_center_coordinates ⇒ String
Returns coordinates for centering a Google map.
86 87 88 89 90 91 92 |
# File 'app/models/collecting_event/georeference.rb', line 86 def verbatim_center_coordinates if self.verbatim_latitude.blank? || self.verbatim_longitude.blank? 'POINT (0.0 0.0 0.0)' else self.verbatim_map_center.to_s end end |
#verbatim_map_center(delta_z = 0.0) ⇒ RGeo::Geographic::ProjectedPointImpl?
Returns for the verbatim latitude/longitude only.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/collecting_event/georeference.rb', line 30 def verbatim_map_center(delta_z = 0.0) retval = nil unless verbatim_latitude.blank? or verbatim_longitude.blank? lat = Utilities::Geo.degrees_minutes_seconds_to_decimal_degrees(verbatim_latitude.to_s) long = Utilities::Geo.degrees_minutes_seconds_to_decimal_degrees(verbatim_longitude.to_s) elev = Utilities::Geo.distance_in_meters(verbatim_elevation.to_s) delta_z = elev unless elev == 0.0 retval = Gis::FACTORY.point(long, lat, delta_z) end retval end |