Class: Chouette::AccessPoint

Inherits:
TridentActiveRecord show all
Includes:
Geokit::Mappable
Defined in:
app/models/chouette/access_point.rb

Constant Summary collapse

@@access_point_types =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TridentActiveRecord

#build_objectid, #clean_object_id, #default_values, #fix_uniq_objectid, model_name, object_id_key, #objectid, #objectid_format_compliance, #prefix, #prepare_auto_columns, #reset_auto_columns, #timestamp_attributes_for_create, #timestamp_attributes_for_update, #uniq_objectid

Methods inherited from ActiveRecord

#human_attribute_name, #nil_if_blank

Instance Attribute Details

#access_point_typeObject

Returns the value of attribute access_point_type.



11
12
13
# File 'app/models/chouette/access_point.rb', line 11

def access_point_type
  @access_point_type
end

#coordinatesObject



46
47
48
# File 'app/models/chouette/access_point.rb', line 46

def coordinates
    @coordinates || combine_lat_lng
end

Class Method Details

.access_point_typesObject



101
102
103
104
105
# File 'app/models/chouette/access_point.rb', line 101

def self.access_point_types
  @@access_point_types ||= Chouette::AccessPointType.all.select do |access_point_type|
    access_point_type.to_i >= 0
  end
end

.nullable_attributesObject



32
33
34
# File 'app/models/chouette/access_point.rb', line 32

def self.nullable_attributes
  [:street_name, :country_code, :comment, :long_lat_type, :zip_code, :city_name]
end

Instance Method Details

#combine_lat_lngObject



38
39
40
41
42
43
44
# File 'app/models/chouette/access_point.rb', line 38

def combine_lat_lng
  if self.latitude.nil? || self.longitude.nil?
    ""
  else
    self.latitude.to_s+","+self.longitude.to_s 
  end
end

#coordinates_to_lat_lngObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/chouette/access_point.rb', line 50

def coordinates_to_lat_lng
  if ! @coordinates.nil?
    if @coordinates.empty?
      self.latitude = nil
      self.longitude = nil
    else
      self.latitude = BigDecimal.new(@coordinates.split(",").first)
      self.longitude = BigDecimal.new(@coordinates.split(",").last)
    end
    @coordinates = nil 
  end
end

#default_positionObject



87
88
89
# File 'app/models/chouette/access_point.rb', line 87

def default_position 
  stop_area.geometry or stop_area.default_position
end


136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'app/models/chouette/access_point.rb', line 136

def detail_access_link_matrix
   matrix = Array.new
   hash = Hash.new
   access_links.each do |link|
      hash[link.link_key] = link
   end
   stop_area.children_at_base.each do |child|
     key=Chouette::AccessLink.build_link_key(self,child,"access_point_to_stop_area")
     if hash.has_key?(key)
       matrix << hash[key]
     else
       link = Chouette::AccessLink.new
       link.access_point = self
       link.stop_area = child
       link.link_orientation_type = "access_point_to_stop_area"
       matrix << link
     end
     key=Chouette::AccessLink.build_link_key(self,child,"stop_area_to_access_point")
     if hash.has_key?(key)
       matrix << hash[key]
     else
       link = Chouette::AccessLink.new
       link.access_point = self
       link.stop_area = child
       link.link_orientation_type = "stop_area_to_access_point"
       matrix << link
     end
   end
   matrix
end


107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'app/models/chouette/access_point.rb', line 107

def generic_access_link_matrix
   matrix = Array.new
   hash = Hash.new
   access_links.each do |link|
      hash[link.link_key] = link
   end
   key=Chouette::AccessLink.build_link_key(self,stop_area,"access_point_to_stop_area")
   if hash.has_key?(key)
     matrix << hash[key]
   else
     link = Chouette::AccessLink.new
     link.access_point = self
     link.stop_area = stop_area
     link.link_orientation_type = "access_point_to_stop_area"
     matrix << link
   end
   key=Chouette::AccessLink.build_link_key(self,stop_area,"stop_area_to_access_point")
   if hash.has_key?(key)
     matrix << hash[key]
   else
     link = Chouette::AccessLink.new
     link.access_point = self
     link.stop_area = stop_area
     link.link_orientation_type = "stop_area_to_access_point"
     matrix << link
   end
   matrix
end

#geometryObject



67
68
69
# File 'app/models/chouette/access_point.rb', line 67

def geometry
  GeoRuby::SimpleFeatures::Point.from_lon_lat(longitude, latitude, 4326) if latitude and longitude
end

#geometry=(geometry) ⇒ Object



71
72
73
74
# File 'app/models/chouette/access_point.rb', line 71

def geometry=(geometry)
  geometry = geometry.to_wgs84
  self.latitude, self.longitude, self.long_lat_type = geometry.lat, geometry.lng, "WGS84"
end

#geometry_presenterObject



167
168
169
# File 'app/models/chouette/access_point.rb', line 167

def geometry_presenter
  Chouette::Geometry::AccessPointPresenter.new self
end

#positionObject



76
77
78
# File 'app/models/chouette/access_point.rb', line 76

def position 
  geometry
end

#position=(position) ⇒ Object



80
81
82
83
84
85
# File 'app/models/chouette/access_point.rb', line 80

def position=(position)
  position = nil if String === position && position == ""
  position = Geokit::LatLng.normalize(position), 4326 if String === position
  self.latitude = position.lat
  self.longitude = position.lng
end

#to_lat_lngObject



63
64
65
# File 'app/models/chouette/access_point.rb', line 63

def to_lat_lng
  Geokit::LatLng.new(latitude, longitude) if latitude and longitude
end