Example #1
0
        public InterseptResult LineContains(CoordinateRectangle line)
        {
            var iLeftTop     = PointContains(line.LeftTop) != InterseptResult.None;
            var iRightBottom = PointContains(line.RightBottom) != InterseptResult.None;

            if (iLeftTop && iRightBottom)
            {
                return(InterseptResult.Contains);
            }
            if (iLeftTop || iRightBottom)
            {
                return(InterseptResult.Intersepts);
            }
            if (GoogleMapUtilities.CheckLinesInterseption(new CoordinateRectangle(Left, Top, Right, Top), line))
            {
                return(InterseptResult.Intersepts);
            }
            if (GoogleMapUtilities.CheckLinesInterseption(new CoordinateRectangle(Right, Top, Right, Bottom), line))
            {
                return(InterseptResult.Intersepts);
            }
            if (GoogleMapUtilities.CheckLinesInterseption(new CoordinateRectangle(Left, Bottom, Right, Bottom), line))
            {
                return(InterseptResult.Intersepts);
            }
            if (GoogleMapUtilities.CheckLinesInterseption(new CoordinateRectangle(Left, Top, Left, Bottom), line))
            {
                return(InterseptResult.Intersepts);
            }
            return(InterseptResult.None);
        }
        public static Coordinate GetNearestPoint(CoordinateRectangle line, Coordinate pt)
        {

            const double r2D = 180 / Math.PI; // Константа для преобразования радиан в градусы 

            var a = GetLength(line.LeftTop, line.RightBottom);
            if (a <= 0)
                return pt;

            var b = GetLength(line.LeftTop, pt);
            var c = GetLength(line.RightBottom, pt);

            var enB = Math.Acos((Math.Pow(a, 2) + Math.Pow(b, 2) - Math.Pow(c, 2)) / (2 * a * b)) * r2D;
            if (enB >= 90)
                return pt;
            var enC = Math.Acos((Math.Pow(a, 2) + Math.Pow(c, 2) - Math.Pow(b, 2)) / (2 * a * c)) * r2D;
            if (enC >= 90)
                return pt;


            var x = ((line.Right - line.Left) * (line.Bottom - line.Top) * (pt.Latitude - line.Top) +
                        line.Left * Math.Pow(line.Bottom - line.Top, 2) + pt.Longitude*Math.Pow(line.Right - line.Left, 2)) /
                       (Math.Pow(line.Bottom - line.Top, 2) + Math.Pow(line.Right - line.Left, 2));
            var y = (line.Bottom - line.Top) * (x - line.Left) / (line.Right - line.Left) + line.Top;

            return new Coordinate(x,y);
        }
Example #3
0
        public static Coordinate GetNearestPoint(CoordinateRectangle line, Coordinate pt)
        {
            const double r2D = 180 / Math.PI; // Константа для преобразования радиан в градусы

            var a = GetLength(line.LeftTop, line.RightBottom);

            if (a <= 0)
            {
                return(pt);
            }

            var b = GetLength(line.LeftTop, pt);
            var c = GetLength(line.RightBottom, pt);

            var enB = Math.Acos((Math.Pow(a, 2) + Math.Pow(b, 2) - Math.Pow(c, 2)) / (2 * a * b)) * r2D;

            if (enB >= 90)
            {
                return(pt);
            }
            var enC = Math.Acos((Math.Pow(a, 2) + Math.Pow(c, 2) - Math.Pow(b, 2)) / (2 * a * c)) * r2D;

            if (enC >= 90)
            {
                return(pt);
            }


            var x = ((line.Right - line.Left) * (line.Bottom - line.Top) * (pt.Latitude - line.Top) +
                     line.Left * Math.Pow(line.Bottom - line.Top, 2) + pt.Longitude * Math.Pow(line.Right - line.Left, 2)) /
                    (Math.Pow(line.Bottom - line.Top, 2) + Math.Pow(line.Right - line.Left, 2));
            var y = (line.Bottom - line.Top) * (x - line.Left) / (line.Right - line.Left) + line.Top;

            return(new Coordinate(x, y));
        }
