public void GetTileTest()
        {
            int       levels = 1;
            PlateFile target = new PlateFile(Path.Combine(TestDataPath, TestPlateFileName), levels);
            Bitmap    actual;

            using (Bitmap expected = new Bitmap(string.Format(ImageFileNameTemplate, 0, 0, 0, TestDataPath)))
            {
                Stream tileStream = target.GetFileStream(0, 0, 0);
                actual = new Bitmap(tileStream);
                Assert.IsTrue(CompareBitmap(expected, actual));
            }

            for (int x = 0; x < 2; x++)
            {
                for (int y = 0; y < 2; y++)
                {
                    using (Bitmap expected = new Bitmap(string.Format(ImageFileNameTemplate, 1, x, y, TestDataPath)))
                    {
                        Stream tileStream = target.GetFileStream(1, x, y);
                        actual = new Bitmap(tileStream);
                        Assert.IsTrue(CompareBitmap(expected, actual));
                    }
                }
            }
        }
        public void CreateTest()
        {
            string fileName = "TestCreateTest.plate";
            int levels = 1;
            PlateFile target = new PlateFile(Path.Combine(TestDataPath, fileName), levels);
            target.Create();
            target.UpdateHeaderAndClose();

            Assert.IsTrue(File.Exists(fileName));
        }
        public void CreateTest()
        {
            string    fileName = "TestCreateTest.plate";
            int       levels   = 1;
            PlateFile target   = new PlateFile(Path.Combine(TestDataPath, fileName), levels);

            target.Create();
            target.UpdateHeaderAndClose();

            Assert.IsTrue(File.Exists(fileName));
        }
        public void GetDemTileTest()
        {
            int levels = 1;
            PlateFile target = new PlateFile(Path.Combine(TestDataPath, TestDEMPlateFileName), levels);
            MockClasses.MockDemTileLocator locator = new MockClasses.MockDemTileLocator();

            short[] expected = locator.Deserialize(0, 0, 0);
            Stream tileStream = target.GetFileStream(0, 0, 0);
            short[] actual = GetDemTileData(tileStream);

            for (int x = 0; x < 2; x++)
            {
                for (int y = 0; y < 2; y++)
                {
                    tileStream = target.GetFileStream(1, x, y);
                    actual = GetDemTileData(tileStream);
                    expected = locator.Deserialize(1, x, y);
                    Assert.IsTrue(CompareShortArray(expected, actual));
                }
            }
        }
