Пример #1
0
        /// <summary>
        /// ���ݵ㼯���������Ҫ��
        /// </summary>
        /// <params name="featureLayer"></params>
        /// <params name="lstPoint"></params>
        public void CreateLine(IFeatureLayer featureLayer, List<IPoint> lstPoint, int ID)
        {
            //try
            //{
            IFeatureClass featureClass = featureLayer.FeatureClass;
            if (featureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
            {
                IPointCollection multipoint = new MultipointClass();
                if (lstPoint.Count < 2)
                {
                    MessageBox.Show(@"��ѡ���������������ϵ�����", "��ʾ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                ISegmentCollection pPath = new PathClass();
                ILine pLine;
                ISegment pSegment;
                object o = Type.Missing;
                for (int i = 0; i < lstPoint.Count - 1; i++)
                {
                    pLine = new LineClass();
                    pLine.PutCoords(lstPoint[i], lstPoint[i + 1]);
                    pSegment = pLine as ISegment;
                    pPath.AddSegment(pSegment, ref o, ref o);
                }
                IGeometryCollection pPolyline = new PolylineClass();
                pPolyline.AddGeometry(pPath as IGeometry, ref o, ref o);

                IDataset dataset = (IDataset)featureClass;
                IWorkspace workspace = dataset.Workspace;
                IWorkspaceEdit workspaceEdit = workspace as IWorkspaceEdit;

                workspaceEdit.StartEditing(true);
                workspaceEdit.StartEditOperation();

                IFeature feature = featureClass.CreateFeature();

                IGeometry geometry = pPolyline as IGeometry;
                DrawCommon.HandleZMValue(feature, geometry);//����ͼ��Zֵ����

                feature.Shape = pPolyline as PolylineClass;
                int iFieldID = feature.Fields.FindField(GIS_Const.FIELD_BID);
                feature.Value[iFieldID] = ID.ToString();
                feature.Store();
                workspaceEdit.StopEditOperation();
                workspaceEdit.StopEditing(false);

                IEnvelope envelop = feature.Shape.Envelope;
                DataEditCommon.g_pMyMapCtrl.ActiveView.Extent = envelop;
                DataEditCommon.g_pMyMapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null);
            }
            else
            {
                MessageBox.Show(@"��ѡ����ͼ�㡣", "��ʾ", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            //}
            //catch
            //{
            //    return;
            //}
        }
Пример #2
0
 static void Main(string[] args)
 {
     string path = Directory.GetCurrentDirectory();
     string totalPath = Path.Combine(path, "V2PublishFixtureMessage.Json");
     //You can also use path+ directory but this is better
     // Make sure to not include any \\ infront of the file name.
     // It will give you an error.
     PathClass p = new PathClass();
     p.ReadAFile(totalPath);
     Console.Read();
 }
Пример #3
0
        private void DrawCircleByCenterAndRadius(ILayer pLayer, IBezierCurveGEN pCircularArc, IScreenDisplay pScreenDisplay)
        {
            object o = Type.Missing;
            if (pLayer != null)
            {
                ISegmentCollection pSegmentCollection = null;
                pSegmentCollection = new PathClass();
                if (pLayer is IFeatureLayer)
                {
                    IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
                    IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                    if (pFeatureClass != null)
                    {

                        ISegment pSegment = pCircularArc as ISegment;
                        pSegmentCollection.AddSegment(pSegment, ref o, ref o);
                        IGeometryCollection pPolyline = new PolylineClass();
                        //ͨ��IGeometryCollectionΪPolyline�������Path����
                        pPolyline.AddGeometry(pSegmentCollection as IGeometry, ref o, ref o);

                        m_pMap.ClearSelection();

                        IFeature pCircleFeature = pFeatureClass.CreateFeature();
                        pCircleFeature.Shape = pPolyline as PolylineClass;
                        pCircleFeature.Store();

                        m_pMap.SelectFeature(m_pCurrentLayer, pCircleFeature);

                        IActiveView pActiveView = (IActiveView)m_pMap;
                        m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null);
                        //�ֲ�ˢ��
                        IInvalidArea pInvalidArea = new InvalidAreaClass();
                        pInvalidArea.Add(pPolyline);

                        pInvalidArea.Display = m_hookHelper.ActiveView.ScreenDisplay;
                        pInvalidArea.Invalidate((short)esriScreenCache.esriAllScreenCaches);
                    }
                }
            }
        }
        ///方法1:根据点要素直接生产线要素,《参考绘制巷道》
        /// <summary>
        /// 根据点集坐标绘制线要素
        /// </summary>
        /// <params name="featureLayer"></params>
        /// <params name="lstPoint"></params>
        public static void CreateLine(IFeatureLayer featureLayer, List<IPoint> lstPoint, string ID)
        {
            try
            {
                IFeatureClass featureClass = featureLayer.FeatureClass;
                if (featureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                {
                    IPointCollection multipoint = new MultipointClass();
                    if (lstPoint.Count < 2)
                    {
                        MessageBox.Show(@"请选择两个及两个以上点数。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    ISegmentCollection pPath = new PathClass();
                    ILine pLine;
                    ISegment pSegment;
                    object o = Type.Missing;
                    for (int i = 0; i < lstPoint.Count - 1; i++)
                    {
                        pLine = new LineClass();
                        pLine.PutCoords(lstPoint[i], lstPoint[i + 1]);
                        pSegment = pLine as ISegment;
                        pPath.AddSegment(pSegment, ref o, ref o);
                    }
                    IGeometryCollection pPolyline = new PolylineClass();
                    pPolyline.AddGeometry(pPath as IGeometry, ref o, ref o);

                    IDataset dataset = (IDataset)featureClass;
                    IWorkspace workspace = dataset.Workspace;
                    IWorkspaceEdit workspaceEdit = workspace as IWorkspaceEdit;
                    workspaceEdit.StartEditing(false);
                    workspaceEdit.StartEditOperation();

                    IFeature feature = featureClass.CreateFeature();

                    IGeometry geometry = pPolyline as IGeometry;
                    DrawCommon.HandleZMValue(feature, geometry);//几何图形Z值处理

                    feature.Shape = pPolyline as PolylineClass;
                    int iFieldID = feature.Fields.FindField("BID");
                    feature.Value[iFieldID] = ID.ToString();
                    feature.Store();
                    workspaceEdit.StopEditOperation();
                    workspaceEdit.StopEditing(true);
                    IEnvelope envelop = feature.Shape.Envelope;
                    DataEditCommon.g_pMyMapCtrl.ActiveView.Extent = envelop;
                    GIS.Common.DataEditCommon.g_pMyMapCtrl.ActiveView.Extent.Expand(1.5, 1.5, true);
                    GIS.Common.DataEditCommon.g_pMyMapCtrl.Map.SelectFeature(featureLayer, feature);
                    GIS.Common.DataEditCommon.g_pMyMapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, null, null);

                    //DataEditCommon.g_pMyMapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null);
                }
                else
                {
                    MessageBox.Show(@"请选择线图层。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch
            {
                return;
            }
        }
Пример #5
0
        /// <summary>
        /// 绘制曲线部分
        /// </summary>
        /// <params name="lyr">推断断层</params>
        /// <params name="newplines">延长点构造的线</params>
        /// <params name="originlines">原始点构造的线</params>
        private void AddCurveToMap(IFeatureLayer lyr, List<IPolyline> newplines, List<IPolyline> originlines)
        {
            IFeatureClass Featureclass = lyr.FeatureClass;
            IWorkspaceEdit workspace = (IWorkspaceEdit)(Featureclass as IDataset).Workspace;
            workspace.StartEditing(true);
            workspace.StartEditOperation();
            object missing = Type.Missing;
            //揭露断层上的曲线对象
            IGeometry geom = new PolylineClass();
            geom.SpatialReference = Global.spatialref;
            IGeometryCollection outgeomcols = geom as IGeometryCollection;
            IFeature fea = Featureclass.CreateFeature();
            ISegmentCollection newpath = new PathClass();
            int kindpos = Featureclass.Fields.FindField(GIS.GIS_Const.FIELD_TYPE);
            int bidpos = Featureclass.Fields.FindField(GIS.GIS_Const.FIELD_BID);
            for (int i = 0; i < newplines.Count; i++)
            {
                ILine lin = new LineClass();
                lin.SpatialReference = Global.spatialref;
                //直线段
                IPath path = new PathClass();
                if (i == 0)
                {
                    lin.FromPoint = newplines[i].FromPoint;
                    lin.ToPoint = originlines[i].ToPoint;
                }
                else if (i == originlines.Count - 1)
                {
                    lin.FromPoint = originlines[i].FromPoint;
                    lin.ToPoint = newplines[i].ToPoint;
                }
                else
                {
                    lin.FromPoint = originlines[i].FromPoint;
                    lin.ToPoint = originlines[i].ToPoint;
                }
                newpath.AddSegment(lin as ISegment, ref missing, ref missing);
                //曲线段
                if (i < newplines.Count - 1)
                {
                    IBezierCurveGEN bezier = new BezierCurveClass();
                    IPoint[] pntcontrols = new IPoint[4];
                    pntcontrols[0] = originlines[i].ToPoint;
                    pntcontrols[1] = newplines[i].ToPoint;
                    pntcontrols[2] = newplines[i + 1].FromPoint;
                    pntcontrols[3] = originlines[i + 1].FromPoint;
                    bezier.PutCoords(ref pntcontrols);

                    newpath.AddSegment(bezier as ISegment, ref missing, ref missing);
                }
            }
            outgeomcols.AddGeometry(newpath as IGeometry, ref missing, ref missing);
            int index = fea.Fields.FindField(GIS_Const.FIELD_SHAPE);
            IGeometryDef geometryDef = fea.Fields.get_Field(index).GeometryDef as IGeometryDef;
            if (geometryDef.HasZ)
            {
                IZAware pZAware = (IZAware)outgeomcols;
                pZAware.ZAware = true;
            }
            fea.Shape = outgeomcols as IPolyline;
            fea.set_Value(kindpos, 1);
            fea.set_Value(bidpos, BID);
            fea.Store();
            //外围曲线绘制
            ITopologicalOperator2 top = outgeomcols as ITopologicalOperator2;
            if (!top.IsSimple)
                top.Simplify();
            IConstructCurve curve = new PolylineClass();
            curve.ConstructOffset(outgeomcols as IPolyline, -3, ref missing, ref missing);
            IPolyline plinnew = curve as IPolyline;
            plinnew.SpatialReference = Global.spatialref;
            plinnew.FromPoint = newplines[0].FromPoint;
            plinnew.ToPoint = newplines[newplines.Count - 1].ToPoint;

            IFeature outcurve = Featureclass.CreateFeature();
            outcurve.set_Value(kindpos, 2);
            outcurve.set_Value(bidpos, BID);
            outcurve.Shape = plinnew;
            outcurve.Store();
            //结束编辑
            workspace.StopEditOperation();
            workspace.StopEditing(true);
            //定位跳转
            Global.commonclss.JumpToGeometry(plinnew);
        }
 private void createpolyline(IPointCollection ippoints)
 {
     ISegmentCollection ppath = new PathClass();
     IGeometryCollection ppolyline = new PolylineClass();
     if (ippoints.PointCount >= 2)
     {
         int i;
         for (i = 0; i < ippoints.PointCount - 1; i++)
         {
             ILine pline = new LineClass();
             pline.PutCoords(ippoints.get_Point(i), ippoints.get_Point(i + 1));
             ISegment psegment = pline as ISegment;
             object o = Type.Missing;
             ppath.AddSegment(psegment, ref o, ref o);
             ppolyline.AddGeometry(ppath as IGeometry, ref o, ref o);
         }
         ipPolyResult = ppolyline as IPolyline;
     }
 }
        private void createpolygon(IPointCollection ippoints)
        {
            ISegmentCollection ppath = new PathClass();
            IGeometryCollection ppolyline = new PolylineClass();
            if (ippoints.PointCount >= 3)
            {
                int i;
                object o = Type.Missing;
                if (ippoints.PointCount >= 4)
                {
                    ippoints.RemovePoints(ippoints.PointCount - 2, 1);
                }
                ippoints.AddPoint(ippoints.get_Point(0));
                for (i = 0; i < ippoints.PointCount - 1; i++)
                {
                    ILine pline = new LineClass();
                    pline.PutCoords(ippoints.get_Point(i), ippoints.get_Point(i + 1));
                    ISegment psegment = pline as ISegment;

                    ppath.AddSegment(psegment, ref o, ref o);
                    ppolyline.AddGeometry(ppath as IGeometry, ref o, ref o);
                }
                ipPolyResult = ppolyline as IPolyline;
                ISegmentCollection pRing = new RingClass();
                IGeometryCollection pGeometryColl = new PolygonClass();
                for (int j = 0; j < ppolyline.GeometryCount; j++)
                {
                    pRing.AddSegmentCollection(ppolyline.get_Geometry(j) as ISegmentCollection);
                    pGeometryColl.AddGeometry(pRing as IGeometry, ref o, ref o);
                }
                ipolygon = pGeometryColl as IPolygon;
            }
        }
Пример #8
0
        private void CreateDongShi(IPoint P0, IPoint P1, IPoint P2, IPoint P3, string hdid, string bid)
        {
            ISegmentCollection pPath = new PathClass();
            //��һ���߶�
            ILine pLine = new LineClass();
            pLine.PutCoords(P0, P1);
            //QI��ISegment
            ISegment pSegment = pLine as ISegment;
            //����һ��Path����
            System.Object o = Type.Missing;
            //ͨ��ISegmentCollection�ӿ�ΪPath�������Segment����
            pPath.AddSegment(pSegment, ref o, ref o);
            //�ڶ����߶�
            ILine pLine2 = new LineClass();
            pLine2.PutCoords(P1, P2);
            ISegment pSegment2 = pLine2 as ISegment;
            //����һ��Path����
            //ͨ��ISegmentCollection�ӿ�ΪPath�������Segment����
            pPath.AddSegment(pSegment2, ref o, ref o);
            //�������߶�
            ILine pLine3 = new LineClass();
            pLine3.PutCoords(P2, P3);
            ISegment pSegment3 = pLine3 as ISegment;
            //����һ��Path����
            //ͨ��ISegmentCollection�ӿ�ΪPath�������Segment����
            pPath.AddSegment(pSegment3, ref o, ref o);

            IGeometryCollection pPolyline = new PolylineClass();
            //ͨ��IGeometryCollectionΪPolyline�������Path����
            pPolyline.AddGeometry(pPath as IGeometry, ref o, ref o);

            if (m_pDongshiFeatureLayer != null)
            {
                System.Collections.Generic.List<ziduan> list = new System.Collections.Generic.List<ziduan>();
                list.Add(new ziduan(GIS_Const.FIELD_HDID, hdid));
                list.Add(new ziduan(GIS_Const.FIELD_BID, bid));
                DataEditCommon.CreateNewFeature(m_pDongshiFeatureLayer, pPolyline as IGeometry,list);
                m_hookHelper.ActiveView.Refresh();
            }
        }
        public void OnFinishSketch()
        {
            //get reference to featurelayer being edited
            IFeatureLayer featureLayer = m_editLayer.TargetLayer as IFeatureLayer;
            //get reference to the sketch geometry
            IGeometry reshapeGeom = m_editSketch.Geometry;

            if (reshapeGeom.IsEmpty == false)
            {
                //get the currently selected feature    
                IFeatureSelection featureSelection = featureLayer as IFeatureSelection;
                ISelectionSet selectionSet = featureSelection.SelectionSet;
                ICursor cursor;
                selectionSet.Search(null, false, out cursor);
                IFeatureCursor featureCursor = cursor as IFeatureCursor;
                //the PerformSketchToolEnabledChecks property has already checked that only 1 feature is selected
                IFeature feature = featureCursor.NextFeature();
                 
                //Take a copy of geometry for the selected feature
                IGeometry editShape = feature.ShapeCopy;

                //create a path from the editsketch geometry
                IPointCollection reshapePath = new PathClass();
                reshapePath.AddPointCollection(reshapeGeom as IPointCollection);

                //reshape the selected feature
                IPolyline polyline = editShape as IPolyline;
                polyline.Reshape(reshapePath as IPath);

                #region Perform an edit operation to store the new geometry for selected feature

                try
                {
                    m_engineEditor.StartOperation();
                    feature.Shape = editShape;
                    feature.Store();
                    m_engineEditor.StopOperation("Reshape Feature");
                }
                catch (Exception ex)
                {
                    m_engineEditor.AbortOperation();
                    System.Diagnostics.Trace.WriteLine(ex.Message, "Reshape Geometry Failed");
                }

                #endregion
            }

            //refresh the display 
            IActiveView activeView = m_engineEditor.Map as IActiveView;
            activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, (object)featureLayer, activeView.Extent);
          

        }
        private IPath MakePath( IPoint ppointStart, IPoint ppointEnd)
        {
            IPath ppath = new PathClass();

            ppath.FromPoint = ppointStart;
            ppath.ToPoint = ppointEnd;

            return ppath;
        }
Пример #11
0
        public bool HasTangentCurveMatchFeatures(IFeatureClass FeatureClass, IPolycurve inPolycurve, string WhereClause,
  double AngleToleranceTangentCompareInDegrees, double StraightLinesBreakLessThanInDegrees, double MaximumDeltaInDegrees, double ExcludeTangentsShorterThan, 
      out int outFoundTangentCurvesCount, ref List<string> CurveInfoFromNeighbours)
        {
            outFoundTangentCurvesCount = 0;

              ILine pOriginalChord = new Line();
              pOriginalChord.PutCoords(inPolycurve.FromPoint, inPolycurve.ToPoint);
              IVector3D vecOriginalSelected = new Vector3DClass();
              vecOriginalSelected.PolarSet(pOriginalChord.Angle, 0, 1);

              int idxRadius = FeatureClass.FindField("RADIUS");
              if (idxRadius == -1)
            return false;

              int idxCenterPointID = FeatureClass.FindField("CENTERPOINTID");
              if (idxCenterPointID == -1)
            return false;

              object val = null;

              IGeometryBag pGeomBag = new GeometryBagClass();
              IGeometryCollection pGeomColl = (IGeometryCollection)pGeomBag;

              IGeometry MultiPartPolyLine = new PolylineClass(); //qi
              IGeoDataset pGeoDS = (IGeoDataset)FeatureClass;
              ISpatialReference spatialRef = pGeoDS.SpatialReference;
              MultiPartPolyLine.SpatialReference = spatialRef;

              IGeometryCollection geometryCollection2 = MultiPartPolyLine as IGeometryCollection;

              ILine pTangentLineAtEnd = new Line(); //new
              ILine pTangentLineAtStart = new Line(); //new
              object objMissing = Type.Missing;

              for (int i = 0; i < 2; i++)
              {
            ILine pThisLine = null;
            if (i == 0)
            {
              inPolycurve.QueryTangent(esriSegmentExtension.esriExtendAtTo, 1.0, true, 0.2, pTangentLineAtEnd);
              pThisLine = new Line();
              pThisLine.PutCoords(pTangentLineAtEnd.FromPoint, pTangentLineAtEnd.ToPoint);
              pGeomColl.AddGeometry(pThisLine);
            }
            else
            {
              inPolycurve.QueryTangent(esriSegmentExtension.esriExtendAtFrom, 0.0, true, 0.2, pTangentLineAtStart);
              pThisLine = new Line();
              pThisLine.PutCoords(pTangentLineAtStart.FromPoint, pTangentLineAtStart.ToPoint);
              pGeomColl.AddGeometry(pThisLine);
            }
            //Create a new path for each line.

            ISegmentCollection newPath = new PathClass();
            newPath.AddSegment((ISegment)pThisLine, ref objMissing, ref objMissing);
            //The spatial reference associated with geometryCollection will be assigned to all incoming paths and segments.
            geometryCollection2.AddGeometry(newPath as IGeometry, ref objMissing, ref objMissing);
              }

              //now buffer the lines
              IGeometryCollection outBufferedGeometryCol = new GeometryBagClass();
              for (int jj = 0; jj < geometryCollection2.GeometryCount; jj++)
              {
            IPath pPath = geometryCollection2.get_Geometry(jj) as IPath;
            IGeometryCollection pPolyL = new PolylineClass();
            pPolyL.AddGeometry((IGeometry)pPath);

            ITopologicalOperator topologicalOperator = (ITopologicalOperator)pPolyL;
            IPolygon pBuffer = topologicalOperator.Buffer(0.1) as IPolygon;
            outBufferedGeometryCol.AddGeometry(pBuffer, ref objMissing, ref objMissing);
              }
              ITopologicalOperator pUnionedBuffers = null;
              pUnionedBuffers = new PolygonClass() as ITopologicalOperator;
              pUnionedBuffers.ConstructUnion((IEnumGeometry)outBufferedGeometryCol);

              ISpatialFilter pSpatFilt = new SpatialFilter();
              pSpatFilt.WhereClause = WhereClause;
              pSpatFilt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
              pSpatFilt.SearchOrder = esriSearchOrder.esriSearchOrderSpatial;

              pSpatFilt.Geometry = (IGeometry)pUnionedBuffers;

              IFeatureCursor pFeatCursLines = null;
              try
              {
            pFeatCursLines = FeatureClass.Search(pSpatFilt, false);
              }
              catch (Exception ex)
              {
            MessageBox.Show(ex.Message);
            return false;
              }
              IVector3D vecFoundGeom = new Vector3DClass();
              IFeature pFeat = pFeatCursLines.NextFeature();
              bool bHasTangentStraightLineAtJunction = false;
              List<int> lstLargeBreak = new List<int>();

              while (pFeat != null)
              {
            IGeometry pFoundLineGeom = pFeat.ShapeCopy;
            IPolycurve pFoundLineAsPolyCurve = pFoundLineGeom as IPolycurve;
            int iRelativeOrientation = GetRelativeOrientation(pFoundLineAsPolyCurve, inPolycurve);
            //iRelativeOrientation == 1 --> closest points are original TO and found TO
            //iRelativeOrientation == 2 --> closest points are original TO and found FROM
            //iRelativeOrientation == 3 --> closest points are original FROM and found TO
            //iRelativeOrientation == 4 --> closest points are original FROM and found FROM

            //if the feature has no radius attribute, skip.
            double dRadius = 0;
            int iCtrPoint = -1;
            val = pFeat.get_Value(idxRadius);
            if (val == DBNull.Value)
              dRadius = 0;
            else
              dRadius = (double)val;

            val = pFeat.get_Value(idxCenterPointID);

            IPolycurve pPolyCurve = pFoundLineGeom as IPolycurve;

            ILine pFoundChordCandidate = new LineClass();
            pFoundChordCandidate.PutCoords(pPolyCurve.FromPoint, pPolyCurve.ToPoint);
            //first check for liklihood that subject line is supposed to stay straight, by
            //geometry chord bearing angle break test
            vecFoundGeom.PolarSet(pFoundChordCandidate.Angle, 0, 1);
            double dDotProd = vecFoundGeom.DotProduct(vecOriginalSelected);
            double dAngleCheck = Math.Acos(dDotProd) * 180 / Math.PI; //in degrees
            dAngleCheck = Math.Abs(dAngleCheck);
            double dLargeAngleBreakInDegrees = 3;
            if (dAngleCheck > dLargeAngleBreakInDegrees && dAngleCheck < (180 - dLargeAngleBreakInDegrees)) //large angle break non-tangent, greater than 3 degrees
            {
              if (!lstLargeBreak.Contains(iRelativeOrientation))
            lstLargeBreak.Add(iRelativeOrientation);
            }

            if ((dAngleCheck <= StraightLinesBreakLessThanInDegrees || (180 - dAngleCheck) < StraightLinesBreakLessThanInDegrees)
            && val == DBNull.Value && dRadius == 0 && !(pPolyCurve.Length< ExcludeTangentsShorterThan))
            {
              if (lstLargeBreak.Contains(iRelativeOrientation))
            bHasTangentStraightLineAtJunction = true;
            }

            if (val == DBNull.Value || dRadius == 0 || pPolyCurve.Length< ExcludeTangentsShorterThan)
            {//if the feature has a null centrpointID then skip.
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            if (Math.Abs(inPolycurve.Length / dRadius * 180 / Math.PI) > MaximumDeltaInDegrees)
            {
              //if the resulting curve would have a central angle more than MaximumDeltaInDegrees degrees then skip
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            iCtrPoint = (int)val;

            //if geometry of curve neighbour curves have been cracked then there can be more than one segment
            //however since all segments would be circular arcs, just need to test the first segment
            ISegmentCollection pFoundLineGeomSegs = pFoundLineGeom as ISegmentCollection;
            ISegment pSeg = pFoundLineGeomSegs.get_Segment(0);
            if (!(pSeg is ICircularArc))
            {
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            dRadius = (double)pFeat.get_Value(idxRadius);

            IVector3D vect1 = new Vector3DClass();
            IVector3D vect2 = new Vector3DClass();
            ILine tang = new Line();
            double dUnitSignChange = 1;
            if (iRelativeOrientation == 1) //closest points are original TO and found TO
            {
              dUnitSignChange = -1;
              vect1.PolarSet(pTangentLineAtEnd.Angle, 0, 1);
              pFoundLineAsPolyCurve.QueryTangent(esriSegmentExtension.esriExtendAtTo, 1.0, true, 1, tang);
              vect2.PolarSet(tang.Angle, 0, 1);
            }
            else if (iRelativeOrientation == 2)//closest points are original TO and found FROM
            {
              vect1.PolarSet(pTangentLineAtEnd.Angle, 0, 1);
              pFoundLineAsPolyCurve.QueryTangent(esriSegmentExtension.esriExtendAtFrom, 0.0, true, 1, tang);
              vect2.PolarSet(tang.Angle, 0, 1);
            }
            else if (iRelativeOrientation == 3)//closest points are original FROM and found TO
            {
              vect1.PolarSet(pTangentLineAtStart.Angle, 0, 1);
              pFoundLineAsPolyCurve.QueryTangent(esriSegmentExtension.esriExtendAtTo, 1.0, true, 1, tang);
              vect2.PolarSet(tang.Angle, 0, 1);
            }
            else if (iRelativeOrientation == 4)//closest points are original FROM and found FROM
            {
              dUnitSignChange = -1;
              vect1.PolarSet(pTangentLineAtStart.Angle, 0, 1);
              pFoundLineAsPolyCurve.QueryTangent(esriSegmentExtension.esriExtendAtFrom, 0.0, true, 1, tang);
              vect2.PolarSet(tang.Angle, 0, 1);
            }

            dDotProd = vect1.DotProduct(vect2);
            dAngleCheck = Math.Acos(dDotProd) * 180 / Math.PI; //in degrees
            dAngleCheck = Math.Abs(dAngleCheck);
            if (dAngleCheck < AngleToleranceTangentCompareInDegrees || (180 - dAngleCheck) < AngleToleranceTangentCompareInDegrees)
            {

              double dDerivedRadius = dRadius * dUnitSignChange;

              string sHarvestedCurveInfo = pFeat.OID.ToString() + "," + dDerivedRadius.ToString("#.000") + "," +
            iCtrPoint.ToString() + "," + "t";
              CurveInfoFromNeighbours.Add(sHarvestedCurveInfo);

              outFoundTangentCurvesCount++;
            }

            Marshal.ReleaseComObject(pFeat);
            pFeat = pFeatCursLines.NextFeature();
              }
              Marshal.FinalReleaseComObject(pFeatCursLines);

              if (bHasTangentStraightLineAtJunction)
            return false; //open to logic change to be less conservative

              bool bHasParallelCurveFeaturesNearby = (outFoundTangentCurvesCount > 0);

              return bHasParallelCurveFeaturesNearby;
        }
Пример #12
0
        public bool HasParallelCurveMatchFeatures(IFeatureClass FeatureClass, IPolycurve inPolycurve, string WhereClause,
      double AngleToleranceTangentCompareInDegrees, double OrthogonalSearchDistance,
       out int outFoundLinesCount, out int outFoundParallelCurvesCount, ref List<string> CurveInfoFromNeighbours)
        {
            outFoundLinesCount = 0;
              outFoundParallelCurvesCount = 0;

              ILine pOriginalChord = new Line();
              pOriginalChord.PutCoords(inPolycurve.FromPoint, inPolycurve.ToPoint);
              IVector3D vecOriginalSelected = new Vector3DClass();
              vecOriginalSelected.PolarSet(pOriginalChord.Angle, 0, 1);

              int idxRadius = FeatureClass.FindField("RADIUS");
              if (idxRadius == -1)
            return false;

              int idxCenterPointID = FeatureClass.FindField("CENTERPOINTID");
              if (idxCenterPointID == -1)
            return false;

              object val = null;

              IGeometryBag pGeomBag = new GeometryBagClass();
              IGeometryCollection pGeomColl = (IGeometryCollection)pGeomBag;

              IGeometry MultiPartPolyLine = new PolylineClass(); //qi
              IGeoDataset pGeoDS = (IGeoDataset)FeatureClass;
              ISpatialReference spatialRef = pGeoDS.SpatialReference;
              MultiPartPolyLine.SpatialReference = spatialRef;

              IGeometryCollection geometryCollection2 = MultiPartPolyLine as IGeometryCollection;

              ILine pNormalLine = new Line(); //new
              for (int i = -1; i < 2; i = i + 2)
              {
            double dOffset = OrthogonalSearchDistance * i;

            inPolycurve.QueryNormal(esriSegmentExtension.esriNoExtension, 0.5, true, dOffset, pNormalLine);
            ILine pThisLine = new Line();

            pThisLine.PutCoords(pNormalLine.FromPoint, pNormalLine.ToPoint);
            pGeomColl.AddGeometry(pThisLine);

            //Although each line is connected to the other, create a new path for each line
            //this allows for future changes in case the input needs to be altered to separate paths.

            ISegmentCollection newPath = new PathClass();
            object obj = Type.Missing;
            newPath.AddSegment((ISegment)pThisLine, ref obj, ref obj);
            //The spatial reference associated with geometryCollection will be assigned to all incoming paths and segments.
            geometryCollection2.AddGeometry(newPath as IGeometry, ref obj, ref obj);
              }

              ISpatialFilter pSpatFilt = new SpatialFilter();
              pSpatFilt.WhereClause = WhereClause;
              pSpatFilt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
              pSpatFilt.SearchOrder = esriSearchOrder.esriSearchOrderSpatial;

              pSpatFilt.Geometry = pGeomBag;

              IFeatureCursor pFeatCursLines = null;
              try
              {
            pFeatCursLines = FeatureClass.Search(pSpatFilt, false);
              }
              catch (Exception ex)
              {
            MessageBox.Show(ex.Message);
            return false;
              }

              IFeature pFeat = pFeatCursLines.NextFeature();
              while (pFeat != null)
              {
            IGeometry pFoundLineGeom = pFeat.ShapeCopy;

            //if the feature has no radius attribute, skip.
            double dRadius = 0;
            int iCtrPoint = -1;
            val = pFeat.get_Value(idxRadius);
            if (val == DBNull.Value)
              dRadius = 0;
            else
              dRadius = (double)val;

            if (dRadius == 0)
            {//null or zero radius so skip.
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            val = pFeat.get_Value(idxCenterPointID);
            if (val == DBNull.Value)
            {//null centrpointID so skip.
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            iCtrPoint = (int)val;

            ITopologicalOperator6 pTopoOp6 = (ITopologicalOperator6)MultiPartPolyLine;
            IGeometry pResultGeom = pTopoOp6.IntersectEx(pFoundLineGeom, false, esriGeometryDimension.esriGeometry0Dimension);
            if (pResultGeom == null)
            {
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }
            if (pResultGeom.IsEmpty)
            {
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            ISegmentCollection pFoundLineGeomSegs = pFoundLineGeom as ISegmentCollection;
            bool bHasCurves = false;
            pFoundLineGeomSegs.HasNonLinearSegments(ref bHasCurves);
            if (!bHasCurves)
            {
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            IPointCollection5 PtColl = (IPointCollection5)pResultGeom;

            if (PtColl.PointCount > 1)
            {
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }
            IPolycurve pPolyCurve4Tangent = pFoundLineGeom as IPolycurve;

            for (int j = 0; j < PtColl.PointCount; j++)
            {
              IPoint p = PtColl.get_Point(j);
              IPoint outPoint = new Point();
              double dDistanceAlong = 0;
              double dDistanceFromCurve = 0;
              bool bOffsetRight = true;

              //work out if the point is to the left or right of the original
              inPolycurve.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, p, false, outPoint,
            ref dDistanceAlong, ref dDistanceFromCurve, ref bOffsetRight);

              ILine pTangent = new Line();
              dDistanceAlong = 0;
              dDistanceFromCurve = 0;
              bool bOnRight = true;

              pPolyCurve4Tangent.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, p, false, outPoint,
            ref dDistanceAlong, ref dDistanceFromCurve, ref bOnRight);
              pPolyCurve4Tangent.QueryTangent(esriSegmentExtension.esriNoExtension, dDistanceAlong, false, 100, pTangent);

              //compare the tangent bearing with the normal to check for orthogonality
              IVector3D vecTangent = new Vector3DClass();
              vecTangent.PolarSet(pTangent.Angle, 0, 1);

              IVector3D vecNormal = new Vector3DClass();
              vecNormal.PolarSet(pNormalLine.Angle, 0, 1);

              ILine pHitDistanceForRadiusDifference = new Line();
              pHitDistanceForRadiusDifference.PutCoords(pNormalLine.FromPoint, outPoint);
              double dRadiusDiff = pHitDistanceForRadiusDifference.Length;

              double dDotProd = vecTangent.DotProduct(vecNormal);
              double dAngleCheck = Math.Acos(dDotProd) * 180 / Math.PI; //in degrees
              dAngleCheck = Math.Abs(dAngleCheck - 90);

              if (dAngleCheck < AngleToleranceTangentCompareInDegrees)
              {
            //work out concavity orientation with respect to the original line using the radius sign and dot product
            dDotProd = vecOriginalSelected.DotProduct(vecTangent);
            double dTangentCheck = Math.Acos(dDotProd) * 180 / Math.PI; // in degrees
            //dTangentCheck at this point should be close to 0 or 180 degrees.
            outFoundLinesCount++;

            bool bIsConvex = ((dTangentCheck < 90 && dRadius < 0 && !bOffsetRight) ||
                              (dTangentCheck > 90 && dRadius > 0 && !bOffsetRight) ||
                              (dTangentCheck < 90 && dRadius > 0 && bOffsetRight) ||
                              (dTangentCheck > 90 && dRadius < 0 && bOffsetRight));

            double dUnitSignChange = 1;

            if (!bIsConvex)
              dUnitSignChange = -1;

            double dDerivedRadius = (Math.Abs(dRadius)) + dRadiusDiff * dUnitSignChange;

            dUnitSignChange = 1;
            //now compute inferred left/right for candidate
            if (bIsConvex && !bOffsetRight)
              dUnitSignChange = -1;

            if (!bIsConvex && bOffsetRight)
              dUnitSignChange = -1;

            dDerivedRadius = dDerivedRadius * dUnitSignChange;

            string sHarvestedCurveInfo = pFeat.OID.ToString() + "," + dDerivedRadius.ToString("#.000") + "," +
              iCtrPoint.ToString() + "," + dRadiusDiff.ToString("#.000");
            CurveInfoFromNeighbours.Add(sHarvestedCurveInfo);
              }
            }

            Marshal.ReleaseComObject(pFeat);
            pFeat = pFeatCursLines.NextFeature();
              }
              Marshal.FinalReleaseComObject(pFeatCursLines);

              bool bHasParallelCurveFeaturesNearby = (outFoundLinesCount > 0);

              return bHasParallelCurveFeaturesNearby;
        }
        public void FlashGeometry(IGeometry Geom, IScreenDisplay Display, IColor Color, int Size, int Interval)
        {
            if (Geom == null)
            return;
              short Cache = Display.ActiveCache;
              Display.ActiveCache = (short)esriScreenCache.esriNoScreenCache;
              Display.StartDrawing(0, Cache);

              if (Geom.GeometryType == esriGeometryType.esriGeometryLine || Geom.GeometryType == esriGeometryType.esriGeometryCircularArc)
              {
            ILineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass();
            ISymbol pSymbol = (ISymbol)pSimpleLineSymbol;
            pSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; //erase itself when drawn twice
            pSimpleLineSymbol.Width = Size;
            pSimpleLineSymbol.Color = Color;
            Display.SetSymbol((ISymbol)pSimpleLineSymbol);
            ISegmentCollection pPath = new PathClass();
            pPath.AddSegment((ISegment)Geom);
            IGeometryCollection pPolyL = new PolylineClass();
            pPolyL.AddGeometry((IGeometry)pPath);
            Display.DrawPolyline((IGeometry)pPolyL);
            System.Threading.Thread.Sleep(Interval);
            Display.DrawPolyline((IGeometry)pPolyL);
               }
              else if (Geom.GeometryType == esriGeometryType.esriGeometryPolyline)
              {
            ILineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass();
            ISymbol pSymbol = (ISymbol)pSimpleLineSymbol; //'QI
            pSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; //erase itself when drawn twice
            pSimpleLineSymbol.Width = Size;
            pSimpleLineSymbol.Color = Color;
            Display.SetSymbol((ISymbol)pSimpleLineSymbol);
            Display.DrawPolyline(Geom);
            System.Threading.Thread.Sleep(Interval);
            Display.DrawPolyline(Geom);
              }
              else if (Geom.GeometryType == esriGeometryType.esriGeometryPolygon)
              {
            ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass();
            ISymbol pSymbol = (ISymbol)pSimpleFillSymbol;
            pSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; //erase itself when drawn twice
            pSimpleFillSymbol.Color = Color;
            Display.SetSymbol((ISymbol)pSimpleFillSymbol);
            Display.DrawPolygon(Geom);
            System.Threading.Thread.Sleep(Interval);
            Display.DrawPolygon(Geom);
              }
              else if (Geom.GeometryType == esriGeometryType.esriGeometryPoint)
              {
            ISimpleMarkerSymbol pSimpleMarkersymbol = new SimpleMarkerSymbolClass();
            ISymbol pSymbol = (ISymbol)pSimpleMarkersymbol;
            pSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen;
            pSimpleMarkersymbol.Color = Color;
            pSimpleMarkersymbol.Size = Size;
            Display.SetSymbol((ISymbol)pSimpleMarkersymbol);
            Display.DrawPoint(Geom);
            System.Threading.Thread.Sleep(Interval);
            Display.DrawPoint(Geom);
              }
              Display.FinishDrawing();
              //reset the cache
              Display.ActiveCache = Cache;
        }
        public static IGeometry GetExample13()
        {
            const double CircleDegrees = 360.0;
            const int CircleDivisions = 36;
            const double VectorComponentOffset = 0.0000001;
            const double CircleRadius = 3.0;
            const double BaseZ = 0.0;
            const double RotationAngleInDegrees = 89.9;

            //Extrusion: 3D Circle Polyline Extruded Along 3D Vector Via ConstructExtrudeRelative()

            IPointCollection pathPointCollection = new PathClass();

            IGeometry pathGeometry = pathPointCollection as IGeometry;

            GeometryUtilities.MakeZAware(pathGeometry);

            IPoint originPoint = GeometryUtilities.ConstructPoint3D(0, 0, 0);

            IVector3D upperAxisVector3D = GeometryUtilities.ConstructVector3D(0, 0, 10);

            IVector3D lowerAxisVector3D = GeometryUtilities.ConstructVector3D(0, 0, -10);

            lowerAxisVector3D.XComponent += VectorComponentOffset;

            IVector3D normalVector3D = upperAxisVector3D.CrossProduct(lowerAxisVector3D) as IVector3D;

            normalVector3D.Magnitude = CircleRadius;

            double rotationAngleInRadians = GeometryUtilities.GetRadians(CircleDegrees / CircleDivisions);

            for (int i = 0; i < CircleDivisions; i++)
            {
                normalVector3D.Rotate(-1 * rotationAngleInRadians, upperAxisVector3D);

                IPoint vertexPoint = GeometryUtilities.ConstructPoint3D(originPoint.X + normalVector3D.XComponent,
                                                                      originPoint.Y + normalVector3D.YComponent,
                                                                      BaseZ);

                pathPointCollection.AddPoint(vertexPoint, ref _missing, ref _missing);
            }

            pathPointCollection.AddPoint(pathPointCollection.get_Point(0), ref _missing, ref _missing);

            //Rotate Geometry

            IVector3D rotationAxisVector3D = GeometryUtilities.ConstructVector3D(0, 10, 0);

            ITransform3D transform3D = pathGeometry as ITransform3D;
            transform3D.RotateVector3D(rotationAxisVector3D, GeometryUtilities.GetRadians(RotationAngleInDegrees));

            //Construct Polyline From Path Vertices

            IGeometry polylineGeometry = new PolylineClass();

            GeometryUtilities.MakeZAware(polylineGeometry);

            IPointCollection polylinePointCollection = polylineGeometry as IPointCollection;

            for (int i = 0; i < pathPointCollection.PointCount; i++)
            {
                polylinePointCollection.AddPoint(pathPointCollection.get_Point(i), ref _missing, ref _missing);
            }

            ITopologicalOperator topologicalOperator = polylineGeometry as ITopologicalOperator;
            topologicalOperator.Simplify();

            //Define Vector To Extrude Along

            IVector3D extrusionVector3D = GeometryUtilities.ConstructVector3D(10, 0, 5);

            //Perform Extrusion

            IConstructMultiPatch constructMultiPatch = new MultiPatchClass();
            constructMultiPatch.ConstructExtrudeRelative(extrusionVector3D, polylineGeometry);

            return constructMultiPatch as IGeometry;
        }
Пример #15
0
        public static IPath MakeTextPath(IPath pPath, double length)
        {
            try
            {
                double angle = GetAngle(pPath);
                IPoint pPt = pPath.ToPoint;
                IConstructPoint pCP = new PointClass();
                double PI = 3.1415926535897;
                double rad = angle * PI / 180;
                pCP.ConstructAngleDistance(pPt, rad, 1);
                IPoint pNew = pCP as IPoint;

                IPath pNewPath = new PathClass();
                pNewPath.FromPoint = pPt;
                pNewPath.ToPoint = pNew;
                if (ShouldFlip(angle))
                {
                    pNewPath.ReverseOrientation();
                }
                return pNewPath;
            }
            catch (Exception eX)
            {
                MessageBox.Show(eX.Message);
                return null;
            }
        }
        public void GeneratePoints2(string sLineLayer, string sDepthPointsLayer, double dblInterval, string strDepthField)
        {
            try
            {
                IMxDocument pmxdoc = ArcMap.Document as IMxDocument;
                IMap pmap = pmxdoc.FocusMap;

                IFeatureLayer pDepthSoundings = FindLayer(pmap, sDepthPointsLayer) as IFeatureLayer;
                IFeatureLayer pLineLayer = FindLayer(pmap, sLineLayer) as IFeatureLayer;
                IFeatureLayer pOutpoints = new FeatureLayerClass();
                pOutpoints.FeatureClass = MakePointFC();
                pOutpoints.Name = "Output Points";
                ArcMap.Document.ActiveView.FocusMap.AddLayer(pOutpoints);

                IProgressDialog2 pProgressDialog = ShowProgressIndicator("Calculating...", pLineLayer.FeatureClass.FeatureCount(null), 1);
                pProgressDialog.ShowDialog();

                //Set up the Outpoints cursor
                IFeatureCursor pFCurOutPoints = pOutpoints.Search(null, false);
                pFCurOutPoints = pOutpoints.FeatureClass.Insert(true);

                //Set up the LineLayer Cursor
                IFeatureCursor pFCur = pLineLayer.Search(null, false);
                IFeature pLineFeature = pFCur.NextFeature();

                IFeatureBuffer pFBuffer = pOutpoints.FeatureClass.CreateFeatureBuffer();

                ICurve pCurve;
                IPoint ppoint;

                int iLineProgressCount = 1;
                double dblDistance = 0;
                double dblTotalDistanceCalculated = 0;
                double iNumIntervals = 0;
                double dblElevationDiff = 0;
                double dblElevationInterval = 0;
                double dblElevation = 0;
                double dlbStartElevation = 0;
                double dblEndElevation = 0;

                pProgressDialog.Description = "Generating points for Line: " + iLineProgressCount + " of " + pLineLayer.FeatureClass.FeatureCount(null).ToString();

                while (pLineFeature != null)
                {

                    int iStartVertex = 0;
                    int iEndVertex = 1;
                    //Get the vertices of the line feature
                    IPointCollection4 pPointColl = pLineFeature.Shape as IPointCollection4;

                    //loop thru the vertices
                    for (int i = 0; i <= pPointColl.PointCount - 1; i++)
                    {

                        IPoint pStartPoint = pPointColl.get_Point(iStartVertex);
                        IPoint pEndPoint = pPointColl.get_Point(iEndVertex);
                        //Make an intermediate line segment between each set of vertices
                        IPath pPath = MakePath(pStartPoint, pEndPoint);

                        //Get the starting elevation from the depth point layer
                        dlbStartElevation = GetPointElevation(pDepthSoundings, pLineLayer, pStartPoint, strDepthField);
                        dblElevation = dlbStartElevation;
                        IPointCollection pPointForPath = null;
                        //Get the ending elevation from the next vertex
                        pEndPoint = pPointColl.get_Point(iEndVertex);
                        dblEndElevation = GetPointElevation(pDepthSoundings, pLineLayer, pEndPoint, strDepthField);
                        //If the returned elevation is 0, then there is no coincident depth point, move to the next vertex for your endpoint
                        if (dblEndElevation == 0)
                        {
                            //IPointCollection reshapePath = new PathClass();
                            object missing = Type.Missing;
                            pPointForPath = new PathClass();
                            pPointForPath.AddPoint(pStartPoint, ref missing, ref missing);
                            while (dblEndElevation == 0)
                            {
                                pEndPoint = pPointColl.get_Point(iEndVertex);
                                dblEndElevation = GetPointElevation(pDepthSoundings, pLineLayer, pEndPoint, strDepthField);

                                pPointForPath.AddPoint(pEndPoint, ref missing, ref missing);
                                //pLineSegment.Reshape(reshapePath as IPath);

                                if (dblEndElevation != 0)
                                {
                                    break;
                                }
                                iEndVertex++;
                            }

                        }

                        if (pPointForPath != null)
                        {
                            pPath = pPointForPath as IPath;
                        }

                        //number of line segments based on the user's interval
                        iNumIntervals = Convert.ToDouble(pPath.Length / dblInterval);
                        dblElevationDiff = dblEndElevation - dlbStartElevation;

                        //The calculated elevation interval to step up each time
                        dblElevationInterval = dblElevationDiff / iNumIntervals;

                        ppoint = new PointClass();

                        while (dblTotalDistanceCalculated <= pPath.Length)
                        {

                            pFBuffer.set_Value(pFBuffer.Fields.FindField("LineOID"), pLineFeature.OID);
                            pFBuffer.set_Value(pFBuffer.Fields.FindField("Distance"), Math.Round(dblDistance, 4));
                            pFBuffer.set_Value(pFBuffer.Fields.FindField("Elevation"), Math.Round(dblElevation, 4));

                            //this code set the point on the line at a distance
                            pPath.QueryPoint(0, dblDistance, false, ppoint);

                            pFBuffer.set_Value(pFBuffer.Fields.FindField("X"), ppoint.X);
                            pFBuffer.set_Value(pFBuffer.Fields.FindField("Y"), ppoint.Y);

                            //reCalc the new distance and elevation values for the next iteration
                            dblDistance = dblDistance + dblInterval;
                            dblTotalDistanceCalculated = dblTotalDistanceCalculated + dblInterval;

                            //Insert the feature into the featureclass
                            pFBuffer.Shape = ppoint;

                            if (!IsPointCoincident(ppoint, pOutpoints))
                            {
                                pFCurOutPoints.InsertFeature(pFBuffer);
                            }

                            if (dblTotalDistanceCalculated >= pPath.Length)
                            {

                                break;
                            }

                            dblElevation = dblElevation + dblElevationInterval;

                        }

                        //start the next line segment at the end of last one
                        iStartVertex = iEndVertex;
                        //look to the next vertex for the new ending point
                        iEndVertex++;

                            if (iEndVertex == pPointColl.PointCount)
                            {

                                ////if its the last vertex of the last line, add a point
                                //pFBuffer.Shape = pPath.ToPoint;
                                //pFBuffer.set_Value(pFBuffer.Fields.FindField("LineOID"), pLineFeature.OID);
                                //pFBuffer.set_Value(pFBuffer.Fields.FindField("Distance"), Math.Round(dblDistance, 4));
                                //pFBuffer.set_Value(pFBuffer.Fields.FindField("Elevation"), Math.Round(dblElevation, 4));
                                //pFBuffer.set_Value(pFBuffer.Fields.FindField("X"), pPath.ToPoint.X);
                                //pFBuffer.set_Value(pFBuffer.Fields.FindField("Y"), pPath.ToPoint.Y);
                                //pFCurOutPoints.InsertFeature(pFBuffer);

                                //Reset the distance values back to 0 for the next feature
                                dblDistance = 0;
                                dblTotalDistanceCalculated = 0;
                                pStepProgressor.Step();
                                iLineProgressCount++;
                                pPath.SetEmpty();
                                break;
                            }

                        //Reset the distance values back to 0 for the next feature
                        dblDistance = 0;
                        dblTotalDistanceCalculated = 0;
                        //pLineFeature = pFCur.NextFeature();
                        pStepProgressor.Step();
                        //pProgressDialog.Description = "Generating points for Line: " + iLineProgressCount + " of " + pLineLayer.FeatureClass.FeatureCount(null).ToString();
                        iLineProgressCount++;
                        pPath.SetEmpty();

                    }
                    pLineFeature = pFCur.NextFeature();

                }

                //cleanup
                pFCurOutPoints.Flush();
                pFCur.Flush();
                pProgressDialog.HideDialog();
                pmxdoc.ActiveView.Refresh();

            }
            catch (Exception ex)
            {

            }
        }
Пример #17
0
        /// <summary>
        /// 绘制小柱状
        /// </summary>
        /// <params name="datasources">各地质层厚度(0.83,0.3,1.2,200)最后一个值为底板标高</params>
        /// <param name="pt">小柱状中心点</params>
        /// <params name="Angle">旋转角度</params>
        /// <params name="bili">比例</params>
        /// <params name="bid">BID</params>
        /// <params name="edit">函数外控制编辑状态为false,函数内自动控制编辑状态为true,当批量绘图时建议函数外控制编辑状态</params>
        public static bool drawXZZ(List<KeyValuePair<int, double>> datasources, IPoint pt,double Angle, string bid, double bili = 1, bool edit = true)
        {
            double angle = -Angle;
            Angle = -Angle * Math.PI / 180;
            DrawXZZMap draw = new DrawXZZMap(bili);
            var AnnoLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.LAYER_ALIAS_MR_AnnotationXZZ) as IFeatureLayer;//注记图层
            var lineLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.LAYER_ALIAS_MR_PolylineXZZ) as IFeatureLayer;//线源图层
            var topLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.LAYER_ALIAS_MR_PolygonXZZ) as IFeatureLayer; //外部图形图层
            if (AnnoLayer == null || lineLayer == null || topLayer == null)
            {
                System.Windows.Forms.MessageBox.Show("小柱状图层缺失!");
                return false;
            }
            IWorkspaceEdit workspaceEdit=null;
            if (edit)
            {
                var dataset = lineLayer.FeatureClass as IDataset;
                workspaceEdit = dataset.Workspace as IWorkspaceEdit;
                workspaceEdit.StartEditing(true);
                workspaceEdit.StartEditOperation();
            }
            try
            {
                //  准备添加数据
                var polygonTopCursor = topLayer.FeatureClass.Insert(true);
                var polylineCursor = lineLayer.FeatureClass.Insert(true);
                var AnnoCursor = AnnoLayer.FeatureClass.Insert(true);
                //  从数据源图层获得数据
                var num1 = datasources[datasources.Count - 1].Value;     //  最后一条横线数值
                datasources.RemoveAt(datasources.Count - 1);
                if (datasources.Count > 1)
                {
                    List<IPoint> txtPoints;
                    List<IPoint> lineStartPoints;

                    var polygons = new List<KeyValuePair<string, IPolygon>>();

                    //  构造图形
                    draw.ContructGeometry(pt, datasources, out polygons, out lineStartPoints, out txtPoints);

                    ITransform2D pTrans2D;

                    //  生成方框图形
                    foreach (var polygon in polygons)
                    {
                        var feature2 = topLayer.FeatureClass.CreateFeatureBuffer();
                        feature2.set_Value(feature2.Fields.FindField("BID"), bid);
                        if (polygon.Key == "top")
                        {
                            feature2.set_Value(feature2.Fields.FindField("type"), 0);
                        }
                        else if (polygon.Key == "white")
                        {
                            feature2.set_Value(feature2.Fields.FindField("type"), 1);
                        }
                        else if (polygon.Key == "black")
                        {
                            feature2.set_Value(feature2.Fields.FindField("type"), 2);
                        }
                        pTrans2D = polygon.Value as ITransform2D;
                        //旋转要素
                        pTrans2D.Rotate(pt, Angle);
                        IPolygon ppp = pTrans2D as IPolygon;

                        GIS.Common.DataEditCommon.ZMValue(feature2, ppp);
                        feature2.Shape = ppp;

                        polygonTopCursor.InsertFeature(feature2);
                    }

                    //  生成注记
                    var enveloplist = new List<IEnvelope>();

                    for (int i = 0; i < txtPoints.Count; i++)
                    {
                        var featureAnno = AnnoLayer.FeatureClass.CreateFeatureBuffer();
                        IAnnotationFeature AnnoFeature = (IAnnotationFeature)featureAnno;

                        pTrans2D = txtPoints[i] as ITransform2D;
                        //旋转要素
                        pTrans2D.Rotate(pt, Angle);

                        ITextSymbol pTextSymbol = new TextSymbolClass();
                        pTextSymbol.Angle = angle;
                        var elementTxt = new TextElementClass
                        {
                            Geometry = pTrans2D as IGeometry,
                            FontName = "微软雅黑",
                            Size = 12 * bili,
                            SymbolID = 0,
                            Symbol=pTextSymbol
                        };

                        if (i == txtPoints.Count - 1)
                        {
                            elementTxt.Text = num1.ToString();  //  最后一条横线的数值
                            elementTxt.VerticalAlignment = esriTextVerticalAlignment.esriTVATop; //  显示在线下边
                            featureAnno.set_Value(featureAnno.Fields.FindField("strType"), 2);
                        }
                        else
                        {
                            elementTxt.Text = datasources[i].Value.ToString();
                            elementTxt.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom;
                            featureAnno.set_Value(featureAnno.Fields.FindField("strType"), datasources[i].Key);
                        }
                        AnnoFeature.Annotation = elementTxt;
                        featureAnno.set_Value(featureAnno.Fields.FindField("strAngle"), -angle);
                        featureAnno.set_Value(featureAnno.Fields.FindField("strX"), pt.X);
                        featureAnno.set_Value(featureAnno.Fields.FindField("strY"), pt.Y);
                        featureAnno.set_Value(featureAnno.Fields.FindField("strScale"), bili);
                        featureAnno.set_Value(featureAnno.Fields.FindField("strIndex"), i+1);
                        featureAnno.set_Value(featureAnno.Fields.FindField("BID"), bid);

                        pTrans2D = featureAnno.Shape as ITransform2D;
                        pTrans2D.Rotate(pt, -Angle);

                        enveloplist.Add(((IGeometry)pTrans2D).Envelope);
                        AnnoCursor.InsertFeature(featureAnno);
                    }
                    //  生成线
                    var polyline = new PolylineClass();
                    for (int i = 0; i < enveloplist.Count; i++)
                    {
                        //  计算注记的终点
                        IPoint toPoint = new PointClass();
                        if (i % 2 == 0)
                        {
                            toPoint.X = enveloplist[i].XMax;
                        }
                        else
                        {
                            toPoint.X = enveloplist[i].XMin;
                        }

                        toPoint.Y = lineStartPoints[i].Y;

                        var line = new PathClass
                        {
                            FromPoint = lineStartPoints[i],
                            ToPoint = toPoint
                        };

                        polyline.AddGeometry(line);
                    }
                    var featureLine = lineLayer.FeatureClass.CreateFeatureBuffer();

                    pTrans2D = polyline as ITransform2D;
                    pTrans2D.Rotate(pt, Angle);
                    IPolyline mline = pTrans2D as IPolyline;
                    GIS.Common.DataEditCommon.ZMValue(featureLine,mline);
                    featureLine.Shape = mline;
                    featureLine.set_Value(featureLine.Fields.FindField("BID"), bid);
                    polylineCursor.InsertFeature(featureLine);
                }

                AnnoCursor.Flush();
                polygonTopCursor.Flush();
                polylineCursor.Flush();
                if (edit)
                {
                    workspaceEdit.StopEditOperation();
                    workspaceEdit.StopEditing(true);

                    DataEditCommon.g_pMyMapCtrl.ActiveView.Refresh();
                }
                return true;
            }
            catch (Exception ex)
            {
                if (edit)
                {
                    workspaceEdit.AbortEditOperation();
                    workspaceEdit.StopEditing(false);
                }
                System.Windows.Forms.MessageBox.Show(ex.Message);
                return false;
            }
        }