Class: Georeference

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Housekeeping
Defined in:
app/models/georeference.rb

Overview

Contains information about a location on the face of the Earth, consisting of:

Direct Known Subclasses

GeoLocate, VerbatimData

Defined Under Namespace

Classes: GeoLocate, VerbatimData

Constant Summary collapse

FACTORY =

groups.google.com/forum/#!topic/rgeo-users/lMCr0mOt1F0 TODone: Some of the GADM polygons seem to violate shapefile spec for some reason (not necessarily those stated in the above group post). As a possible remedy, adding “:uses_lenient_multi_polygon_assertions => true” TODone: This is also supposed to be the default factory (in fact, the only factory), but that does not seem to be the case. See lib/tasks/build_geographic_areas.rake

RGeo::Geographic.projected_factory(srid:                    4326,
projection_srid:         4326,
projection_proj4:        '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs',
uses_lenient_assertions: true,
has_z_coordinate:        true)

Instance Attribute Summary collapse

Method Summary

Methods included from Housekeeping

#has_polymorphic_relationship?

Instance Attribute Details

#collecting_event_idInteger

Returns the id of a CollectingEvent that represents the event of this georeference definition

Returns:

  • (Integer)

    the id of a CollectingEvent that represents the event of this georeference definition



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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/georeference.rb', line 30

class Georeference < ActiveRecord::Base
  include Housekeeping

#  https://groups.google.com/forum/#!topic/rgeo-users/lMCr0mOt1F0
# TODone: Some of the GADM polygons seem to violate shapefile spec for *some* reason (not necessarily those stated in the above group post). As a possible remedy, adding ":uses_lenient_multi_polygon_assertions => true"
# TODone: This is also supposed to be the default factory (in fact, the *only* factory), but that does not seem to be the case. See lib/tasks/build_geographic_areas.rake

  FACTORY = RGeo::Geographic.projected_factory(srid:                    4326,
                                               projection_srid:         4326,
                                               projection_proj4:        '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs',
                                               uses_lenient_assertions: true,
                                               has_z_coordinate:        true)
=begin
  FACTORY = ::RGeo::Geos.factory(native_interface:                      :ffi,
                                 uses_lenient_multi_polygon_assertions: true,
                                 srid:                                  4326,
                                 has_z_coordinate:                      true)
=end



  # this represents a GeographicItem, but has a name (error_geographic_item) which is *not* the name of the column used in the table;
  # therefore, we need to tell it *which* table, and what to use to address the record we want
  belongs_to :error_geographic_item, class_name: 'GeographicItem', foreign_key: :error_geographic_item_id

  belongs_to :collecting_event
  belongs_to :geographic_item

  accepts_nested_attributes_for :geographic_item, :error_geographic_item

  validate :proper_data_is_provided
  validates :geographic_item, presence: true
  validates :collecting_event, presence: true
  validates :type, presence: true

  protected

  def proper_data_is_provided
    retval = true
    #case
    #when GeographicItem.find(geographic_item_id) == nil
    #  errors.add(:geographic_item, 'ID must be from item of class Geographic_Item.') # THis isn't necessary, we'll have an index on the db
    #when CollectingEvent.find(collecting_event_id) == nil
    #  errors.add(:collecting_event, 'ID must be from item of class CollectingEvent.')
    #when GeographicItem.find(error_geographic_item_id).geo_object.geometry_type.type_name != 'Polygon'
    #  errors.add(:geographic_item, 'ID must be from item of class Geographic_Item of type \'POLYGON\'.')
    #when GeoreferenceHash[*arr]
    #  Type.find(type).to_s != 'Georeference::GeoreferenceType'
    #  errors.add(:georeference, 'type must be of class Georeference::GeoreferenceType.')
    #else
    #true
    #end
    unless error_radius.nil?
      errors.add(:error_radius, 'error_radius must be less than 20,000 kilometers (12,400 miles).') if error_radius > 20000000 # 20,000 km
      retval = false
    end
    unless error_depth.nil?
      errors.add(:error_depth, 'error_depth must be less than 8,800 kilometers (5.5 miles).') if error_depth > 8800 # 8,800 meters
      retval = false
    end
    #unless error_geographic_item.nil?
    #  errors.add(:error_geographic_item, 'error_geographic_item must contain geographic_item.') unless error_geographic_item.geo_object.contains?(geographic_item.geo_object)
    #end
    retval
  end
end

#error_depthInteger

