Sha256: e29fa26d268c2d513d52702adeeeb887825212a7f42e0ce5235a378247761af2
Contents?: true
Size: 1.35 KB
Versions: 1
Compression:
Stored size: 1.35 KB
Contents
module ActiveRoad class LogicalRoad < ActiveRoad::Base extend ActiveSupport::Memoizable attr_accessible :objectid, :name, :boundary_id has_many :physical_roads, :class_name => "ActiveRoad::PhysicalRoad", :inverse_of => :logical_road has_many :numbers, :through => :physical_roads, :class_name => "ActiveRoad::StreetNumber" belongs_to :boundary, :class_name => "ActiveRoad::Boundary" #validates_uniqueness_of :objectid #validates :boundary, presence: true def geometry GeoRuby::SimpleFeatures::MultiLineString.from_line_strings physical_roads.map(&:geometry) end def at(value) if Float === value geometry_at_location value else geometry_at_number value end end def geometry_at_number(number) numbers.find_or_initialize_by_number(number.to_s).tap do |number| number.road = self end.geometry if number.present? end memoize :geometry_at_number def geometry_at_location(location) geometry.interpolate_point(location) if geometry end def self.find_all_by_bounds(bounds) ne_corner, sw_corner = bounds.upper_corner, bounds.lower_corner sql_box = "SetSRID('BOX3D(#{ne_corner.lng} #{ne_corner.lat}, #{sw_corner.lng} #{sw_corner.lat})'::box3d, #{ActiveRoad.srid})" find :all, :conditions => "geometry && #{sql_box}" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
active_road-0.0.3 | app/models/active_road/logical_road.rb |