//=========================================================================== // GPS TRACK NEW // // After you download your Garmin GPS 12 track data and save it // as a CartaLinx file, you must reformat that file using only // a blank space as the record separator and then preface // it with the number of records it contains. Then you may open // it in this application and visualize the track color coded to // represent the passage of time. The program has been adjusted // to accommodate a number of different data files. //=========================================================================== #include #pragma hdrstop #include "Unit1.h" #include #include //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- //----------------------------------------------------------------- VARIABLES float lon[10000], lat[10000]; float maxLon = -360; float minLon = 0; float maxLat = 0; float minLat = 90; float dummy; int d[10000], h[10000], m[10000], s[10000]; int seconds[10000]; int record; int scale = 15000; int maxSec = 0; int minSec = 100000000; int timeRange; int secondsSinceStart; int records = 0; //---------------------------------------------------------------- INITIALIZE void initialize (void) { maxLon = -360; minLon = 0; maxLat = 0; minLat = 90; maxSec = 0; minSec = 100000000; records = 0; } //------------------------------------------------------- COLOR RAMP FUNCTION int colorRamp (int range, int value) { if (range==0) range=1; int pixelDistanceAlongPath = (value*1792)/range; int red, green, blue; if (pixelDistanceAlongPath < 256) { red=0; green=0; blue=pixelDistanceAlongPath; } else if (pixelDistanceAlongPath < 512) { red=0; green=pixelDistanceAlongPath-256; blue=255; } else if (pixelDistanceAlongPath < 768) { red=0; green=255; blue=255-(pixelDistanceAlongPath-512); } else if (pixelDistanceAlongPath < 1024) { red=(pixelDistanceAlongPath-768); green=255; blue=0; } else if (pixelDistanceAlongPath < 1280) { red= 255; green= 255-(pixelDistanceAlongPath-1024); blue=0; } else if (pixelDistanceAlongPath < 1536) { red=255; green=0; blue=pixelDistanceAlongPath-1280; } else { red=255; green=pixelDistanceAlongPath-1536; blue=255; } return (RGB(red,green,blue)); } //-------------------------------------------------------- OPEN FILE FUNCTION void openFile (void) { initialize(); if (Form1->OpenDialog->Execute()) { ifstream infile(Form1->OpenDialog->FileName.c_str()); infile >> records; for (record = 0; record < records; record++) { infile >> lon[record]; infile >> lat[record]; infile >> dummy; infile >> dummy; infile >> d[record]; infile >> h[record]; infile >> m[record]; infile >> s[record]; infile >> dummy; maxLat = max(maxLat, lat[record]); minLat = min(minLat, lat[record]); maxLon = max(maxLon, lon[record]); minLon = min(minLon, lon[record]); seconds[record] = d[record]*86400 + h[record]*3600 + m[record]*60 + s[record]; maxSec = max(maxSec, seconds[record]); minSec = min(minSec, seconds[record]); } } } //----------------------------------------------------------- RENDER FUNCTION void render (void) { Form1->Refresh(); Application->ProcessMessages(); int x, y; timeRange = maxSec - minSec; Form1->Canvas->Pen->Width=5; Form1->Canvas->MoveTo ((lon[0]-minLon)*scale+25, (maxLat-minLat)*scale-((lat[0]-minLat)*scale)+65); for (int i=0; iCanvas->Pen->Color=static_cast (colorRamp(timeRange, secondsSinceStart)); Form1->Canvas->LineTo(x, y); } } //---------------------------------------------------------- OPEN FILE BUTTON void __fastcall TForm1::ButtonOpenClick(TObject *Sender) { openFile(); } //------------------------------------------------------------- RENDER BUTTON void __fastcall TForm1::ButtonRenderClick(TObject *Sender) { Refresh(); render(); } //-------------------------------------------------------------- CLEAR BUTTON void __fastcall TForm1::ButtonClearClick(TObject *Sender) { Refresh(); } //---------------------------------------------------------------- THAT'S ALL void __fastcall TForm1::TrackBarScaleChange(TObject *Sender) { scale = TrackBarScale->Position; render(); } //---------------------------------------------------------------------------