示例#1
0
文件: Form1.cs 项目: vijaysm/ENigMA
        private void DrawLineDistance(PaintEventArgs e)
        {
            var aPoint1 = new GeoCoordinate(10.0, 2.0 * trackBar1.Value + 10.0, 0.0);
            var aPoint2 = new GeoCoordinate(400.0, 400.0, 0.0);

            var aPoint3 = new GeoCoordinate(10.0, 10.0, 0.0);
            var aPoint4 = new GeoCoordinate(400.0, 3.5 * trackBar1.Value + 10.0, 0.0);

            var aLine1 = new GeoLine(aPoint1, aPoint2);
            var aLine2 = new GeoLine(aPoint3, aPoint4);

            DrawLine(e, aLine1, Color.FromArgb(255, 255, 0, 0));
            DrawLine(e, aLine2, Color.FromArgb(255, 0, 255, 0));

            var aPoint5 = new GeoCoordinate();
            var aPoint6 = new GeoCoordinate();

            double aDistance;

            if (aLine1.distance(aLine2, aPoint5, aPoint6, out aDistance))
            {
                DrawPoint(e, aPoint5, Color.FromArgb(255, 0, 0, 255), 10);
                DrawPoint(e, aPoint6, Color.FromArgb(255, 0, 0, 255), 10);

                label1.Text = aDistance.ToString();
            }
        }
示例#2
0
    public void SetWriting(Vector3[] pos, string fomula)
    {
        GeoLine line = new GeoLine(index, pos, fomula);

        currentfomula = fomula;
        lines.Add(line);
        AddGeoLine(line);
        index += 1;

        //增加极值点

        /*Vector3[] res = GetExtreme(pos);
         * VertexSpace u0 = new VertexSpace(res[0].x, res[0].y, 0);
         * VertexSpace u0x = new VertexSpace(res[0].x, 0, 0);
         * VertexSpace u0y = new VertexSpace(0, res[0].y, 0);
         * AddBaseVertex(u0);
         * GeoVertex v0 = new GeoVertex(u0, true);
         * AddGeoVertex(v0);
         * GeoEdge e0x = new GeoEdge(u0, u0x, true);
         * GeoEdge e0y = new GeoEdge(u0, u0y, true);
         * AddGeoEdge(e0x);
         * AddGeoEdge(e0y);
         *
         * VertexSpace u1 = new VertexSpace(res[1].x, res[1].y, 0);
         * VertexSpace u1x = new VertexSpace(res[1].x, 0, 0);
         * VertexSpace u1y = new VertexSpace(0, res[1].y, 0);
         * AddBaseVertex(u1);
         * GeoVertex v1 = new GeoVertex(u1, true);
         * AddGeoVertex(v1);
         * GeoEdge e1x = new GeoEdge(u1, u1x, true);
         * GeoEdge e1y = new GeoEdge(u1, u1y, true);
         * AddGeoEdge(e1x);
         * AddGeoEdge(e1y);*/
    }
示例#3
0
        private void Map1_Loaded(object sender, RoutedEventArgs e)
        {
            Map1.MapUnit = GeoUnit.Meter;
            Map1.UseOpenStreetMapAsBaseMap();

            GeoLine greatCircle = CreateGreatCircle();

            MemoryLayer baselineLayer = new MemoryLayer {
                Name = "BaseLineLayer"
            };

            baselineLayer.Styles.Add(new LineStyle(GeoColors.White, 8));
            baselineLayer.Styles.Add(new LineStyle(GeoColor.FromHtml("#88FAB04D"), 4));
            baselineLayer.Features.Add(new Feature(greatCircle));
            Map1.AddStaticLayers(baselineLayer);

            Stream airplaneIconStream = Application.GetResourceStream(new Uri("/SlimGis.WpfSamples;component/Images/airplane.png", UriKind.RelativeOrAbsolute)).Stream;

            MemoryLayer highlightLayer = new MemoryLayer {
                Name = "HighlightLayer"
            };

            highlightLayer.Styles.Add(new LineStyle(GeoColor.FromHtml("#9903A9F4"), 4));
            highlightLayer.Styles.Add(new IconStyle(new GeoImage(airplaneIconStream))
            {
                AspectRatio = 0.6667
            });
            Map1.AddDynamicLayers("HighlightOverlay", highlightLayer);

            GeoBound bound = baselineLayer.GetBound();

            bound.ScaleUp(25);
            Map1.ZoomTo(bound);
        }
