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.
151 152 153 154 155 156 157 158 159 160 161 |
# File 'app/models/collecting_event/georeference.rb', line 151 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.
40 41 42 43 44 45 46 |
# File 'app/models/collecting_event/georeference.rb', line 40 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
88 89 90 91 92 93 94 |
# File 'app/models/collecting_event/georeference.rb', line 88 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
97 98 99 100 101 102 103 |
# File 'app/models/collecting_event/georeference.rb', line 97 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)
142 143 144 145 146 |
# File 'app/models/collecting_event/georeference.rb', line 142 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
63 64 65 |
# File 'app/models/collecting_event/georeference.rb', line 63 def latitude verbatim_map_center.try(:y) end |
#longitude ⇒ Object
67 68 69 |
# File 'app/models/collecting_event/georeference.rb', line 67 def longitude verbatim_map_center.try(:x) end |
#map_center ⇒ Rgeo::Geographic::ProjectedPointImpl?
126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/models/collecting_event/georeference.rb', line 126 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.
118 119 120 121 122 123 |
# File 'app/models/collecting_event/georeference.rb', line 118 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
79 80 81 82 83 84 85 |
# File 'app/models/collecting_event/georeference.rb', line 79 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.
107 108 109 110 111 112 113 |
# File 'app/models/collecting_event/georeference.rb', line 107 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.
51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/collecting_event/georeference.rb', line 51 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 |