Class: Geokit::Adapters::SQLServer

Inherits:
Abstract
  • Object
show all
Defined in:
lib/geokit-rails/adapters/sqlserver.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Abstract

#method_missing

Constructor Details

#initialize(*args) ⇒ SQLServer

Returns a new instance of SQLServer.



22
23
24
# File 'lib/geokit-rails/adapters/sqlserver.rb', line 22

def initialize(*args)
  super(*args)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Geokit::Adapters::Abstract

Class Method Details

.load(klass) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/geokit-rails/adapters/sqlserver.rb', line 7

def load(klass)
  klass.connection.execute <<-EOS
    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[geokit_least]') and xtype in (N'FN', N'IF', N'TF'))
    drop function [dbo].[geokit_least]
  EOS

  klass.connection.execute <<-EOS
    CREATE FUNCTION [dbo].geokit_least (@value1 float,@value2 float) RETURNS float AS BEGIN
    return (SELECT CASE WHEN @value1 < @value2 THEN  @value1 ELSE @value2 END) END
  EOS
  self.loaded = true
end

Instance Method Details

#flat_distance_sql(origin, lat_degree_units, lng_degree_units) ⇒ Object



34
35
36
37
38
39
# File 'lib/geokit-rails/adapters/sqlserver.rb', line 34

def flat_distance_sql(origin, lat_degree_units, lng_degree_units)
  %|
    SQRT(POWER(#{lat_degree_units}*(#{origin.lat}-#{qualified_lat_column_name}),2)+
    POWER(#{lng_degree_units}*(#{origin.lng}-#{qualified_lng_column_name}),2))
   |
end

#sphere_distance_sql(lat, lng, multiplier) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/geokit-rails/adapters/sqlserver.rb', line 26

def sphere_distance_sql(lat, lng, multiplier)
  %|
    (ACOS([dbo].geokit_least(1,COS(#{lat})*COS(#{lng})*COS(RADIANS(#{qualified_lat_column_name}))*COS(RADIANS(#{qualified_lng_column_name}))+
    COS(#{lat})*SIN(#{lng})*COS(RADIANS(#{qualified_lat_column_name}))*SIN(RADIANS(#{qualified_lng_column_name}))+
    SIN(#{lat})*SIN(RADIANS(#{qualified_lat_column_name}))))*#{multiplier})
   |
end