Class: ActiveRoad::PhysicalRoad

Inherits:
Base
  • Object
show all
Extended by:
ActiveModel::Naming, Enumerize
Defined in:
app/models/active_road/physical_road.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.nearest_to(location, distance = 0.001) ⇒ Object

distance in srid format 0.001 ~= 111.3 m à l’équateur TODO : Must convert distance in meters => distance in srid



53
54
55
56
57
# File 'app/models/active_road/physical_road.rb', line 53

def self.nearest_to(location, distance = 0.001)
  # FIX Limit to 1 physical roads for perf, must be extended
  pr = all_dwithin(location, distance)
  pr == [] ? [] : [pr.first]
end

Instance Method Details

#difference(other) ⇒ Object



47
48
49
# File 'app/models/active_road/physical_road.rb', line 47

def difference(other)
  postgis_calculate(:difference, [self, other])
end

#intersection(other) ⇒ Object



43
44
45
# File 'app/models/active_road/physical_road.rb', line 43

def intersection(other)
  postgis_calculate(:intersection, [self, other])
end

#street_nameObject



39
40
41
# File 'app/models/active_road/physical_road.rb', line 39

def street_name
  logical_road.try(:name) or objectid
end

#update_length_in_meterObject



31
32
33
34
35
36
37
# File 'app/models/active_road/physical_road.rb', line 31

def update_length_in_meter
  if geometry.present?
    spherical_factory = ::RGeo::Geographic.spherical_factory  
    self.length_in_meter = spherical_factory.line_string(geometry.points.collect(&:to_rgeo)).length
    #self.length_in_meter = length
  end
end