Example #1
0
        private CoorPoint GetTopLeft()
        {
            if(!rg.IsInMap())
            {
                return new CoorPoint(rg.GetTopLeft.x, rg.GetTopLeft.y);
            }

            CoordinateTransform ct = new CoordinateTransform();
            CoorPoint pt = new CoorPoint();
            switch (bkImgType)
            {
                case BackgroundMapType.None:
                    pt = ct.CalLonLatDegToTwd97(rg.GetTopLeft.x, rg.GetTopLeft.y);
                    break;
                case BackgroundMapType.GoogleStaticMap:
                    pt = ct.CalLonLatDegToTwd97(rg.GetTopLeft.x, rg.GetTopLeft.y);
                    break;
                case BackgroundMapType.ImportImage:
                    pt = topLeft;
                    break;
            }
            return pt;
        }
Example #2
0
        private Matrix GetMatrix()
        {
            if (rg==null || !rg.IsReadFinished())
            {
                return null;
            }
            CoordinateTransform ct = new CoordinateTransform();
            CoorPoint lt = GetTopLeft();
            CoorPoint rb = GetBottomRight(); ;

            float w = 0;
            float h = 0;
            if (BackgroundMapType.GoogleStaticMap == bkImgType)
            {
                w = GetGridBitmap().Width;
                h = GetGridBitmap().Height;
            }
            else if (BackgroundMapType.ImportImage == bkImgType)
            {
                w = GetGridBitmap().Width;
                h = GetGridBitmap().Height;
            }
            else //if (BackgroundMapType.None == bkImgType)
            {
                w = 640 * 2;
                h = 640 * 2;
            }
            if(!rg.IsInMap())
            {
                double coorW = rb.x - lt.x;
                double coorH = lt.y - rb.y;
                if (coorW > coorH)
                {   //�e�j��
                    lt.y += (coorW - coorH) / 2;
                    rb.y -= (coorW - coorH) / 2;
                }
                else if (coorW < coorH)
                {   //���j��e
                    lt.x -= (coorH - coorW) / 2;
                    rb.x += (coorH - coorW) / 2;
                }
                coorW = rb.x - lt.x;
                coorH = lt.y - rb.y;

                lt.x -= coorW * 0.1;
                rb.x += coorW * 0.1;
                lt.y += coorH * 0.1;
                rb.y -= coorH * 0.1;
            }

            Matrix m = new Matrix(1f, 0, 0, -1f, 0, 0);
            float xScale = w / (float)(rb.x - lt.x);
            float yScale = h / (float)(lt.y - rb.y);

            m.Scale(xScale, yScale);
            m.Translate((float)-lt.x, (float)-lt.y);
            return m;
        }
Example #3
0
        private bool ConvertGrid(CoorPoint[,] grid)
        {
            _j = grid.GetLength(1);
            _i = grid.GetLength(0);
            maxX = double.MinValue;
            minX = double.MaxValue;
            maxY = double.MinValue;
            minY = double.MaxValue;

            foreach(CoorPoint pt in grid)
            {
                if (pt.x > maxX)
                    maxX = pt.x;
                if (pt.x < minX)
                    minX = pt.x;
                if (pt.y > maxY)
                    maxY = pt.y;
                if (pt.y < minY)
                    minY = pt.y;
            }

            //Finished read
            CoordinateTransform ct = new CoordinateTransform();
            if (IsInMap())
            {
                zoomScale = CalZoomScale(ct.CalTwd97ToLatLonCoorRad(maxX, maxY), ct.CalTwd97ToLatLonCoorRad(minX, minY));
            }
            else
            {
                zoomScale = 1;
            }

            if (zoomScale == 0)
            {
                return false;
            }

            if (IsInMap())
            {
                CoorPoint center = ct.CalTwd97ToLatLonCoorRad((maxX + minX) / 2, (maxY + minY) / 2);
                bottomRight = ct.CalCenterLatLonToOffsetPixelLonLat(center.x, center.y, 640, 640, zoomScale).RadToDegree();
                topLeft = ct.CalCenterLatLonToOffsetPixelLonLat(center.x, center.y, -640, -640, zoomScale).RadToDegree();
                centerPoint = center.RadToDegree();
            }
            else
            {
                centerPoint = new CoorPoint((maxX + minX) / 2, (maxY + minY) / 2);
                bottomRight = new CoorPoint(maxX, minY);
                topLeft = new CoorPoint(minX, maxY);
            }
            return true;
        }
