Module: CollectingEvent::Georeference

Extended by:
ActiveSupport::Concern
Included in:
CollectingEvent
Defined in:
app/models/collecting_event/georeference.rb

Instance Method Summary collapse

Instance Method Details

#dwc_georeference_sourceSymbol?

Returns Prioritizes and identifies the source of the latitude/longitude values that will be calculated for DWCA and primary display.

Returns:

  • (Symbol, nil)

    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_keyObject

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_latitudeObject

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_longitudeObject

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_radiusInteger

@TODO: See Utilities::Geo.distance_in_meters(String)

Returns:

  • (Integer)


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

#latitudeObject



71
72
73
# File 'app/models/collecting_event/georeference.rb', line 71

def latitude
  verbatim_map_center.try(:y)
end

#longitudeObject



75
76
77
# File 'app/models/collecting_event/georeference.rb', line 75

def longitude
  verbatim_map_center.try(:x)
end

#map_centerRgeo::Geographic::ProjectedPointImpl?

Returns:

  • (Rgeo::Geographic::ProjectedPointImpl, nil)


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_methodSymbol?

Returns the name of the method that will return an Rgeo object that represent the "preferred" centroid for this collecing event.

Returns:

  • (Symbol, nil)

    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_georeferenceCollectingEvent

TODO: Helper method

Returns:

  • (CollectingEvent)

    return the next collecting event without a georeference in this collecting events project sort order

    1. verbatim_locality
    2. geography_id
    3. start_date_year
    4. updated_on
    5. id


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_coordinatesString

Returns coordinates for centering a Google map.

Returns:

  • (String)

    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.

Parameters:

  • delta_z, (Float)

    will be used to fill in the z coordinate of the point

Returns:

  • (RGeo::Geographic::ProjectedPointImpl, nil)

    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