Returns the distance in meters of the radius of the area of vertical uncertainty of the accuracy of the location of this georeference definition

Returns:

  • (Integer)

    the distance in meters of the radius of the area of vertical uncertainty of the accuracy of the location of this georeference definition



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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/georeference.rb', line 30

class Georeference < ActiveRecord::Base
  include Housekeeping

#  https://groups.google.com/forum/#!topic/rgeo-users/lMCr0mOt1F0
# TODone: Some of the GADM polygons seem to violate shapefile spec for *some* reason (not necessarily those stated in the above group post). As a possible remedy, adding ":uses_lenient_multi_polygon_assertions => true"
# TODone: This is also supposed to be the default factory (in fact, the *only* factory), but that does not seem to be the case. See lib/tasks/build_geographic_areas.rake

  FACTORY = RGeo::Geographic.projected_factory(srid:                    4326,
                                               projection_srid:         4326,
                                               projection_proj4:        '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs',
                                               uses_lenient_assertions: true,
                                               has_z_coordinate:        true)
=begin
  FACTORY = ::RGeo::Geos.factory(native_interface:                      :ffi,
                                 uses_lenient_multi_polygon_assertions: true,
                                 srid:                                  4326,
                                 has_z_coordinate:                      true)
=end



  # this represents a GeographicItem, but has a name (error_geographic_item) which is *not* the name of the column used in the table;
  # therefore, we need to tell it *which* table, and what to use to address the record we want
  belongs_to :error_geographic_item, class_name: 'GeographicItem', foreign_key: :error_geographic_item_id

  belongs_to :collecting_event
  belongs_to :geographic_item

  accepts_nested_attributes_for :geographic_item, :error_geographic_item

  validate :proper_data_is_provided
  validates :geographic_item, presence: true
  validates :collecting_event, presence: true
  validates :type, presence: true

  protected

  def proper_data_is_provided
    retval = true
    #case
    #when GeographicItem.find(geographic_item_id) == nil
    #  errors.add(:geographic_item, 'ID must be from item of class Geographic_Item.') # THis isn't necessary, we'll have an index on the db
    #when CollectingEvent.find(collecting_event_id) == nil
    #  errors.add(:collecting_event, 'ID must be from item of class CollectingEvent.')
    #when GeographicItem.find(error_geographic_item_id).geo_object.geometry_type.type_name != 'Polygon'
    #  errors.add(:geographic_item, 'ID must be from item of class Geographic_Item of type \'POLYGON\'.')
    #when GeoreferenceHash[*arr]
    #  Type.find(type).to_s != 'Georeference::GeoreferenceType'
    #  errors.add(:georeference, 'type must be of class Georeference::GeoreferenceType.')
    #else
    #true
    #end
    unless error_radius.nil?
      errors.add(:error_radius, 'error_radius must be less than 20,000 kilometers (12,400 miles).') if error_radius > 20000000 # 20,000 km
      retval = false
    end
    unless error_depth.nil?
      errors.add(:error_depth, 'error_depth must be less than 8,800 kilometers (5.5 miles).') if error_depth > 8800 # 8,800 meters
      retval = false
    end
    #unless error_geographic_item.nil?
    #  errors.add(:error_geographic_item, 'error_geographic_item must contain geographic_item.') unless error_geographic_item.geo_object.contains?(geographic_item.geo_object)
    #end
    retval
  end
end

#error_geographic_item_idInteger

Returns the id of a GeographicItem that represents the (error) representation of this georeference definition

Returns:

  • (Integer)

    the id of a GeographicItem that represents the (error) representation of this georeference definition



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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/georeference.rb', line 30

class Georeference < ActiveRecord::Base
  include Housekeeping

#  https://groups.google.com/forum/#!topic/rgeo-users/lMCr0mOt1F0
# TODone: Some of the GADM polygons seem to violate shapefile spec for *some* reason (not necessarily those stated in the above group post). As a possible remedy, adding ":uses_lenient_multi_polygon_assertions => true"
# TODone: This is also supposed to be the default factory (in fact, the *only* factory), but that does not seem to be the case. See lib/tasks/build_geographic_areas.rake

  FACTORY = RGeo::Geographic.projected_factory(srid:                    4326,
                                               projection_srid:         4326,
                                               projection_proj4:        '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs',
                                               uses_lenient_assertions: true,
                                               has_z_coordinate:        true)
