Wednesday, April 13, 2011

recover delete file from Linux

Refer to this page

$ sudo yum install ext3grep

Create a file called: strangefile.txt

$ rm strangefile.txt

$ sudo ext3grep  /dev/mapper/VolGroup00-LogVol00  --restore-file home/username/strangefile.txt

Tuesday, April 12, 2011

combine bing map

I want to combine bing birdview map to create a bigger map. In Linux, a few commands can help:
djpeg: this will convert the jpg to ppm format.
pnmcat: this will combine the images
cjpeg: this will convert the ppm back to jpg.

Also, the bing images in such a format:
http://ecn.t2.tiles.virtualearth.net/tiles/cmd/ObliqueHybrid?a=03022313120-1715-20-120&g=671
Each row has 16 small tiles.

The code looks like this:
#!/usr/bin/perl

#965    1715      1989
#    2590 703
my $url="http://ecn.t2.tiles.virtualearth.net/tiles/cmd/ObliqueHybrid?a=03022313120-";
my $colnum=16;
my $startcut=$colnum;
my $curtilenum=1715;
my $rownum=(191-$startcut)/$colnum-1;
#my @tilenum=(965, 1715, 1989, 2590, 703);
my @tilenum=(1715);

sub callCmd($)
{
    my ($cmd) = @_;
    open(CMD, "$cmd 2>&1 |") or die "Couldn't open CMD file to execute command";
    my $commandOutput= <CMD>;
    close(CMD);
}

sub combineTile($)
{
    my ($curtilenum) = @_;
    my $combinexfile="";
    my $combineyfile="";
    for ($row=0;$row<$rownum;$row++)
    {
       for ($col=0; $col<$colnum; $col++)
       {
         my $x=$col;
         my $y=$row;
         my $num=$startcut+$x+$y*$colnum;
         my $cmd="curl \"$url$curtilenum-20-$num&g=671\" -o tmp/t.$x.$y.jpg";
         print $cmd . "\n";
         system($cmd);
         #Convert JPEGs into PPM bitmaps
         callCmd("djpeg tmp/t.$x.$y.jpg > tmp/$x.$y.ppm");
         $combinexfile = $combinexfile . "tmp/$x.$y.ppm ";
       }
       #combine the cols
       callCmd("pnmcat -leftright $combinexfile > tmp/row.$row.ppm");
       $combinexfile="";
       $combineyfile = $combineyfile . "tmp/row.$row.ppm ";
     }
     callCmd("pnmcat -topbottom $combineyfile > tmp/final.ppm");
     callCmd("cjpeg -quality 100 tmp/final.ppm > final$curtilenum.jpg");
     callCmd("rm tmp/*.ppm tmp/*.jpg");
}



foreach $tile (@tilenum){
    combineTile($tile);
}