Class: Georeference::GeoLocate

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

Overview

A Georeference derived from a call to the Tulane GeoLocate API.

Defined Under Namespace

Classes: Request, RequestUI, Response

Constant Summary

URI_HOST =
'www.museum.tulane.edu'
URI_PATH =
'/webservices/geolocatesvcv2/glcwrap.aspx?'
URI_EMBED_PATH =
'/geolocate/web/webgeoreflight.aspx?'

Instance Attribute Summary (collapse)

Attributes inherited from Georeference

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

Class Method Summary (collapse)

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?

Instance Attribute Details

- (Object) api_response

Returns the value of attribute api_response



4
5
6
# File 'app/models/georeference/geo_locate.rb', line 4

def api_response
  @api_response
end

- (Object) iframe_response

Returns the value of attribute iframe_response



4
5
6
# File 'app/models/georeference/geo_locate.rb', line 4

def iframe_response
  @iframe_response
end

Class Method Details

+ (Object) build(request_params)

Build a georeference starting with a set of request parameters.



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'app/models/georeference/geo_locate.rb', line 104

def self.build(request_params)
  g = self.new

  # @todo write a Request.valid_params? method to use here
  # @todo #1: Just what will be the validation criteria for the request?
  # @todo #2: Why not judge validity from the response?
  if request_params.nil?
    g.errors.add(:base, 'invalid or no request parameters provided.')
    return g
  end

  request = Request.new(request_params)
  request.locate

  if request.succeeded?
    g.api_response = request.response
    g.api_request  = request.request_param_string
  else
    g.errors.add(:api_request, 'requested parameters did not succeed to return a result')
  end
  g
end

+ (Array) parse_iframe_result(response_string)

parsing the four possible bits of a response into an array

Parameters:

  • response_string (String)

Returns:

  • (Array)


90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/models/georeference/geo_locate.rb', line 90

def self.parse_iframe_result(response_string)
  lat, long, error_radius, uncertainty_polygon = response_string.split("|")
  uncertainty_points                           = nil
  unless uncertainty_polygon.nil?
    if uncertainty_polygon =~ /unavailable/i # todo: there are many more possible error conditions
      uncertainty_points = nil
    else
      uncertainty_points = uncertainty_polygon.split(',').reverse.in_groups_of(2)
    end
  end
  [lat, long, error_radius, uncertainty_points]
end

Instance Method Details

- (Object) make_error_geographic_item(uncertainty_polygon, uncertainty_radius)

TODO:

get geoJson results and handle all this automatically?



78
79
80
81
82
83
84
85
# File 'app/models/georeference/geo_locate.rb', line 78

def make_error_geographic_item(uncertainty_polygon, uncertainty_radius)
  self.error_radius = uncertainty_radius if !uncertainty_radius.nil?
  unless uncertainty_polygon.nil?
    err_array = []
    uncertainty_polygon.each { |point| err_array.push(Gis::FACTORY.point(point[0], point[1])) }
    self.error_geographic_item = GeographicItem.new(polygon: Gis::FACTORY.polygon(Gis::FACTORY.line_string(err_array)))
  end
end

- (Object) make_geographic_point(x, y, z = '0.0')

Parameters:

  • x (String)

    longitude

  • y (String)

    latitude

  • z (String) (defaults to: '0.0')

    elevation



40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/georeference/geo_locate.rb', line 40

def make_geographic_point(x, y, z = '0.0')
  if x.blank? or y.blank?
    test_grs = []
  else
    test_grs = GeographicItem::Point.where("point = ST_GeographyFromText('POINT(#{x} #{y})::geography')").where("ST_Z(point::geometry) = #{z}")
  end
  if test_grs.empty? # put a new one in the array
    test_grs = [GeographicItem.new(point: Gis::FACTORY.point(x, y, z))]
  end
  self.geographic_item = test_grs.first
end

- (Object) request_hash



33
34
35
# File 'app/models/georeference/geo_locate.rb', line 33

def request_hash
  Hash[*self.api_request.split('&').collect { |a| a.split('=', 2) }.flatten]
end