Class: Feature

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/spatial_features/models/feature.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for_kml(options = {}) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/spatial_features/models/feature.rb', line 24

def self.for_kml(options = {})
  if options[:simplified]
    select("features.name, features.kml, features.metadata").where("features.name IS NULL OR features.name NOT IN ('s', 't')")
  else
    select("features.name, ST_AsKML(features.geog, 6) AS kml, features.metadata")
  end
end

.invalidObject



32
33
34
# File 'lib/spatial_features/models/feature.rb', line 32

def self.invalid
  select('features.*, ST_IsValidReason(geog::geometry) AS invalid_geometry_message').where.not('ST_IsValid(geog::geometry)')
end

.linesObject



16
17
18
# File 'lib/spatial_features/models/feature.rb', line 16

def self.lines
  where(:feature_type => 'line')
end

.pointsObject



20
21
22
# File 'lib/spatial_features/models/feature.rb', line 20

def self.points
  where(:feature_type => 'point')
end

.polygonsObject



12
13
14
# File 'lib/spatial_features/models/feature.rb', line 12

def self.polygons
  where(:feature_type => 'polygon')
end

Instance Method Details

#envelope(buffer_in_meters = 0) ⇒ Object



36
37
38
# File 'lib/spatial_features/models/feature.rb', line 36

def envelope(buffer_in_meters = 0)
  self.class.select("ST_Envelope(ST_Buffer(features.geog, #{buffer_in_meters})::geometry) AS result").where(:id => id).first.result.exterior_ring.points.values_at(0,2)
end