Parent

Files

GeoRuby::Shp4r::ShpTransaction

An object returned from ShpFile#transaction. Buffers updates to a Shapefile

Attributes

rollbacked[R]

Public Class Methods

new(shp, dbf) click to toggle source
# File lib/geo_ruby/shp4r/shp.rb, line 343
def initialize(shp, dbf)
  @deleted = Hash.new
  @added = Array.new
  @shp = shp
  @dbf = dbf
end

Public Instance Methods

add(record) click to toggle source

add a ShpRecord at the end

# File lib/geo_ruby/shp4r/shp.rb, line 363
def add(record)
  record_type = to_shp_type(record.geometry)
  raise IncompatibleGeometryException.new("Incompatible type") unless record_type==@shp.shp_type
  @added << record
end
commit() click to toggle source

updates the physical files

# File lib/geo_ruby/shp4r/shp.rb, line 370
def commit
  @shp.close
  @shp_r = open(@shp.file_root + ".shp", "rb")
  @dbf_r = open(@shp.file_root + ".dbf", "rb")
  @shp_io = open(@shp.file_root + ".shp.tmp.shp", "wb")
  @shx_io = open(@shp.file_root + ".shx.tmp.shx", "wb")
  @dbf_io = open(@shp.file_root + ".dbf.tmp.dbf", "wb")
  index = commit_delete
  min_x,max_x,min_y,max_y,min_z,max_z,min_m,max_m = commit_add(index)
  commit_finalize(min_x,max_x,min_y,max_y,min_z,max_z,min_m,max_m)
  @shp_r.close
  @dbf_r.close
  @dbf_io.close
  @shp_io.close
  @shx_io.close
  FileUtils.move(@shp.file_root + ".shp.tmp.shp", @shp.file_root + ".shp")
  FileUtils.move(@shp.file_root + ".shx.tmp.shx", @shp.file_root + ".shx")
  FileUtils.move(@shp.file_root + ".dbf.tmp.dbf", @shp.file_root + ".dbf")
  
  @deleted = Hash.new
  @added = Array.new
  
  @shp.reload!
 end
delete(i) click to toggle source

delete a record. Does not take into account the records added in the current transaction

# File lib/geo_ruby/shp4r/shp.rb, line 351
def delete(i)
  raise UnexistantRecordException.new("Invalid index : #{i}") if @shp.record_count <= i 
  @deleted[i] = true
end
rollback() click to toggle source

prevents the udpate from taking place

# File lib/geo_ruby/shp4r/shp.rb, line 396
def rollback
  @deleted = Hash.new
  @added = Array.new
  @rollbacked = true
end
update(i, record) click to toggle source

Update a record. In effect just a delete followed by an add.

# File lib/geo_ruby/shp4r/shp.rb, line 357
def update(i, record)
  delete(i)
  add(record)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.