=begin
  FACTORY = ::RGeo::Geos.factory(native_interface:                      :ffi,
                                 uses_lenient_multi_polygon_assertions: true,
                                 srid:                                  4326,
                                 has_z_coordinate:                      true)
=end



  # this represents a GeographicItem, but has a name (error_geographic_item) which is *not* the name of the column used in the table;
  # therefore, we need to tell it *which* table, and what to use to address the record we want
  belongs_to :error_geographic_item, class_name: 'GeographicItem', foreign_key: :error_geographic_item_id

  belongs_to :collecting_event
  belongs_to :geographic_item

  accepts_nested_attributes_for :geographic_item, :error_geographic_item

  validate :proper_data_is_provided
  validates :geographic_item, presence: true
  validates :collecting_event, presence: true
  validates :type, presence: true

  protected

  def proper_data_is_provided
    retval = true
    #case
    #when GeographicItem.find(geographic_item_id) == nil
    #  errors.add(:geographic_item, 'ID must be from item of class Geographic_Item.') # THis isn't necessary, we'll have an index on the db
    #when CollectingEvent.find(collecting_event_id) == nil
    #  errors.add(:collecting_event, 'ID must be from item of class CollectingEvent.')
    #when GeographicItem.find(error_geographic_item_id).geo_object.geometry_type.type_name != 'Polygon'
    #  errors.add(:geographic_item, 'ID must be from item of class Geographic_Item of type \'POLYGON\'.')
    #when GeoreferenceHash[*arr]
    #  Type.find(type).to_s != 'Georeference::GeoreferenceType'
    #  errors.add(:georeference, 'type must be of class Georeference::GeoreferenceType.')
    #else
    #true
    #end
    unless error_radius.nil?
      errors.add(:error_radius, 'error_radius must be less than 20,000 kilometers (12,400 miles).') if error_radius > 20000000 # 20,000 km
      retval = false
    end
    unless error_depth.nil?
      errors.add(:error_depth, 'error_depth must be less than 8,800 kilometers (5.5 miles).') if error_depth > 8800 # 8,800 meters
      retval = false
    end
    #unless error_geographic_item.nil?
    #  errors.add(:error_geographic_item, 'error_geographic_item must contain geographic_item.') unless error_geographic_item.geo_object.contains?(geographic_item.geo_object)
    #end
    retval
  end
end

#error_radiusInteger

Returns the distance in meters of the radius of the area of horizontal uncertainty of the accuracy of the location of this georeference definition

Returns:

  • (Integer)

    the distance in meters of the radius of the area of horizontal uncertainty of the accuracy of the location of this georeference definition



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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/georeference.rb', line 30

class Georeference < ActiveRecord::Base
  include Housekeeping

#  https://groups.google.com/forum/#!topic/rgeo-users/lMCr0mOt1F0
# TODone: Some of the GADM polygons seem to violate shapefile spec for *some* reason (not necessarily those stated in the above group post). As a possible remedy, adding ":uses_lenient_multi_polygon_assertions => true"
# TODone: This is also supposed to be the default factory (in fact, the *only* factory), but that does not seem to be the case. See lib/tasks/build_geographic_areas.rake

  FACTORY = RGeo::Geographic.projected_factory(srid:                    4326,
                                               projection_srid:         4326,
                                               projection_proj4:        '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs',
                                               uses_lenient_assertions: true,
                                               has_z_coordinate:        true)
=begin
  FACTORY = ::RGeo::Geos.factory(native_interface:                      :ffi,
                                 uses_lenient_multi_polygon_assertions: true,
                                 srid:                                  4326,
                                 has_z_coordinate:                      true)