Example #4
0
        /// <summary>
        /// Приблизительное растояние от точки до отрезка прямой
        /// Передаваемые широта/долгота в градусах и сотых долях
        /// </summary>
        public static double GetDistance(CoordinateRectangle line, Coordinate pt)
        {
            const double r2D = 180 / Math.PI; // Константа для преобразования радиан в градусы

            var a = GetLength(line.LeftTop, line.RightBottom);

            var b = GetLength(line.LeftTop, pt);
            var c = GetLength(line.RightBottom, pt);

            if (a <= 0)
            {
                return((b + c) / 2);
            }

            var enB = Math.Acos((Math.Pow(a, 2) + Math.Pow(b, 2) - Math.Pow(c, 2)) / (2 * a * b)) * r2D;

            if (enB >= 90)
            {
                return(b);
            }
            var enC = Math.Acos((Math.Pow(a, 2) + Math.Pow(c, 2) - Math.Pow(b, 2)) / (2 * a * c)) * r2D;

            if (enC >= 90)
            {
                return(c);
            }

            var s  = (a + b + c) / 2;
            var ar = Math.Sqrt(s * (s - a) * (s - b) * (s - c));

            return(ar * 2 / a);
        }
Example #5
0
        public InterseptResult RectangleContains(CoordinateRectangle rectangle)
        {
            var iLeftTop     = PointContains(rectangle.LeftTop) != InterseptResult.None;
            var iRightBottom = PointContains(rectangle.RightBottom) != InterseptResult.None;

            if (iLeftTop && iRightBottom)
            {
                return(InterseptResult.Contains);
            }
            if (iLeftTop || iRightBottom)
            {
                return(InterseptResult.Intersepts);
            }

            if (PointContains(rectangle.LeftBottom) != InterseptResult.None)
            {
                return(InterseptResult.Intersepts);
            }
            if (PointContains(rectangle.RightTop) != InterseptResult.None)
            {
                return(InterseptResult.Intersepts);
            }

            iLeftTop     = rectangle.PointContains(LeftTop) != InterseptResult.None;
            iRightBottom = rectangle.PointContains(RightBottom) != InterseptResult.None;

            if (iLeftTop && iRightBottom)
            {
                return(InterseptResult.Supersets);
            }
            if (iLeftTop || iRightBottom)
            {
                return(InterseptResult.Intersepts);
            }

            if (rectangle.PointContains(LeftBottom) != InterseptResult.None)
            {
                return(InterseptResult.Intersepts);
            }
            if (rectangle.PointContains(RightTop) != InterseptResult.None)
            {
                return(InterseptResult.Intersepts);
            }

            if (GoogleMapUtilities.CheckLinesInterseption(new CoordinateRectangle(Left, Top, Left, Bottom),
                                                          new CoordinateRectangle(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Top)))
            {
                return(InterseptResult.Intersepts);
            }
            if (GoogleMapUtilities.CheckLinesInterseption(new CoordinateRectangle(Left, Top, Right, Top),
                                                          new CoordinateRectangle(rectangle.Left, rectangle.Top, rectangle.Left, rectangle.Bottom)))
            {
                return(InterseptResult.Intersepts);
            }

            return(InterseptResult.None);
        }
 public bool IncludeTo(CoordinateRectangle rect)
 {
     for (var i = 0; i < Coordinates.Count; i++)
     {
         if (rect.PointContains(Coordinates[i]) != InterseptResult.Contains)
             return false;
     }
     return true;
 }
Example #7
0
 public bool IncludeTo(CoordinateRectangle rect)
 {
     for (var i = 0; i < Coordinates.Count; i++)
     {
         if (rect.PointContains(Coordinates[i]) != InterseptResult.Contains)
         {
             return(false);
         }
     }
     return(true);
 }
        public bool Add(Coordinate coordinate)
        {
            if (Count > 2)
            {
                var line1 = new CoordinateRectangle(First, coordinate);
                var line2 = new CoordinateRectangle(Last, coordinate);
                for (var i = 0; i < Count - 1; i++)
                {
                    if (GoogleMapUtilities.CheckLinesInterseption(this[i], line1)
                        || GoogleMapUtilities.CheckLinesInterseption(this[i], line2))
                        return false;
                }
            }

            Coordinates.Add(coordinate);
            return true;
        }
