private static bool ValidateCsib(string csib) { var sb = new StringBuilder(); var bytes = Encoding.ASCII.GetBytes(csib); for (var i = 0; i < bytes.Length; i++) { sb.Append(bytes[i]).Append(' '); } var blocks = sb.ToString().TrimEnd().Split(' '); var data = new sbyte[blocks.Length]; var index = 0; foreach (var b in blocks) { data[index++] = (sbyte)Convert.ToByte(b); } using var csmCsibData = new CSMCsibBlobContainer(data); using var csFromCSIB = new CSMCoordinateSystemContainer(); lock (TGLLock.CsdManagementLock) { CsdManagement.csmImportCoordSysFromCsib(csmCsibData, csFromCSIB) .Validate("attempting to import coordinate system from CSMCsibBlobContainer"); } return(true); }
/// <inheritdoc/> private ICoordinateSystem GetDatumBySystemId(int datumSystemId) { using var datumContainer = new CSMCoordinateSystemContainer(); lock (TGLLock.CsdManagementLock) { CsdManagement.csmGetDatumFromCSDSelectionById((uint)datumSystemId, false, null, null, datumContainer) .Validate($"attempting to retrieve datum {datumSystemId} by id."); } return(datumContainer.GetSelectedRecord()); }
/// <inheritdoc/> public CoordinateSystem GetCSDFromCSIB(string csibString) { if (string.IsNullOrEmpty(csibString)) { throw new ArgumentNullException(nameof(csibString), "CSIB string cannot be null"); } using var csContainer = new CSMCoordinateSystemContainer(); var csmCsibData = CreateCSMCsibBlobContainer(csibString); lock (TGLLock.CsdManagementLock) { CsdManagement.csmImportCoordSysFromCsib(csmCsibData, csContainer). Validate("attempting to import coordinate system from CSIB"); } return(ConvertICoordinateSystem(csContainer.GetSelectedRecord())); }
/// <inheritdoc/> public CoordinateSystem GetCSDFromDCFileContent(string dcFileStr) { if (string.IsNullOrEmpty(dcFileStr)) { throw new ArgumentNullException(nameof(dcFileStr), "DC file string cannot be null"); } // We may receive coordinate system file content that's been uploaded (encoded) from a web api, must decode first. var fileContent = dcFileStr.DecodeFromBase64(); using var csContainer = new CSMCoordinateSystemContainer(); lock (TGLLock.CsdManagementLock) { CsdManagement.csmGetCoordinateSystemFromDCFile(fileContent, false, Utils.FileListCallBack, Utils.EmbeddedDataCallback, csContainer) .Validate("attempting to retrieve the DC file's CSD"); } return(ConvertICoordinateSystem(csContainer.GetSelectedRecord())); }
/// <inheritdoc/> public string GetCSIBFromCSDSelection(string zoneGroupNameString, string zoneNameQueryString) { lock (TGLLock.CsdManagementLock) { using var retStructZoneGroups = new CSMStringListContainer(); CsdManagement.csmGetListOfZoneGroups(retStructZoneGroups) .Validate("attempting to retrieve list of zone groups"); var zoneGroups = retStructZoneGroups .stringList .Split(new[] { CsdManagement.STRING_SEPARATOR }, StringSplitOptions.RemoveEmptyEntries) .Select(s => s.Split(CsdManagement.ITEM_SEPERATOR)[1]); if (!zoneGroups.Any()) { throw new Exception("The count of zone groups should be greater than 0"); } var zoneGroupName = zoneGroupNameString.Substring(zoneGroupNameString.IndexOf(",") + 1); using var retStructListOfZones = new CSMStringListContainer(); CsdManagement.csmGetListOfZones(zoneGroupName, retStructListOfZones) .Validate($"attempting to retrieve list of zones for group '{zoneGroupName}'"); var zones = retStructListOfZones .stringList .Split(new[] { CsdManagement.STRING_SEPARATOR }, StringSplitOptions.RemoveEmptyEntries); if (zones.Length == 0) { throw new Exception($"The count of zones in {zoneGroupName} should be greater than 0"); } var zoneElement = Array.Find(zones, element => element.EndsWith(zoneNameQueryString, StringComparison.OrdinalIgnoreCase)); if (string.IsNullOrEmpty(zoneElement)) { throw new Exception($"Could not find '{zoneNameQueryString}' in the list of zones for group '{zoneGroupName}'"); } var zoneName = zoneElement.Substring(zoneElement.IndexOf(",") + 1); var items = zoneElement.Split(CsdManagement.ITEM_SEPERATOR); var zoneId = uint.Parse(items[0]); using var retCsStruct = new CSMCoordinateSystemContainer(); CsdManagement.csmGetCoordinateSystemFromCSDSelectionDefaults(zoneGroupName, zoneName, false, Utils.FileListCallBack, Utils.EmbeddedDataCallback, retCsStruct) .Validate($"attempting to retrieve coordinate system from CSD selection; zone group: '{zoneGroupName}', zone: {zoneName}"); var coordinateSystem = retCsStruct.GetSelectedRecord(); // Many of our test calibration files fail validation; is this expected or do we have a parsing problem? // This validation logic was taken from TGL unit test classes, may not be correctly implemented. // coordinateSystem.Validate(); var zoneID = unchecked ((uint)coordinateSystem.ZoneSystemId()); var datumID = unchecked ((uint)coordinateSystem.DatumSystemId()); var geoidID = unchecked ((uint)coordinateSystem.GeoidSystemId()); if (coordinateSystem.DatumSystemId() > 0) { return(GetCSIBFromCSD(coordinateSystem)); } else { var datumResult = GetDatumBySystemId(1034); using var csibFromIDs = new CSMCsibBlobContainer(); CsdManagement.csmGetCSIBFromCSDSelectionById(zoneID, datumId: 1034, geoidId: 0, false, Utils.FileListCallBack, Utils.EmbeddedDataCallback, csibFromIDs); var csib = GetCSIB(csibFromIDs); if (!string.IsNullOrEmpty(csib)) { return(csib); } } throw new Exception($"Error attempting to retrieve coordinate system from CSD selection; zone group: '{zoneGroupName}', zone: {zoneName}, no datum found"); } }