=end



  # this represents a GeographicItem, but has a name (error_geographic_item) which is *not* the name of the column used in the table;
  # therefore, we need to tell it *which* table, and what to use to address the record we want
  belongs_to :error_geographic_item, class_name: 'GeographicItem', foreign_key: :error_geographic_item_id

  belongs_to :collecting_event
  belongs_to :geographic_item

  accepts_nested_attributes_for :geographic_item, :error_geographic_item

  validate :proper_data_is_provided
  validates :geographic_item, presence: true
  validates :collecting_event, presence: true
  validates :type, presence: true

  protected

  def proper_data_is_provided
    retval = true
    #case
    #when GeographicItem.find(geographic_item_id) == nil
    #  errors.add(:geographic_item, 'ID must be from item of class Geographic_Item.') # THis isn't necessary, we'll have an index on the db
    #when CollectingEvent.find(collecting_event_id) == nil
    #  errors.add(:collecting_event, 'ID must be from item of class CollectingEvent.')
    #when GeographicItem.find(error_geographic_item_id).geo_object.geometry_type.type_name != 'Polygon'
    #  errors.add(:geographic_item, 'ID must be from item of class Geographic_Item of type \'POLYGON\'.')
    #when GeoreferenceHash[*arr]
    #  Type.find(type).to_s != 'Georeference::GeoreferenceType'
    #  errors.add(:georeference, 'type must be of class Georeference::GeoreferenceType.')
    #else
    #true
    #end
    unless error_radius.nil?
      errors.add(:error_radius, 'error_radius must be less than 20,000 kilometers (12,400 miles).') if error_radius > 20000000 # 20,000 km
      retval = false
    end
    unless error_depth.nil?
      errors.add(:error_depth, 'error_depth must be less than 8,800 kilometers (5.5 miles).') if error_depth > 8800 # 8,800 meters
      retval = false
    end
    #unless error_geographic_item.nil?
    #  errors.add(:error_geographic_item, 'error_geographic_item must contain geographic_item.') unless error_geographic_item.geo_object.contains?(geographic_item.geo_object)
    #end
    retval
  end
end

#geographic_item_idInteger

Returns the id of a GeographicItem that represents the (non-error) representation of this georeference definition

Returns:

  • (Integer)

    the id of a GeographicItem that represents the (non-error) representation of this georeference definition



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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/georeference.rb', line 30

class Georeference < ActiveRecord::Base
  include Housekeeping

#  https://groups.google.com/forum/#!topic/rgeo-users/lMCr0mOt1F0
# TODone: Some of the GADM polygons seem to violate shapefile spec for *some* reason (not necessarily those stated in the above group post). As a possible remedy, adding ":uses_lenient_multi_polygon_assertions => true"
# TODone: This is also supposed to be the default factory (in fact, the *only* factory), but that does not seem to be the case. See lib/tasks/build_geographic_areas.rake

  FACTORY = RGeo::Geographic.projected_factory(srid:                    4326,
                                               projection_srid:         4326,
                                               projection_proj4:        '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs',
                                               uses_lenient_assertions: true,
                                               has_z_coordinate:        true)
=begin
  FACTORY = ::RGeo::Geos.factory(native_interface:                      :ffi,
                                 uses_lenient_multi_polygon_assertions: true,
                                 srid:                                  4326,
                                 has_z_coordinate:                      true)
=end



  # this represents a GeographicItem, but has a name (error_geographic_item) which is *not* the name of the column used in the table;
  # therefore, we need to tell it *which* table, and what to use to address the record we want
  belongs_to :error_geographic_item, class_name: 'GeographicItem', foreign_key: :error_geographic_item_id

  belongs_to :collecting_event
  belongs_to :geographic_item

  accepts_nested_attributes_for :geographic_item, :error_geographic_item

  validate :proper_data_is_provided
  validates :geographic_item, presence: true
  validates :collecting_event, presence: true
  validates :type, presence: true

  protected

  def proper_data_is_provided
    retval = true
    #case
    #when GeographicItem.find(geographic_item_id) == nil
    #  errors.add(:geographic_item, 'ID must be from item of class Geographic_Item.') # THis isn't necessary, we'll have an index on the db
    #when CollectingEvent.find(collecting_event_id) == nil
    #  errors.add(:collecting_event, 'ID must be from item of class CollectingEvent.')
    #when GeographicItem.find(error_geographic_item_id).geo_object.geometry_type.type_name != 'Polygon'
    #  errors.add(:geographic_item, 'ID must be from item of class Geographic_Item of type \'POLYGON\'.')
    #when GeoreferenceHash[*arr]
    #  Type.find(type).to_s != 'Georeference::GeoreferenceType'
    #  errors.add(:georeference, 'type must be of class Georeference::GeoreferenceType.')
    #else
    #true
    #end
    unless error_radius.nil?
      errors.add(:error_radius, 'error_radius must be less than 20,000 kilometers (12,400 miles).') if error_radius > 20000000 # 20,000 km
      retval = false
    end
    unless error_depth.nil?
      errors.add(:error_depth, 'error_depth must be less than 8,800 kilometers (5.5 miles).') if error_depth > 8800 # 8,800 meters
      retval = false
    end
    #unless error_geographic_item.nil?
    #  errors.add(:error_geographic_item, 'error_geographic_item must contain geographic_item.') unless error_geographic_item.geo_object.contains?(geographic_item.geo_object)
    #end
    retval
  end
