Class: SearchModel
- Defined in:
- app/models/search_model.rb
Constant Summary collapse
- LOCATE_MAX_COUNT =
50
- SEARCH_MAX_COUNT =
50
Class Method Summary collapse
-
.bbox(features) ⇒ Object
calculate bbox of all features.
-
.envelope(features) ⇒ Object
calculate envelope of all features.
-
.layer_locate(layer, search_field, locations, client_srid = nil) ⇒ Object
Generic location search with one search field.
- .locate(locations, client_srid = nil) ⇒ Object
-
.map_center(features) ⇒ Object
calculate center and scale for feature locations.
- .query(fields, params) ⇒ Object
-
.search_locations(param) ⇒ Object
“261,AU4998$261,AU4999” -> [[“261”,“AU4998”],] TODO: inconsistent with single field search -> “261|AU4998,261|AU4999” -> [[“261”,“AU4998”],].
- .selection_layer ⇒ Object
- .selection_scalerange ⇒ Object
- .selection_topic ⇒ Object
- .soap_query(fields, soap_params, soap_action) ⇒ Object
Methods inherited from GeoModel
area_field, #bbox, bbox_filter, can_edit?, #csv_header, #csv_row, #customize_geojson, default_client_srid, default_rgeo_factory, extent_field, forbidden, geo_factory, geojson_decode, geometry_column, geometry_column_info, geometry_column_name, geometry_field, geometry_type, identify_filter, #modified_by, select_geojson_geom, set_default_client_srid, set_default_rgeo_factory, srid, #to_geojson, transform_geom_sql, #update_attributes_from_geojson_feature, user_filter, validate_feature, validate_feature_collection, validate_geometry, validate_geometry_type
Class Method Details
.bbox(features) ⇒ Object
calculate bbox of all features
63 64 65 66 |
# File 'app/models/search_model.rb', line 63 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
51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/search_model.rb', line 51 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, client_srid = nil) ⇒ Object
Generic location search with one search field
31 32 33 34 |
# File 'app/models/search_model.rb', line 31 def self.layer_locate(layer, search_field, locations, client_srid=nil) feature_class = layer.feature_class feature_class.where(search_field => locations).select(feature_class.primary_key).select(feature_class.extent_field(client_srid)).limit(LOCATE_MAX_COUNT).all end |
.locate(locations, client_srid = nil) ⇒ Object
13 14 15 16 |
# File 'app/models/search_model.rb', line 13 def self.locate(locations, client_srid=nil) #return {:features => []} raise NotImplementedError.new end |
.map_center(features) ⇒ Object
calculate center and scale for feature locations
69 70 71 72 73 |
# File 'app/models/search_model.rb', line 69 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
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”],] TODO: inconsistent with single field search -> “261|AU4998,261|AU4999” -> [[“261”,“AU4998”],]
38 39 40 41 |
# File 'app/models/search_model.rb', line 38 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_scalerange ⇒ Object
26 27 28 |
# File 'app/models/search_model.rb', line 26 def self.selection_scalerange 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
43 44 45 46 47 48 |
# File 'app/models/search_model.rb', line 43 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 |