Module: TheGeomGeoJSON::ActiveRecord

Defined in:
lib/the_geom_geojson/active_record.rb

Instance Method Summary collapse

Instance Method Details

#the_geomObject



65
66
67
68
69
70
71
# File 'lib/the_geom_geojson/active_record.rb', line 65

def the_geom
  if @the_geom_geojson_dirty
    raise TheGeomGeoJSON::Dirty, "the_geom can't be accessed on #{self.class.name} id #{id.inspect} until it has been saved"
  else
    read_attribute :the_geom
  end
end

#the_geom_geojson(simplify: nil) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/the_geom_geojson/active_record.rb', line 48

def the_geom_geojson(simplify: nil)
  if @the_geom_geojson_dirty
    simplify ? raise("can't get simplified the_geom_geojson until you save") : @the_geom_geojson_change
  elsif !simplify and (preselected = read_attribute(:the_geom_geojson))
    preselected
  elsif the_geom
    self.class.connection_pool.with_connection do |c|
      sql = if simplify
        "SELECT ST_AsGeoJSON(ST_Simplify(the_geom, #{c.quote(simplify)}::float)) FROM #{self.class.quoted_table_name} WHERE #{self.class.quoted_primary_key} = #{c.quote(id)} LIMIT 1"
      else
        "SELECT ST_AsGeoJSON(the_geom) FROM #{self.class.quoted_table_name} WHERE #{self.class.quoted_primary_key} = #{c.quote(id)} LIMIT 1"
      end
      c.select_value sql
    end
  end
end

#the_geom_geojson=(v) ⇒ Object



42
43
44
45
# File 'lib/the_geom_geojson/active_record.rb', line 42

def the_geom_geojson=(v)
  @the_geom_geojson_dirty = true
  @the_geom_geojson_change = v
end

#the_geom_webmercatorObject



73
74
75
76
77
78
79
# File 'lib/the_geom_geojson/active_record.rb', line 73

def the_geom_webmercator
  if @the_geom_geojson_dirty
    raise TheGeomGeoJSON::Dirty, "the_geom_webmercator can't be accessed on #{self.class.name} id #{id.inspect} until it has been saved"
  else
    read_attribute :the_geom_webmercator
  end
end