Class: Georeference::VerbatimData

Inherits:
Georeference
  • Object
show all
Defined in:
app/models/georeference/verbatim_data.rb

Overview

Verbatim data definition…

Instance Attribute Summary

Attributes inherited from Georeference

#api_request, #collecting_event_id, #error_depth, #error_geographic_item_id, #error_radius, #geographic_item_id, #iframe_response, #is_median_z, #is_public, #is_undefined_z, #no_cached, #position, #project_id, #type

Instance Method Summary (collapse)

Methods inherited from Georeference

#add_err_geo_item_inside_err_radius, #add_error_depth, #add_error_geo_item_inside_area, #add_error_radius, #add_error_radius_inside_area, #add_obj_inside_area, #add_obj_inside_err_geo_item, #add_obj_inside_err_radius, batch_create_from_georeference_matcher, #check_err_geo_item_inside_err_radius, #check_error_geo_item_inside_area, #check_error_radius_inside_area, #check_obj_inside_area, #check_obj_inside_err_geo_item, #check_obj_inside_err_radius, #error_box, #error_radius_buffer_polygon, filter, generate_download, #geographic_item_present_if_error_radius_provided, #heading, #latitude, #longitude, #method_name, #set_cached, #to_geo_json_feature, #to_simple_json_feature, with_geographic_area, with_locality, with_locality_as, with_locality_like, within_radius_of_item

Methods included from Housekeeping

#has_polymorphic_relationship?

Constructor Details

- (VerbatimData) initialize(params = {})

Returns a new instance of VerbatimData



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/georeference/verbatim_data.rb', line 5

def initialize(params = {})
  super

  self.is_median_z    = false
  self.is_undefined_z = false # and delta_z is zero, or ignored

  unless collecting_event.nil? || geographic_item

    # value from collecting_event is normalised to meters
    z1 = collecting_event.minimum_elevation
    z2 = collecting_event.maximum_elevation
    if z1.blank?
      # no valid elevation provided
      self.is_undefined_z = true
      delta_z             = 0.0
    else
      # we have at least half of the range data
      # delta_z = z1
      if z2.blank?
        # we have *only* half of the range data
        delta_z = z1
      else
        # we have full range data, so elevation is (top - bottom) / 2
        #z2               = z2.to_f
        delta_z          = z1 + ((z2 - z1) * 0.5)
        # and show calculated median
        self.is_median_z = true
      end
    end

    point      = collecting_event.verbatim_map_center(delta_z)
    attributes = {point: point}
    attributes[:by] = self.by if self.by

    if point.nil?
      test_grs = []
    else
      test_grs = GeographicItem::Point.where("point = ST_GeographyFromText('POINT(#{point.x} #{point.y})::geography')").where("ST_Z(point::geometry) = #{point.z}")
    end

    if test_grs.empty?
      test_grs = [GeographicItem.new(attributes)]
    end

    self.geographic_item = test_grs.first
  end

  geographic_item
end