Class: Georeference::VerbatimData

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

Overview

The Georeference that is derived exclusively from verbatim_latitude/longitude and fields in a CollectingEvent.

While it might be concievable that verbatim data are WKT shapes not points, we assume they are for now.

!! TODO: presently does not include verbatim_geolocation_uncertainty translation into radius !! See github.com/SpeciesFileGroup/taxonworks/issues/1770

Constant Summary collapse

GEO_AREA_TOLERANCE =

Meters. Maximum allowed distance to consider geographic area valid.Exif

10000.0

Constants included from SoftValidation

SoftValidation::ANCESTORS_WITH_SOFT_VALIDATIONS

Instance Attribute Summary

Attributes inherited from Georeference

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

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_geo_item_intersects_area, #add_error_radius, #add_error_radius_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_geo_item_intersects_area, #check_error_radius_inside_area, #check_obj_inside_area, #check_obj_inside_err_geo_item, #check_obj_inside_err_radius, #dwc_occurrences, #error_box, #error_radius_buffer_polygon, filter_by, #geographic_item_present_if_error_radius_provided, #heading, #latitude, #longitude, #method_name, point_type, #radius_from_error_shape, #round_error_radius, #set_cached, #set_cached_collecting_event, #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 Shared::IsData

#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar

Methods included from Shared::Confidences

#reject_confidences

Methods included from Shared::DataAttributes

#import_attributes, #internal_attributes, #keyword_value_hash, #reject_data_attributes

Methods included from Shared::Citations

#cited?, #mark_citations_for_destruction, #nomenclature_date, #origin_citation_source_id, #reject_citations, #requires_citation?, #sources_by_topic_id

Methods included from Shared::ProtocolRelationships

#protocolled?, #reject_protocols

Methods included from Shared::Tags

#reject_tags, #tag_with, #tagged?, #tagged_with?

Methods included from Shared::Notes

#concatenated_notes_string, #reject_notes

Methods included from SoftValidation

#clear_soft_validations, #fix_for, #fix_soft_validations, #soft_fixed?, #soft_valid?, #soft_validate, #soft_validated?, #soft_validations, #soft_validators

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods inherited from ApplicationRecord

transaction_with_retry

Constructor Details

#initialize(params = {}) ⇒ VerbatimData

Returns a new instance of VerbatimData.

Parameters:

  • params (ActionController::Parameters) (defaults to: {})


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
54
55
56
57
58
59
60
61
# File 'app/models/georeference/verbatim_data.rb', line 14

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
        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) # hmm

    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, point.z)
    end

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

    self.error_radius = collecting_event.geolocate_uncertainty_in_meters
    self.geographic_item = test_grs.first
  end
end

Instance Method Details

#add_obj_inside_areaBoolean

Returns true iff collecting_event contains georeference geographic_item.

Returns:

  • (Boolean)

    true iff collecting_event contains georeference geographic_item.



95
96
97
98
99
100
101
102
103
104
# File 'app/models/georeference/verbatim_data.rb', line 95

def add_obj_inside_area
  unless check_obj_within_distance_from_area(GEO_AREA_TOLERANCE)
    errors.add(
      :geographic_item,
      'for georeference is not contained in the geographic area bound to the collecting event')
    errors.add(
      :collecting_event,
      'is assigned a geographic area which does not contain the supplied georeference/geographic item')
  end
end

#check_obj_within_distance_from_area(distance) ⇒ Boolean

.default_geographic_item

Returns:

  • (Boolean)

    true if geographic_item.geo_object is completely contained in collecting_event.geographic_area



81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/models/georeference/verbatim_data.rb', line 81

def check_obj_within_distance_from_area(distance)
  # case 6
  retval = true
  if collecting_event.present?
    if geographic_item.present? && collecting_event.geographic_area.present?
      if geographic_item.geo_object && collecting_event.geographic_area.default_geographic_item.present?
        retval = geographic_item.st_distance_to_geographic_item(collecting_event.geographic_area.default_geographic_item) <= distance
      end
    end
  end
  retval
end

#dwc_georeference_attributesObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/models/georeference/verbatim_data.rb', line 63

def dwc_georeference_attributes
  h = {}
  super(h)
  h.merge!(
    verbatimLatitude: collecting_event.verbatim_latitude,
    verbatimLongitude: collecting_event.verbatim_longitude,
    coordinateUncertaintyInMeters: error_radius,
    georeferenceSources: "Physical collection object.",
    georeferenceRemarks: "Derived from a instance of TaxonWorks' Georeference::VerbatimData.",
    geodeticDatum: nil  # TODO: check
  )
  h[:georeferenceProtocol] = 'A geospatial point translated from verbatim values recorded on human-readable media (e.g. paper specimen label, field notebook).' if h[:georeferenceProtocol].blank?  
  h
end