Example #9
0
        public bool Add(Coordinate coordinate)
        {
            if (Count > 2)
            {
                var line1 = new CoordinateRectangle(First, coordinate);
                var line2 = new CoordinateRectangle(Last, coordinate);
                for (var i = 0; i < Count - 1; i++)
                {
                    if (GoogleMapUtilities.CheckLinesInterseption(this[i], line1) ||
                        GoogleMapUtilities.CheckLinesInterseption(this[i], line2))
                    {
                        return(false);
                    }
                }
            }

            Coordinates.Add(coordinate);
            return(true);
        }
Example #10
0
        /// <summary>
        /// Приблизительное растояние от точки до отрезка прямой
        /// Передаваемые широта/долгота в градусах и сотых долях
        /// </summary>
        public static double GetDistance(CoordinateRectangle line, Coordinate pt)
        {
            const double r2D = 180 / Math.PI; // Константа для преобразования радиан в градусы 

            var a = GetLength(line.LeftTop, line.RightBottom);

            var b = GetLength(line.LeftTop, pt);
            var c = GetLength(line.RightBottom, pt);
            if (a <= 0)
                return (b + c) / 2;

            var enB = Math.Acos((Math.Pow(a, 2) + Math.Pow(b, 2) - Math.Pow(c, 2)) / (2 * a * b)) * r2D;
            if (enB >= 90)
                return b;
            var enC = Math.Acos((Math.Pow(a, 2) + Math.Pow(c, 2) - Math.Pow(b, 2)) / (2 * a * c)) * r2D;
            if (enC >= 90)
                return c;

            var s = (a + b + c) / 2;
            var ar = Math.Sqrt(s * (s - a) * (s - b) * (s - c));

            return ar * 2 / a;
        }
        public InterseptResult LineContains(CoordinateRectangle line)
        {
            var iLeftTop = PointContains(line.LeftTop) != InterseptResult.None;
            var iRightBottom = PointContains(line.RightBottom) != InterseptResult.None;

            if (iLeftTop && iRightBottom)
                return InterseptResult.Contains;
            if (iLeftTop || iRightBottom)
                return InterseptResult.Intersepts;
            if (GoogleMapUtilities.CheckLinesInterseption(new CoordinateRectangle(Left, Top, Right, Top), line))
                return InterseptResult.Intersepts;
            if (GoogleMapUtilities.CheckLinesInterseption(new CoordinateRectangle(Right, Top, Right, Bottom), line))
                return InterseptResult.Intersepts;
            if (GoogleMapUtilities.CheckLinesInterseption(new CoordinateRectangle(Left, Bottom, Right, Bottom), line))
                return InterseptResult.Intersepts;
            if (GoogleMapUtilities.CheckLinesInterseption(new CoordinateRectangle(Left, Top, Left, Bottom), line))
                return InterseptResult.Intersepts;
            return InterseptResult.None;
        }
        public InterseptResult RectangleContains(CoordinateRectangle coordinate)
        {
            //to do

            return InterseptResult.None;
        }
        public InterseptResult RectangleContains(CoordinateRectangle rectangle)
        {
            var iLeftTop = PointContains(rectangle.LeftTop) != InterseptResult.None;
            var iRightBottom = PointContains(rectangle.RightBottom) != InterseptResult.None;

            if (iLeftTop && iRightBottom)
                return InterseptResult.Contains;
            if (iLeftTop || iRightBottom)
                return InterseptResult.Intersepts;

            if (PointContains(rectangle.LeftBottom) != InterseptResult.None)
                return InterseptResult.Intersepts;
            if (PointContains(rectangle.RightTop) != InterseptResult.None)
                return InterseptResult.Intersepts;

            iLeftTop = rectangle.PointContains(LeftTop) != InterseptResult.None;
            iRightBottom = rectangle.PointContains(RightBottom) != InterseptResult.None;

            if (iLeftTop && iRightBottom)
                return InterseptResult.Supersets;
            if (iLeftTop || iRightBottom)
                return InterseptResult.Intersepts;

            if (rectangle.PointContains(LeftBottom) != InterseptResult.None)
                return InterseptResult.Intersepts;
            if (rectangle.PointContains(RightTop) != InterseptResult.None)
                return InterseptResult.Intersepts;

            if (GoogleMapUtilities.CheckLinesInterseption(new CoordinateRectangle(Left, Top, Left, Bottom),
                    new CoordinateRectangle(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Top)))
                return InterseptResult.Intersepts;
            if (GoogleMapUtilities.CheckLinesInterseption(new CoordinateRectangle(Left, Top, Right, Top),
                    new CoordinateRectangle(rectangle.Left, rectangle.Top, rectangle.Left, rectangle.Bottom)))
                return InterseptResult.Intersepts;

            return InterseptResult.None;
        }