Example #4
0
 private int CalZoomScale(CoorPoint tl, CoorPoint br)
 {
     CoordinateTransform ct = new CoordinateTransform();
     for (int i = 21; i > 1; --i)
     {
         CoorPoint c2 = ct.CalLonLatRadToCoorPixel(tl.x, tl.y, i);
         CoorPoint c1 = ct.CalLonLatRadToCoorPixel(br.x, br.y, i);
         if ((c2.x - c1.x) < 1280 && c2.y - c1.y < 1280)
         {
             return i;
         }
     }
     return 0;
 }
Example #5
0
        public bool DownloadGridMap(int coorType, string tl, string tr, string bl, string br)
        {
            try
            {
                CoorPoint tlp = topLeft, cp = centerPoint, brp = bottomRight;
                if ((GridPictureBox.CoorType)coorType == GridPictureBox.CoorType.TWD64)
                {
                    CoordinateTransform ct = new CoordinateTransform();
                    tlp = ct.Twd97ToTwd67(topLeft);
                    cp = ct.Twd97ToTwd67(centerPoint);
                    brp = ct.Twd97ToTwd67(bottomRight);
                }

                DownloadStaticMap((topLeft.x + centerPoint.x) / 2, (topLeft.y + centerPoint.y) / 2, zoomScale, br);
                DownloadStaticMap((bottomRight.x + centerPoint.x) / 2, (topLeft.y + centerPoint.y) / 2, zoomScale, bl);
                DownloadStaticMap((topLeft.x + centerPoint.x) / 2, (bottomRight.y + centerPoint.y) / 2, zoomScale, tr);
                DownloadStaticMap((bottomRight.x + centerPoint.x) / 2, (bottomRight.y + centerPoint.y) / 2, zoomScale, tl);
            }
            catch
            {
                return false;
            }
            return true;
        }
Example #6
0
        public bool ReadInputFile(string path)
        {
            const int MaxLineWord = 3;

            try
            {
                System.IO.StreamReader file = new System.IO.StreamReader(path);
                char[] charSeparators       = new char[] { '\t', ' ' };

                string   line  = file.ReadLine();
                string[] words = line.Split(charSeparators, MaxLineWord);
                _j = Convert.ToInt32(words[0]);
                _i = Convert.ToInt32(words[1]);

                inputCoor = new CoorPoint[_i, _j];
                int i = 0, j = _j - 1;
                while ((line = file.ReadLine()) != null)
                {
                    words           = line.Split(charSeparators, MaxLineWord);
                    inputCoor[i, j] = new CoorPoint(Convert.ToDouble(words[0]), Convert.ToDouble(words[1]));
                    if (inputCoor[i, j].x > maxX)
                    {
                        maxX = inputCoor[i, j].x;
                    }
                    if (inputCoor[i, j].x < minX)
                    {
                        minX = inputCoor[i, j].x;
                    }
                    if (inputCoor[i, j].y > maxY)
                    {
                        maxY = inputCoor[i, j].y;
                    }
                    if (inputCoor[i, j].y < minY)
                    {
                        minY = inputCoor[i, j].y;
                    }

                    if (--j < 0)
                    {
                        j = _j - 1;
                        ++i;
                    }
                    if (i == _i)
                    {
                        break;
                    }
                }
                //Finished read
                CoordinateTransform coorConv = new CoordinateTransform();
                //CoorPoint topLeft = coorConv.CalTwd97ToLatLonCoorRad(maxX, maxY);
                //CoorPoint bottomRight = coorConv.CalTwd97ToLatLonCoorRad(minX, minY);
                zoomScale = CalZoomScale(coorConv.CalTwd97ToLatLonCoorRad(maxX, maxY), coorConv.CalTwd97ToLatLonCoorRad(minX, minY));
                if (zoomScale == 0)
                {
                    return(false);
                }

                CoorPoint center             = coorConv.CalTwd97ToLatLonCoorRad((maxX + minX) / 2, (maxY + minY) / 2);
                bottomRight = coorConv.CalCenterLatLonToOffsetPixelLonLat(center.x, center.y, 640, 640, zoomScale).RadToDegree();
                topLeft     = coorConv.CalCenterLatLonToOffsetPixelLonLat(center.x, center.y, -640, -640, zoomScale).RadToDegree();
                centerPoint = center.RadToDegree();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return(false);
            }
            return(true);
        }