app/models/map.rb
#attempts to align based on the extent and offset of the
#reference map's warped image
#results it nicer gpcs to edit with later
attempts to align based on the extent and offset of the
reference map's warped image
results it nicer gpcs to edit with later
attempts to align based on the extent and offset of the reference map ' s warped image results it nicer gpcs to edit with later
def align_with_warped (srcmap, align = nil, append = false)
      srcmap = Map.find(srcmap)
      origgcps = srcmap.gcps.hard
      self.gcps.hard.destroy_all unless append == true
      stdin, stdout, sterr = Open3::popen3("#{GDAL_PATH}gdalinfo #{srcmap.warped_filename}")
      info = stdout.readlines.to_s
      stringLW,west,south = info.match(/Lower Left\s+\(\s*([-.\d]+), \s+([-.\d]+)/).to_a
      stringUR,east,north = info.match(/Upper Right\s+\(\s*([-.\d]+), \s+([-.\d]+)/).to_a
      lon_shift = west.to_f - east.to_f
      lat_shift = south.to_f - north.to_f
      origgcps.each do |gcp|
         a = Gcp.new()
         a = gcp.clone
         if align == "east"
            a.lon -= lon_shift
         elsif align == "west"
            a.lon += lon_shift
         elsif align == "north"
            a.lat -= lat_shift
         elsif align == "south"
            a.lat += lat_shift
         else
         end
         a.map = self
         a.save
      end
      newgcps = self.gcps.hard
   end
def align_with_warped ( srcmap , align = nil , append = false ) srcmap = Map . find ( srcmap ) origgcps = srcmap . gcps . hard self . gcps . hard . destroy_all unless append == true stdin , stdout , sterr = Open3 :: popen3 ( "#{GDAL_PATH}gdalinfo #{srcmap.warped_filename}" ) info = stdout . readlines . to_s stringLW , west , south = info . match ( / Lower Left \s + \( \s *([-. \d ]+),  \s +([-. \d ]+) / ) . to_a stringUR , east , north = info . match ( / Upper Right \s + \( \s *([-. \d ]+),  \s +([-. \d ]+) / ) . to_a lon_shift = west . to_f - east . to_f lat_shift = south . to_f - north . to_f origgcps . each do | gcp | a = Gcp . new ( ) a = gcp . clone if align == "east" a . lon -= lon_shift elsif align == "west" a . lon += lon_shift elsif align == "north" a . lat -= lat_shift elsif align == "south" a . lat += lat_shift else end a . map = self a . save end newgcps = self . gcps . hard end
attempts to align based on the extent and offset of the
reference map's warped image
results it nicer gpcs to edit with later
attempts to align based on the extent and offset of the reference map ' s warped image results it nicer gpcs to edit with later
#clear out original gcps, unless we want to append the copied gcps to the existing ones #extent of source from gdalinfo #if no align, then dont change the gcps
srcmap
<not_specific>
align
<not_specific>
append
<not_specific>