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



147
148
149
150
151
152
153
154
155
156
157
# File 'app/models/collecting_event/georeference.rb', line 147

def dwc_georeference_source
  if preferred_georeference
    :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?}

Parameters:

  • reference_self (Boolean) (defaults to: false)
  • no_cached (Boolean) (defaults to: false)

Returns:

  • (Georeference::VerbatimData, false)

    generates (creates) a Georeference::VerbatimReference from verbatim_latitude and verbatim_longitude values



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'app/models/collecting_event/georeference.rb', line 125

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_latitudeObject

TODO: refactor to nil on no georeference



58
59
60
61
62
63
64
# File 'app/models/collecting_event/georeference.rb', line 58

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



67
68
69
70
71
72
73
# File 'app/models/collecting_event/georeference.rb', line 67

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)


113
114
115
116
117
# File 'app/models/collecting_event/georeference.rb', line 113

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



32
33
34
# File 'app/models/collecting_event/georeference.rb', line 32

def latitude
  verbatim_map_center.try(:y)
end

#longitudeObject



36
37
38
# File 'app/models/collecting_event/georeference.rb', line 36

def longitude
  verbatim_map_center.try(:x)
end

#map_centerRgeo::Geographic::ProjectedPointImpl?

Returns:

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


97
98
99
100
101
102
103
104
105
106
107
108
# File 'app/models/collecting_event/georeference.rb', line 97

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.geo_object.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 collecting event.

Returns:

  • (Symbol, nil)

    the name of the method that will return an Rgeo object that represent the “preferred” centroid for this collecting event



89
90
91
92
93
94
# File 'app/models/collecting_event/georeference.rb', line 89

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



49
50
51
52
53
54
55
# File 'app/models/collecting_event/georeference.rb', line 49

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



77
78
79
80
81
82
83
# File 'app/models/collecting_event/georeference.rb', line 77

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



20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/collecting_event/georeference.rb', line 20

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