Exemplo n.º 1
0
        public static void MovePointWithLine(IFeature pointFeature, List <IFeature> lineFeatures, IPoint targetPoint, double tolerance)
        {
            IPoint linkPoint = pointFeature.Shape as IPoint;

            foreach (IFeature lineFeature in lineFeatures)
            {
                IPolyline linkPolyline = lineFeature.Shape as IPolyline;
                if (linkPolyline == null)
                {
                    continue;
                }
                IPointCollection pointCollection = linkPolyline as IPointCollection;
                if (CommonHelper.GetDistance(linkPolyline.FromPoint, linkPoint) < tolerance)
                {
                    IPoint fromPoint = pointCollection.Point[0];
                    fromPoint.PutCoords(targetPoint.X, targetPoint.Y);
                    pointCollection.UpdatePoint(0, fromPoint);
                }
                else if (CommonHelper.GetDistance(linkPolyline.ToPoint, linkPoint) < tolerance)
                {
                    IPoint toPoint = pointCollection.Point[pointCollection.PointCount - 1];
                    toPoint.PutCoords(targetPoint.X, targetPoint.Y);
                    pointCollection.UpdatePoint(pointCollection.PointCount - 1, toPoint);
                }
                lineFeature.Shape = pointCollection as IPolyline;
                lineFeature.Store();
            }

            linkPoint.PutCoords(targetPoint.X, targetPoint.Y);
            pointFeature.Shape = linkPoint;
            pointFeature.Store();
        }
Exemplo n.º 2
0
 private void listView1_ValueChanged(object sender, ValueChangedEventArgs e)
 {
     try
     {
         IPoint tag = this.listView1.Items[e.Row].Tag as IPoint;
         if (tag != null)
         {
             if (e.Column == 1)
             {
                 tag.X = double.Parse((string)e.NewValue);
             }
             else if (e.Column == 2)
             {
                 tag.Y = double.Parse((string)e.NewValue);
             }
             else if (e.Column == 3)
             {
                 if (this.m_HasZ)
                 {
                     tag.Z = double.Parse((string)e.NewValue);
                 }
                 else
                 {
                     tag.M = double.Parse((string)e.NewValue);
                 }
             }
             else if (e.Column == 4)
             {
                 tag.M = double.Parse((string)e.NewValue);
             }
             if ((this.m_pGeometry is IPolygon) || (this.m_pGeometry is IPolyline))
             {
                 IPointCollection points =
                     (this.m_pGeometry as IGeometryCollection).get_Geometry(this.listBox1.SelectedIndex) as
                     IPointCollection;
                 points.UpdatePoint(e.Row, tag);
                 if ((points as ICurve).IsClosed && (e.Row == 0))
                 {
                     points.UpdatePoint(points.PointCount - 1, tag);
                 }
             }
             IWorkspaceEdit workspace = (this.m_pEditFeature.Class as IDataset).Workspace as IWorkspaceEdit;
             (this.m_pMap as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGeography, null,
                                                         this.m_pEditFeature.Extent);
             workspace.StartEditOperation();
             this.m_pEditFeature.Shape = this.m_pGeometry;
             this.m_pEditFeature.Store();
             workspace.StopEditOperation();
             (this.m_pMap as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGeography, null,
                                                         this.m_pGeometry.Envelope);
             this.SetStatus();
         }
     }
     catch (Exception exception)
     {
         CErrorLog.writeErrorLog(null, exception, "");
     }
 }
Exemplo n.º 3
0
        public override void OnClick()
        {
            frmInputValue1 frmInputValue = new frmInputValue1();

            frmInputValue.Text = "输入偏移值";
            if (frmInputValue.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                double    inputValue  = frmInputValue.InputValue1;
                double    inputValue2 = frmInputValue.InputValue2;
                IGeometry shape       = EditTools.EditFeature.Shape;
                if (shape != null && EditTools.PartIndex != -1 && EditTools.PointIndex != -1 &&
                    (shape.GeometryType == esriGeometryType.esriGeometryPolyline ||
                     shape.GeometryType == esriGeometryType.esriGeometryPolygon))
                {
                    IPointCollection pointCollection =
                        (shape as IGeometryCollection).get_Geometry(EditTools.PartIndex) as IPointCollection;
                    IPoint point = pointCollection.get_Point(EditTools.PointIndex);
                    point.X += inputValue;
                    point.Y += inputValue2;
                    double arg_C5_0 = point.Z;
                    pointCollection.UpdatePoint(EditTools.PointIndex, point);
                    (shape as IGeometryCollection).GeometriesChanged();
                    Yutai.ArcGIS.Common.Editor.Editor.EditWorkspace.StartEditOperation();
                    EditTools.EditFeature.Shape = shape;
                    EditTools.EditFeature.Store();
                    Yutai.ArcGIS.Common.Editor.Editor.EditWorkspace.StopEditOperation();
                    (_context.FocusMap as IActiveView).Refresh();
                }
            }
        }