Example #14
0
        public InterseptResult PoligonContains(CoordinateRectangle coordinate)
        {
            //to do

            return(InterseptResult.None);
        }
Example #15
0
 virtual protected void TranslateCoords()
 {
     _screenView = _centerCoordinate.GetScreenViewFromCenter(Width, Height, _level);
     _coordinateView = ScreenView;
 }
Example #16
0
        public HashItem[] FindNearestCable(Coordinate pt)
        {
            var list = new NearestSet();
            try
            {
                _lockCr.EnterReadLock();

                if (_rCableTree.NodeCount == 0)
                    return list.ToArray();

                var res = _rCableTree.Distance(pt, CoordinateTolerance);
                foreach (var node in res)
                {
                    var row = (SimpleMapDb.CablesRow)node.Row;

                    var cableRect = new CoordinateRectangle(row.Longitude1, row.Latitude1, row.Longitude2, row.Latitude2);

                    var distance = cableRect.LineDistance(pt);
                    list.Add(new HashItem(distance, row.ID));
                }
            }
            finally
            {
                _lockCr.ExitReadLock();
            }
            
            return list.OrderBy(item => item.Key).ToArray();
        }
Example #17
0
        private void RedrawCables(GoogleRectangle localScreenView)
        {
            try
             {
                _lockCr.EnterReadLock();

                if (_rCableTree.NodeCount == 0) return;

                var res = _rCableTree.Query(localScreenView);
                foreach (var node in res)
                {
                    var row = (SimpleMapDb.CablesRow) node.Row;

                    var cabRect = new CoordinateRectangle(row.Longitude1, row.Latitude1, row.Longitude2, row.Latitude2);
                    var rect = cabRect.GetScreenRect(localScreenView);

                    DrawLine(rect, 2, Color.Blue);

                    if (Level >= 14)
                    {
                        var caption = row.Caption;
                        if (!String.IsNullOrEmpty(caption))
                        {
                            var coordinate = cabRect.LineMiddlePoint;
                            var point = coordinate.GetScreenPoint(localScreenView);
                            DrawString(caption, HalfVertexSize.Height, Point.Add(point, HalfVertexSize));
                        }
                    }
                }
             }
             catch(Exception ex)
             {
                 //do nothing
                 System.Diagnostics.Trace.WriteLine(ex.Message);
             }
            finally
            {
                _lockCr.ExitReadLock();
            }
        }
