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.
-
#geo_json_shape_key ⇒ Object
Returns [shape_type, shape_id] for the preferred geographic representation without fetching or computing the geometry.
-
#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.
159 160 161 162 163 164 165 166 167 168 169 |
# File 'app/models/collecting_event/georeference.rb', line 159 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 |
#geo_json_shape_key ⇒ Object
Returns [shape_type, shape_id] for the preferred geographic representation without fetching or computing the geometry. Returns nil if no mappable location exists. Uses the same precedence logic as geo_json_data.
Note on georeference deduplication: georeferences are collecting-event-specific objects. Two collecting events at the same geographic location will have different georeference IDs and will NOT be deduplicated. Deduplication of georeference shapes only occurs when multiple records (e.g. collection objects from different OTUs) share the same collecting event.
Geographic area deduplication is broader: any two records referencing the same geographic area share the same shape key regardless of which collecting event they belong to.
48 49 50 51 52 53 54 |
# File 'app/models/collecting_event/georeference.rb', line 48 def geo_json_shape_key if gr_id = georeferences.order(:position).pluck(:id).first ['Georeference', gr_id] elsif geographic_area_default_geographic_item_id ['GeographicArea', geographic_area_id] end end |
#georeference_latitude ⇒ Object
TODO: refactor to nil on no georeference
96 97 98 99 100 101 102 |
# File 'app/models/collecting_event/georeference.rb', line 96 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
105 106 107 108 109 110 111 |
# File 'app/models/collecting_event/georeference.rb', line 105 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)
150 151 152 153 154 |
# File 'app/models/collecting_event/georeference.rb', line 150 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
71 72 73 |
# File 'app/models/collecting_event/georeference.rb', line 71 def latitude verbatim_map_center.try(:y) end |
#longitude ⇒ Object
75 76 77 |
# File 'app/models/collecting_event/georeference.rb', line 75 def longitude verbatim_map_center.try(:x) end |
#map_center ⇒ Rgeo::Geographic::ProjectedPointImpl?
134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'app/models/collecting_event/georeference.rb', line 134 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.
126 127 128 129 130 131 |
# File 'app/models/collecting_event/georeference.rb', line 126 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
87 88 89 90 91 92 93 |
# File 'app/models/collecting_event/georeference.rb', line 87 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.
115 116 117 118 119 120 121 |
# File 'app/models/collecting_event/georeference.rb', line 115 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.
59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/models/collecting_event/georeference.rb', line 59 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 |