Class: Tasks::Gis::MatchGeoreferenceController

Inherits:
ApplicationController
  • Object
show all
Includes:
TaskControllerConfiguration
Defined in:
app/controllers/tasks/gis/match_georeference_controller.rb

Instance Method Summary (collapse)

Methods included from TaskControllerConfiguration

#set_is_task_controller

Instance Method Details

- (Object) batch_create_match_georeferences

def anti_meridian_check(last_x, this_x) # returns true if anti-meridian crossed

if last_x
  if last_x <= 0
    if (((this_x >= 0 || this_x < -180))) # sign change from west to east
      xm = (0.5 * (this_x - last_x)).abs # find intersection
      if (xm > 90)
        return true
      end
    end
  end
  if last_x >= 0
    if (((this_x <= 0) || this_x > 180))
      xm = (0.5 * (last_x - this_x)).abs
      if (xm > 90)
        return true
      end
    end
  end
end
false

end



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 178

def batch_create_match_georeferences
  message = ''
  respond_to do |format|
    format.json {
      # we want to repackage the checkmarks we get from the client side into an array of ids with which
      # to feed Georeference.
      keys = params.keys
      checked_ids = []
      arguments = {}
      keys.each { |key|
        if /check\d+/ =~ key
          checked_ids.push(params[key].to_i)
        end
      }

      arguments[:georeference_id] = params['georeference_id']
      arguments[:checked_ids] = checked_ids

      results = Georeference.with_project_id(sessions_current_project_id)
                    .batch_create_from_georeference_matcher(arguments)

      if results.blank?
        message = 'No collecting events were selected.'
      end

      html = render_to_string(partial: 'georeference_success', formats: 'html',
                              locals: {georeferences_results: results}
      )

      render json: {message: message,
                    html: html
      }
    }
  end
end

- (String) ce_render_to_html

Returns of html for partial

Returns:

  • (String)

    of html for partial



228
229
230
231
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 228

def ce_render_to_html
  render_to_string(partial: 'tasks/gis/match_georeference/collecting_event_selections',
                   locals: {collecting_events: @collecting_events})
end

- (Object) drawn_collecting_events



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
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 53

def drawn_collecting_events

  message = ''
  value = params['ce_geographic_item_attributes_shape']
  if value.blank?
    @collecting_events = CollectingEvent.where('false')
  else
    feature = RGeo::GeoJSON.decode(value, json_parser: :json)
    # isolate the WKT
    geometry = feature.geometry
    this_type = geometry.geometry_type.to_s.downcase
    geometry = geometry.as_text
    radius = feature['radius']
    case this_type
      when 'point'
        @collecting_events = CollectingEvent.with_project_id(sessions_current_project_id)
                                 .joins(:geographic_items)
                                 .where(GeographicItem.within_radius_of_wkt_sql(geometry, radius))
      when 'polygon'
        @collecting_events = CollectingEvent.with_project_id(sessions_current_project_id)
                                 .joins(:geographic_items)
                                 .where(GeographicItem.contained_by_wkt_sql(geometry))
      else
    end
  end

  if @collecting_events.blank?
    message = 'no georeferences found'
  end
  render_ce_select_json(message)
end

- (Object) drawn_georeferences



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 125

def drawn_georeferences
  message = ''
  value = params['gr_geographic_item_attributes_shape']
  if value.blank?
    @georeferences = Georeference.where('false')
  else
    feature = RGeo::GeoJSON.decode(value, json_parser: :json)
    # isolate the WKT
    geometry = feature.geometry
    this_type = geometry.geometry_type.to_s.downcase
    geometry = geometry.as_text
    radius = feature['radius']
    case this_type
      when 'point'
        @georeferences = Georeference.with_project_id(sessions_current_project_id)
                             .joins(:geographic_item)
                             .where(GeographicItem.within_radius_of_wkt_sql(geometry, radius))
      when 'polygon'
        @georeferences = Georeference.with_project_id(sessions_current_project_id)
                             .joins(:geographic_item)
                             .where(GeographicItem.contained_by_wkt_sql(geometry))
      else
    end
  if @georeferences.blank?
    message = 'no objects contained in drawn shape'
  end
  render_gr_select_json(message)
  end
