module Skra::Geo

Constants

VERSION

Public Class Methods

defaults() click to toggle source
# File lib/skra/geo.rb, line 9
def self.defaults
  {
    :service => :wfs,
    :version => "1.1.0",
    :request => 'GetFeature',
    :typename => 'fasteignaskra:VSTADF',
    :outputformat => 'json'
  }
end
heinum(id, options={}) click to toggle source
# File lib/skra/geo.rb, line 23
def self.heinum(id, options={})
  get_features([{:name => :HEINUM, :value => id}], options)
end
landnr(id, options={}) click to toggle source
# File lib/skra/geo.rb, line 27
def self.landnr(id, options={})
  get_features([{:name => :LANDNR, :value => id}], options)
end
query(filter, options={}) click to toggle source
# File lib/skra/geo.rb, line 19
def self.query(filter, options={})
  get_features(filter, options)
end
street(name, number=nil, postcode=nil, options={}) click to toggle source
# File lib/skra/geo.rb, line 31
def self.street(name, number=nil, postcode=nil, options={})
  property = options.delete(:dative) ? :HEITI_TGF : :HEITI_NF
  filter = [
    {:name => property, :value => name}
  ]
  filter << {:name => :HUSNR,  :value => number}   if number
  filter << {:name => :POSTNR, :value => postcode} if postcode
  get_features(filter, options)
end

Protected Class Methods

build_wfs_filter(properties=[]) click to toggle source
# File lib/skra/geo.rb, line 51
    def self.build_wfs_filter(properties=[])
      conditions = properties.map do |condition|
        <<-eos
          <PropertyIsLike wildCard="*" singleChar="#" escapeChar="!">
            <PropertyName>fasteignaskra:#{condition[:name]}</PropertyName>
            <Literal>#{condition[:value]}</Literal>
          </PropertyIsLike>
        eos
      end.join
      conditions = "<And>#{conditions}</And>" if properties.size > 1
      properties.size > 0 ? { :filter => "<Filter>#{conditions}</Filter>" } : {}
    end
get_features(filter, options) click to toggle source
# File lib/skra/geo.rb, line 44
def self.get_features(filter, options)
  query  = defaults.merge(options)
  wfs_filter = build_wfs_filter(filter)
  response = post('/geoserver/wfs', { :query => query.merge(wfs_filter) })
  query[:outputformat] == 'json' ? response["features"] : response
end