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



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 162

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.batch_create_from_georeference_matcher(arguments)

      if results.length == 0
        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



211
212
213
214
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 211

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



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

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.joins(:geographic_items).where(GeographicItem.within_radius_of_wkt_sql(geometry, radius))
      when 'polygon'
        @collecting_events = CollectingEvent.joins(:geographic_items).where(GeographicItem.contained_by_wkt_sql(geometry))
      else
    end
  end

  if @collecting_events.length == 0
    message = 'no georeferences found'
  end
  render_ce_select_json(message)
end

- (Object) drawn_georeferences



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 113

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.joins(:geographic_item).where(GeographicItem.within_radius_of_wkt_sql(geometry, radius))
      when 'polygon'
          @georeferences = Georeference.joins(:geographic_item).where(GeographicItem.contained_by_wkt_sql(geometry))
      else
    end
  if @georeferences.length == 0
    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.filter(params)

  if @collecting_events.length == 0
    message = 'no collecting events selected'
  end
  render_ce_select_json(message)
end

- (Object) filtered_georeferences



77
78
79
80
81
82
83
84
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 77

def filtered_georeferences
  message = ''
  @georeferences = Georeference.filter(params)
  if @georeferences.length == 0
    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



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

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

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

  if @collecting_events.length == 0
    message = 'no recent objects selected'
  end

  render_ce_select_json(message)
end

- (Object) recent_georeferences



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

def recent_georeferences
  message = ''
  how_many = params['how_many']
  @georeferences = Georeference.where(project_id: $project_id).order(updated_at: :desc).limit(how_many.to_i)
  if @georeferences.length == 0
    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)



199
200
201
202
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 199

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)



206
207
208
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 206

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

- (Object) tagged_collecting_events



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

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.where(project_id: $project_id).order(updated_at: :desc).tagged_with_keyword(keyword)
  end

  if @collecting_events.length == 0
    message = 'no tagged objects selected'
  end
  render_ce_select_json(message)
end

- (Object) tagged_georeferences



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 96

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.where(project_id: $project_id).order(updated_at: :desc).tagged_with_keyword(keyword)
  end
  if @georeferences.length == 0
    message = 'no tagged objects selected'
  end
  render_gr_select_json(message)
end