Exemplo n.º 1
0
        /// <summary>
        /// Select graphics by an extent
        /// </summary>
        /// <param name="aExtent">extent</param>
        /// <param name="selectedGraphics">ref selected graphics</param>
        /// <returns>if selected</returns>
        public bool SelectGraphics(Extent aExtent, ref GraphicCollection selectedGraphics)
        {
            selectedGraphics.GraphicList.Clear();
            int    i, j;
            PointD aPoint = new PointD();

            aPoint.X = (aExtent.minX + aExtent.maxX) / 2;
            aPoint.Y = (aExtent.minY + aExtent.maxY) / 2;

            foreach (Graphic aGraphic in _graphicList)
            {
                switch (aGraphic.Shape.ShapeType)
                {
                case ShapeTypes.Point:
                    for (i = 0; i < Count; i++)
                    {
                        PointShape aPS = (PointShape)_graphicList[i].Shape;
                        if (MIMath.PointInExtent(aPS.Point, aExtent))
                        {
                            selectedGraphics.Add(aGraphic);
                        }
                    }
                    break;

                case ShapeTypes.Polyline:
                case ShapeTypes.PolylineZ:
                    for (i = 0; i < Count; i++)
                    {
                        PolylineShape aPLS = (PolylineShape)_graphicList[i].Shape;
                        if (MIMath.IsExtentCross(aExtent, aPLS.Extent))
                        {
                            for (j = 0; j < aPLS.Points.Count; j++)
                            {
                                aPoint = aPLS.Points[j];
                                if (MIMath.PointInExtent(aPoint, aExtent))
                                {
                                    selectedGraphics.Add(aGraphic);
                                    break;
                                }
                            }
                        }
                    }
                    break;

                case ShapeTypes.Polygon:
                case ShapeTypes.Rectangle:
                    for (i = Count - 1; i >= 0; i--)
                    {
                        PolygonShape aPGS = (PolygonShape)_graphicList[i].Shape;
                        if (!(aPGS.PartNum > 1))
                        {
                            if (MIMath.PointInPolygon(aPGS.Points, aPoint))
                            {
                                selectedGraphics.Add(aGraphic);
                            }
                        }
                        else
                        {
                            for (int p = 0; p < aPGS.PartNum; p++)
                            {
                                ArrayList pList = new ArrayList();
                                if (p == aPGS.PartNum - 1)
                                {
                                    for (int pp = aPGS.parts[p]; pp < aPGS.PointNum; pp++)
                                    {
                                        pList.Add(aPGS.Points[pp]);
                                    }
                                }
                                else
                                {
                                    for (int pp = aPGS.parts[p]; pp < aPGS.parts[p + 1]; pp++)
                                    {
                                        pList.Add(aPGS.Points[pp]);
                                    }
                                }
                                if (MIMath.PointInPolygon(pList, aPoint))
                                {
                                    selectedGraphics.Add(aGraphic);
                                    break;
                                }
                            }
                        }
                    }
                    break;
                }
            }

            if (selectedGraphics.Count > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Override paint method
        /// </summary>
        /// <param name="g">graphics</param>
        public override void Paint(Graphics g)
        {
            if (_mapFrame != null)
            {
                g.FillRectangle(new SolidBrush(_mapFrame.MapView.BackColor), _mapFrame.LayoutBounds);

                //Region oldRegion = g.Clip;
                //GraphicsPath path = new GraphicsPath();
                //Rectangle rect = this.Bounds;
                //path.AddRectangle(rect);
                //g.SetClip(path);
                //Matrix oldMatrix = g.Transform;
                //g.TranslateTransform(this.Left, this.Top);

                _mapFrame.MapView.PaintGraphics(g, _mapFrame.LayoutBounds);

                //Draw lon/lat grid labels
                if (_mapFrame.DrawGridLabel)
                {
                    List <Extent> extentList = new List <Extent>();
                    Extent        maxExtent  = new Extent();
                    Extent        aExtent    = new Extent();
                    SizeF         aSF        = new SizeF();
                    SolidBrush    aBrush     = new SolidBrush(this.ForeColor);
                    Pen           aPen       = new Pen(_mapFrame.GridLineColor);
                    aPen.Width = _mapFrame.GridLineSize;
                    string drawStr;
                    PointF sP = new PointF(0, 0);
                    PointF eP = new PointF(0, 0);
                    Font   font = new Font(_mapFrame.GridFont.Name, _mapFrame.GridFont.Size, _mapFrame.GridFont.Style);
                    float  labX, labY;
                    int    len   = 5;
                    int    space = len + 2;
                    for (int i = 0; i < _mapFrame.MapView.GridLabels.Count; i++)
                    {
                        GridLabel aGL = _mapFrame.MapView.GridLabels[i];
                        switch (_mapFrame.GridLabelPosition)
                        {
                        case GridLabelPosition.LeftBottom:
                            switch (aGL.LabDirection)
                            {
                            case Direction.East:
                            case Direction.North:
                                continue;
                            }
                            break;

                        case GridLabelPosition.LeftUp:
                            switch (aGL.LabDirection)
                            {
                            case Direction.East:
                            case Direction.South:
                                continue;
                            }
                            break;

                        case GridLabelPosition.RightBottom:
                            switch (aGL.LabDirection)
                            {
                            case Direction.Weast:
                            case Direction.North:
                                continue;
                            }
                            break;

                        case GridLabelPosition.RightUp:
                            switch (aGL.LabDirection)
                            {
                            case Direction.Weast:
                            case Direction.South:
                                continue;
                            }
                            break;
                        }

                        labX = (float)aGL.LabPoint.X;
                        labY = (float)aGL.LabPoint.Y;
                        labX = labX + this.Left;
                        labY = labY + this.Top;
                        sP.X = labX;
                        sP.Y = labY;

                        drawStr = aGL.LabString;
                        aSF     = g.MeasureString(drawStr, font);
                        switch (aGL.LabDirection)
                        {
                        case Direction.South:
                            labX = labX - aSF.Width / 2;
                            labY = labY + space;
                            eP.X = sP.X;
                            eP.Y = sP.Y + len;
                            break;

                        case Direction.Weast:
                            labX = labX - aSF.Width - space;
                            labY = labY - aSF.Height / 2;
                            eP.X = sP.X - len;
                            eP.Y = sP.Y;
                            break;

                        case Direction.North:
                            labX = labX - aSF.Width / 2;
                            labY = labY - aSF.Height - space;
                            eP.X = sP.X;
                            eP.Y = sP.Y - len;
                            break;

                        case Direction.East:
                            labX = labX + space;
                            labY = labY - aSF.Height / 2;
                            eP.X = sP.X + len;
                            eP.Y = sP.Y;
                            break;
                        }

                        bool  ifDraw = true;
                        float aSize  = aSF.Width / 2;
                        float bSize  = aSF.Height / 2;
                        aExtent.minX = labX;
                        aExtent.maxX = labX + aSF.Width;
                        aExtent.minY = labY - aSF.Height;
                        aExtent.maxY = labY;

                        //Judge extent
                        if (extentList.Count == 0)
                        {
                            maxExtent = aExtent;
                            extentList.Add(aExtent);
                        }
                        else
                        {
                            if (!MIMath.IsExtentCross(aExtent, maxExtent))
                            {
                                extentList.Add(aExtent);
                                maxExtent = MIMath.GetLagerExtent(maxExtent, aExtent);
                            }
                            else
                            {
                                for (int j = 0; j < extentList.Count; j++)
                                {
                                    if (MIMath.IsExtentCross(aExtent, extentList[j]))
                                    {
                                        ifDraw = false;
                                        break;
                                    }
                                }
                                if (ifDraw)
                                {
                                    extentList.Add(aExtent);
                                    maxExtent = MIMath.GetLagerExtent(maxExtent, aExtent);
                                }
                            }
                        }

                        if (ifDraw)
                        {
                            g.DrawLine(aPen, sP, eP);
                            g.DrawString(drawStr, font, aBrush, labX, labY);
                        }
                    }

                    aPen.Dispose();
                    aBrush.Dispose();
                }

                //g.Transform = oldMatrix;
                //g.Clip = oldRegion;

                if (_mapFrame.DrawNeatLine)
                {
                    Pen aPen = new Pen(_mapFrame.NeatLineColor, _mapFrame.NeatLineSize);
                    g.DrawRectangle(aPen, _mapFrame.LayoutBounds);
                    aPen.Dispose();
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Override PaintOnLayout method
        /// </summary>
        /// <param name="g">graphics</param>
        /// <param name="pageLocation">page location</param>
        /// <param name="zoom">zoom</param>
        public override void PaintOnLayout(Graphics g, PointF pageLocation, float zoom)
        {
            if (_mapFrame != null)
            {
                PointF    aP   = PageToScreen(this.Left, this.Top, pageLocation, zoom);
                Rectangle rect = new Rectangle((int)aP.X, (int)aP.Y, (int)(Width * zoom), (int)(Height * zoom));
                g.FillRectangle(new SolidBrush(_mapFrame.MapView.BackColor), rect);

                _mapFrame.MapView.PaintGraphics(g, rect);

                //Draw lon/lat grid labels
                if (_mapFrame.DrawGridLabel || _mapFrame.DrawGridTickLine)
                {
                    List <Extent> extentList = new List <Extent>();
                    Extent        maxExtent  = new Extent();
                    Extent        aExtent    = new Extent();
                    SizeF         aSF        = new SizeF();
                    SolidBrush    aBrush     = new SolidBrush(this.ForeColor);
                    Pen           aPen       = new Pen(_mapFrame.GridLineColor);
                    aPen.Width = _mapFrame.GridLineSize;
                    string drawStr;
                    PointF sP = new PointF(0, 0);
                    PointF eP = new PointF(0, 0);
                    Font   font = new Font(_mapFrame.GridFont.Name, _mapFrame.GridFont.Size * zoom, _mapFrame.GridFont.Style);
                    float  labX, labY;
                    int    len   = _mapFrame.TickLineLength;
                    int    space = len + _mapFrame.GridLabelShift;
                    if (_mapFrame.InsideTickLine)
                    {
                        space = _mapFrame.GridLabelShift;
                    }

                    for (int i = 0; i < _mapFrame.MapView.GridLabels.Count; i++)
                    {
                        GridLabel aGL = _mapFrame.MapView.GridLabels[i];
                        switch (_mapFrame.GridLabelPosition)
                        {
                        case GridLabelPosition.LeftBottom:
                            switch (aGL.LabDirection)
                            {
                            case Direction.East:
                            case Direction.North:
                                continue;
                            }
                            break;

                        case GridLabelPosition.LeftUp:
                            switch (aGL.LabDirection)
                            {
                            case Direction.East:
                            case Direction.South:
                                continue;
                            }
                            break;

                        case GridLabelPosition.RightBottom:
                            switch (aGL.LabDirection)
                            {
                            case Direction.Weast:
                            case Direction.North:
                                continue;
                            }
                            break;

                        case GridLabelPosition.RightUp:
                            switch (aGL.LabDirection)
                            {
                            case Direction.Weast:
                            case Direction.South:
                                continue;
                            }
                            break;
                        }

                        labX = (float)aGL.LabPoint.X;
                        labY = (float)aGL.LabPoint.Y;
                        labX = labX + this.Left * zoom + pageLocation.X;
                        labY = labY + this.Top * zoom + pageLocation.Y;
                        sP.X = labX;
                        sP.Y = labY;

                        drawStr = aGL.LabString;
                        if (_mapFrame.DrawDegreeSymbol)
                        {
                            if (drawStr.EndsWith("E") || drawStr.EndsWith("W") || drawStr.EndsWith("N") || drawStr.EndsWith("S"))
                            {
                                drawStr = drawStr.Substring(0, drawStr.Length - 1) + ((char)186).ToString() + drawStr.Substring(drawStr.Length - 1);
                            }
                            else
                            {
                                drawStr = drawStr + ((char)186).ToString();
                            }
                        }
                        aSF = g.MeasureString(drawStr, font);
                        switch (aGL.LabDirection)
                        {
                        case Direction.South:
                            labX = labX - aSF.Width / 2;
                            labY = labY + space;
                            eP.X = sP.X;
                            if (_mapFrame.InsideTickLine)
                            {
                                eP.Y = sP.Y - len;
                            }
                            else
                            {
                                eP.Y = sP.Y + len;
                            }
                            break;

                        case Direction.Weast:
                            labX = labX - aSF.Width - space;
                            labY = labY - aSF.Height / 2;
                            eP.Y = sP.Y;
                            if (_mapFrame.InsideTickLine)
                            {
                                eP.X = sP.X + len;
                            }
                            else
                            {
                                eP.X = sP.X - len;
                            }
                            break;

                        case Direction.North:
                            labX = labX - aSF.Width / 2;
                            labY = labY - aSF.Height - space;
                            eP.X = sP.X;
                            if (_mapFrame.InsideTickLine)
                            {
                                eP.Y = sP.Y + len;
                            }
                            else
                            {
                                eP.Y = sP.Y - len;
                            }
                            break;

                        case Direction.East:
                            labX = labX + space;
                            labY = labY - aSF.Height / 2;
                            eP.Y = sP.Y;
                            if (_mapFrame.InsideTickLine)
                            {
                                eP.X = sP.X - len;
                            }
                            else
                            {
                                eP.X = sP.X + len;
                            }
                            break;
                        }

                        bool  ifDraw = true;
                        float aSize  = aSF.Width / 2;
                        float bSize  = aSF.Height / 2;
                        aExtent.minX = labX;
                        aExtent.maxX = labX + aSF.Width;
                        aExtent.minY = labY - aSF.Height;
                        aExtent.maxY = labY;

                        //Judge extent
                        if (extentList.Count == 0)
                        {
                            maxExtent = aExtent;
                            extentList.Add(aExtent);
                        }
                        else
                        {
                            if (!MIMath.IsExtentCross(aExtent, maxExtent))
                            {
                                extentList.Add(aExtent);
                                maxExtent = MIMath.GetLagerExtent(maxExtent, aExtent);
                            }
                            else
                            {
                                for (int j = 0; j < extentList.Count; j++)
                                {
                                    if (MIMath.IsExtentCross(aExtent, extentList[j]))
                                    {
                                        ifDraw = false;
                                        break;
                                    }
                                }
                                if (ifDraw)
                                {
                                    extentList.Add(aExtent);
                                    maxExtent = MIMath.GetLagerExtent(maxExtent, aExtent);
                                }
                            }
                        }

                        if (ifDraw)
                        {
                            if (_mapFrame.DrawGridTickLine)
                            {
                                g.DrawLine(aPen, sP, eP);
                            }
                            if (_mapFrame.DrawGridLabel)
                            {
                                g.DrawString(drawStr, font, aBrush, labX, labY);
                            }
                        }
                    }

                    aPen.Dispose();
                    aBrush.Dispose();
                }

                //Draw neat line
                if (_mapFrame.DrawNeatLine)
                {
                    Pen aPen = new Pen(_mapFrame.NeatLineColor, _mapFrame.NeatLineSize);
                    g.DrawRectangle(aPen, rect);
                    aPen.Dispose();
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Override operator / for two station data
        /// </summary>
        /// <param name="aStData">a station data</param>
        /// <param name="bStData">a station data</param>
        /// <returns>result station data</returns>
        public static StationData operator /(StationData aStData, StationData bStData)
        {
            if (!MIMath.IsExtentCross(aStData.DataExtent, bStData.DataExtent))
            {
                return(null);
            }

            StationData     cStData = new StationData();
            List <double[]> cData   = new List <double[]>();
            string          aStid;
            int             stIdx = -1;
            double          minX, maxX, minY, maxY;

            minX = 0;
            maxX = 0;
            minY = 0;
            maxY = 0;
            for (int i = 0; i < aStData.Stations.Count; i++)
            {
                aStid = aStData.Stations[i];
                if (aStid == "99999")
                {
                    continue;
                }

                double aValue = aStData.Data[2, i];
                if (aValue == aStData.MissingValue)
                {
                    //aValue = 0;
                    continue;
                }

                stIdx = bStData.Stations.IndexOf(aStid);
                if (stIdx >= 0)
                {
                    double bValue = bStData.Data[2, stIdx];
                    if (bValue == bStData.MissingValue)
                    {
                        //bValue = 0;
                        continue;
                    }

                    cStData.Stations.Add(aStid);
                    double[] theData = new double[3];
                    theData[0] = aStData.Data[0, i];
                    theData[1] = aStData.Data[1, i];
                    theData[2] = aValue / bValue;
                    cData.Add(theData);

                    if (cStData.Stations.Count == 1)
                    {
                        minX = theData[0];
                        maxX = minX;
                        minY = theData[1];
                        maxY = minY;
                    }
                    else
                    {
                        if (minX > theData[0])
                        {
                            minX = theData[0];
                        }
                        else if (maxX < theData[0])
                        {
                            maxX = theData[0];
                        }
                        if (minY > theData[1])
                        {
                            minY = theData[1];
                        }
                        else if (maxY < theData[1])
                        {
                            maxY = theData[1];
                        }
                    }
                }
            }
            cStData.DataExtent.minX = minX;
            cStData.DataExtent.maxX = maxX;
            cStData.DataExtent.minY = minY;
            cStData.DataExtent.maxY = maxY;
            cStData.Data            = new double[3, cData.Count];
            for (int i = 0; i < cData.Count; i++)
            {
                cStData.Data[0, i] = cData[i][0];
                cStData.Data[1, i] = cData[i][1];
                cStData.Data[2, i] = cData[i][2];
            }

            return(cStData);
        }