示例#4
0
        private GeoMultiLine CreateMultiLine()
        {
            GeoLine line1 = new GeoLine();
            GeoLine line2 = new GeoLine();

            double startX                  = Map1.CurrentBound.MinX + Map1.CurrentBound.Width * .15;
            double endX                    = Map1.CurrentBound.MinX + Map1.CurrentBound.Width * .85;
            double height                  = Map1.CurrentBound.Height * .25;
            double centerY1                = Map1.CurrentCenter.Y + height;
            double centerY2                = Map1.CurrentCenter.Y - height;
            int    segmentCount            = 30;
            double segmentHorizontalLength = (endX - startX) / segmentCount;

            for (int i = 0; i < segmentCount; i++)
            {
                double x1 = startX + segmentHorizontalLength * i;
                double y1 = Math.Sin(Math.PI * 2 * i / segmentCount) * height + centerY1;
                line1.Coordinates.Add(new GeoCoordinate(x1, y1));

                double x2 = startX + segmentHorizontalLength * i;
                double y2 = Math.Cos(Math.PI * 2 * i / segmentCount) * height + centerY2;
                line2.Coordinates.Add(new GeoCoordinate(x2, y2));
            }

            GeoMultiLine multiLine = new GeoMultiLine();

            multiLine.Lines.Add(line1);
            multiLine.Lines.Add(line2);
            return(multiLine);
        }
示例#5
0
    private void RemoveLine(GeoLine geoLine)
    {
        LineBehaviour lineBehaviour = lineMap[geoLine];

        Destroy(lineBehaviour.gameObject);
        lineMap.Remove(geoLine);
    }
示例#6
0
        private async Task MoveLine(MemoryLayer highlightLayer, GeoLine baseline, double percentageRatio, int i, bool reverse = false)
        {
            GeoLine line = await Task.Run(() => (GeoLine)baseline.GetSegmentation((float)percentageRatio *i));

            highlightLayer.Features.Clear();

            if (line != null)
            {
                highlightLayer.Features.Add(new Feature(line));

                GeoCoordinate currentPoint = line.Coordinates.Last();
                highlightLayer.Features.Add(new Feature(new GeoPoint(currentPoint)));
                if (line.Coordinates.Count > 1)
                {
                    GeoCoordinate previousPoint = line.Coordinates.ElementAt(line.Coordinates.Count - 2);
                    double        angle         = Math.Atan2(currentPoint.Y - previousPoint.Y, currentPoint.X - previousPoint.X);
                    float         degree        = (float)(angle * 180 / Math.PI);
                    if (reverse)
                    {
                        degree = degree + 180;
                    }
                    highlightLayer.Styles.OfType <IconStyle>().First().Rotation = degree;
                }
            }
            Map1.Refresh("HighlightOverlay");

            await Task.Run(() => Thread.Sleep(50));
        }
        public void Polygons()
        {
            GeoLine line = new GeoLine(
                new[]
                {
                    new GeoPosition(0, 0),
                    new GeoPosition(0, 1),
                    new GeoPosition(1, 1),
                    new GeoPosition(0, 0),
                });
            Assert.AreEqual(
                "geo.intersects(Foo, geography'POLYGON((0 0,0 1,1 1,0 0))')",
                SearchFilter.Create($"geo.intersects(Foo, {line})"));

            GeoPolygon polygon = new GeoPolygon(new[] { line });
            Assert.AreEqual(
                "geo.intersects(Foo, geography'POLYGON((0 0,0 1,1 1,0 0))')",
                SearchFilter.Create($"geo.intersects(Foo, {polygon})"));

            Assert.Throws<ArgumentException>(() => SearchFilter.Create(
                $"{new GeoLine(new[] { new GeoPosition(0, 0) })}"));
            Assert.Throws<ArgumentException>(() => SearchFilter.Create(
                $"{new GeoLine(new[] { new GeoPosition(0, 0), new GeoPosition(0, 0), new GeoPosition(0, 0), new GeoPosition(1, 1) })}"));
            Assert.Throws<ArgumentException>(() => SearchFilter.Create(
                $"{new GeoPolygon(new[] { line, line })}"));
        }
示例#8
0
 /// <inheritdoc />
 /// <summary>
 ///     Extraction Constructor, requires filling out of an <see cref="T:Dxflib.Entities.EntityBuffer" />
 /// </summary>
 /// <param name="lineBuffer">
 ///     The Line Buffer that was filled
 ///     in the extraction process
 /// </param>
 public Line(LineBuffer lineBuffer) : base(lineBuffer)
 {
     EntityType = lineBuffer.EntityType;
     Thickness  = lineBuffer.Thickness;
     // Setting the GeoLine
     GLine = new GeoLine(new Vertex(lineBuffer.X0, lineBuffer.Y0),
                         new Vertex(lineBuffer.X1, lineBuffer.Y1));
 }