Example #18
0
        private void GenerateSampleData()
        {
            _netLayer.ClearData();

            //--sample for show smothness
            var rnd = new Random();
            var rangeX = Convert.ToInt32((Settings.Default.RightMapBound - Settings.Default.LeftMapBound) * 100000);
            var rangeY = Convert.ToInt32((Settings.Default.TopMapBound - Settings.Default.BottomMapBound) * 100000);

            var longitude1 = Convert.ToDecimal(Settings.Default.LeftMapBound + (double) rnd.Next(0, rangeX)/100000);
            var latitude1 = Convert.ToDecimal(Settings.Default.BottomMapBound + (double)rnd.Next(0, rangeY) / 100000);

            var cableDbRows = new SimpleMapDb.CablesDataTable();
            var vertexDbRows = new SimpleMapDb.VertexesDataTable();
            while (cableDbRows.Count < 200)
            {
                var cableRow = cableDbRows.NewCablesRow();

                cableRow.Longitude1 = longitude1;
                cableRow.Latitude1 = latitude1;
                cableRow.Longitude2 = Convert.ToDecimal(Settings.Default.LeftMapBound + (double)rnd.Next(0, rangeX) / 100000);
                cableRow.Latitude2 = Convert.ToDecimal(Settings.Default.BottomMapBound + (double)rnd.Next(0, rangeY) / 100000);
                var rect = new CoordinateRectangle(cableRow.Longitude1, cableRow.Latitude1, cableRow.Longitude2, cableRow.Latitude2);
                cableRow.Length = Convert.ToDecimal(rect.LineLength);
                if (cableRow.Length <= 5000 && cableRow.Length > 200)
                {
                    longitude1 = cableRow.Longitude2;
                    latitude1 = cableRow.Latitude2;
                    cableRow.Caption = rect.ToString();
                    cableDbRows.AddCablesRow(cableRow);

                    var vertexRow = vertexDbRows.NewVertexesRow();

                    vertexRow.Longitude = longitude1;
                    vertexRow.Latitude = latitude1;

                    var pt = new Coordinate(vertexRow.Longitude, vertexRow.Latitude);
                    vertexRow.Caption = pt.ToString();
                    vertexDbRows.AddVertexesRow(vertexRow);
                }
            }
            _netLayer.MergeData(vertexDbRows);
            _netLayer.MergeData(cableDbRows);
            //--end sample
        }
        private void DownloadThread(CancellationToken ct)
        {
            var leftBound = new Coordinate(Properties.Settings.Default.LeftMapBound, Properties.Settings.Default.TopMapBound);
            var rightBound = new Coordinate(Properties.Settings.Default.RightMapBound, Properties.Settings.Default.BottomMapBound);

            var rectBound = new CoordinateRectangle(leftBound, rightBound);

            var mapBlockCount = 0;
            for (var mapLevel = Properties.Settings.Default.MinZoomLevel; mapLevel <= Properties.Settings.Default.MaxZoomLevel; mapLevel++)
            {
                var mapWidth = Convert.ToInt32((new GoogleCoordinate(rectBound.RightTop, mapLevel)).X - (new GoogleCoordinate(rectBound.LeftTop, mapLevel)).X) + 2 * GoogleBlock.BlockSize;
                var mapHeight = Convert.ToInt32((new GoogleCoordinate(rectBound.LeftBottom, mapLevel)).Y - (new GoogleCoordinate(rectBound.LeftTop, mapLevel)).Y) + 2 * GoogleBlock.BlockSize;

                var viewBound = rectBound.LineMiddlePoint.GetScreenViewFromCenter(mapWidth, mapHeight, mapLevel);
                var blockView = viewBound.BlockView;
                mapBlockCount += (blockView.Right - blockView.Left + 1) * (blockView.Bottom - blockView.Top + 1);
            }

            var mapBlockNumber = 0;
            BeginInvoke(ProgressEvent, new Object[] {mapBlockNumber * 100 / mapBlockCount, mapBlockNumber, mapBlockCount});

            for (var mapLevel = Properties.Settings.Default.MinZoomLevel; mapLevel <= Properties.Settings.Default.MaxZoomLevel; mapLevel++)
            {
                var mapWidth = Convert.ToInt32((new GoogleCoordinate(rectBound.RightTop, mapLevel)).X - (new GoogleCoordinate(rectBound.LeftTop, mapLevel)).X) + 2 * GoogleBlock.BlockSize;
                var mapHeight = Convert.ToInt32((new GoogleCoordinate(rectBound.LeftBottom, mapLevel)).Y - (new GoogleCoordinate(rectBound.LeftTop, mapLevel)).Y) + 2 * GoogleBlock.BlockSize;

                var viewBound = rectBound.LineMiddlePoint.GetScreenViewFromCenter(mapWidth, mapHeight, mapLevel);
                var blockView = viewBound.BlockView;

                for (var x = blockView.Left; x <= blockView.Right; x++)
                {
                    for (var y = blockView.Top; y <= blockView.Bottom; y++)
                    {
                        var block = new GoogleBlock(x, y, mapLevel);

                        var fileName = Properties.Settings.GetMapFileName(block);
                        if (!File.Exists(fileName))
                            MapLayer.DownloadImageFromGoogle(block, false);

                        mapBlockNumber++;

                        BeginInvoke(ProgressEvent, new Object[] {mapBlockNumber * 100 / mapBlockCount, mapBlockNumber, mapBlockCount});

                        if (ct.IsCancellationRequested)
                            return;
                    }
                }
            }
            BeginInvoke(ProgressEvent, new Object[] {101, mapBlockNumber, mapBlockCount});
        }
        private void GetFullMapThread(CancellationToken ct)
        {
            var leftBound = new Coordinate(Properties.Settings.Default.LeftMapBound, Properties.Settings.Default.TopMapBound);
            var rightBound = new Coordinate(Properties.Settings.Default.RightMapBound, Properties.Settings.Default.BottomMapBound);

            var rectBound = new CoordinateRectangle(leftBound, rightBound);

            try
            {
                var mapWidth = Convert.ToInt32((new GoogleCoordinate(rectBound.RightTop, _mapLevel)).X - (new GoogleCoordinate(rectBound.LeftTop, _mapLevel)).X) + 2 * GoogleBlock.BlockSize;
                var mapHeight = Convert.ToInt32((new GoogleCoordinate(rectBound.LeftBottom, _mapLevel)).Y - (new GoogleCoordinate(rectBound.LeftTop, _mapLevel)).Y) + 2 * GoogleBlock.BlockSize;

                var image = GraphicLayer.CreateCompatibleBitmap(null, mapWidth, mapHeight, _mapPiFormat);
                var graphics = Graphics.FromImage(image);

                var viewBound = rectBound.LineMiddlePoint.GetScreenViewFromCenter(mapWidth, mapHeight, _mapLevel);
                var blockView = viewBound.BlockView;
                var mapBlockCount = (blockView.Right - blockView.Left + 1) * (blockView.Bottom - blockView.Top + 1);
                var mapBlockNumber = 0;
            
                BeginInvoke(ProgressEvent, new Object[] {mapBlockNumber * 100 / mapBlockCount, mapBlockNumber, mapBlockCount});

                for (var x = blockView.Left; x <= blockView.Right; x++)
                {
                    for (var y = blockView.Top; y <= blockView.Bottom; y++)
                    {
                        var block = new GoogleBlock(x, y, _mapLevel);
                        var bmp = GraphicLayer.CreateCompatibleBitmap(
                            MapLayer.DownloadImageFromFile(block) ?? MapLayer.DownloadImageFromGoogle(block, true),
                            GoogleBlock.BlockSize, GoogleBlock.BlockSize, _mapPiFormat);

                        var rect = ((GoogleRectangle) block).GetScreenRect(viewBound);
                        graphics.DrawImageUnscaled(bmp, rect.Location.X, rect.Location.Y);

                        mapBlockNumber++;

                        BeginInvoke(ProgressEvent, new Object[]{mapBlockNumber * 100 / mapBlockCount, mapBlockNumber, mapBlockCount});

                        if (ct.IsCancellationRequested)
                            return;
                    }
                }

                BeginInvoke(SaveMapEvent, new Object[] {image});
            }
            catch (Exception e)
            {
                BeginInvoke(ProgressEvent, new Object[] { 101, 0, 0 });
                MessageBox.Show(e.Message, @"Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }