Output:#!/usr/bin/env perl use strict; use warnings; use Data::Table; use Math::Round; my $tol = 50; # Tolerance, i.e. round values to the neared multiple of + $tol my $t1 = Data::Table::fromCSV("data1.txt", 1, undef); # Delete lat & lon columns are replace with rounded values my $gps_lat_col = $t1->delCol("GPSlat"); my $gps_lon_col = $t1->delCol("GPSlon"); my @nGPSlat = map{ nearest($tol, $_) } @{$gps_lat_col}; my @nGPSlon = map{ nearest($tol, $_) } @{$gps_lon_col}; $t1->addCol(\@nGPSlat, "GPSlat"); $t1->addCol(\@nGPSlon, "GPSlon"); print "\nTable 1\n"; print $t1->csv; my $t2 = Data::Table::fromCSV("data2.txt", 1, undef); #, { delimiter = +> " " }); # Delete lat & lon columns are replace with rounded values my $lat_col = $t2->delCol("Lat"); # Delete column 'age'. my $lon_col = $t2->delCol("Lon"); # Delete column 'age'. my @nlat = map{ nearest($tol, $_) } @{$lat_col}; my @nlon = map{ nearest($tol, $_) } @{$lon_col}; $t2->addCol(\@nlat, "Lat"); $t2->addCol(\@nlon, "Lon"); print "\nTable 2\n"; print $t2->csv; # Join the tables for cases where the rounded lat/lon pairs are exact +matches my $t3 = $t1->join($t2, Data::Table::INNER_JOIN, [ 'GPSlat', 'GPSlon' +], ['Lat', 'Lon']); print "\nJoined Table\n"; print $t3->csv; exit;
Table 1 Seq#,TransType,LocnNum,TankNum,Date,TimeStart,TimeEnd,TktVol,AltVol,To +talSrt,TotalEnd,Driver,Trip,Route,MeanDegC,MaxDegC,ColCd,Ccode,TestTy +pe,TrpSdate,GPSlat,GPSlon 174,0,291061000,59,141130,104945,105755,3355,0,255094551,255094551,500 +5,2,505,3.0,3.5,00,00,00,141130,5140600,645550 175,0,250401500,133,141130,110343,110858,760,0,255102140,255102140,500 +5,2,505,3.0,3.2,00,00,00,141130,5141450,647450 176,0,250400800,29,141130,115529,120130,1695,0,255119079,255119079,500 +5,2,505,3.7,4.2,00,00,00,141130,5147650,656150 Table 2 LocnID,TestCo#,LastVol,LocnName,LocnAdr,Lat,Lon 291061000,205,3568,Evans Marcross,,5140600,645550 250401500,205,857,Thomas And Ptns Somerset,,5141450,647450 250400800,205,1727,Thomas J Newton House,,5147650,656150 Joined Table Seq#,TransType,LocnNum,TankNum,Date,TimeStart,TimeEnd,TktVol,AltVol,To +talSrt,TotalEnd,Driver,Trip,Route,MeanDegC,MaxDegC,ColCd,Ccode,TestTy +pe,TrpSdate,GPSlat,GPSlon,LocnID,TestCo#,LastVol,LocnName,LocnAdr 176,0,250400800,29,141130,115529,120130,1695,0,255119079,255119079,500 +5,2,505,3.7,4.2,00,00,00,141130,5147650,656150,250400800,205,1727,Tho +mas J Newton House, 175,0,250401500,133,141130,110343,110858,760,0,255102140,255102140,500 +5,2,505,3.0,3.2,00,00,00,141130,5141450,647450,250401500,205,857,Thom +as And Ptns Somerset, 174,0,291061000,59,141130,104945,105755,3355,0,255094551,255094551,500 +5,2,505,3.0,3.5,00,00,00,141130,5140600,645550,291061000,205,3568,Eva +ns Marcross,
In reply to Re: CSV Cross Referencing
by kevbot
in thread CSV Cross Referencing
by Jalcock501
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |