예제 #1
0
        /// <summary>
        /// Converts the given geometry to 2D geometry if it's not 2D otherwsie it will return the same input.
        /// </summary>
        /// <param name="geometry"></param>
        /// <returns></returns>
        public static IGeometry CreateFlatGeometry(IGeometry geometry)
        {
            //if (geometry.IsEmpty || geometry.Dimension == esriGeometryDimension.esriGeometry2Dimension)
            //    return geometry;

            IGeometry flatGeo = null;

            if (geometry.GeometryType == esriGeometryType.esriGeometryPoint)
            {
                IPoint point = geometry as IPoint;
                flatGeo = new Point()
                {
                    X = point.X, Y = point.Y, SpatialReference = point.SpatialReference
                };
            }
            else if (geometry.GeometryType == esriGeometryType.esriGeometryPolyline)
            {
                Polyline           newPolyline         = new Polyline();
                ISegmentCollection newPolylineSegments = newPolyline as ISegmentCollection;
                ISegmentCollection segments            = geometry as ISegmentCollection;
                newPolylineSegments.AddSegmentCollection(segments);

                flatGeo = newPolyline as IGeometry;
            }
            else if (geometry.GeometryType == esriGeometryType.esriGeometryPolygon)
            {
                Polygon            newPolygon         = new Polygon();
                ISegmentCollection newPolygonSegments = newPolygon as ISegmentCollection;
                ISegmentCollection segments           = geometry as ISegmentCollection;
                newPolygonSegments.AddSegmentCollection(segments);

                flatGeo = newPolygon as IGeometry;
            }

            else if (geometry.GeometryType == esriGeometryType.esriGeometryEnvelope)
            {
                IEnvelope envelope = geometry as IEnvelope;

                Envelope newEnvelope = new Envelope
                {
                    XMin = envelope.XMin,
                    XMax = envelope.XMax,
                    YMin = envelope.YMin,
                    YMax = envelope.YMax
                };

                flatGeo = newEnvelope as IGeometry;
            }

            return(flatGeo);
        }
예제 #2
0
        public IPolyline GetSubpart(int part, int startSegmentIndex, double startFraction,
                                    int endSegmentIndex, double endFraction)
        {
            double l0 = IndexedSegmentUtils.GetLength(this, part, 0, 0, startSegmentIndex,
                                                      startFraction);
            double l1 = IndexedSegmentUtils.GetLength(this, part, startSegmentIndex,
                                                      startFraction,
                                                      endSegmentIndex, endFraction);

            IGeometry sourcePart  = ((IGeometryCollection)_segments).Geometry[part];
            var       sourceCurve = (ICurve)sourcePart;

            ICurve subcurve;

            sourceCurve.GetSubcurve(l0, l0 + l1, false, out subcurve);

            ISegmentCollection line = QaGeometryUtils.CreatePolyline(subcurve);

            ((IZAware)line).ZAware = ((IZAware)subcurve).ZAware;
            line.AddSegmentCollection((ISegmentCollection)subcurve);

            return((IPolyline)line);
        }
예제 #3
0
        public void OtherRule(string idname, string checkname, string IN_RuleType, string TABLENAME, string SUPTABLE, string inputtext, IHookHelper m_hookHelper)
        {
            CommonClass common = new CommonClass();

            IFeatureClass     IN_FeatureClass     = common.GetLayerByName(TABLENAME).FeatureClass;
            IGeoDataset       pGeoDataset         = IN_FeatureClass as IGeoDataset;
            ISpatialReference spatialReference    = pGeoDataset.SpatialReference;
            IFeatureClass     IN_Sup_FeatureClass = null;

            if (SUPTABLE != null)
            {
                IN_Sup_FeatureClass = common.GetLayerByName(SUPTABLE).FeatureClass;
            }
            string ErrorFilePath = this.topoDir + "\\" + checkname + idname + ".shp";

            if (IN_RuleType == "面多部件检查")
            {
                try
                {
                    common.CreatShpFile(this.topoDir, spatialReference, esriGeometryType.esriGeometryPolygon, checkname + idname);
                    List <ErrorEntity> list   = new List <ErrorEntity>();
                    IFeatureCursor     cursor = IN_FeatureClass.Search(null, false);
                    int      tempCount        = 0;
                    IFeature pFeature         = cursor.NextFeature();
                    while (pFeature != null)
                    {
                        IGeometry            pGeo          = pFeature.ShapeCopy;
                        ITopologicalOperator pTopoOperator = pGeo as ITopologicalOperator;
                        int iCount = 0;
                        if (IN_FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                        {
                            iCount = (pGeo as IPolygon).ExteriorRingCount;
                        }
                        else if (IN_FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                        {
                            iCount = ((pGeo as IPolyline) as IGeometryCollection).GeometryCount;
                        }
                        else if (IN_FeatureClass.ShapeType == esriGeometryType.esriGeometryMultipoint)
                        {
                            iCount = ((pGeo as IMultipoint) as IPointCollection).PointCount;
                        }
                        if (iCount > 1)
                        {
                            tempCount++;
                            common.GenerateSHPFile(pFeature.ShapeCopy, ErrorFilePath);
                        }
                        pFeature = cursor.NextFeature();
                    }
                    //new ErrorTable().AddErr(list, ErrType.MultiPart, idname);
                    if (!DicTopoError.ContainsKey(idname))
                    {
                        DicTopoError.Add(idname, tempCount);
                    }
                    else
                    {
                        DicTopoError[idname] = tempCount;
                    }

                    Marshal.ReleaseComObject(cursor);

                    if (tempCount == 0)
                    {
                        string            shpFolder         = System.IO.Path.GetDirectoryName(ErrorFilePath);
                        IWorkspaceFactory pWorkspaceFac     = new ShapefileWorkspaceFactoryClass();
                        IWorkspace        pWorkSpace        = pWorkspaceFac.OpenFromFile(ErrorFilePath, 0);
                        IFeatureWorkspace pFeatureWorkSpace = pWorkSpace as IFeatureWorkspace;
                        if (System.IO.File.Exists(ErrorFilePath))
                        {
                            IFeatureClass pFCChecker = pFeatureWorkSpace.OpenFeatureClass(ErrorFilePath);
                            if (pFCChecker != null)
                            {
                                IDataset pds = pFCChecker as IDataset;
                                pds.Delete();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog(typeof(TopoChecker), ex);
                }
            }
            else if (IN_RuleType == "面自相交检查")
            {
                int errorCount = 0;
                try
                {
                    common.CreatShpFile(this.topoDir, spatialReference, esriGeometryType.esriGeometryPoint, checkname + idname);
                    IFeatureLayer pLayer = new FeatureLayer();
                    pLayer.FeatureClass = IN_FeatureClass;
                    TopoClassChecker topo = new TopoClassChecker();

                    IFeatureCursor cursor;
                    IQueryFilter   filter = new QueryFilterClass();
                    filter.SubFields = pLayer.FeatureClass.OIDFieldName + "," + pLayer.FeatureClass.ShapeFieldName;
                    cursor           = pLayer.FeatureClass.Search(filter, true);
                    IFeature feature = null;
                    object   missing = Type.Missing;
                    while ((feature = cursor.NextFeature()) != null)
                    {
                        IPoint              tempPoint = null;
                        StringBuilder       builder   = new StringBuilder();
                        IGeometryCollection shape     = feature.Shape as IGeometryCollection;
                        for (int i = 0; i < shape.GeometryCount; i++)
                        {
                            esriNonSimpleReasonEnum enum2;
                            IPointCollection        newPoints = shape.get_Geometry(i) as IPointCollection;
                            IRing ring = newPoints as IRing;
                            int   num2 = 0;
                            if (ring.IsClosed)
                            {
                                num2 = 1;
                            }
                            PolylineClass o = new PolylineClass();
                            o.AddPointCollection(newPoints);
                            o.SpatialReference = spatialReference;

                            ITopologicalOperator3 @operator = o;
                            @operator.IsKnownSimple_2 = false;
                            if ([email protected]_IsSimpleEx(out enum2) && (enum2 == esriNonSimpleReasonEnum.esriNonSimpleSelfIntersections))
                            {
                                List <string> list2 = new List <string>();
                                List <string> list3 = new List <string>();
                                for (int j = num2; j < newPoints.PointCount; j++)
                                {
                                    IPoint point = newPoints.get_Point(j);
                                    tempPoint = point;
                                    string item = point.X.ToString() + "," + point.Y.ToString();
                                    if (list2.Contains(item))
                                    {
                                        if (!list3.Contains(item))
                                        {
                                            builder.Append(";");
                                            builder.Append(item);
                                            list3.Add(item);
                                        }
                                    }
                                    else
                                    {
                                        list2.Add(item);
                                    }
                                }
                            }
                            Marshal.ReleaseComObject(o);
                            o = null;
                        }
                        if (builder.Length > 0)
                        {
                            errorCount++;

                            string[] strArray = builder.ToString().Substring(1).Split(new char[] { ';' });
                            ESRI.ArcGIS.Geometry.IPointCollection pPointCollection1 = new ESRI.ArcGIS.Geometry.MultipointClass();
                            foreach (string str in strArray)
                            {
                                if (!string.IsNullOrEmpty(str))
                                {
                                    string[] strArray2 = str.Split(new char[] { ',' });
                                    double   pX        = double.Parse(strArray2[0]);
                                    double   pY        = double.Parse(strArray2[1]);
                                    ESRI.ArcGIS.Geometry.IPoint point = new ESRI.ArcGIS.Geometry.PointClass();
                                    point.X = pX;
                                    point.Y = pY;
                                    common.GenerateSHPFile(point, ErrorFilePath);
                                }
                            }
                        }
                    }
                    Marshal.ReleaseComObject(cursor);
                    if (errorCount == 0)
                    {
                        string            shpFolder         = System.IO.Path.GetDirectoryName(ErrorFilePath);
                        IWorkspaceFactory pWorkspaceFac     = new ShapefileWorkspaceFactoryClass();
                        IWorkspace        pWorkSpace        = pWorkspaceFac.OpenFromFile(ErrorFilePath, 0);
                        IFeatureWorkspace pFeatureWorkSpace = pWorkSpace as IFeatureWorkspace;
                        if (System.IO.File.Exists(ErrorFilePath))
                        {
                            IFeatureClass pFCChecker = pFeatureWorkSpace.OpenFeatureClass(ErrorFilePath);
                            if (pFCChecker != null)
                            {
                                IDataset pds = pFCChecker as IDataset;
                                pds.Delete();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog(typeof(TopoChecker), ex);
                }
                if (!DicTopoError.ContainsKey(idname))
                {
                    DicTopoError.Add(idname, errorCount);
                }
                else
                {
                    DicTopoError[idname] = errorCount;
                }
            }
            else if (IN_RuleType == "缝隙检查")
            {
                int errorCount = 0;
                try
                {
                    common.CreatShpFile(this.topoDir, spatialReference, esriGeometryType.esriGeometryPolygon, checkname + idname);
                    this.m_hookHelper = m_hookHelper;
                    IFeatureClass pFClass = IN_FeatureClass;
                    //获取空间参考
                    IGeometry   geometryBag = new GeometryBagClass();
                    IGeoDataset geoDataset  = pFClass as IGeoDataset;
                    geometryBag.SpatialReference = geoDataset.SpatialReference;

                    ////属性过滤
                    IFeatureCursor featureCursor = pFClass.Search(null, false);

                    // 遍历游标
                    IFeature            currentFeature     = featureCursor.NextFeature();
                    IGeometryCollection geometryCollection = geometryBag as IGeometryCollection;
                    object missing = Type.Missing;
                    while (currentFeature != null)
                    {
                        geometryCollection.AddGeometry(currentFeature.Shape, ref missing, ref missing);
                        currentFeature = featureCursor.NextFeature();
                    }

                    // 合并要素
                    ITopologicalOperator unionedPolygon = null;
                    unionedPolygon = new Polygon() as ITopologicalOperator;
                    unionedPolygon.ConstructUnion(geometryCollection as IEnumGeometry);

                    Marshal.ReleaseComObject(featureCursor);
                    IPolygon4           pMergerPolygon     = unionedPolygon as IPolygon4;
                    IGeometryBag        pOutGeometryBag    = pMergerPolygon.ExteriorRingBag; //获取外部环
                    IGeometryCollection pOutGmtyCollection = pOutGeometryBag as IGeometryCollection;

                    for (int i = 0; i < pOutGmtyCollection.GeometryCount; i++)   //对外部环遍历
                    {
                        IGeometry pOutRing = pOutGmtyCollection.get_Geometry(i); //外部环
                        //【此处可以对外部环进行操作】
                        IPointCollection pOutRingCollection = pOutRing as IPointCollection;
                        for (int j = 0; j < pOutRingCollection.PointCount; j++)
                        {
                            IPoint pOutRingPoint = pOutRingCollection.get_Point(j);//获取外环上的点
                        }

                        IGeometryBag        pInteriotGeometryBag        = pMergerPolygon.get_InteriorRingBag(pOutRing as IRing); //获取内部环
                        IGeometryCollection pInteriorGeometryCollection = pInteriotGeometryBag as IGeometryCollection;

                        for (int j = 0; j < pInteriorGeometryCollection.GeometryCount; j++)
                        {
                            ISegmentCollection SegCol = pInteriorGeometryCollection.get_Geometry(j) as ISegmentCollection;

                            IPolygon           PPolygon  = new PolygonClass();
                            ISegmentCollection newSegCol = PPolygon as ISegmentCollection;
                            newSegCol.AddSegmentCollection(SegCol);
                            //pInteriorGeometry即为多边形的内部环
                            IGeometry inRing = PPolygon as IGeometry;
                            inRing.SpatialReference = geometryBag.SpatialReference;
                            IArea  area    = inRing as IArea;
                            Double getarea = System.Math.Abs(Convert.ToDouble(area.Area));
                            if (inputtext == null || inputtext == "" || getarea < Convert.ToDouble(inputtext))
                            {
                                Boolean        flag   = true;
                                ISpatialFilter filter = new SpatialFilterClass();
                                filter.Geometry   = inRing;
                                filter.SubFields  = pFClass.OIDFieldName + "," + pFClass.ShapeFieldName;
                                filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                IFeatureCursor o       = pFClass.Search(filter, true);
                                IFeature       feature = o.NextFeature();
                                while (feature != null && flag)
                                {
                                    IPolygon4           pPolygon           = feature.Shape as IPolygon4;
                                    IGeometryBag        iOutGeometryBag    = pPolygon.ExteriorRingBag; //获取外部环
                                    IGeometryCollection iOutGmtyCollection = iOutGeometryBag as IGeometryCollection;

                                    for (int m = 0; m < iOutGmtyCollection.GeometryCount && flag; m++)  //对外部环遍历
                                    {
                                        IGeometry           outGeo     = iOutGmtyCollection.get_Geometry(m);
                                        IGeometryCollection polyGonGeo = new PolygonClass();
                                        polyGonGeo.AddGeometry(outGeo);
                                        IPolygon iPolygon = polyGonGeo as IPolygon;
                                        iPolygon.SimplifyPreserveFromTo();
                                        IRelationalOperator2 pRelationalOperator2 = iPolygon as IRelationalOperator2;
                                        if (!pRelationalOperator2.Contains(inRing))
                                        {
                                            errorCount++;
                                            common.GenerateSHPFile(inRing, ErrorFilePath);
                                            flag = false;
                                        }
                                    }
                                    feature = o.NextFeature();
                                }
                                Marshal.ReleaseComObject(o);
                            }
                        }
                        if (errorCount == 0)
                        {
                            string            shpFolder         = System.IO.Path.GetDirectoryName(ErrorFilePath);
                            IWorkspaceFactory pWorkspaceFac     = new ShapefileWorkspaceFactoryClass();
                            IWorkspace        pWorkSpace        = pWorkspaceFac.OpenFromFile(ErrorFilePath, 0);
                            IFeatureWorkspace pFeatureWorkSpace = pWorkSpace as IFeatureWorkspace;
                            if (System.IO.File.Exists(ErrorFilePath))
                            {
                                IFeatureClass pFCChecker = pFeatureWorkSpace.OpenFeatureClass(ErrorFilePath);
                                if (pFCChecker != null)
                                {
                                    IDataset pds = pFCChecker as IDataset;
                                    pds.Delete();
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog(typeof(TopoChecker), ex);
                }
                if (!DicTopoError.ContainsKey(idname))
                {
                    DicTopoError.Add(idname, errorCount);
                }
                else
                {
                    DicTopoError[idname] = errorCount;
                }
            }
            else if (IN_RuleType == "面重叠检查")
            {
                IFeatureClass outIFC = null;
                this.m_hookHelper = m_hookHelper;
                ESRI.ArcGIS.AnalysisTools.Intersect intersect = new ESRI.ArcGIS.AnalysisTools.Intersect();
                string outString = this.topoDir + "\\" + checkname + idname + ".shp";
                intersect.in_features       = common.GetPathByName(TABLENAME);
                intersect.out_feature_class = outString;
                Geoprocessor geoProcessor = new Geoprocessor();
                geoProcessor.OverwriteOutput = true;
                try
                {
                    if (this.gp == null)
                    {
                        this.gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                    }
                    IGeoProcessorResult result = (IGeoProcessorResult)this.gp.Execute(intersect, null);

                    if (result.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
                    {
                        Console.WriteLine("gp工具执行错误");
                    }
                    else
                    {
                        outIFC = this.gp.Open(result.ReturnValue) as IFeatureClass;
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog(typeof(TopoChecker), ex);
                    Console.WriteLine(ex.Message);
                }

                if (outIFC.FeatureCount(null) == 0)
                {
                    string            shpFolder         = System.IO.Path.GetDirectoryName(ErrorFilePath);
                    IWorkspaceFactory pWorkspaceFac     = new ShapefileWorkspaceFactoryClass();
                    IWorkspace        pWorkSpace        = pWorkspaceFac.OpenFromFile(ErrorFilePath, 0);
                    IFeatureWorkspace pFeatureWorkSpace = pWorkSpace as IFeatureWorkspace;
                    if (System.IO.File.Exists(ErrorFilePath))
                    {
                        IFeatureClass pFCChecker = pFeatureWorkSpace.OpenFeatureClass(ErrorFilePath);
                        if (pFCChecker != null)
                        {
                            IDataset pds = pFCChecker as IDataset;
                            pds.Delete();
                        }
                    }
                }

                if (!DicTopoError.ContainsKey(idname))
                {
                    DicTopoError.Add(idname, outIFC.FeatureCount(null));
                }
                else
                {
                    DicTopoError[idname] = outIFC.FeatureCount(null);
                }
            }
            else if (IN_RuleType == "面重叠检查(与其他图层)")
            {
                IFeatureClass outIFC = null;
                this.m_hookHelper = m_hookHelper;
                ESRI.ArcGIS.AnalysisTools.Intersect intersect = new ESRI.ArcGIS.AnalysisTools.Intersect();
                string outString = this.topoDir + "\\" + checkname + idname + ".shp";
                intersect.in_features       = @common.GetPathByName(TABLENAME) + ";" + @common.GetPathByName(SUPTABLE);
                intersect.out_feature_class = outString;
                Geoprocessor geoProcessor = new Geoprocessor();
                geoProcessor.OverwriteOutput = true;
                try
                {
                    if (this.gp == null)
                    {
                        this.gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                    }
                    IGeoProcessorResult result = (IGeoProcessorResult)this.gp.Execute(intersect, null);

                    if (result.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
                    {
                        Console.WriteLine("gp工具执行错误");
                    }
                    else
                    {
                        outIFC = this.gp.Open(result.ReturnValue) as IFeatureClass;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    LogHelper.WriteLog(typeof(TopoChecker), ex);
                }
                if (outIFC.FeatureCount(null) == 0)
                {
                    string            shpFolder         = System.IO.Path.GetDirectoryName(ErrorFilePath);
                    IWorkspaceFactory pWorkspaceFac     = new ShapefileWorkspaceFactoryClass();
                    IWorkspace        pWorkSpace        = pWorkspaceFac.OpenFromFile(ErrorFilePath, 0);
                    IFeatureWorkspace pFeatureWorkSpace = pWorkSpace as IFeatureWorkspace;
                    if (System.IO.File.Exists(ErrorFilePath))
                    {
                        IFeatureClass pFCChecker = pFeatureWorkSpace.OpenFeatureClass(ErrorFilePath);
                        if (pFCChecker != null)
                        {
                            IDataset pds = pFCChecker as IDataset;
                            pds.Delete();
                        }
                    }
                }
                if (!DicTopoError.ContainsKey(idname))
                {
                    DicTopoError.Add(idname, outIFC.FeatureCount(null));
                }
                else
                {
                    DicTopoError[idname] = outIFC.FeatureCount(null);
                }
            }
            Marshal.ReleaseComObject(IN_FeatureClass);
            if (SUPTABLE != null)
            {
                Marshal.ReleaseComObject(IN_Sup_FeatureClass);
            }
        }
        protected override void OnClick()
        {
            IEditor  pEd  = (IEditor)ArcMap.Editor;
            IEditor2 pEd2 = (IEditor2)ArcMap.Editor;

            IEditProperties  pEdProps1 = pEd as IEditProperties;
            IEditProperties2 pEdProps2 = pEd as IEditProperties2;

            IEditSketch2       pSketch2 = ArcMap.Editor as IEditSketch2;
            ISegmentCollection pSegColl = pSketch2.Geometry as ISegmentCollection;

            double dLineDirection = 0;

            ISketchTool sketchTool = ArcMap.Application.CurrentTool.Command as ISketchTool;

            if (sketchTool.Constraint == esriSketchConstraint.esriConstraintAngle)
            {
                dLineDirection = sketchTool.AngleConstraint;
            }
            else
            {
                ILine pRubberBandLine = new LineClass();
                pRubberBandLine.PutCoords(pSketch2.LastPoint, pEd2.Location);
                dLineDirection = pRubberBandLine.Angle;
            }

            IAngularConverter pAngConv = new AngularConverterClass();

            pAngConv.SetAngle(dLineDirection, esriDirectionType.esriDTPolar, esriDirectionUnits.esriDURadians);

            int iSegCnt = pSegColl.SegmentCount;
            dlgSpiralParameters SpiralEntryDialog = new dlgSpiralParameters();

            string sBearing = pAngConv.GetString(pEdProps2.DirectionType, pEdProps2.DirectionUnits, pEdProps2.AngularUnitPrecision);

            SpiralEntryDialog.txtDirection.Text = sBearing;
            //Display the dialog
            DialogResult pDialogResult = SpiralEntryDialog.ShowDialog();

            esriCurveDensifyMethod DensifyMethod = esriCurveDensifyMethod.esriCurveDensifyByAngle; //default
            double dDensifyParameter             = 2 * Math.PI / 180;                              //2 degrees //default

            if (SpiralEntryDialog.optCustomDensification.Checked)
            {
                DensifyMethod = (esriCurveDensifyMethod)SpiralEntryDialog.cboDensificationType.SelectedIndex;
                if (DensifyMethod == esriCurveDensifyMethod.esriCurveDensifyByAngle)
                {
                    dDensifyParameter = Convert.ToDouble(SpiralEntryDialog.numAngleDensification.Value) * Math.PI / 180;
                }
                else
                {
                    if (!Double.TryParse(SpiralEntryDialog.txtDensifyValue.Text, out dDensifyParameter))
                    {
                        dDensifyParameter = 2;
                    }
                }
            }

            if (pDialogResult != DialogResult.OK)
            {
                return;
            }

            if (SpiralEntryDialog.txtStartRadius.Text.ToLower().Trim() == "infinity" && SpiralEntryDialog.txtEndRadius.Text.ToLower().Trim() == "infinity")
            {
                return;
            }


            double dSpiralRadius1 = Double.MaxValue; //default to infinity
            double dFromCurvature = 0;

            if (SpiralEntryDialog.txtStartRadius.Text.ToLower() != "infinity")
            {
                if (Double.TryParse(SpiralEntryDialog.txtStartRadius.Text, out dSpiralRadius1))
                {
                    dFromCurvature = 1 / dSpiralRadius1;
                }
                else
                {
                    return;
                }
            }

            double dSpiralRadius2 = Double.MaxValue; //default to infinity
            double dToCurvature   = 0;

            if (SpiralEntryDialog.txtEndRadius.Text.ToLower() != "infinity")
            {
                if (Double.TryParse(SpiralEntryDialog.txtEndRadius.Text, out dSpiralRadius2))
                {
                    dToCurvature = 1 / dSpiralRadius2;
                }
                else
                {
                    return;
                }
            }

            bool bIsCCW = (dSpiralRadius1 > dSpiralRadius2) ? SpiralEntryDialog.optRight.Checked : SpiralEntryDialog.optLeft.Checked;

            bool bSpecialCaseCircularArc = (dSpiralRadius1 == dSpiralRadius2);

            if (!pAngConv.SetString(SpiralEntryDialog.txtDirection.Text, pEdProps2.DirectionType, pEdProps2.DirectionUnits))
            {
                return;
            }

            double dNorthAzimuthRadians = pAngConv.GetAngle(esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDURadians);

            IVector3D pVec = new Vector3DClass();

            pVec.PolarSet(dNorthAzimuthRadians, 0, 500);

            IPoint pTangentPoint = new PointClass();

            pTangentPoint.PutCoords(pSketch2.LastPoint.X + pVec.XComponent, pSketch2.LastPoint.Y + pVec.YComponent);

            //double dStreamingTol = pEdProps1.StreamTolerance;
            //if (dStreamingTol == 0)
            //  dStreamingTol = 0.001 * 5000; //metric

            //double dSpiralOffsetGeometryPrecision = 0.001 * 250; //metric 0.25 m

            IPolyline6 theSpiralPolyLine = null;
            double     dExitTangent      = 0;

            if (SpiralEntryDialog.cboPathLengthParameter.SelectedIndex == 0)
            {
                double dSpiralArcLength;
                if (!Double.TryParse(SpiralEntryDialog.txtPathLengthParameter.Text, out dSpiralArcLength))
                {
                    return;
                }

                if (bSpecialCaseCircularArc)
                {
                    ILine pInTangentLine = new LineClass();
                    pInTangentLine.PutCoords(pSketch2.LastPoint, pTangentPoint);

                    ISegment pTangentSegment = (ISegment)pInTangentLine;
                    IConstructCircularArc2 pCircArcConstr = new ESRI.ArcGIS.Geometry.CircularArcClass() as IConstructCircularArc2;
                    pCircArcConstr.ConstructTangentRadiusArc(pTangentSegment, false, bIsCCW, dSpiralRadius1, dSpiralArcLength);
                    ICircularArc pArcSegment = pCircArcConstr as ICircularArc;

                    //Get chord Line from tangent curve constructor
                    ILine pChordLine = new LineClass();
                    pChordLine.PutCoords(pArcSegment.FromPoint, pArcSegment.ToPoint);
                    double dPolarRadians = pChordLine.Angle; //to get the chord azimuth

                    pCircArcConstr.ConstructBearingRadiusArc(pSketch2.LastPoint, dPolarRadians, bIsCCW, dSpiralRadius1, dSpiralArcLength);

                    dExitTangent = pArcSegment.ToAngle + Math.PI / 2;

                    ISegmentCollection segCollection = new PolylineClass() as ISegmentCollection;
                    object             obj           = Type.Missing;
                    segCollection.AddSegment((ISegment)pArcSegment, ref obj, ref obj);
                    theSpiralPolyLine = segCollection as IPolyline6;
                }
                else
                {
                    theSpiralPolyLine = ConstructSpiralbyLength(pSketch2.LastPoint, pTangentPoint, dFromCurvature, dToCurvature, bIsCCW, dSpiralArcLength,
                                                                DensifyMethod, dDensifyParameter, out dExitTangent);
                }
            }

            if (SpiralEntryDialog.cboPathLengthParameter.SelectedIndex == 1)
            {
                if (!pAngConv.SetString(SpiralEntryDialog.txtPathLengthParameter.Text, esriDirectionType.esriDTPolar, pEdProps2.DirectionUnits))
                {
                    return;
                }
                double dSpiralDeltaAngle = pAngConv.GetAngle(esriDirectionType.esriDTPolar, esriDirectionUnits.esriDURadians);

                if (bSpecialCaseCircularArc)
                {
                    ILine pInTangentLine = new LineClass();
                    pInTangentLine.PutCoords(pSketch2.LastPoint, pTangentPoint);

                    ISegment pTangentSegment = (ISegment)pInTangentLine;
                    IConstructCircularArc2 pCircArcConstr = new ESRI.ArcGIS.Geometry.CircularArcClass() as IConstructCircularArc2;
                    pCircArcConstr.ConstructTangentRadiusAngle(pTangentSegment, false, bIsCCW, dSpiralRadius1, dSpiralDeltaAngle);
                    ICircularArc pArcSegment = pCircArcConstr as ICircularArc;

                    //Get chord Line from tangent curve constructor
                    ILine pChordLine = new LineClass();
                    pChordLine.PutCoords(pArcSegment.FromPoint, pArcSegment.ToPoint);
                    double dPolarRadians = pChordLine.Angle; //to get the chord azimuth

                    pCircArcConstr.ConstructBearingRadiusAngle(pSketch2.LastPoint, dPolarRadians, bIsCCW, dSpiralRadius1, dSpiralDeltaAngle);

                    dExitTangent = pArcSegment.ToAngle + Math.PI / 2;

                    ISegmentCollection segCollection = new PolylineClass() as ISegmentCollection;
                    object             obj           = Type.Missing;
                    segCollection.AddSegment((ISegment)pArcSegment, ref obj, ref obj);
                    theSpiralPolyLine = segCollection as IPolyline6;
                }
                else
                {
                    theSpiralPolyLine = ConstructSpiralbyDeltaAngle(pSketch2.LastPoint, pTangentPoint, dFromCurvature, dToCurvature, bIsCCW, dSpiralDeltaAngle,
                                                                    DensifyMethod, dDensifyParameter, out dExitTangent);
                }
            }

            if (theSpiralPolyLine == null)
            {
                MessageBox.Show("A spiral could not be created with the entered parameters.");
                return;
            }

            ISegmentCollection pSpiralSegCollection = theSpiralPolyLine as ISegmentCollection;
            //Start a sketch operation and insert the new envelope into the sketch
            ISketchOperation2 sketchOp = new SketchOperationClass();

            sketchOp.Start(ArcMap.Editor);
            sketchOp.MenuString = "Add Spiral";
            pSegColl.AddSegmentCollection(pSpiralSegCollection);
            IGeometry geom = pSegColl as IGeometry;

            pSketch2.Geometry = geom;

            //set the angle constraint to the exit tangent of the spiral
            sketchTool.Constraint      = esriSketchConstraint.esriConstraintAngle;
            sketchTool.AngleConstraint = dExitTangent;

            sketchOp.Finish(ArcMap.Document.ActiveView.Extent, esriSketchOperationType.esriSketchOperationGeneral, null);
        }
예제 #5
0
        /// <summary>
        /// 合并多条多义线,如果合并的多义线不是简单的多义线则抛出异常
        /// </summary>
        /// <param name="pPolylines">多义线集</param>
        /// <returns>多义线</returns>
        public static IPolyline UnionPolylines(IPolyline[] pPolylines)
        {
            // 第一条线段
            int indexFirst                           = -1;
            int degree                               = 0;
            IRelationalOperator pRO                  = null;
            int                  nSelected           = pPolylines.Length;
            IPolyline            pRetPolyline        = new PolylineClass();
            ITopologicalOperator pTopoOper           = (ITopologicalOperator)pRetPolyline;
            IGeometryCollection  pGeometryCollection = new GeometryBagClass();

            for (int i = 0; i < pPolylines.Length; i++)
            {
                object o = Type.Missing;
                pGeometryCollection.AddGeometry(pPolylines[i],
                                                ref o, ref o);
            }
            pTopoOper.ConstructUnion((IEnumGeometry)pGeometryCollection);
            IGeometryCollection pGeometryColl = (IGeometryCollection)pTopoOper;

            if (pGeometryColl.GeometryCount > 1)
            {
                throw new Exception("线段的空间连接不正确");
            }

            return((IPolyline)pTopoOper);

            // AddGeometry
            // 数据检查
            //ConstructUnion

            /*
             * double tol = GeometryHelper.ConvertPixelsToMapUnits(pActiveView, 4);
             * IPoint pHitPoint = null;
             * double hitDist = 0;
             * int partIndex = 0;
             * int vertexIndex = 0;
             * int vertexOffset = 0;
             * bool vertex = false;
             * if (EditHelper.HitTest(tol, _pMenuPosition, pFeature, ref pHitPoint, ref hitDist, ref partIndex, ref vertexIndex, ref vertexOffset, ref vertex))
             * {
             *
             * }
             */
            for (int i = 0; i < nSelected; i++)
            {
                int nTouch = 0;
                pRO = (IRelationalOperator)pPolylines[i];
                IHitTest hittest = (IHitTest)pRO;
                for (int j = 0; j < nSelected; j++)
                {
                    if (i != j && pRO.Touches(pPolylines[j]))
                    {
                        nTouch++;
                    }
                }
                if (nTouch == 0 || nTouch > 2)
                {
                    throw new Exception("line touch error");
                }
                else if (nTouch == 1)
                {
                    if (indexFirst == -1)
                    {
                        indexFirst = i;
                    }

                    if (++degree > 2)
                    {
                        throw new Exception("multi patchs");
                    }
                }
            }
            // 依据第一条线topo有序
            if (indexFirst == -1)
            {
                throw new Exception("line circle");
            }

            IPolyline pTemp = pPolylines[indexFirst];

            pPolylines[indexFirst] = pPolylines[0];
            pPolylines[0]          = pTemp;
            IPolyline          pPolyline = new PolylineClass();
            ISegmentCollection pSegments = (ISegmentCollection)pPolyline;

            pSegments.AddSegmentCollection((ISegmentCollection)pPolylines[0]);
            for (int i = 0; i < nSelected - 1; i++)
            {
                pRO = (IRelationalOperator)pPolylines[i];
                for (int j = i + 1; j < nSelected; j++)
                {
                    if (pRO.Touches(pPolylines[j]))
                    {
                        pTemp             = pPolylines[j];
                        pPolylines[j]     = pPolylines[i + 1];
                        pPolylines[i + 1] = pTemp;
                        if (IdentialPoint(pPolylines[i].FromPoint, pPolylines[i + 1].ToPoint))
                        {
                            //pSegments.AddSegmentCollection();
                        }
                        break;
                    }
                }
            }
            return(null);
        }
예제 #6
0
        /// <summary>
        /// 缝隙检查。融合后去内环。
        /// </summary>
        /// <param name="pFeature"></param>
        /// <returns></returns>
        public List <Dictionary <string, IGeometry> > CheckFeatureGap(IFeatureClass pFClass, string inputtext)
        {
            List <Dictionary <string, IGeometry> > listGeo = new List <Dictionary <string, IGeometry> >();

            if (pFClass == null)
            {
                return(null);
            }

            //Stopwatch watch = new Stopwatch();
            //watch.Start();

            //获取空间参考
            IGeometry   geometryBag = new GeometryBagClass();
            IGeoDataset geoDataset  = pFClass as IGeoDataset;

            geometryBag.SpatialReference = geoDataset.SpatialReference;

            ////属性过滤
            //ISpatialFilter queryFilter = new SpatialFilterClass();
            //queryFilter.SubFields = "Shape";
            IFeatureCursor featureCursor = pFClass.Search(null, false);

            // 遍历游标
            IFeature currentFeature = featureCursor.NextFeature();

            if (currentFeature == null)
            {
                return(null);
            }
            IGeometryCollection geometryCollection = geometryBag as IGeometryCollection;
            object missing = Type.Missing;

            while (currentFeature != null)
            {
                geometryCollection.AddGeometry(currentFeature.Shape, ref missing, ref missing);
                currentFeature = featureCursor.NextFeature();
            }

            // 合并要素
            ITopologicalOperator unionedPolygon = null;

            if (pFClass.ShapeType == esriGeometryType.esriGeometryPoint)
            {
                unionedPolygon = new Multipoint() as ITopologicalOperator;
                unionedPolygon.ConstructUnion(geometryCollection as IEnumGeometry);
            }
            else if (pFClass.ShapeType == esriGeometryType.esriGeometryPolyline)
            {
                unionedPolygon = new Polyline() as ITopologicalOperator;
                unionedPolygon.ConstructUnion(geometryCollection as IEnumGeometry);
            }
            else
            {
                unionedPolygon = new Polygon() as ITopologicalOperator;
                unionedPolygon.ConstructUnion(geometryCollection as IEnumGeometry);
            }
            Marshal.ReleaseComObject(featureCursor);
            IPolygon4           pMergerPolygon     = unionedPolygon as IPolygon4;
            IGeometryBag        pOutGeometryBag    = pMergerPolygon.ExteriorRingBag; //获取外部环
            IGeometryCollection pOutGmtyCollection = pOutGeometryBag as IGeometryCollection;

            for (int i = 0; i < pOutGmtyCollection.GeometryCount; i++)   //对外部环遍历
            {
                IGeometry pOutRing = pOutGmtyCollection.get_Geometry(i); //外部环
                //【此处可以对外部环进行操作】
                IPointCollection pOutRingCollection = pOutRing as IPointCollection;
                for (int j = 0; j < pOutRingCollection.PointCount; j++)
                {
                    IPoint pOutRingPoint = pOutRingCollection.get_Point(j);//获取外环上的点
                }

                IGeometryBag        pInteriotGeometryBag        = pMergerPolygon.get_InteriorRingBag(pOutRing as IRing); //获取内部环
                IGeometryCollection pInteriorGeometryCollection = pInteriotGeometryBag as IGeometryCollection;


                for (int j = 0; j < pInteriorGeometryCollection.GeometryCount; j++)
                {
                    ISegmentCollection SegCol = pInteriorGeometryCollection.get_Geometry(j) as ISegmentCollection;

                    IPolygon           PPolygon  = new PolygonClass();
                    ISegmentCollection newSegCol = PPolygon as ISegmentCollection;
                    newSegCol.AddSegmentCollection(SegCol);
                    //pInteriorGeometry即为多边形的内部环
                    IGeometry inRing = PPolygon as IGeometry;
                    inRing.SpatialReference = geometryBag.SpatialReference;
                    IArea  area    = inRing as IArea;
                    Double getarea = System.Math.Abs(Convert.ToDouble(area.Area));
                    if (inputtext == null || inputtext == "" || getarea < Convert.ToDouble(inputtext))
                    {
                        Boolean        flag   = true;
                        ISpatialFilter filter = new SpatialFilterClass();
                        filter.Geometry   = inRing;
                        filter.SubFields  = pFClass.OIDFieldName + "," + pFClass.ShapeFieldName;
                        filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                        IFeatureCursor o       = pFClass.Search(filter, true);
                        IFeature       feature = o.NextFeature();
                        while (feature != null && flag)
                        {
                            Console.WriteLine(feature.OID);
                            IPolygon4           pPolygon           = feature.Shape as IPolygon4;
                            IGeometryBag        iOutGeometryBag    = pPolygon.ExteriorRingBag; //获取外部环
                            IGeometryCollection iOutGmtyCollection = iOutGeometryBag as IGeometryCollection;

                            for (int m = 0; m < iOutGmtyCollection.GeometryCount && flag; m++)  //对外部环遍历
                            {
                                IGeometry           outGeo     = iOutGmtyCollection.get_Geometry(m);
                                IGeometryCollection polyGonGeo = new PolygonClass();
                                polyGonGeo.AddGeometry(outGeo);
                                IPolygon iPolygon = polyGonGeo as IPolygon;
                                iPolygon.SimplifyPreserveFromTo();
                                IRelationalOperator2 pRelationalOperator2 = iPolygon as IRelationalOperator2;
                                if (!pRelationalOperator2.Contains(inRing))
                                {
                                    Dictionary <string, IGeometry> itemDic = new Dictionary <string, IGeometry>();
                                    itemDic.Add(feature.OID.ToString(), inRing);
                                    listGeo.Add(itemDic);
                                    flag = false;
                                }
                            }
                            feature = o.NextFeature();
                        }
                        Marshal.ReleaseComObject(o);
                    }
                }
            }
            if (listGeo.Count > 0)
            {
                return(listGeo);
            }
            else
            {
                return(null);
            }
        }