Exemplo n.º 4
0
        public override void OnDblClick()
        {
            try
            {
                if (_lineFeedback == null)
                {
                    return;
                }
                IPolyline polyline = _lineFeedback.Stop();
                _context.ActiveView.Refresh();
                _lineFeedback = null;
                if (polyline == null)
                {
                    return;
                }

                ISnappingResult snappingResult = _pointSnapper.Snap(polyline.ToPoint);
                if (snappingResult != null)
                {
                    IPointCollection pointCollection = polyline as IPointCollection;
                    pointCollection.UpdatePoint(pointCollection.PointCount - 1, snappingResult.Location);
                }
                CommonHelper.MovePointWithLine(_pointFeature, _lineFeatures, polyline.ToPoint, _tolerance);

                _lineFeedback = null;
                _pointFeature = null;
                _lineFeatures = null;
                _context.ActiveView.Refresh();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 为几何形体增加Z值和M值
        /// </summary>
        /// <param name="pGeo">存储几何形体</param>
        /// <param name="pPointArray">用于更新几何形体Z值、M值的点数组</param>
        public static void AddZMValueForGeometry(ref IGeometry pGeo, IArray pPointArray)
        {
            IPointCollection pPointCol = (IPointCollection)pGeo;

            for (int j = 0; j < pPointCol.PointCount; j++)
            {
                IPoint  pPoint = pPointCol.get_Point(j);
                IZAware pZ     = (IZAware)pPoint;
                pZ.ZAware = true;
                pPoint.Z  = 0;
                IMAware pM = (IMAware)pPoint;
                pM.MAware = true;
                pPoint.M  = 0;

                for (int k = 0; k < pPointArray.Count; k++)
                {
                    IPoint pTempPoint = (IPoint)pPointArray.get_Element(k);
                    if (Math.Abs(pPoint.X - pTempPoint.X) < 0.001 && Math.Abs(pPoint.Y - pTempPoint.Y) < 0.001 && pTempPoint.Z != -999)
                    {
                        pPoint.Z = pTempPoint.Z;
                        pPoint.M = pTempPoint.M;
                        break;
                    }
                }
                pPointCol.UpdatePoint(j, pPoint);
            }

            IZAware pG = (IZAware)pGeo;

            pG.ZAware = true;
            pGeo      = (IGeometry)pPointCol;
        }
Exemplo n.º 6
0
        public override void OnDblClick()
        {
            try
            {
                if (_lineFeedback == null)
                {
                    return;
                }
                IPolyline polyline = _lineFeedback.Stop();
                _context.ActiveView.Refresh();
                _lineFeedback = null;
                if (polyline == null)
                {
                    return;
                }

                ISnappingResult snappingResult = _pointSnapper.Snap(polyline.ToPoint);
                if (snappingResult != null)
                {
                    IPointCollection pointCollection = polyline as IPointCollection;
                    pointCollection.UpdatePoint(pointCollection.PointCount - 1, snappingResult.Location);
                }
                CommonHelper.MovePointWithLine(_pointFeature, _lineFeatures, polyline.ToPoint, _tolerance);
                //IPoint linkPoint = _pointFeature.Shape as IPoint;
                //linkPoint.PutCoords(polyline.ToPoint.X, polyline.ToPoint.Y);
                //_pointFeature.Shape = linkPoint;
                //_pointFeature.Store();

                //foreach (IFeature lineFeature in _lineFeatures)
                //{
                //    IPolyline linkPolyline = lineFeature.Shape as IPolyline;
                //    if (linkPolyline == null)
                //        continue;
                //    IPointCollection pointCollection = linkPolyline as IPointCollection;
                //    if (CommonHelper.GetDistance(linkPolyline.FromPoint, polyline.FromPoint) < _tolerance)
                //    {
                //        IPoint fromPoint = pointCollection.Point[0];
                //        fromPoint.PutCoords(polyline.ToPoint.X, polyline.ToPoint.Y);
                //        pointCollection.UpdatePoint(0, fromPoint);
                //    }
                //    else if (CommonHelper.GetDistance(linkPolyline.ToPoint, polyline.FromPoint) < _tolerance)
                //    {
                //        IPoint toPoint = pointCollection.Point[pointCollection.PointCount - 1];
                //        toPoint.PutCoords(polyline.ToPoint.X, polyline.ToPoint.Y);
                //        pointCollection.UpdatePoint(pointCollection.PointCount - 1, toPoint);
                //    }
                //    lineFeature.Shape = pointCollection as IPolyline;
                //    lineFeature.Store();
                //}
                _lineFeedback = null;
                _pointFeature = null;
                _lineFeatures = null;
                _context.ActiveView.Refresh();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
        public void Update(double newvalue, int row, int column)//x,y一起修改
        {
            IPoint ipoint = (IPoint)pointCollection.Point[row];

            switch (column)
            {
            case 0:
                break;

            case 1:
                ipoint.X = newvalue;
                break;

            case 2:
                ipoint.Y = newvalue;
                break;
            }
            //对于pointCollection进行修改
            pointCollection.UpdatePoint(row, ipoint);
            //清空图像容器
            pGraphicsContainer.DeleteAllElements();

            IGeometry       polygon        = pointCollection as IGeometry;
            IPolygonElement polygonElement = new PolygonElementClass();
            IElement        polyElement    = polygonElement as IElement;

            polyElement.Geometry = polygon;
            pGraphicsContainer.AddElement((IElement)polygonElement, 0);
            m_form.axMapControl1.ActiveView.Refresh();

            for (int i = 0; i < pointCollection.PointCount; i++)
            {
                IMarkerSymbol markerSymbol = new SimpleMarker3DSymbolClass();
                //markerSymbol的类型和分辨率
                ((ISimpleMarker3DSymbol)markerSymbol).Style             = esriSimple3DMarkerStyle.esriS3DMSSphere;
                ((ISimpleMarker3DSymbol)markerSymbol).ResolutionQuality = 1.0;

                //markerSymbol的颜色和大小
                IRgbColor color = new RgbColorClass();
                color.Red   = 255;
                color.Green = 0;
                color.Blue  = 0;

                markerSymbol.Size  = 5;
                markerSymbol.Color = color as IColor;

                IElement pElement = new MarkerElementClass();
                ((IMarkerElement)pElement).Symbol = markerSymbol;
                pElement.Geometry = pointCollection.Point[i];
                pGraphicsContainer.AddElement(pElement, 0);

                /*IElement pElement=new MarkerElementClass();
                *  pElement.Geometry = pointCollection.Point[i];
                *  pGraphicsContainer.AddElement(pElement, 0);*/
            }
            m_form.axMapControl1.ActiveView.Refresh();
        }
Exemplo n.º 8
0
        private void TransCoordiante(IWorkspace pWorkSpace, IFeatureClass pFeatureclass)
        {
            // IWorkspaceEdit workspaceEdit = pWorkSpace as IWorkspaceEdit;
            //workspaceEdit.StartEditing(true);
            // workspaceEdit.StartEditOperation();

            IFeatureCursor pOutFCursor = pFeatureclass.Update(null, true);
            IFeature       pFeature    = pOutFCursor.NextFeature();

            while (pFeature != null)
            {
                // IGeometry pGeometry = pFeature.Shape;
                IPointCollection pPointCollection = pFeature.Shape as IPointCollection;
                if (pPointCollection != null)
                {
                    for (int i = 0; i < pPointCollection.PointCount; i++)
                    {
                        //多边形最后一个点和第一个点是同一个点,改两次又会改回去了
                        if (i == pPointCollection.PointCount - 1)
                        {
                            if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                            {
                                continue;
                            }
                            //IPoint firstpoint = pPointCollection.get_Point(0);
                            //IPoint lastpoint = pPointCollection.get_Point(pPointCollection.PointCount-1);
                        }
                        double tempvalue;
                        IPoint pt = pPointCollection.get_Point(i);
                        tempvalue = pt.Y;
                        pt.Y      = pt.X;
                        pt.X      = tempvalue;
                        pt.Z      = 0 - pt.Z;
                        pPointCollection.UpdatePoint(i, pt);
                    }
                    //pFeature.Shape = pPointCollection as IGeometry;
                    pFeature.Store();
                }
                //不能转为pointcollection 说明是单点
                if (pPointCollection == null)
                {
                    IPoint pt = pFeature.Shape as IPoint;
                    double tempvalue;
                    tempvalue = pt.Y;
                    pt.Y      = pt.X;
                    pt.X      = tempvalue;
                    pt.Z      = 0 - pt.Z;
                    //pFeature.Shape = pt as IGeometry;
                    pFeature.Store();
                }
                pFeature = pOutFCursor.NextFeature();
            }
            //  workspaceEdit.StopEditing(true);
            //  workspaceEdit.StopEditOperation();
        }
Exemplo n.º 9
0
        public void UpdatePoint(int partIndex, int pointIndex, IPoint newPoint)
        {
            // TODO:  添加 ModifyPoint.WSGRI.DigitalFactory.DFQuery.IUpdatePoint.UpdatePoint 实现
            IPointCollection pColl = (IPointCollection)m_GeoColl.get_Geometry(partIndex);

            if ((pointIndex > -1) && (pointIndex < pColl.PointCount))
            {
                pColl.UpdatePoint(pointIndex, newPoint);
                Feature.Shape = m_GeoColl as IGeometry;
                Feature.Store();
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// 鼠标移动实时更新测量线和方位角
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void mapControl_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
 {
     if (isMouseDown && !isControl && e.button == 1)
     {
         IPointCollection pointCollection = lineElement.Geometry as IPointCollection;
         IPoint           point           = new PointClass();
         point.PutCoords(e.mapX, e.mapY);
         pointCollection.UpdatePoint(1, point);
         lineElement.Geometry = pointCollection as IGeometry;
         angle            = GetAngle(e.mapX, e.mapY);
         textElement.Text = string.Format("角度{0}°", angle);
         mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
     }
 }
Exemplo n.º 11
0
 public void SaveEdit()
 {
     try
     {
         Editor.UniqueInstance.StartEditOperation();
         object before  = new object();
         object missing = Type.Missing;
         foreach (LinkArgs args in this._las)
         {
             if (args.PartIndex >= 0)
             {
                 IFeature            feature   = args.feature;
                 IGeometryCollection shapeCopy = feature.ShapeCopy as IGeometryCollection;
                 IPointCollection    points    = shapeCopy.get_Geometry(args.PartIndex) as IPointCollection;
                 for (int i = 0; i < this._editInfoList.Count; i++)
                 {
                     EditInfo info  = this._editInfoList[i] as EditInfo;
                     int      index = args.VertexIndex[i];
                     IPoint   p     = (info.NewPoint as IClone).Clone() as IPoint;
                     if (p.SpatialReference != (EditTask.EditLayer.FeatureClass as IGeoDataset).SpatialReference)
                     {
                         p.Project((EditTask.EditLayer.FeatureClass as IGeoDataset).SpatialReference);
                         p.SpatialReference = (EditTask.EditLayer.FeatureClass as IGeoDataset).SpatialReference;
                     }
                     if (index == 0)
                     {
                         points.UpdatePoint(0, p);
                     }
                     else
                     {
                         points.ReplacePoints(index, 1, 1, ref p);
                     }
                 }
                 shapeCopy.RemoveGeometries(args.PartIndex, 1);
                 before = args.PartIndex;
                 shapeCopy.AddGeometry(points as IGeometry, ref before, ref missing);
                 IGeometry geometry = (IGeometry)shapeCopy;
                 feature.Shape = geometry;
                 feature.Store();
             }
         }
         Editor.UniqueInstance.StopEditOperation("Linkage Edit");
     }
     catch (Exception exception)
     {
         Editor.UniqueInstance.AbortEditOperation();
         this._mErrOpt.ErrorOperate(this._mSubSysName, "ShapeEdit.LinkageEdit", "SaveEdit", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
     }
 }
Exemplo n.º 12
0
        private void buildPolyline(IPointCollection pGonColl, double x, double y)
        {
            m_workPts[0].PutCoords(x - 500, y - 500);
            m_workPts[1].PutCoords(x + 500, y - 500);
            m_workPts[2].PutCoords(x + 500, y + 500);
            m_workPts[3].PutCoords(x - 500, y + 500);
            m_workPts[4].PutCoords(x, y);

            try
            {
                bool add = (pGonColl.PointCount == 0);

                object missingVal = System.Reflection.Missing.Value;
                for (int i = 0; i < m_workPts.Length; i++)
                {
                    ((IZAware)m_workPts[i]).ZAware = m_bZ;
                    ((IMAware)m_workPts[i]).MAware = m_bM;

                    if (m_bM)
                    {
                        m_workPts[i].M = i;
                    }
                    if (m_bZ)
                    {
                        m_workPts[i].Z = i * 100;
                    }
                    //add it point by point - .Net IDL limitation to do batch update?
                    if (add)                                                             //pGonColl.AddPoints(5, ref m_workPts[0]);//strange error of type mismatch
                    {
                        pGonColl.AddPoint(m_workPts[i], ref missingVal, ref missingVal); //The Add method only accepts either a before index or an after index.
                    }
                    else
                    {
                        pGonColl.UpdatePoint(i, m_workPts[i]);
                    }
                }

                //Can I user replace point collection or addPointcollection?
            }

            catch (Exception Ex)
            { System.Diagnostics.Debug.WriteLine(Ex.Message); }
            //Attempted to store an element of the incorrect type into the array.
        }
Exemplo n.º 13
0
 public void OnMouseUp(int button, int shift, int x, int y)
 {
     if ((button == 1) && this._isVertexSelected)
     {
         this._feedBack.Stop();
         this._feedBack.Refresh(this._viewMap.ScreenDisplay.hDC);
         this._endPoint         = this._viewMap.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
         this._isVertexSelected = false;
         IPointCollection linageShape = Editor.UniqueInstance.LinageShape as IPointCollection;
         IPoint           point       = linageShape.get_Point(this._vertexIndex);
         linageShape.UpdatePoint(this._vertexIndex, this._endPoint);
         EditInfo info = new EditInfo {
             VertexIndex = this._vertexIndex,
             OldPoint    = point,
             NewPoint    = this._endPoint
         };
         this._editInfoList.Add(info);
         this._viewMap.PartialRefresh(esriViewDrawPhase.esriViewForeground, Editor.UniqueInstance.TargetLayer, this._editBound.Envelope);
     }
 }
Exemplo n.º 14
0
        //如果是要素具有Z值,则判断该要素的Z值是否有效,
        //无效时对其进行剪切后赋值给新的要素时会出错
        public static bool ValidateZValue(ref IGeometry pDesGeometry)
        {
            IZAware          pZAware = default(IZAware);
            IPoint           pPnt    = default(IPoint);
            IPointCollection pPntCol = default(IPointCollection);
            int    i            = 0;
            double dZ           = 0;
            int    lValidPntNum = 0;

            pZAware = (IZAware)pDesGeometry;
            if (pZAware.ZAware == true)
            {
                if (pZAware.ZSimple == false)
                {
                    pPntCol = (IPointCollection)pDesGeometry;
                    //取所有有效点的高程平均值
                    for (i = 0; i <= pPntCol.PointCount - 1; i++)
                    {
                        pPnt    = pPntCol.get_Point(i);
                        pZAware = (IZAware)pPnt;
                        if (pZAware.ZSimple == true)
                        {
                            dZ           = dZ + pPnt.Z;
                            lValidPntNum = lValidPntNum + 1;
                        }
                    }
                    dZ = dZ / lValidPntNum;
                    for (i = 0; i <= pPntCol.PointCount - 1; i++)
                    {
                        pPnt    = pPntCol.get_Point(i);
                        pZAware = (IZAware)pPnt;
                        if (pZAware.ZSimple == false)
                        {
                            pPnt.Z = dZ;
                            pPntCol.UpdatePoint(i, pPnt);
                        }
                    }
                }
            }
            return(true);
        }
Exemplo n.º 15
0
        /// <summary>
        /// 编辑点移动事件
        /// </summary>
        /// <param name="element"></param>
        /// <param name="e"></param>
        void editPoint_MarkerMouseMoveEvent(IElement element, IMapControlEvents2_OnMouseMoveEvent e)
        {
            IPoint point;

            if (isControlDown)
            {
                IPointCollection pointCollection = polygonElement.Geometry as IPointCollection;
                double           x = currentPoint.X - e.mapX;
                double           y = currentPoint.Y - e.mapY;
                for (int i = 0; i < pointCollection.PointCount - 1; i++)
                {
                    point    = pointCollection.get_Point(i);
                    point.X -= x; point.Y -= y;
                    pointCollection.UpdatePoint(i, point);
                }
                foreach (var item in markerList)
                {
                    point    = item.Geometry as IPoint;
                    point.X -= x;
                    point.Y -= y;
                    item.MoveTo(point);
                }
                polygonElement.Geometry = pointCollection as IGeometry;
                mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, polygonElement, null);
            }
            else
            {
                IPointCollection pointCollection = polygonElement.Geometry as IPointCollection;

                IPoint newPoint = new PointClass();
                newPoint.PutCoords(e.mapX, e.mapY);
                currentMarker.MoveTo(newPoint);
                pointCollection.UpdatePoint(int.Parse(currentMarker.Name), newPoint);

                polygonElement.Geometry = pointCollection as IGeometry;
                mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, polygonElement, null);
            }
            currentPoint = new PointClass();
            currentPoint.PutCoords(e.mapX, e.mapY);
        }
Exemplo n.º 16
0
        private void buildPolygon(IPointCollection pGonColl, double x, double y)
        {
            m_workPts[0].PutCoords(x - 500, y - 500);
            m_workPts[1].PutCoords(x + 500, y - 500);
            m_workPts[2].PutCoords(x + 500, y + 500);
            m_workPts[3].PutCoords(x - 500, y + 500);
            m_workPts[4].PutCoords(x - 500, y - 500);
            try
            {
                bool   add        = (pGonColl.PointCount == 0);
                object missingVal = System.Reflection.Missing.Value;

                for (int i = 0; i < m_workPts.Length; i++)
                {
                    ((IZAware)m_workPts[i]).ZAware = m_bZ;
                    ((IMAware)m_workPts[i]).MAware = m_bM;

                    if (m_bM)
                    {
                        m_workPts[i].M = i % 4;
                    }
                    if (m_bZ)
                    {
                        m_workPts[i].Z = (i % 4) * 100;                         //match start and end points
                    }
                    if (add)
                    {
                        pGonColl.AddPoint(m_workPts[i], ref missingVal, ref missingVal);                                //The Add method only accepts either a before index or an after index.
                    }
                    else
                    {
                        pGonColl.UpdatePoint(i, m_workPts[i]);
                    }
                }
            }

            catch (Exception Ex)
            { System.Diagnostics.Debug.WriteLine(Ex.Message); }
            //Attempted to store an element of the incorrect type into the array.
        }
Exemplo n.º 17
0
        //点集合坐标转换
        private void PointCollCoordConvert(double A1, double B1, double C1, double A2, double B2, double C2, double A3, double C3, ref IPointCollection pPointCollection)
        {
            IArray pArray = new ArrayClass();

            for (int i = 0; i < pPointCollection.PointCount; i++)
            {
                pArray.Add(pPointCollection.get_Point(i));
            }

            double X, Y, Z, M;

            for (int i = 0; i < pPointCollection.PointCount; i++)
            {
                X = (pArray.get_Element(i) as Point).X;
                Y = (pArray.get_Element(i) as Point).Y;
                Z = (pArray.get_Element(i) as Point).Z;
                M = (pArray.get_Element(i) as Point).M;


                IPoint pTempPoint = new PointClass();
                pTempPoint.Y = A1 * Y + B1 * X + C1;
                pTempPoint.X = A2 * Y + B2 * X + C2;

                if (Z == 0)
                {
                    C3 = 0;
                }

                pTempPoint.Z = A3 * Z + C3;
                pTempPoint.M = M;

                pPointCollection.UpdatePoint(i, pTempPoint);
            }

            pArray = null;
        }
Exemplo n.º 18
0
        private void KalibreerVormpuntenOpBasisVanSpoorhartlijn(IFeatureSelection FeatureSelectionMShape)
        {
            #region Bepaal de overlappende extent van raaien en selectie
            IGeoDataset GeoDatasetMShape = flMShape as IGeoDataset;
            IGeoDataset GeodatasetLRS    = fcLRS as IGeoDataset;

            IEnvelope pQueryingGeometryFullExtent = GeoDatasetMShape.Extent;
            pQueryingGeometryFullExtent.Union(GeodatasetLRS.Extent);
            pQueryingGeometryFullExtent.Expand(10000, 10000, false);
            #endregion Bepaal de overlappende extent van raaien en selectie

            int featurecount   = FeatureSelectionMShape.SelectionSet.Count;
            int featurecounter = 0;

            ICursor SelectionCursor = null;

            if (featurecount == 0)
            {
                SelectionCursor = ((FeatureSelectionMShape as IFeatureLayer).FeatureClass.Search(null, false)) as ICursor;
                featurecount    = (FeatureSelectionMShape as IFeatureLayer).FeatureClass.FeatureCount(null);
            }
            else
            {
                FeatureSelectionMShape.SelectionSet.Search(null, false, out SelectionCursor);
            }

            IPolyline        Polyline        = null;
            IPolygon         buffer          = null;
            IPointCollection PointCollection = null;

            IList <IPolyline> PolylinesLRS = null;

            try
            {
                IFeature feature = SelectionCursor.NextRow() as IFeature;
                while (feature != null)
                {
                    Polyline        = feature.ShapeCopy as IPolyline;
                    PointCollection = Polyline as IPointCollection;

                    #region lees de begin- en eindkilometrering en het selectie criterium
                    double m_begin  = (Polyline as IPointCollection).get_Point(0).M;
                    double m_eind   = (Polyline as IPointCollection).get_Point((Polyline as IPointCollection).PointCount - 1).M;
                    string sleutel1 = Convert.ToString(feature.get_Value(feature.Fields.FindField(this.mshape_sleutel1)));
                    string sleutel2 = null;
                    if (this.mshape_sleutel2 != "")
                    {
                        sleutel2 = Convert.ToString(feature.get_Value(feature.Fields.FindField(this.mshape_sleutel2)));
                    }

                    #endregion

                    // Selecteer alle LRS lijnen binnen de zoekafstand
                    ISpatialFilter SpatialFilter = new SpatialFilter();
                    IQueryFilter   QueryFilter   = SpatialFilter;

                    buffer = (Polyline as ITopologicalOperator).Buffer(Properties.Settings.Default.mshape_maxafstand) as IPolygon;

                    SpatialFilter.Geometry      = buffer;
                    SpatialFilter.GeometryField = fcLRS.ShapeFieldName;
                    string whereclauseLRS = Properties.Settings.Default.lrs_selectie;
                    SpatialFilter.WhereClause = string.Format(whereclauseLRS, sleutel1, sleutel2);
                    SpatialFilter.SpatialRel  = esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects;

                    ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = fcLRS.Search(QueryFilter, false);

                    try
                    {
                        PolylinesLRS = new List <IPolyline>();
                        IFeature featureLRS = featureCursor.NextFeature();
                        while (featureLRS != null)
                        {
                            PolylinesLRS.Add(featureLRS.ShapeCopy as IPolyline);
                            featureLRS = featureCursor.NextFeature();
                        }
                    }
                    catch
                    {
                        throw;
                    }
                    finally
                    {
                        ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(featureCursor);
                    }

                    // Controleer of er een spoorhartlijn (LRS) in de buurt ligt. Zo niet, dan evt. markeren
                    if ((PolylinesLRS.Count == 0) && (this.MarkeerLijnBuitenZoekAfstand))
                    {
                        _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Polyline, this.KleurLijnBuitenZoekAfstand, this.KleurLijnBuitenZoekAfstand);
                        // Als er geen spoorhartlijn (LRS) in de buurt ligt, dan hoeven ook niet alle vormpunten doorlopen te worden.
                        continue; // while (feature != null)
                    }

                    #region Doorloop alle vormpunten en werk de vormpunten bij
                    bool   bUpdated         = false;
                    bool   bNietMonotoon    = false;
                    bool   outPointGevonden = false;
                    double pDistance        = 0;

                    for (int i = 1; i < PointCollection.PointCount - 1; i++) // sla het eerste en het laatste punt over
                    {
                        // zoek de dichtstbijzijnde feature, eventueel aangevuld met geocode in een queryfilter
                        IPoint Point    = PointCollection.get_Point(i);
                        IPoint outPoint = new ESRI.ArcGIS.Geometry.Point();
                        outPointGevonden = false;
                        pDistance        = double.PositiveInfinity;
                        bUpdated         = false;

                        this.ZoekPuntOpSpoorhartlijn(Point, PolylinesLRS, m_begin, m_eind, out outPoint, out outPointGevonden, out pDistance);
                        if (this.LogVormpunten)
                        {
                            if (outPointGevonden)
                            {
                                this._ArcObjectsHelper.LogRecord(logtable, feature.OID, i, Point.X, Point.Y, Point.M, outPoint.X, outPoint.Y, outPoint.M);
                            }
                            else
                            {
                                this._ArcObjectsHelper.LogRecord(logtable, feature.OID, i, Point.X, Point.Y, Point.M, Point.X, Point.Y, Point.M);
                            }
                        }

                        // Als er een punt gevonden is, binnen de zoekafstand en binnen het kilometerinterval
                        if (outPointGevonden)
                        {
                            if (Math.Abs((Point as IPoint).M - outPoint.M) > (this.VerschilVormpuntMetAfwijking / 1000))
                            {
                                if (MarkeerVormpuntMetAfwijking)
                                {
                                    _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntMetAfwijking, this.KleurVormpuntMetAfwijking);
                                }
                            }

                            if ((pDistance > this.AfstandVormpuntBuitenZoekAfstand) && (this.MarkeerVormpuntBuitenZoekAfstand))
                            {
                                _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntBuitenZoekAfstand, this.KleurVormpuntBuitenZoekAfstand);
                            }

                            Point.M = outPoint.M;

                            PointCollection.UpdatePoint(i, Point);
                            bUpdated = true;
                        }
                        else if ((!outPointGevonden) && (outPoint != null)) // er is wel een punt gevonden, maar niet binnen het kilometerinterval.
                        {
                            // Als er een punt buiten het kilometerinterval gevonden is, binnen de zoekafstand, markeer het punt dan
                            if ((this.MarkeerVormpuntMetAfwijking) && (Math.Abs((Point as IPoint).M - outPoint.M) > (this.VerschilVormpuntMetAfwijking / 1000)))
                            {
                                _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntMetAfwijking, this.KleurVormpuntMetAfwijking);
                            }

                            if ((this.MarkeerVormpuntBuitenInterval) && !(between(m_begin, m_eind, outPoint.M, (TolerantieVormpuntBuitenInterval / 1000))))
                            {
                                _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntBuitenInterval, this.KleurVormpuntBuitenInterval);
                            }

                            if ((pDistance > this.AfstandVormpuntBuitenZoekAfstand) && (this.MarkeerVormpuntBuitenZoekAfstand))
                            {
                                _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntBuitenZoekAfstand, this.KleurVormpuntBuitenZoekAfstand);
                            }
                        }
                        else if (!outPointGevonden) // er is geen punt gevonden binnen de zoekafstand
                        {
                            if (this.MarkeerVormpuntBuitenZoekAfstand)
                            {
                                _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntBuitenZoekAfstand, this.KleurVormpuntBuitenZoekAfstand);
                            }
                        }

                        #region Markeer de bijgewerkte en niet bijgewerkte punten
                        if ((bUpdated) && (this.MarkeerVormpuntBijgewerkt))
                        {
                            _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntBijgewerkt, this.KleurVormpuntBijgewerkt);
                        }
                        if (!(bUpdated) && (this.MarkeerVormpuntNietBijgewerkt))
                        {
                            _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntNietBijgewerkt, this.KleurVormpuntNietBijgewerkt);
                        }
                        #endregion
                    }
                    #endregion // doorloop de vormpunten

                    #region Reset begin- en eindkilometer
                    this.ResetBeginEnEindMeasure(Polyline, m_begin, m_eind, false);
                    #endregion

                    #region Controleer of de lijn monotoon oplopend of aflopend is en markeer de lijn.
                    int MMonotonicity = ((PointCollection as IMSegmentation3).MMonotonicity);
                    if (MMonotonicity == 5 || MMonotonicity == 7 || MMonotonicity == 15)
                    {
                        bNietMonotoon = true;
                        if (this.MarkeerLijnNietMonotoon)
                        {
                            _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, PointCollection as IPolyline, this.KleurLijnNietMonotoon, this.KleurLijnNietMonotoon);
                        }
                    }

                    if ((bNietMonotoon) && (this.OpslaanLijnNietMonotoon))
                    {
                        feature.Shape = (PointCollection as IGeometry);
                        // UpdateCursor.UpdateFeature(feature);
                    }
                    else if (!bNietMonotoon)
                    {
                        feature.Shape = (PointCollection as IGeometry);
                    }
                    #endregion

                    // Voortgang
                    featurecounter += 1;
                    this.progress   = (100 * featurecounter) / featurecount;

                    // Bijwerken
                    feature.Store();

                    // Volgende feature
                    feature = SelectionCursor.NextRow() as IFeature;
                }
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Er is een onverwachte fout opgetreden; raadpleeg de logfile: " + ex.Message + ": " + ex.StackTrace, "Foutmelding");
                logger.LogException(LogLevel.Trace, "FOUT", ex);
                throw;
            }
            finally
            {
                ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(SelectionCursor);
            }
        }
		private void buildPolyline(IPointCollection pGonColl, double x, double y)
		{
			m_workPts[0].PutCoords(x - 500, y - 500);
			m_workPts[1].PutCoords(x + 500, y - 500);
			m_workPts[2].PutCoords(x + 500, y + 500);
			m_workPts[3].PutCoords(x - 500, y + 500);
			m_workPts[4].PutCoords(x, y);

			try
			{
				bool add = (pGonColl.PointCount == 0);
			
					object missingVal = System.Reflection.Missing.Value;
					for (int i = 0; i< m_workPts.Length; i++)
					{
						((IZAware)m_workPts[i]).ZAware = m_bZ;
						((IMAware)m_workPts[i]).MAware = m_bM;

						if (m_bM)
							m_workPts[i].M =  i;
						if (m_bZ)
							m_workPts[i].Z = i * 100;
						//add it point by point - .Net IDL limitation to do batch update?
						if (add)	//pGonColl.AddPoints(5, ref m_workPts[0]);//strange error of type mismatch
							pGonColl.AddPoint(m_workPts[i], ref missingVal, ref missingVal);	//The Add method only accepts either a before index or an after index.	
						else
							pGonColl.UpdatePoint(i, m_workPts[i]);
					}

				//Can I user replace point collection or addPointcollection?
			}

			catch (Exception Ex)
			{System.Diagnostics.Debug.WriteLine(Ex.Message);}	
			//Attempted to store an element of the incorrect type into the array.
		}
        private void EditMouseUp(IPoint pPnt)
        {
            IPolygon       pPolyResult;
            IPolyline      pPolylineResult;
            IFeatureCursor pFeatureCursor;
            IFeature       pFeature;
            IFeatureLayer  pFeatLyr = m_EngineEditLayers.TargetLayer;

            //检查编辑的地物
            if (m_editDispFeed != null)
            {
                switch (m_pHitElem.Geometry.GeometryType)
                {
                case esriGeometryType.esriGeometryLine:
                case esriGeometryType.esriGeometryPolyline:
                    pPolylineResult = m_polylineMvPtFeed.Stop();
                    //作有效性检查
                    if ((pPolylineResult != null))
                    {
                        //更新元素
                        m_pHitElem.Geometry = pPolylineResult;

                        //获取选中的地物
                        pFeatureCursor = MapManager.GetSelectedFeatures(pFeatLyr);
                        if (pFeatureCursor == null)
                        {
                            return;
                        }
                        pFeature = pFeatureCursor.NextFeature();
                        m_EngineEditor.StartOperation();
                        //更新要素形状
                        pFeature.Shape = pPolylineResult;
                        pFeature.Store();
                        //停止编辑
                        m_EngineEditor.StopOperation("MoveVertex");
                        EditVertexClass.ShowAllVertex(pFeatLyr);
                    }
                    break;

                case esriGeometryType.esriGeometryPolygon:
                case esriGeometryType.esriGeometryEnvelope:
                    //得到反馈的结果
                    pPolyResult = m_polyMvPtFeed.Stop();
                    //作有效性检查
                    if (pPolyResult != null)
                    {
                        //更新元素
                        m_pHitElem.Geometry = pPolyResult;
                        //获取选中的地物
                        pFeatureCursor = MapManager.GetSelectedFeatures(pFeatLyr);
                        if (pFeatureCursor == null)
                        {
                            return;
                        }
                        pFeature = pFeatureCursor.NextFeature();
                        m_EngineEditor.StartOperation();
                        //更新要素形状
                        pFeature.Shape = pPolyResult;
                        pFeature.Store();
                        //停止编辑
                        m_EngineEditor.StopOperation("MoveVertex");
                        if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon ||
                            pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
                        {
                            EditVertexClass.ShowAllVertex(pFeatLyr);
                        }
                    }
                    IFeature pTempParcel;
                    //定义存储多边形要素的局部变量
                    IPoint pDestPoint;
                    //定义节点移动的目标位置
                    pDestPoint = pPnt;
                    IZAware pZAware = pDestPoint as IZAware;
                    pZAware.ZAware = true;
                    pDestPoint.Z   = 0;
                    //所有包含该节点的多边形都进行操作
                    for (int i = 0; i <= EditVertexClass.m_featArray.Count - 1; i++)
                    {
                        pTempParcel = EditVertexClass.m_featArray.get_Element(i) as IFeature;
                        //记录节点序号
                        int pIndex = 0;
                        pIndex = EditVertexClass.GetVertexIndex(m_fromPoint, pTempParcel.Shape);
                        if (!(pIndex == -2))
                        {
                            ITopologicalOperator pTopoOpt         = default(ITopologicalOperator);
                            IPolygon             pPolygon         = default(IPolygon);
                            IPointCollection     pPolygonPointCol = default(IPointCollection);
                            pPolygonPointCol = pTempParcel.ShapeCopy as IPointCollection;
                            pPolygonPointCol.UpdatePoint(pIndex, pDestPoint);
                            pPolygon = pPolygonPointCol as IPolygon;
                            pPolygon.Close();
                            pTopoOpt = pPolygon as ITopologicalOperator;
                            pTopoOpt.Simplify();
                            pTempParcel.Shape = pPolygon;
                            pTempParcel.Store();
                        }
                    }
                    EditVertexClass.m_featArray.RemoveAll();
                    break;
                }

                //释放内存
                m_polyMvPtFeed     = null;
                m_polylineMvPtFeed = null;
                m_editDispFeed     = null;
                m_pHitElem         = null;
                //刷新地图
                m_activeView.Refresh();
            }
        }
		private void buildPolygon(IPointCollection pGonColl, double x, double y)
		{
			m_workPts[0].PutCoords(x - 500, y - 500);
			m_workPts[1].PutCoords(x + 500, y - 500);
			m_workPts[2].PutCoords(x + 500, y + 500);
			m_workPts[3].PutCoords(x - 500, y + 500);
			m_workPts[4].PutCoords(x - 500, y - 500);
			try
			{
				bool add = (pGonColl.PointCount == 0);
				object missingVal = System.Reflection.Missing.Value;
					
				for (int i = 0; i< m_workPts.Length; i++)
				{
					((IZAware)m_workPts[i]).ZAware = m_bZ;
					((IMAware)m_workPts[i]).MAware = m_bM;

					if (m_bM)
						m_workPts[i].M = i % 4;
					if (m_bZ)
						m_workPts[i].Z = (i % 4) * 100;	//match start and end points
						
					if (add)
						pGonColl.AddPoint(m_workPts[i], ref missingVal, ref missingVal);	//The Add method only accepts either a before index or an after index.	
					else
						pGonColl.UpdatePoint(i, m_workPts[i]);
				}
			}

			catch (Exception Ex)
			{System.Diagnostics.Debug.WriteLine(Ex.Message);}	
			//Attempted to store an element of the incorrect type into the array.
		}