end

- (Object) filtered_collecting_events



11
12
13
14
15
16
17
18
19
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 11

def filtered_collecting_events
  message = ''
  @collecting_events = CollectingEvent.with_project_id(sessions_current_project_id).filter(params)

  if @collecting_events.blank?
    message = 'no collecting events selected'
  end
  render_ce_select_json(message)
end

- (Object) filtered_georeferences



85
86
87
88
89
90
91
92
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 85

def filtered_georeferences
  message = ''
  @georeferences = Georeference.with_project_id(sessions_current_project_id).filter(params)
  if @georeferences.blank?
    message = 'no georeferences found'
  end
  render_gr_select_json(message)
end

- (String) gr_render_to_html

Returns of html for partial

Returns:

  • (String)

    of html for partial



234
235
236
237
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 234

def gr_render_to_html
  render_to_string(partial: 'tasks/gis/match_georeference/georeferences_selections_form',
                   locals: {georeferences: @georeferences})
end

- (Object) index



4
5
6
7
8
9
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 4

def index
  @collecting_event = CollectingEvent.new
  @georeference = Georeference.new
  @collecting_events = []
  @georeferences = []
end

- (Object) recent_collecting_events



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 21

def recent_collecting_events
  message = ''
  how_many = params['how_many']
  @collecting_events = CollectingEvent.with_project_id(sessions_current_project_id)
                           .order(updated_at: :desc)
                           .limit(how_many.to_i)

  if @collecting_events.blank?
    message = 'no recent objects selected'
  end

  render_ce_select_json(message)
end

- (Object) recent_georeferences



94
95
96
97
98
99
100
101
102
103
104
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 94

def recent_georeferences
  message = ''
  how_many = params['how_many']
  @georeferences = Georeference.with_project_id(sessions_current_project_id)
                       .order(updated_at: :desc)
                       .limit(how_many.to_i)
  if @georeferences.blank?
    message = 'no recent georeferences selected'
  end
  render_gr_select_json(message)
end

- (JSON) render_ce_select_json(message)

Returns with html for collecting events display (table of selectable collecting events)

Parameters:

  • message (String)

    to be conveyed to client side

Returns:

  • (JSON)

    with html for collecting events display (table of selectable collecting events)



216
217
218
219
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 216

def render_ce_select_json(message)
  # retval = render_to_html
  render json: {message: message, html: ce_render_to_html}
end

- (JSON) render_gr_select_json(message)

Returns with html for georeferences display (feature collection)

Parameters:

  • message (String)

    to be conveyed to client side

Returns:

  • (JSON)

    with html for georeferences display (feature collection)



223
224
225
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 223

def render_gr_select_json(message)
  render json: {message: message, html: gr_render_to_html}
end

- (Object) tagged_collecting_events



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 35

def tagged_collecting_events
  message = ''
  if params[:keyword_id].blank?
    # Bad search request; return not a list but back to the form
    @collecting_events = CollectingEvent.where('false')
  else
    keyword = Keyword.find(params[:keyword_id])
    @collecting_events = CollectingEvent.with_project_id(sessions_current_project_id)
                             .order(updated_at: :desc)
                             .tagged_with_keyword(keyword)
  end

  if @collecting_events.blank?
    message = 'no tagged objects selected'
  end
  render_ce_select_json(message)
end

- (Object) tagged_georeferences



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 106

def tagged_georeferences
  message = ''

  # todo: this needs to be rationalized, but works, after a fashion.
  if params[:keyword_id].blank?
    # render json: {html: 'Empty set'} #and return
    @georeferences = Georeference.where('false')
  else
    keyword = Keyword.find(params[:keyword_id])
    @georeferences = Georeference.with_project_id(sessions_current_project_id)
                         .order(updated_at: :desc)
                         .tagged_with_keyword(keyword)
  end
  if @georeferences.blank?
    message = 'no tagged objects selected'
  end
  render_gr_select_json(message)
end