Beispiel #5
0
        public void GetDemTileTest()
        {
            int       levels = 1;
            PlateFile target = new PlateFile(Path.Combine(TestDataPath, TestDEMPlateFileName), levels);

            MockClasses.MockDemTileLocator locator = new MockClasses.MockDemTileLocator();

            short[] expected   = locator.Deserialize(0, 0, 0);
            Stream  tileStream = target.GetFileStream(0, 0, 0);

            short[] actual = GetDemTileData(tileStream);

            for (int x = 0; x < 2; x++)
            {
                for (int y = 0; y < 2; y++)
                {
                    tileStream = target.GetFileStream(1, x, y);
                    actual     = GetDemTileData(tileStream);
                    expected   = locator.Deserialize(1, x, y);
                    Assert.IsTrue(CompareShortArray(expected, actual));
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Gets Dem for the specified tile id.
        /// </summary>
        /// <param name="id">Tile details id.</param>
        /// <param name="level">Level of the image.</param>
        /// <param name="x">X axis image.</param>
        /// <param name="y">Y axis image.</param>
        /// <returns>Dem for the specified image.</returns>
        public Stream GetDem(string id, int level, int x, int y)
        {
            Stream outputStream = null;

            try
            {
                string        pyramidFolderPath   = Path.Combine(this.PyramidLocation, id, Constants.PyramidFolder);
                string        demPlatesFolderPath = Path.Combine(this.PyramidLocation, id, Constants.DEMPlatesFolder);
                DirectoryInfo pyramidFolder       = new DirectoryInfo(pyramidFolderPath);
                DirectoryInfo platesFolder        = new DirectoryInfo(demPlatesFolderPath);

                if (pyramidFolder.Exists)
                {
                    string pyramidPath = Path.Combine(this.PyramidLocation, id, Constants.DemTilePath);

                    string filename = string.Format(CultureInfo.InvariantCulture, pyramidPath, level, x, y, Constants.DemExtension);
                    if (File.Exists(filename))
                    {
                        byte[] data = null;
                        using (Stream s = File.OpenRead(filename))
                        {
                            int length = (int)s.Length;
                            data = new byte[length];
                            s.Read(data, 0, length);
                            outputStream = new MemoryStream(data);
                        }
                    }
                }
                else if (platesFolder.Exists)
                {
                    // Get from multiple plates
                    outputStream = PlateFileHelper.GetDEMTileFromMultiplePlates(level, x, y, platesFolder.FullName);
                }
                else
                {
                    // If Pyramid folder is not available, then try to read from plate file.
                    FileInfo plateFile = pyramidFolder.Parent.GetFiles(Constants.PlateFileSearchPattern).FirstOrDefault();
                    if (plateFile != null && plateFile.Exists)
                    {
                        PlateFile plateFileInstance = new PlateFile(plateFile.FullName, level);
                        outputStream = plateFileInstance.GetFileStream(level, x, y);
                    }
                }
            }
            catch (ArgumentException ex)
            {
                ErrorHandler.LogException(ex);
                throw new FaultException(ex.Message);
            }
            catch (IOException ex)
            {
                ErrorHandler.LogException(ex);
                throw new FaultException(ex.Message);
            }
            catch (ObjectDisposedException ex)
            {
                ErrorHandler.LogException(ex);
                throw new FaultException(ex.Message);
            }

            return(outputStream);
        }
Beispiel #7
0
        /// <summary>
        /// Gets tile image for the specified tile id.
        /// </summary>
        /// <param name="id">Tile details id.</param>
        /// <param name="level">Level of the image.</param>
        /// <param name="x">X axis image.</param>
        /// <param name="y">Y axis image.</param>
        /// <returns>Tile image for the specified image.</returns>
        public Stream GetTileImage(string id, int level, int x, int y)
        {
            Stream outputStream = null;

            try
            {
                string        pyramidFolderPath = Path.Combine(this.PyramidLocation, id, Constants.PyramidFolder);
                string        platesFolderPath  = Path.Combine(this.PyramidLocation, id, Constants.PlatesFolder);
                DirectoryInfo pyramidFolder     = new DirectoryInfo(pyramidFolderPath);
                DirectoryInfo platesFolder      = new DirectoryInfo(platesFolderPath);

                if (pyramidFolder.Exists)
                {
                    string pyramidPath = Path.Combine(this.PyramidLocation, id, Constants.TileImagePath);

                    string filename = string.Format(CultureInfo.InvariantCulture, pyramidPath, level, x, y, ImageFormat.Png.ToString());

                    if (File.Exists(filename))
                    {
                        using (Bitmap bmp = new Bitmap(filename, false))
                        {
                            if (bmp != null)
                            {
                                outputStream = new MemoryStream();
                                bmp.Save(outputStream, ImageFormat.Png);
                                outputStream.Seek(0, SeekOrigin.Begin);
                            }
                        }
                    }
                }
                else if (platesFolder.Exists)
                {
                    outputStream = PlateFileHelper.GetTileFromMultiplePlates(level, x, y, platesFolder.FullName);
                }
                else
                {
                    // If Pyramid folder is not available, then try to read from plate file.
                    FileInfo plateFile = pyramidFolder.Parent.GetFiles(Constants.PlateFileSearchPattern).FirstOrDefault();
                    if (plateFile != null && plateFile.Exists)
                    {
                        PlateFile plateFileInstance = new PlateFile(plateFile.FullName, level);
                        outputStream = plateFileInstance.GetFileStream(level, x, y);
                    }
                }
            }
            catch (ArgumentException ex)
            {
                ErrorHandler.LogException(ex);
                throw new FaultException(ex.Message);
            }
            catch (IOException ex)
            {
                ErrorHandler.LogException(ex);
                throw new FaultException(ex.Message);
            }
            catch (ObjectDisposedException ex)
            {
                ErrorHandler.LogException(ex);
                throw new FaultException(ex.Message);
            }
            return(outputStream);
        }
        public void GetTileTest()
        {
            int levels = 1;
            PlateFile target = new PlateFile(Path.Combine(TestDataPath, TestPlateFileName), levels);
            Bitmap actual;
            using (Bitmap expected = new Bitmap(string.Format(ImageFileNameTemplate, 0, 0, 0, TestDataPath)))
            {
                Stream tileStream = target.GetFileStream(0, 0, 0);
                actual = new Bitmap(tileStream);
                Assert.IsTrue(CompareBitmap(expected, actual));
            }

            for (int x = 0; x < 2; x++)
            {
                for (int y = 0; y < 2; y++)
                {
                    using (Bitmap expected = new Bitmap(string.Format(ImageFileNameTemplate, 1, x, y, TestDataPath)))
                    {
                        Stream tileStream = target.GetFileStream(1, x, y);
                        actual = new Bitmap(tileStream);
                        Assert.IsTrue(CompareBitmap(expected, actual));
                    }
                }
            }
        }