Class: SearchModel

Inherits:
GeoModel
  • Object
show all
Defined in:
app/models/search_model.rb

Constant Summary collapse

LOCATE_MAX_COUNT =
50

Class Method Summary collapse

Methods inherited from GeoModel

#bbox, bbox_filter, can_edit?, #csv_header, #csv_row, extent_field, forbidden, geo_factory, geojson_decode, geometry_column, geometry_column_info, geometry_column_name, geometry_type, identify_filter, #modified_by, srid, #to_geojson, #update_attributes_from_geojson_feature, user_filter

Class Method Details

.bbox(features) ⇒ Object

calculate bbox of all features



58
59
60
61
# File 'app/models/search_model.rb', line 58

def self.bbox(features)
  envelope = envelope(features)
  [envelope.lower_corner.x, envelope.lower_corner.y, envelope.upper_corner.x, envelope.upper_corner.y]
end

.envelope(features) ⇒ Object

calculate envelope of all features



46
47
48
49
50
51
52
53
54
55
# File 'app/models/search_model.rb', line 46

def self.envelope(features)
  unless features.empty?
    envelope = GeoRuby::SimpleFeatures::Geometry.from_hex_ewkb(features.first['extent']).envelope
    features.each do |feature|
      next if feature == features.first
      envelope.extend!(GeoRuby::SimpleFeatures::Geometry.from_hex_ewkb(feature['extent']).envelope)
    end
    envelope
  end
end

.layer_locate(layer, search_field, locations) ⇒ Object

Generic location search with one search field



27
28
29
30
# File 'app/models/search_model.rb', line 27

def self.layer_locate(layer, search_field, locations)
  feature_class = layer.feature_class
  feature_class.where(search_field => locations).select(feature_class.primary_key).select(feature_class.extent_field).limit(LOCATE_MAX_COUNT).all
end

.locate(locations) ⇒ Object

Raises:

  • (NotImplementedError)


13
14
15
16
# File 'app/models/search_model.rb', line 13

def self.locate(locations)
  #return {:features => []}
  raise NotImplementedError.new
end

.map_center(features) ⇒ Object

calculate center and scale for feature locations



64
65
66
67
68
# File 'app/models/search_model.rb', line 64

def self.map_center(features)
  env = envelope(features)
  scale = 500 #FIXME: use self.bbox instead of map_center 
  [env.center.x, env.center.y, scale]
end

.query(fields, params) ⇒ Object

Raises:

  • (NotImplementedError)


8
9
10
11
# File 'app/models/search_model.rb', line 8

def self.query(fields, params)
  #return {:features => [], :quality => n}
  raise NotImplementedError.new
end

.search_locations(param) ⇒ Object

"261,AU4998;261,AU4999" -> [["261","AU4998"],["261","AU4999"]]



33
34
35
36
# File 'app/models/search_model.rb', line 33

def self.search_locations(param)
  locations = param.split(';')
  locations.collect {|l| l.split(',') }
end

.selection_layer ⇒ Object



22
23
24
# File 'app/models/search_model.rb', line 22

def self.selection_layer
  nil
end

.selection_topic ⇒ Object



18
19
20
# File 'app/models/search_model.rb', line 18

def self.selection_topic
  nil
end

.soap_query(fields, soap_params, soap_action) ⇒ Object

Raises:

  • (NotImplementedError)


38
39
40
41
42
43
# File 'app/models/search_model.rb', line 38

def self.soap_query(fields, soap_params, soap_action)
  #return {:feature => f, :hits => n, :quality => n, :template => str}
  #return {:features => [], :template => str}
  #return {:error => str}
  raise NotImplementedError.new
end