Module: MapLayers::WFS

Defined in:
lib/map_layers/wfs.rb

Overview

WFS Server methods

Constant Summary collapse

WGS84 =
4326

Instance Method Summary collapse

Instance Method Details

#wfsObject

Publish layer in WFS format


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/map_layers/wfs.rb', line 9

def wfs
  minx, miny, maxx, maxy = extract_params
  model = map_layers_config.model
  if map_layers_config.geometry
    db_srid = model.columns_hash[map_layers_config.geometry.to_s].srid
    if db_srid != @srid && !db_srid.nil? && db_srid != -1
      #Transform geometry from db_srid to requested srid (not possible for undefined db_srid)
      geom = "Transform(#{geom},#{@srid}) AS #{geom}"
    end
    
    spatial_cond = if model.respond_to?(:sanitize_sql_hash_for_conditions)
      model.sanitize_sql_hash_for_conditions(map_layers_config.geometry => [[minx, miny],[maxx, maxy], db_srid])
    else # Rails < 2
      model.sanitize_sql_hash(map_layers_config.geometry => [[minx, miny],[maxx, maxy], db_srid])
    end
    #spatial_cond = "Transform(#{spatial_cond}, #{db_srid}) )" Not necessary: bbox is always WGS84 !?

    rows = model.find(:all, :conditions => spatial_cond, :limit => @maxfeatures)
    @features = rows.collect do |row|
      Feature.from_geom(row.send(map_layers_config.text), row.send(map_layers_config.geometry.to_s))
    end
  else
    rows = model.find(:all, :limit => @maxfeatures)
    @features = rows.collect do |row|
      Feature.new(row.send(map_layers_config.text), row.send(map_layers_config.lon), row.send(map_layers_config.lat))
    end
  end
  logger.info "MapLayers::WFS: returning #{@features.size} features"
  render :inline => WFS_XML_ERB, :content_type => "text/xml"
rescue Exception => e
  logger.error "MapLayers::WFS: returning no features - Caught exception '#{e}'"
  render :text => WFS_EMPTY_RESPONSE, :content_type => "text/xml"
end