end

#positionInteger

Returns the position of this georeference definition

Returns:

  • (Integer)

    the position of this georeference definition



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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/georeference.rb', line 30

class Georeference < ActiveRecord::Base
  include Housekeeping

#  https://groups.google.com/forum/#!topic/rgeo-users/lMCr0mOt1F0
# TODone: Some of the GADM polygons seem to violate shapefile spec for *some* reason (not necessarily those stated in the above group post). As a possible remedy, adding ":uses_lenient_multi_polygon_assertions => true"
# TODone: This is also supposed to be the default factory (in fact, the *only* factory), but that does not seem to be the case. See lib/tasks/build_geographic_areas.rake

  FACTORY = RGeo::Geographic.projected_factory(srid:                    4326,
                                               projection_srid:         4326,
                                               projection_proj4:        '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs',
                                               uses_lenient_assertions: true,
                                               has_z_coordinate:        true)
=begin
  FACTORY = ::RGeo::Geos.factory(native_interface:                      :ffi,
                                 uses_lenient_multi_polygon_assertions: true,
                                 srid:                                  4326,
                                 has_z_coordinate:                      true)
=end



  # this represents a GeographicItem, but has a name (error_geographic_item) which is *not* the name of the column used in the table;
  # therefore, we need to tell it *which* table, and what to use to address the record we want
  belongs_to :error_geographic_item, class_name: 'GeographicItem', foreign_key: :error_geographic_item_id

  belongs_to :collecting_event
  belongs_to :geographic_item

  accepts_nested_attributes_for :geographic_item, :error_geographic_item

  validate :proper_data_is_provided
  validates :geographic_item, presence: true
  validates :collecting_event, presence: true
  validates :type, presence: true

  protected

  def proper_data_is_provided
    retval = true
    #case
    #when GeographicItem.find(geographic_item_id) == nil
    #  errors.add(:geographic_item, 'ID must be from item of class Geographic_Item.') # THis isn't necessary, we'll have an index on the db
    #when CollectingEvent.find(collecting_event_id) == nil
    #  errors.add(:collecting_event, 'ID must be from item of class CollectingEvent.')
    #when GeographicItem.find(error_geographic_item_id).geo_object.geometry_type.type_name != 'Polygon'
    #  errors.add(:geographic_item, 'ID must be from item of class Geographic_Item of type \'POLYGON\'.')
    #when GeoreferenceHash[*arr]
    #  Type.find(type).to_s != 'Georeference::GeoreferenceType'
    #  errors.add(:georeference, 'type must be of class Georeference::GeoreferenceType.')
    #else
    #true
    #end
    unless error_radius.nil?
      errors.add(:error_radius, 'error_radius must be less than 20,000 kilometers (12,400 miles).') if error_radius > 20000000 # 20,000 km
      retval = false
    end
    unless error_depth.nil?
      errors.add(:error_depth, 'error_depth must be less than 8,800 kilometers (5.5 miles).') if error_depth > 8800 # 8,800 meters
      retval = false
    end
    #unless error_geographic_item.nil?
    #  errors.add(:error_geographic_item, 'error_geographic_item must contain geographic_item.') unless error_geographic_item.geo_object.contains?(geographic_item.geo_object)
    #end
    retval
  end
end

#requestString

Returns the text of the GeoLocation request (::GeoLocate), or the verbatim data (VerbatimData)

Returns:

  • (String)

    the text of the GeoLocation request (::GeoLocate), or the verbatim data (VerbatimData)



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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/georeference.rb', line 30

class Georeference < ActiveRecord::Base
  include Housekeeping

#  https://groups.google.com/forum/#!topic/rgeo-users/lMCr0mOt1F0
# TODone: Some of the GADM polygons seem to violate shapefile spec for *some* reason (not necessarily those stated in the above group post). As a possible remedy, adding ":uses_lenient_multi_polygon_assertions => true"
# TODone: This is also supposed to be the default factory (in fact, the *only* factory), but that does not seem to be the case. See lib/tasks/build_geographic_areas.rake

  FACTORY = RGeo::Geographic.projected_factory(srid:                    4326,
                                               projection_srid:         4326,
                                               projection_proj4:        '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs',
                                               uses_lenient_assertions: true,
                                               has_z_coordinate:        true)
