public Datum[] GetDatums() { using var returnListStruct = new CSMStringListContainer(); lock (TGLLock.CsdManagementLock) { var resultCode = CsdManagement.csmGetListOfDatums(returnListStruct); if (resultCode == csmErrorCode.cecSuccess) { var datums = returnListStruct.stringList.Split(new[] { CsdManagement.STRING_SEPARATOR }, StringSplitOptions.RemoveEmptyEntries) .Select(s => new Datum( datumSystemId: int.Parse(s.Split(CsdManagement.ITEM_SEPERATOR)[0]), datumType: int.Parse(s.Split(CsdManagement.ITEM_SEPERATOR)[1]), datumName: s.Split(CsdManagement.ITEM_SEPERATOR)[3])); if (datums == null) { throw new Exception("Error attempting to retrieve list of datums, null result"); } if (!datums.Any()) { throw new Exception("No datums found"); } return(datums.ToArray()); } } return(null); }
/// <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"); } }