Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        private string GetCSIBFromCSD(ICoordinateSystem coordinateSystem)
        {
            using var retStructFromICoordinateSystem = new CSMCsibBlobContainer();

            lock (TGLLock.CsdManagementLock)
            {
                CsdManagement.csmGetCSIBFromCoordinateSystem(coordinateSystem, false, Utils.FileListCallBack, Utils.EmbeddedDataCallback, retStructFromICoordinateSystem)
                .Validate("attempting to get CSMCsibBlobContainer from ICoordinateSystem");
            }

            return(GetCSIB(retStructFromICoordinateSystem));
        }
Esempio n. 3
0
        private CSMCsibBlobContainer GetCSIBFromDCFileContent(string fileContent)
        {
            // We may receive coordinate system file content that's been uploaded (encoded) from a web api, must decode first.
            fileContent = fileContent.DecodeFromBase64();

            lock (TGLLock.CsdManagementLock)
            {
                var csmCsibBlobContainer = new CSMCsibBlobContainer();

                // Slow, takes 2.5 seconds, need to speed up somehow?
                var result = CsdManagement.csmGetCSIBFromDCFileData(
                    fileContent,
                    false,
                    Utils.FileListCallBack,
                    Utils.EmbeddedDataCallback,
                    csmCsibBlobContainer);

                if (result != (int)csmErrorCode.cecSuccess)
                {
                    switch ($"{result}")
                    {
                    case "cecGRID_FILE_OPEN_ERROR":
                    {
                        var geoidModelName = CalibrationFileHelper.GetGeoidModelName(Encoding.UTF8.GetBytes(fileContent));
                        throw new InvalidOperationException($"{nameof(GetCSIBFromDCFileContent)}: Geodata file not found for geoid model '{geoidModelName}'");
                    }

                    default:
                    {
                        throw new InvalidOperationException($"{nameof(GetCSIBFromDCFileContent)}: Get CSIB from file content failed, error {result}");
                    }
                    }
                }

                return(csmCsibBlobContainer);
            }
        }
Esempio n. 4
0
 private string GetCSIB(CSMCsibBlobContainer csibBlobContainer) =>
 Convert.ToBase64String(Array.ConvertAll(Utils.IntPtrToSByte(csibBlobContainer.pCSIBData, (int)csibBlobContainer.CSIBDataLength), sb => unchecked ((byte)sb)));
Esempio n. 5
0
        /// <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");
            }
        }