Esempio n. 1
0
        private void Process_Click(object sender, RoutedEventArgs e)
        {
            bool bLon = float.TryParse(Longitude.Text, out float lon);
            bool bLat = float.TryParse(Latitude.Text, out float lat);
            bool bRad = int.TryParse(Radius.Text, out int rad);

            if (bLon && bLat && bRad)
            {
                AreaRange range      = Controller.GetAreaRange(lon, lat, rad);
                string    format     = comboBox.SelectionBoxItem as string;
                string    minminPath = FilePath + @"\N" + ((int)range.minPt.Y).ToString("000") + "E" + ((int)range.minPt.X).ToString("000") + "_AVE_" + format + ".tif";
                string    minmaxPath = FilePath + @"\N" + ((int)range.maxPt.Y).ToString("000") + "E" + ((int)range.minPt.X).ToString("000") + "_AVE_" + format + ".tif";
                string    maxminPath = FilePath + @"\N" + ((int)range.minPt.Y).ToString("000") + "E" + ((int)range.maxPt.X).ToString("000") + "_AVE_" + format + ".tif";
                string    maxmaxPath = FilePath + @"\N" + ((int)range.maxPt.Y).ToString("000") + "E" + ((int)range.maxPt.X).ToString("000") + "_AVE_" + format + ".tif";

                string log = "";

                // 좌하단 위경도 tiff 로드
                short[,] minmin = LoadTiff(minminPath, ref log);

                // 좌상단 위경도 tiff 로드
                short[,] minmax = LoadTiff(minmaxPath, ref log);

                // 우하단 위경도 tiff 로드
                short[,] maxmin = LoadTiff(maxminPath, ref log);

                // 우상단 위경도 tiff 로드
                short[,] maxmax = LoadTiff(maxmaxPath, ref log);

                // 로그 출력
                LogWindow.Text = log;

                // 클립, 리사이징
                Controller.FileHeight = (IO.ImageHeight != 0)? IO.ImageHeight : Resolution;
                Controller.FileWidth  = (IO.ImageWidth != 0)? IO.ImageWidth : Resolution;
                short[,] clipArea     = Controller.ClipSpecificArea(minmin, minmax, maxmin, maxmax, range);
                short[,] refineArea   = Controller.ResizeHeightMap(clipArea, Resolution);

                // 사용자 정의 변환
                resultArea = Controller.ConvCustom(refineArea);

                RenderTiff(resultArea);

                Save.IsEnabled = true;
            }
            else
            {
                // 입력 포맷 불일치
                LogWindow.Text = "Input format is invalid. Please re - input area. ex) lon = 126.2, lat = 37.3, rad = 100000 \n";
            }
        }
        public AreaRange GetAreaRange(float lon, float lat, int rad)
        {
            AreaRange areaRange = new AreaRange();

            Point minPt = new Point();
            Point maxPt = new Point();

            minPt.Y = lat - rad / 880000.0f;
            minPt.X = lon - rad / 1110000.0f;
            maxPt.Y = lat + rad / 880000.0f;
            maxPt.X = lon + rad / 1110000.0f;

            areaRange.minPt = minPt;
            areaRange.maxPt = maxPt;

            return(areaRange);
        }
        public short[,] ClipSpecificArea(short[,] minmin, short[,] minmax, short[,] maxmin, short[,] maxmax, AreaRange areaRange)
        {
            int originY = (int)((areaRange.minPt.Y - (int)areaRange.minPt.Y) * FileHeight);
            int originX = (int)((areaRange.minPt.X - (int)areaRange.minPt.X) * FileWidth);
            int destY   = (int)((areaRange.maxPt.Y - (int)areaRange.minPt.Y) * FileHeight);
            int destX   = (int)((areaRange.maxPt.X - (int)areaRange.minPt.X) * FileWidth);

            short[,] heightMap = new short[destY - originY, destX - originX];

            // Load specific height map data from textures.
            for (int y = FileHeight; y < destY; y++)
            {
                for (int x = originX; x < ((FileWidth < destX) ? FileWidth : destX); x++)
                {
                    heightMap[y - originY, x - originX] = minmin[y - FileHeight, x];
                }
                for (int x = FileWidth; x < destX; x++)
                {
                    heightMap[y - originY, x - originX] = maxmin[y - FileHeight, x - FileWidth];
                }
            }
            for (int y = originY; y < ((FileHeight < destY) ? FileHeight : destY); y++)
            {
                for (int x = originX; x < ((FileWidth < destX) ? FileWidth : destX); x++)
                {
                    heightMap[y - originY, x - originX] = minmax[y, x];
                }
                for (int x = FileWidth; x < destX; x++)
                {
                    heightMap[y - originY, x - originX] = maxmax[y, x - FileWidth];
                }
            }
            return(heightMap);
        }