示例#9
0
 public void HighlightLine(GeoLine line)
 {
     foreach (KeyValuePair <GeoLine, LineBehaviour> item in lineMap)
     {
         item.Value.ChangeColor(0);
     }
     lineMap[line].ChangeColor(1);
 }
        /// <summary>
        /// 进行网络分析分析
        /// </summary>
        public void BeginNetworkAnalyst()
        {
            try
            {
                mAnalystResult = mAnalyst.FindTSPPath(mAnalystParameter, false);
                if (mAnalystResult != null)
                {
                    int[][] EdgeId = new int[mAnalystResult.Edges.Length][];
                    //拿到交错数组中第一行元素ID
                    int[] IDedge = new int[mAnalystResult.Edges[0].Length];
                    for (int i = 0; i < IDedge.Length; i++)
                    {
                        IDedge[i] = mAnalystResult.Edges[0][i];
                    }
                    //拿到弧段ID后查询路名
                    string[]  RodeName  = new string[IDedge.Length];
                    Recordset recordset = null;
                    for (int i = 0; i < IDedge.Length; i++)
                    {
                        recordset         = mRodeNetWork.Query("SmID =" + IDedge[i], CursorType.Static);
                        RodeName[i]       = recordset.GetFieldValue("RodeName").ToString().Trim();
                        mRodeTotalLength += Convert.ToInt32(recordset.GetFieldValue("SmLength"));
                    }
                    //编辑路名显示形式
                    string mStartRode = "起点→";
                    string mNewRode   = null;
                    for (int i = 0; i < RodeName.Length; i++)
                    {
                        if (i == 0)
                        {
                            mNewRode = mStartRode.Insert(mStartRode.Length, RodeName[i] + "→");
                        }
                        else
                        {
                            mNewRode = mNewRode.Insert(mNewRode.Length, RodeName[i] + "→");
                        }
                    }
                    mTextBoxRodeName = mNewRode + "终点";
                }
                GeoLine line = mAnalystResult.Routes[0].ConvertToLine();
                if (mLine3D == null)
                {
                    mLine3D = new GeoLine3D();
                }

                for (Int32 i = 0; i < line.PartCount; i++)
                {
                    mLine3D.AddPart(line[i].ToPoint3Ds());
                }
                mLine3D[0].Insert(0, new Point3D(mStartPoint.X, mStartPoint.Y, 0));
                mLine3D[0].Add(new Point3D(mEndPoint.X, mEndPoint.Y, 0));
                DisplayFlyRoute();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
示例#11
0
        /// <summary>
        /// 对象选择事件。
        /// GeometrySelectedEvent
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void m_mapControl_GeometrySelected(Object sender, SuperMap.UI.GeometrySelectedEventArgs e)
        {
            if (m_selectMode != SelectMode.SelectBarrier)
            {
                return;
            }
            Selection selection = m_layerPoint.Selection;

            if (selection.Count <= 0)
            {
                selection = m_layerLine.Selection;
            }
            GeoStyle style = new GeoStyle();

            style.LineColor = Color.Red;
            Recordset recordset = selection.ToRecordset();

            try
            {
                Geometry geometry = recordset.GetGeometry();

                // 捕捉到点时,将捕捉到的点添加到障碍点列表中
                // If a point is snapped, the point is added to the barrier list
                if (geometry.Type == GeometryType.GeoPoint)
                {
                    GeoPoint geoPoint = (GeoPoint)geometry;
                    int      id       = recordset.GetID();
                    m_barrierNodes.Add(id);
                    style.MarkerSize = new Size2D(4, 4);
                    geoPoint.Style   = style;
                    m_trackingLayer.Add(geoPoint, "barrierNode");
                }

                // 捕捉到线时,将线对象添加到障碍线列表中
                // If a line is snapped, the line is added to the barrier list
                if (geometry.Type == GeometryType.GeoLine)
                {
                    GeoLine geoLine = (GeoLine)geometry;
                    int     id      = recordset.GetID();
                    m_barrierEdges.Add(id);

                    style.LineWidth = 0.6;
                    geoLine.Style   = style;
                    m_trackingLayer.Add(geoLine, "barrierEdge");
                }
                m_mapControl.Map.Refresh();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
            finally
            {
                recordset.Dispose();
            }
        }
示例#12
0
        private async Task MovePoint(MemoryLayer highlightLayer, GeoLine baseline, double percentageRatio, int i)
        {
            GeoPoint point = await Task.Run(() => baseline.GetPoint((float)percentageRatio *i));

            highlightLayer.Features.Clear();
            highlightLayer.Features.Add(new Feature(point));
            Map1.Refresh("HighlightOverlay");

            await Task.Run(() => Thread.Sleep(50));
        }
        private void 开始模拟ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                geoStyle_P.MarkerAngle = 14.0;
                geoStyle_P.MarkerSize  = new Size2D(5, 5);
                geoStyle_P.LineColor   = Color.Red;
                平抛运动 open = new 平抛运动();
                open.ShowDialog();
                str = open.name();
                ts  = open.con();
                Map     map = mapControl1.Map;
                bool    h   = true;
                Point2D p   = map.Center;
                Point2D pl  = map.Center;
                int     m   = 0;
                Xx = ts.Keys.ToList <double>();
                Yy = ts.Values.ToList <double>();

                Point2Ds point2Ds = new Point2Ds();
                for (int i = 0; i < Xx.Count; i++)
                {
                    Point2D point2D = new Point2D(Xx[i], Yy[i]);
                    point2Ds.Add(point2D);
                }
                GeoLine geoLine = new GeoLine(point2Ds);
                mapControl1.Map.TrackingLayer.Add(geoLine, "线");
                mapControl1.Map.Refresh();
                foreach (var t in ts)
                {
                    if (h)
                    {
                        p.X = t.Key;
                        p.Y = t.Value + 10;
                        h   = false;
                    }
                    m++;
                    if (m == ts.Count)
                    {
                        pl.X = t.Key;
                        pl.Y = t.Value;
                    }
                }
                Rectangle2D rectangle = new Rectangle2D(p, pl);
                mapControl1.Map.ViewBounds = rectangle;
                mapControl1.Map.Refresh();
                this.timer1.Enabled = true;
            }
            catch
            {
                MessageBox.Show("模拟失败,请确保参数输入正确");
            }
        }
示例#14
0
        private DatasetVector DatasetConvertRegionToLine(DatasetVector dtVector2)
        {
            DatasetVector dtVector = null;

            if (dtVector2 != null)
            {
                DatasetVectorInfo dvi = new DatasetVectorInfo();
                dvi.Name = m_selLayer.Dataset.Datasource.Datasets.GetAvailableDatasetName("C_geoLine");
                dvi.Type = DatasetType.Line;

                //DatasetVector
                dtVector = m_selLayer.Dataset.Datasource.Datasets.Create(dvi);
                foreach (FieldInfo fi in dtVector2.FieldInfos)
                {
                    if (dtVector.FieldInfos.IndexOf(fi.Name) < 0 && !fi.IsSystemField)
                    {
                        dtVector.FieldInfos.Add(fi.Clone());
                    }
                }

                Recordset recdst = dtVector.GetRecordset(true, CursorType.Dynamic);

                recdst.Batch.Begin();
                try
                {
                    Recordset recdst2 = dtVector2.GetRecordset(false, CursorType.Static);
                    while (!recdst2.IsEOF)
                    {
                        GeoRegion geoR = recdst2.GetGeometry() as GeoRegion;

                        if (geoR != null)
                        {
                            GeoLine geoLine = geoR.ConvertToLine();
                            recdst.AddNew(geoLine);
                            foreach (FieldInfo fi in dtVector2.FieldInfos)
                            {
                                if (dtVector.FieldInfos.IndexOf(fi.Name) > -1 && !fi.IsSystemField)
                                {
                                    recdst.SetFieldValue(fi.Name, recdst2.GetFieldValue(fi.Name));
                                }
                            }
                            geoR.Dispose();
                        }
                        recdst2.MoveNext();
                    }
                    recdst2.Dispose();
                }
                catch { }
                recdst.Batch.Update();
                recdst.Dispose();
            }
            return(dtVector);
        }
示例#15
0
        /// <summary>
        /// MapControl MouseMove事件。
        /// MapControl MouseMove event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void m_mapControl_MouseMove(object sender, MouseEventArgs e)
        {
            try
            {
                m_mapControl.DoMouseMove(e);
                if (m_mapControl.Action == SuperMap.UI.Action.Select ||
                    m_mapControl.Action == SuperMap.UI.Action.Select2)
                {
                    // 获取鼠标点对应的地图点
                    // Get the map point that corresponds to the mouse point
                    m_mousePoint = new Point(e.X, e.Y);
                    Point2D point2D = m_mapControl.Map.PixelToMap(m_mousePoint);

                    // 根据当前比例尺设置捕捉框的大小
                    // Set the snap box size according to the current scale
                    double    scale     = (3 * 10E-4) / m_mapControl.Map.Scale;
                    Selection selection = m_layerPoint.HitTest(point2D, 4 / 3 * scale);
                    int       index     = m_trackingLayer.IndexOf("geoLine");
                    if (index != -1)
                    {
                        m_trackingLayer.Remove(index);
                    }
                    if (selection != null && selection.Count > 0)
                    {
                        Recordset recordset = selection.ToRecordset();
                        GeoPoint  geoPoint  = (GeoPoint)recordset.GetGeometry();
                        recordset.Dispose();
                        double pointX = geoPoint.X;
                        double pointY = geoPoint.Y;

                        // 构造捕捉框
                        // Build snap box
                        Point2Ds point2Ds = new Point2Ds();
                        point2Ds.Add(new Point2D(pointX - scale, pointY - scale));
                        point2Ds.Add(new Point2D(pointX + scale, pointY - scale));
                        point2Ds.Add(new Point2D(pointX + scale, pointY + scale));
                        point2Ds.Add(new Point2D(pointX - scale, pointY + scale));
                        point2Ds.Add(new Point2D(pointX - scale, pointY - scale));
                        GeoLine geoLine = new GeoLine(point2Ds);

                        // 刷新地图
                        // Refresh the map
                        m_mapControl.SelectionTolerance = 2;
                        m_trackingLayer.Add(geoLine, "geoLine");
                        m_mapControl.Map.Refresh();
                    }
                }
            }
            catch (System.Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
示例#16
0
        /// <summary>
        /// 打开需要的工作空间文件及地图
        /// </summary>
        private void Initialize()
        {
            try
            {
                //初始化点线面
                m_point = new GeoPoint(25, 25);

                Point2Ds point2DsLine = new Point2Ds();
                point2DsLine.Add(new Point2D(5, 35));
                point2DsLine.Add(new Point2D(65, 35));
                m_line = new GeoLine(point2DsLine);

                Point2Ds point2DsRegion = new Point2Ds();
                point2DsRegion.Add(new Point2D(5, 5));
                point2DsRegion.Add(new Point2D(5, 69));
                point2DsRegion.Add(new Point2D(69, 69));
                point2DsRegion.Add(new Point2D(69, 5));
                m_region = new GeoRegion(point2DsRegion);
                //初始化点线面符号的风格
                m_markerGeoStyle            = new GeoStyle();
                m_markerGeoStyle.LineColor  = Color.Blue;
                m_markerGeoStyle.MarkerSize = new Size2D(12, 12);
                m_point.Style = m_markerGeoStyle;

                m_lineGeoStyle           = new GeoStyle();
                m_lineGeoStyle.LineColor = Color.Blue;
                m_lineGeoStyle.LineWidth = 0.5;
                m_line.Style             = m_lineGeoStyle;

                m_fillGeoStyle = new GeoStyle();
                m_fillGeoStyle.FillForeColor  = Color.Blue;
                m_fillGeoStyle.FillBackOpaque = false;
                m_region.Style = m_fillGeoStyle;

                // 得到点线面的RootGroup
                Resources     resources           = m_workspace.Resources;
                SymbolLibrary symbolMarkerLibrary = resources.MarkerLibrary;
                m_symbolMarkerRootGroup = symbolMarkerLibrary.RootGroup;

                SetTreeGroup(m_symbolMarkerRootGroup);

                SymbolLibrary symbolLineLibrary = resources.LineLibrary;
                m_symbolLineRootGroup = symbolLineLibrary.RootGroup;

                SymbolLibrary symbolFillLibrary = resources.FillLibrary;
                m_symbolFillRootGroup = symbolFillLibrary.RootGroup;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#17
0
        private static Marker GetVehicle(int index, GeoLine route)
        {
            Marker vehicle = new Marker();

            vehicle.DropShadow      = false;
            vehicle.OffsetY         = 4;
            vehicle.RenderTransform = new RotateTransform {
                CenterX = 17, CenterY = 7
            };
            vehicle.ImageSource = new BitmapImage(new Uri($"pack://application:,,,/Resources/vehicle-{vehicleColors[index % vehicleColors.Length]}.png", UriKind.RelativeOrAbsolute));
            vehicle.Location    = route.GetVertices().First();
            return(vehicle);
        }
示例#18
0
    //generate function line
    public void AddLine(GeoLine geoLine)
    {
        if (!lineMap.ContainsKey(geoLine))
        {
            GameObject planeObject = new GameObject(geoLine.ToString());
            planeObject.transform.SetParent(lineWrapper.transform);

            LineBehaviour lineBehaviour = planeObject.AddComponent <LineBehaviour>();
            lineBehaviour.Init(geoLine, geoCamera);
            lineMap.Add(geoLine, lineBehaviour);
            elementMap.Add(geoLine, lineBehaviour);
            HighlightLine(geoLine);
        }
    }
示例#19
0
    public void Init(GeoLine geoLine, GeoCamera geoCamera)
    {
        lineRenderer            = gameObject.AddComponent <LineRenderer>();
        lineRenderer.material   = new Material(Shader.Find("Sprites/Default"));
        lineRenderer.startWidth = LINE_WIDTH;
        lineRenderer.endWidth   = LINE_WIDTH;
        Color color = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), 1f);

        lineRenderer.startColor = new Color(0.5f, 0.5f, 0.5f, 1);
        lineRenderer.endColor   = new Color(0.5f, 0.5f, 0.5f, 1);
        positions = geoLine.Position();
        lineRenderer.positionCount = positions.Length;
        lineRenderer.SetPositions(positions);
    }
示例#20
0
        private async Task MoveLine(MemoryLayer highlightLayer, GeoLine baseline, double percentageRatio, int i)
        {
            GeoLinearBase line = await Task.Run(() => baseline.GetSegmentation((float)percentageRatio *i));

            highlightLayer.Features.Clear();

            if (line != null)
            {
                highlightLayer.Features.Add(new Feature(line));
            }
            Map1.Refresh("HighlightOverlay");

            await Task.Run(() => Thread.Sleep(50));
        }
示例#21
0
        //设置区划中心点和边界
        private void SetRegionInfo(csGovRegion csGR)
        {
            try
            {
                //获取GIS信息
                Recordset recdst2 = GetRecordsetByCode(csGR.RegionCode);

                if (recdst2 != null && recdst2.RecordCount > 0)
                {
                    csGR.RegionCenter = new csCenter();
                    csGR.RegionBounds = new csBounds();
                    GeoLine geoLine1 = recdst2.GetGeometry() as GeoLine;
                    csGR.RegionCenter.center = GetCenterPoint(csGR.RegionCode);
                    double dKey = 10714896 / 111000 / 0.08;
                    while (!recdst2.IsEOF)
                    {
                        try
                        {
                            GeoLine geoLine2 = recdst2.GetGeometry() as GeoLine;

                            for (int i = 0; i < geoLine2.PartCount; i++)
                            {
                                GeoLine geoL    = new GeoLine(geoLine2[i]);
                                GeoLine geoLine = null;
                                if (geoL[0].Count < 400)
                                {
                                    geoLine = geoL;
                                }
                                else
                                {
                                    double dTolerance = geoL.Length / dKey;
                                    {
                                        //dTolerance = GetTolerance(csGR.RegionCode);
                                    }
                                    geoLine = Geometrist.Resample(geoL, ResampleType.RTGeneral, dTolerance) as GeoLine;
                                }
                                csGR.RegionBounds.bounds.Add(geoLine[0].Clone());
                            }
                        }
                        catch (SystemException sysEx)
                        {
                            string strErr = sysEx.Message;
                        }
                        recdst2.MoveNext();
                    }
                }
            }
            catch {}
        }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            MemoryLayer resultLayer = Map1.FindLayer <MemoryLayer>("ResultLayer");

            if (resultLayer.Features.Count == 0)
            {
                GeoMultiLine shortestResult = await Task.Run(() => feature1.Geometry.GetShortestLineTo(feature2.Geometry));

                GeoLine shortestLine = shortestResult.Lines.First();

                resultLayer.Features.Add(new Feature(shortestLine));
                resultLayer.Features.Add(new Feature(new GeoPoint(shortestLine.Coordinates.First())));
                resultLayer.Features.Add(new Feature(new GeoPoint(shortestLine.Coordinates.Last())));
                Map1.Refresh("ResultOverlay");
            }
        }
示例#23
0
        /// <summary>
        /// 按距离求线段及延长线上的点
        /// </summary>
        /// <param name="distance"></param>
        /// <returns></returns>
        public static Point2D findPointOnWholeLinesByDistance(this GeoLine refLine, double distance)
        {
            Point2D resultPoint = new Point2D();
            //GeoLine refLine = new GeoLine(new Point2Ds(p1, p2));
            double dl = refLine.Length;

            if (distance <= dl)
            {
                resultPoint = refLine.FindPointOnLineByDistance(distance);
            }
            else
            {
                resultPoint = findPointOnExtensionLinesByDistance(refLine[0][0], refLine[0][1], distance - dl);
            }
            return(resultPoint);
        }
示例#24
0
        public void ChangeingVertexReference_ShouldUpdateGeometry()
        {
            // Set up
            var vertex0  = new Vertex(0, 0);
            var vertex1  = new Vertex(3, 4);
            var testLine = new GeoLine(vertex0, vertex1);

            // Length should be 5
            Assert.IsTrue(Math.Abs(testLine.Length - 5) < GeoMath.Tolerance);

            // Change the vertex to see if lenght updates
            testLine.Vertex0 = new Vertex(3, 0);

            // Lenght should now be 4
            Assert.IsTrue(Math.Abs(testLine.Length - 4) < GeoMath.Tolerance);
        }
示例#25
0
        /// <summary>
        /// 鼠标移动时绘制捕捉框
        /// Draw the snap box when the mouse moves
        /// </summary>
        /// <param name="point"></param>
        public void SetBound(Point point)
        {
            try
            {
                // 清除跟踪图层上的捕捉框
                // Clear snap box on the tracking layer
                Int32 indexSnapPane = m_trackingLayer.IndexOf("snapPane");
                if (indexSnapPane != -1)
                {
                    m_trackingLayer.Remove(indexSnapPane);
                    m_mapControl.Map.RefreshTrackingLayer();
                }

                // 将屏幕坐标转换为地图坐标
                // Transform the pixel coordinates to the map coordinates
                Point2D mapPoint = m_mapControl.Map.PixelToMap(point);

                Double scale = (3 * 10E-4) / m_mapControl.Map.Scale;
                m_selection = m_layerStop.HitTest(mapPoint, 4 / 3 * scale);
                if (m_selection != null && m_selection.Count > 0)
                {
                    Recordset recordset = m_selection.ToRecordset();
                    GeoPoint  stopPoint = recordset.GetGeometry() as GeoPoint;

                    // 构造捕捉框
                    // Build the snap box
                    Point2Ds points = new Point2Ds();
                    points.Add(new Point2D(stopPoint.X - scale, stopPoint.Y - scale));
                    points.Add(new Point2D(stopPoint.X + scale, stopPoint.Y - scale));
                    points.Add(new Point2D(stopPoint.X + scale, stopPoint.Y + scale));
                    points.Add(new Point2D(stopPoint.X - scale, stopPoint.Y + scale));
                    points.Add(new Point2D(stopPoint.X - scale, stopPoint.Y - scale));
                    GeoLine snapPane = new GeoLine(points);

                    m_mapControl.SelectionTolerance = 2.0;
                    m_trackingLayer.Add(snapPane, "snapPane");
                    m_mapControl.Map.RefreshTrackingLayer();

                    recordset.Dispose();
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
示例#26
0
 /// <summary>
 /// 线型颜色改变事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void buttonLineColor_Click(object sender, EventArgs e)
 {
     try
     {
         if (colorDialog2.ShowDialog() == DialogResult.OK)
         {
             GeoLine line = pictureBoxLine.Tag as GeoLine;
             line.Style.LineColor      = colorDialog2.Color;
             buttonLineColor.BackColor = colorDialog2.Color;
             DrawSymbol(m_symbol, line, pictureBoxLine.Size.Width, pictureBoxLine.Size.Height, pictureBoxLine);
             m_lineStyle.LineColor = line.Style.LineColor;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
示例#27
0
        public void ChangeVertexProperty_UpdateLengthCheck()
        {
            // Set up
            var vertex0  = new Vertex(0, 0);
            var vertex1  = new Vertex(3, 4);
            var testLine = new GeoLine(vertex0, vertex1);

            // The length should be 5
            Assert.IsTrue(Math.Abs(testLine.Length - 5) < GeoMath.Tolerance);

            // Changing the vertex property should recalcuate the length
            testLine.Vertex0.X = 3;
            testLine.Vertex1.Y = 3;


            // The length should now be 4
            Assert.IsTrue(Math.Abs(testLine.Length - 3) < GeoMath.Tolerance);
        }
示例#28
0
        public void GenericGeoPolylineTest_1Arc()
        {
            // Line 0
            var v0 = new Vertex(3.5, 0);
            var v1 = new Vertex(6, 0);
            var l0 = new GeoLine(v0, v1);

            Assert.IsTrue(Math.Abs(l0.Length - 2.5) < GeoMath.Tolerance);

            // Line 1
            var v2 = new Vertex(6, 2.5);
            var l1 = new GeoLine(v1, v2);

            Assert.IsTrue(Math.Abs(l1.Length - 2.5) < GeoMath.Tolerance);

            // Arc
            var          centerPoint = new Vertex(4.75, 1.75);
            var          startAngle  = GeoMath.DegToRad(30.964);
            var          endAngle    = GeoMath.DegToRad(149.036);
            const double radius      = 1.4577;
            var          arc0        = new GeoArc(centerPoint, startAngle, endAngle, radius);

            Assert.IsTrue(Math.Abs(arc0.Length - 3.0040) < GeoMath.Tolerance);

            // Line 2
            var v3 = new Vertex(3.5, 2.5);
            var l2 = new GeoLine(v3, v0);

            Assert.IsTrue(Math.Abs(l2.Length - 2.5) < GeoMath.Tolerance);

            // GeoPolyline
            var geoPolyline = new GeoPolyline(); // Initialized

            // Adding sections to the GeoPolyline
            geoPolyline.Add(l0);
            geoPolyline.Add(l1);
            geoPolyline.Add(arc0);
            geoPolyline.Add(l2);

            // Assert
            Assert.IsTrue(Math.Abs(geoPolyline.Length - 10.5040) < GeoMath.Tolerance);
            Assert.IsTrue(Math.Abs(geoPolyline.Area - 7.5021) < GeoMath.Tolerance);
        }
示例#29
0
        public void InterpolateHeight(Int32 count)
        {
            Point2Ds curPoint2Ds = new Point2Ds();
            Point2Ds point2Ds    = new Point2Ds();

            for (int i = 0; i < m_point3Ds.Count; i++)
            {
                curPoint2Ds.Add(new Point2D(m_point3Ds[i].X, m_point3Ds[i].Y));
                GeoCardinal geoCardinal = new GeoCardinal(curPoint2Ds);
                GeoLine     geoLine     = geoCardinal.ConvertToLine(count);
                double      dLength     = geoLine.Length;
                Point2D     point2D     = new Point2D(dLength, m_point3Ds[i].Z);
                point2Ds.Add(point2D);
            }

            GeoCardinal geoCardinalHeight = new GeoCardinal(point2Ds);
            GeoLine     geoLineHeight     = geoCardinalHeight.ConvertToLine(count);

            for (Int32 i = 0; i < m_point3DsAll.Count; i++)
            {
                Point3D point3D = new Point3D(m_point3DsAll[i].X, m_point3DsAll[i].Y, geoLineHeight[0][i].Y);
                m_point3DsAll[i] = point3D;
            }

            Int32 indexLine = scontrol.Scene.TrackingLayer.IndexOf("line");

            m_geoLine3D.SetEmpty();
            m_geoLine3D.AddPart(m_point3DsAll);

            if (indexLine > 0)
            {
                scontrol.Scene.TrackingLayer.Set(indexLine, m_geoLine3D);
            }
            else
            {
                scontrol.Scene.TrackingLayer.Add(m_geoLine3D, "line");
            }

            SetPointStyle3D(m_index.ToString(), true);

            m_flyManager.Routes.Remove(0);
            m_flyManager.Routes.Add(GetRoute());
        }
        // Support for both Azure.Core.GeoJson and Microsoft.Spatial encoding are duplicated
        // below to avoid extraneous allocations for adapters and to consolidate them to a single
        // source file for easier maintenance.

#if EXPERIMENTAL_SPATIAL
        /// <summary>
        /// Encodes a polygon for use in OData filters.
        /// </summary>
        /// <param name="line">The <see cref="GeoLine"/> to encode.</param>
        /// <returns>The OData filter-encoded POLYGON string.</returns>
        /// <exception cref="ArgumentException">The <paramref name="line"/> has fewer than 4 points, or the first and last points do not match.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="line"/> or <see cref="GeoLine.Positions"/> is null.</exception>
        public static string EncodePolygon(GeoLine line)
        {
            Argument.AssertNotNull(line, nameof(line));
            Argument.AssertNotNull(line.Positions, $"{nameof(line)}.{nameof(line.Positions)}");

            if (line.Positions.Count < 4)
            {
                throw new ArgumentException(
                          $"A {nameof(GeoLine)} must have at least four {nameof(GeoLine.Positions)} to form a searchable polygon.",
                          $"{nameof(line)}.{nameof(line.Positions)}");
            }
            else if (line.Positions[0] != line.Positions[line.Positions.Count - 1])
            {
                throw new ArgumentException(
                          $"A {nameof(GeoLine)} must have matching first and last {nameof(GeoLine.Positions)} to form a searchable polygon.",
                          $"{nameof(line)}.{nameof(line.Positions)}");
            }

            StringBuilder odata = new StringBuilder("geography'POLYGON((");

            bool first = true;

            foreach (GeoPosition position in line.Positions)
            {
                if (!first)
                {
                    odata.Append(",");
                }
                else
                {
                    first = false;
                }

                odata.Append(JsonSerialization.Double(position.Longitude, CultureInfo.InvariantCulture))
                .Append(" ")
                .Append(JsonSerialization.Double(position.Latitude, CultureInfo.InvariantCulture));
            }

            return(odata
                   .Append("))'")
                   .ToString());
        }