=begin
  FACTORY = ::RGeo::Geos.factory(native_interface:                      :ffi,
                                 uses_lenient_multi_polygon_assertions: true,
                                 srid:                                  4326,
                                 has_z_coordinate:                      true)
=end



  # this represents a GeographicItem, but has a name (error_geographic_item) which is *not* the name of the column used in the table;
  # therefore, we need to tell it *which* table, and what to use to address the record we want
  belongs_to :error_geographic_item, class_name: 'GeographicItem', foreign_key: :error_geographic_item_id

  belongs_to :collecting_event
  belongs_to :geographic_item

  accepts_nested_attributes_for :geographic_item, :error_geographic_item

  validate :proper_data_is_provided
  validates :geographic_item, presence: true
  validates :collecting_event, presence: true
  validates :type, presence: true

  protected

  def proper_data_is_provided
    retval = true
    #case
    #when GeographicItem.find(geographic_item_id) == nil
    #  errors.add(:geographic_item, 'ID must be from item of class Geographic_Item.') # THis isn't necessary, we'll have an index on the db
    #when CollectingEvent.find(collecting_event_id) == nil
    #  errors.add(:collecting_event, 'ID must be from item of class CollectingEvent.')
    #when GeographicItem.find(error_geographic_item_id).geo_object.geometry_type.type_name != 'Polygon'
    #  errors.add(:geographic_item, 'ID must be from item of class Geographic_Item of type \'POLYGON\'.')
    #when GeoreferenceHash[*arr]
    #  Type.find(type).to_s != 'Georeference::GeoreferenceType'
    #  errors.add(:georeference, 'type must be of class Georeference::GeoreferenceType.')
    #else
    #true
    #end
    unless error_radius.nil?
      errors.add(:error_radius, 'error_radius must be less than 20,000 kilometers (12,400 miles).') if error_radius > 20000000 # 20,000 km
      retval = false
    end
    unless error_depth.nil?
      errors.add(:error_depth, 'error_depth must be less than 8,800 kilometers (5.5 miles).') if error_depth > 8800 # 8,800 meters
      retval = false
    end
    #unless error_geographic_item.nil?
    #  errors.add(:error_geographic_item, 'error_geographic_item must contain geographic_item.') unless error_geographic_item.geo_object.contains?(geographic_item.geo_object)
    #end
    retval
  end
end

#source_idInteger

Returns the id of the source of this georeference definition

Returns:

  • (Integer)

    the id of the source of this georeference definition



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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/georeference.rb', line 30

class Georeference < ActiveRecord::Base
  include Housekeeping

#  https://groups.google.com/forum/#!topic/rgeo-users/lMCr0mOt1F0
# TODone: Some of the GADM polygons seem to violate shapefile spec for *some* reason (not necessarily those stated in the above group post). As a possible remedy, adding ":uses_lenient_multi_polygon_assertions => true"
# TODone: This is also supposed to be the default factory (in fact, the *only* factory), but that does not seem to be the case. See lib/tasks/build_geographic_areas.rake

  FACTORY = RGeo::Geographic.projected_factory(srid:                    4326,
                                               projection_srid:         4326,
                                               projection_proj4:        '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs',
                                               uses_lenient_assertions: true,
                                               has_z_coordinate:        true)
=begin
  FACTORY = ::RGeo::Geos.factory(native_interface:                      :ffi,
                                 uses_lenient_multi_polygon_assertions: true,
                                 srid:                                  4326,
                                 has_z_coordinate:                      true)
