Skip to content

Commit 8f210d9

Browse files
committed
Initialise epoch for static datums
1 parent 7339512 commit 8f210d9

File tree

3 files changed

+124
-54
lines changed

3 files changed

+124
-54
lines changed

dynadjust/dynadjust/dnaimport/dnainterop.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,14 +495,15 @@ void dna_import::ParseXML(const std::string& fileName, vdnaStnPtr* vStations, PU
495495
// is specified in DynaML.xsd, this value will never be empty, unless the user
496496
// has inadvertently set in the xml file, e.g.:
497497
// <DnaXmlFormat epoch="" ... >
498-
if (fileEpoch.empty())
498+
// Or, is the file reference frame a static datum?
499+
if (fileEpoch.empty() || isEpsgDatumStatic(LongFromString<UINT32>(fileEpsg)))
499500
{
500501
// Get the epoch of the nominated epsg (whether default or from the file)
501502
fileEpoch = referenceepochFromEpsgString<std::string>(fileEpsg);
502503
}
503504

504505
// Has the user supplied a reference frame on the command line (--reference-frame)?
505-
if (projectSettings_.i.override_input_rfame)
506+
if (projectSettings_.i.user_supplied_frame)
506507
{
507508
// A frame has been supplied. Now check for epoch.
508509

@@ -1086,6 +1087,19 @@ void dna_import::ParseDNA(const std::string& fileName, vdnaStnPtr* vStations, PU
10861087
throw XMLInteropException(e.what(), 0);
10871088
}
10881089

1090+
// Set to defaults if reference frame and epoch fields are empty
1091+
if (fileEpsg.empty())
1092+
fileEpsg = datum_.GetEpsgCode_s();
1093+
if (fileEpoch.empty())
1094+
fileEpoch = datum_.GetEpoch_s();
1095+
1096+
// Is the file reference frame a static datum?
1097+
if (isEpsgDatumStatic(LongFromString<UINT32>(fileEpsg)))
1098+
{
1099+
// Get the reference epoch of the nominated epsg
1100+
fileEpoch = referenceepochFromEpsgString<std::string>(fileEpsg);
1101+
}
1102+
10891103
// Has the user supplied a reference frame on the command line (--reference-frame)?
10901104
if (projectSettings_.i.user_supplied_frame)
10911105
{

dynadjust/dynadjust/dnaimportwrapper/dnaimportwrapper.cpp

Lines changed: 98 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ int ParseCommandLineOptions(const int& argc, char* argv[], const boost::program_
240240
else if (p.i.epoch.rfind(".") == std::string::npos)
241241
p.i.epoch.insert(0, "01.01.");
242242
p.i.user_supplied_epoch = 1;
243-
}
243+
}
244244

245245
//////////////////////////////////////////////////////////////////////////////
246246
// Data screening options
@@ -984,9 +984,11 @@ int ImportDataFiles(dna_import& parserDynaML, vdnaStnPtr* vStations, vdnaMsrPtr*
984984
// Capture the input file's default reference frame and set the
985985
// project reference frame (if not specified on the command-line)
986986
std::string inputFileEpsg(""), inputFileDatum(""), inputFileEpoch("");
987+
UINT32 inputFileEpsgi;
987988
try {
988989
inputFileDatum = datumFromEpsgString<std::string>(input_file_meta.epsgCode);
989990
inputFileEpsg = input_file_meta.epsgCode;
991+
inputFileEpsgi = LongFromString<UINT32>(inputFileEpsg);
990992
inputFileEpoch = input_file_meta.epoch;
991993
}
992994
catch (...)
@@ -998,7 +1000,7 @@ int ImportDataFiles(dna_import& parserDynaML, vdnaStnPtr* vStations, vdnaMsrPtr*
9981000

9991001
// Is this the first file? If so, attempt to set the default datum from
10001002
// the input file (if applicable).
1001-
UINT32 inputFileEpsgi;
1003+
10021004
bool referenceframeChanged(false);
10031005

10041006
if (firstFile)
@@ -1012,29 +1014,38 @@ int ImportDataFiles(dna_import& parserDynaML, vdnaStnPtr* vStations, vdnaMsrPtr*
10121014
{
10131015
// Set the project defaults
10141016
referenceframeChanged = true;
1015-
inputFileEpsgi = LongFromString<UINT32>(inputFileEpsg);
1017+
10161018
p.i.reference_frame = inputFileDatum;
10171019
p.r.reference_frame = inputFileDatum;
10181020
}
10191021

1020-
if (!p.i.user_supplied_epoch)
1022+
// Force reference epoch if reference frame is static
1023+
if (isEpsgDatumStatic(inputFileEpsgi))
10211024
{
1022-
if (inputFileEpoch.empty())
1025+
p.i.epoch = referenceepochFromEpsgCode<UINT32>(inputFileEpsgi);
1026+
p.r.epoch = p.i.epoch;
1027+
}
1028+
else
1029+
{
1030+
if (!p.i.user_supplied_epoch)
10231031
{
1024-
// Has an epoch been provided but no frame?
1025-
if (inputFileEpsg.empty())
1026-
// revert to epoch of
1027-
p.i.epoch = referenceepochFromEpsgCode<UINT32>(inputFileEpsgi);
1032+
if (inputFileEpoch.empty())
1033+
{
1034+
// Has an epoch been provided but no frame?
1035+
if (inputFileEpsg.empty())
1036+
// revert to epoch of
1037+
p.i.epoch = referenceepochFromEpsgCode<UINT32>(inputFileEpsgi);
1038+
else
1039+
p.i.epoch = referenceepochFromEpsgString<std::string>(projctEpsgCode);
1040+
p.r.epoch = p.i.epoch;
1041+
}
10281042
else
1029-
p.i.epoch = referenceepochFromEpsgString<std::string>(projctEpsgCode);
1030-
p.r.epoch = p.i.epoch;
1031-
}
1032-
else
1033-
{
1034-
p.i.epoch = inputFileEpoch;
1035-
p.r.epoch = p.i.epoch;
1043+
{
1044+
p.i.epoch = inputFileEpoch;
1045+
p.r.epoch = p.i.epoch;
1046+
}
10361047
}
1037-
}
1048+
}
10381049

10391050
try {
10401051
// Initialise the 'default' datum (frame and epoch) for the project, from the first file, unless the
@@ -1403,6 +1414,53 @@ int main(int argc, char* argv[])
14031414
vstationsTotal.clear();
14041415
vmeasurementsTotal.clear();
14051416

1417+
dna_import parserDynaML;
1418+
1419+
////////////////////////////////////////////////////////////////////////////////////
1420+
// First things first!
1421+
// Set the 'default' reference frame for the binary station and measurement files
1422+
// At this point, the frame may be the hard-coded default, or a user-specified
1423+
// frame via: -r [--reference-frame] arg
1424+
// See comments in InitialiseDatum()
1425+
try {
1426+
// Initialise the 'default' datum for the project.
1427+
parserDynaML.InitialiseDatum(p.i.reference_frame, p.i.epoch);
1428+
}
1429+
catch (const XMLInteropException& e) {
1430+
1431+
std::cout << std::endl << cmd_line_banner;
1432+
1433+
std::stringstream ss;
1434+
ss << "- Error: ";
1435+
std::cout << ss.str() << e.what() << std::endl;
1436+
return EXIT_FAILURE;
1437+
}
1438+
1439+
// obtain the project reference frame
1440+
UINT32 epsgCode(epsgCodeFromName<UINT32>(p.i.reference_frame));
1441+
1442+
// set the default output reference frame and epoch, so that
1443+
// if adjust is called without reftran, it reflects the datum
1444+
// supplied on import
1445+
p.r.reference_frame = p.i.reference_frame;
1446+
1447+
// if the reference frame supplied is static, then force the epoch
1448+
// to be the reference epoch
1449+
if (isEpsgDatumStatic(epsgCode))
1450+
{
1451+
p.i.epoch = referenceepochFromEpsgCode<UINT32>(epsgCode);
1452+
p.r.epoch = p.i.epoch;
1453+
}
1454+
else
1455+
{
1456+
if (p.i.user_supplied_epoch)
1457+
p.r.epoch = p.i.epoch;
1458+
else
1459+
p.r.epoch = referenceepochFromEpsgCode<UINT32>(epsgCode);
1460+
}
1461+
1462+
////////////////////////////////////////////////////////////////////////////////////
1463+
14061464
if (vm.count(QUIET))
14071465
p.g.quiet = 1;
14081466

@@ -1430,10 +1488,15 @@ int main(int argc, char* argv[])
14301488
if (p.i.override_input_rfame)
14311489
std::cout << std::setw(PRINT_VAR_PAD) << std::left << " Override input file ref frame:" << yesno_string(p.i.override_input_rfame) << std::endl;
14321490

1433-
if (p.i.user_supplied_epoch)
1434-
std::cout << std::setw(PRINT_VAR_PAD) << std::left << " Project epoch:" << p.i.epoch << " (user supplied)" << std::endl;
1491+
if (isEpsgDatumStatic(epsgCode) && p.i.user_supplied_frame)
1492+
std::cout << std::setw(PRINT_VAR_PAD) << std::left << " Project epoch:" << p.i.epoch << " (adopted reference epoch of " << p.i.reference_frame << ")" << std::endl;
14351493
else
1436-
std::cout << std::setw(PRINT_VAR_PAD) << std::left << " Project epoch:" << "To be assumed from the first input file" << std::endl;
1494+
{
1495+
if (p.i.user_supplied_epoch)
1496+
std::cout << std::setw(PRINT_VAR_PAD) << std::left << " Project epoch:" << p.i.epoch << " (user supplied)" << std::endl;
1497+
else
1498+
std::cout << std::setw(PRINT_VAR_PAD) << std::left << " Project epoch:" << "To be assumed from the first input file" << std::endl;
1499+
}
14371500

14381501
if (p.i.export_dynaml)
14391502
{
@@ -1494,42 +1557,13 @@ int main(int argc, char* argv[])
14941557

14951558
PrintOutputFileHeaderInfo(&imp_file, p.i.imp_file, &p, "DYNADJUST IMPORT LOG FILE");
14961559

1497-
dna_import parserDynaML;
14981560
MsrTally parsemsrTally;
14991561
StnTally parsestnTally;
15001562

15011563
CDnaProjection projection(UTM);
15021564

15031565
vifm_t vinput_file_meta;
15041566

1505-
// First things first!
1506-
// Set the 'default' reference frame for the binary station and measurement files
1507-
// At this point, the frame may be the hard-coded default, or a user-specified
1508-
// frame via: -r [--reference-frame] arg
1509-
// See comments in InitialiseDatum()
1510-
try {
1511-
// Initialise the 'default' datum for the project.
1512-
parserDynaML.InitialiseDatum(p.i.reference_frame, p.i.epoch);
1513-
}
1514-
catch (const XMLInteropException& e) {
1515-
std::stringstream ss;
1516-
ss << "- Error: ";
1517-
std::cout << ss.str() << e.what() << std::endl;
1518-
return EXIT_FAILURE;
1519-
}
1520-
1521-
// obtain the project reference frame
1522-
UINT32 epsgCode(epsgCodeFromName<UINT32>(p.i.reference_frame));
1523-
1524-
// set the default output reference frame and epoch, so that
1525-
// if adjust is called without reftran, it reflects the datum
1526-
// supplied on import
1527-
p.r.reference_frame = p.i.reference_frame;
1528-
if (p.i.user_supplied_epoch)
1529-
p.r.epoch = p.i.epoch;
1530-
else
1531-
p.r.epoch = referenceepochFromEpsgCode<UINT32>(epsgCode);
1532-
15331567
///////////////////////////////////////////////////////////////////////////////////////////////////////////
15341568
// start "total" time
15351569
boost::timer::cpu_timer time;
@@ -1619,7 +1653,9 @@ int main(int argc, char* argv[])
16191653
if (ImportDataFiles(parserDynaML, &vStations, &vMeasurements, &vstationsTotal, &vmeasurementsTotal,
16201654
&imp_file, &vinput_file_meta, &parsestnTally, &parsemsrTally, errorCount, p) != EXIT_SUCCESS)
16211655
return EXIT_FAILURE;
1622-
}
1656+
}
1657+
1658+
epsgCode = epsgCodeFromName<UINT32>(p.i.reference_frame);
16231659

16241660
if (!p.g.quiet)
16251661
std::cout << std::endl;
@@ -1894,6 +1930,7 @@ int main(int argc, char* argv[])
18941930

18951931
if (!p.i.user_supplied_frame && !p.i.import_block && !p.i.import_network)
18961932
{
1933+
// reference frame
18971934
std::stringstream datumSource;
18981935
switch (vinput_file_meta.at(0).filetype)
18991936
{
@@ -1907,6 +1944,17 @@ int main(int argc, char* argv[])
19071944
if (!p.g.quiet)
19081945
std::cout << std::setw(PRINT_VAR_PAD) << std::left << "+ Project reference frame:" << p.i.reference_frame << datumSource.str() << std::endl;
19091946
imp_file << std::setw(PRINT_VAR_PAD) << std::left << "+ Project reference frame:" << p.i.reference_frame << datumSource.str() << std::endl;
1947+
1948+
// epoch
1949+
std::stringstream epochSource;
1950+
if (isEpsgDatumStatic(epsgCode))
1951+
epochSource << ". Adopted static reference epoch (" << p.i.reference_frame << ")";
1952+
else
1953+
epochSource << ". Taken from first file (" << FormatFileType<std::string>(vinput_file_meta.at(0).filetype) << ")";
1954+
1955+
if (!p.g.quiet)
1956+
std::cout << std::setw(PRINT_VAR_PAD) << std::left << "+ Project epoch:" << p.i.epoch << epochSource.str() << std::endl;
1957+
imp_file << std::setw(PRINT_VAR_PAD) << std::left << "+ Project epoch:" << p.i.epoch << epochSource.str() << std::endl;
19101958
}
19111959

19121960
if (!p.g.quiet)

dynadjust/dynadjust/dnareftranwrapper/dnareftranwrapper.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,14 +444,20 @@ int main(int argc, char* argv[])
444444
epsgCode = epsgCodeFromName<UINT32>(p.r.reference_frame);
445445
}
446446
catch (const std::runtime_error& e) {
447+
std::cout << std::endl << cmd_line_banner;
448+
447449
std::cout << "- Error: " << e.what() << std::endl;
448450
return EXIT_FAILURE;
449451
}
450452

451-
452453
if (ParseCommandLineOptions(argc, argv, vm, p, epsgCode) != EXIT_SUCCESS)
453454
return EXIT_FAILURE;
454455

456+
// if the reference frame supplied is static, then force the epoch
457+
// to be the reference epoch
458+
if (isEpsgDatumStatic(epsgCode))
459+
p.r.epoch = referenceepochFromEpsgCode<UINT32>(epsgCode);
460+
455461
std::ofstream rft_file;
456462
try {
457463
// Create import log file. Throws runtime_error on failure.
@@ -464,6 +470,8 @@ int main(int argc, char* argv[])
464470
return EXIT_FAILURE;
465471
}
466472

473+
474+
467475
if (vm.count(QUIET))
468476
p.g.quiet = 1;
469477

@@ -496,7 +504,7 @@ int main(int argc, char* argv[])
496504
std::cout << std::setw(PRINT_VAR_PAD) << std::left << " Target epoch: " <<
497505
formattedDateStringFromNumericString<boost::gregorian::date>(p.r.epoch);
498506
if (isEpsgDatumStatic(epsgCode))
499-
std::cout << " (ignored: " << p.r.reference_frame << " is static)";
507+
std::cout << " (adopted reference epoch of " << p.r.reference_frame << ")";
500508
std::cout << std::endl;
501509
}
502510
}

0 commit comments

Comments
 (0)