=end



  # this represents a GeographicItem, but has a name (error_geographic_item) which is *not* the name of the column used in the table;
  # therefore, we need to tell it *which* table, and what to use to address the record we want
  belongs_to :error_geographic_item, class_name: 'GeographicItem', foreign_key: :error_geographic_item_id

  belongs_to :collecting_event
  belongs_to :geographic_item

  accepts_nested_attributes_for :geographic_item, :error_geographic_item

  validate :proper_data_is_provided
  validates :geographic_item, presence: true
  validates :collecting_event, presence: true
  validates :type, presence: true

  protected

  def proper_data_is_provided
    retval = true
    #case
    #when GeographicItem.find(geographic_item_id) == nil
    #  errors.add(:geographic_item, 'ID must be from item of class Geographic_Item.') # THis isn't necessary, we'll have an index on the db
    #when CollectingEvent.find(collecting_event_id) == nil
    #  errors.add(:collecting_event, 'ID must be from item of class CollectingEvent.')
    #when GeographicItem.find(error_geographic_item_id).geo_object.geometry_type.type_name != 'Polygon'
    #  errors.add(:geographic_item, 'ID must be from item of class Geographic_Item of type \'POLYGON\'.')
    #when GeoreferenceHash[*arr]
    #  Type.find(type).to_s != 'Georeference::GeoreferenceType'
    #  errors.add(:georeference, 'type must be of class Georeference::GeoreferenceType.')
    #else
    #true
    #end
    unless error_radius.nil?
      errors.add(:error_radius, 'error_radius must be less than 20,000 kilometers (12,400 miles).') if error_radius > 20000000 # 20,000 km
      retval = false
    end
    unless error_depth.nil?
      errors.add(:error_depth, 'error_depth must be less than 8,800 kilometers (5.5 miles).') if error_depth > 8800 # 8,800 meters
      retval = false
    end
    #unless error_geographic_item.nil?
    #  errors.add(:error_geographic_item, 'error_geographic_item must contain geographic_item.') unless error_geographic_item.geo_object.contains?(geographic_item.geo_object)
    #end
    retval
  end
end

#typeString

Returns the type name of the this georeference definition

Returns:

  • (String)

    the type name of the this georeference definition



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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/georeference.rb', line 30

class Georeference < ActiveRecord::Base
  include Housekeeping

#  https://groups.google.com/forum/#!topic/rgeo-users/lMCr0mOt1F0
# TODone: Some of the GADM polygons seem to violate shapefile spec for *some* reason (not necessarily those stated in the above group post). As a possible remedy, adding ":uses_lenient_multi_polygon_assertions => true"
# TODone: This is also supposed to be the default factory (in fact, the *only* factory), but that does not seem to be the case. See lib/tasks/build_geographic_areas.rake

  FACTORY = RGeo::Geographic.projected_factory(srid:                    4326,
                                               projection_srid:         4326,
                                               projection_proj4:        '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs',
                                               uses_lenient_assertions: true,
                                               has_z_coordinate:        true)
=begin
  FACTORY = ::RGeo::Geos.factory(native_interface:                      :ffi,
                                 uses_lenient_multi_polygon_assertions: true,
                                 srid:                                  4326,
                                 has_z_coordinate:                      true)
=end



  # this represents a GeographicItem, but has a name (error_geographic_item) which is *not* the name of the column used in the table;
  # therefore, we need to tell it *which* table, and what to use to address the record we want
  belongs_to :error_geographic_item, class_name: 'GeographicItem', foreign_key: :error_geographic_item_id

  belongs_to :collecting_event
  belongs_to :geographic_item

  accepts_nested_attributes_for :geographic_item, :error_geographic_item

  validate :proper_data_is_provided
  validates :geographic_item, presence: true
  validates :collecting_event, presence: true
  validates :type, presence: true

  protected

  def proper_data_is_provided
    retval = true
    #case
    #when GeographicItem.find(geographic_item_id) == nil
    #  errors.add(:geographic_item, 'ID must be from item of class Geographic_Item.') # THis isn't necessary, we'll have an index on the db
    #when CollectingEvent.find(collecting_event_id) == nil
    #  errors.add(:collecting_event, 'ID must be from item of class CollectingEvent.')
    #when GeographicItem.find(error_geographic_item_id).geo_object.geometry_type.type_name != 'Polygon'
    #  errors.add(:geographic_item, 'ID must be from item of class Geographic_Item of type \'POLYGON\'.')
    #when GeoreferenceHash[*arr]
    #  Type.find(type).to_s != 'Georeference::GeoreferenceType'
    #  errors.add(:georeference, 'type must be of class Georeference::GeoreferenceType.')
    #else
    #true
    #end
    unless error_radius.nil?
      errors.add(:error_radius, 'error_radius must be less than 20,000 kilometers (12,400 miles).') if error_radius > 20000000 # 20,000 km
      retval = false
    end
    unless error_depth.nil?
      errors.add(:error_depth, 'error_depth must be less than 8,800 kilometers (5.5 miles).') if error_depth > 8800 # 8,800 meters
      retval = false
    end
    #unless error_geographic_item.nil?
    #  errors.add(:error_geographic_item, 'error_geographic_item must contain geographic_item.') unless error_geographic_item.geo_object.contains?(geographic_item.geo_object)
    #end
    retval
  end
end