Example #1
0
        static private IPoint nextPoint(IEnumVertex vertices, out int partIndex, out int vertexIndex)
        {
            IPoint p;

            vertices.Next(out p, out partIndex, out vertexIndex);
            return(p);
        }
Example #2
0
        public static ICollection <IPoint> GetPointsWithInvalidM(
            [NotNull] IPointCollection points,
            [NotNull] IPoint pointTemplate,
            double invalidValue)
        {
            Assert.ArgumentNotNull(points, nameof(points));
            Assert.ArgumentNotNull(pointTemplate, nameof(pointTemplate));

            IEnumVertex enumVertex = points.EnumVertices;
            int         partIndex;
            int         vertexIndex;

            enumVertex.QueryNext(pointTemplate, out partIndex, out vertexIndex);

            var result = new List <IPoint>();

            while (partIndex >= 0 && vertexIndex >= 0)
            {
                if (IsInvalidValue(pointTemplate.M, invalidValue))
                {
                    result.Add(GeometryFactory.Clone(pointTemplate));
                }

                enumVertex.QueryNext(pointTemplate, out partIndex, out vertexIndex);
            }

            return(result);
        }
Example #3
0
        private static List <WKSPointVA> GetFromEnumVertex([NotNull] IMultiPatch multiPatch)
        {
            var pts = (IPointCollection)multiPatch;

            int         pointCount = pts.PointCount;
            var         result     = new List <WKSPointVA>(pointCount);
            IEnumVertex enumVertex = pts.EnumVertices;

            enumVertex.Reset();
            IPoint p = new PointClass();
            int    part;
            int    vertex;

            for (enumVertex.QueryNext(p, out part, out vertex);
                 vertex >= 0;
                 enumVertex.QueryNext(p, out part, out vertex))
            {
                var    pnt = new WKSPointVA();
                double x;
                double y;
                p.QueryCoords(out x, out y);
                pnt.m_x  = x;
                pnt.m_y  = y;
                pnt.m_z  = p.Z;
                pnt.m_m  = p.M;
                pnt.m_id = p.ID;

                result.Add(pnt);
            }

            return(result);
        }
Example #4
0
        private List <IPoint> SplitPolyline(IPolyline polyline, IPointCollection intersectpointsColl, IPoint presentCP)
        {
            IEnumVertex pEnumVertex = intersectpointsColl.EnumVertices;
            //IPolycurve2 has SplitAtPoints

            IPolycurve2 pPolyCurve = polyline as IPolycurve2;

            pPolyCurve.SplitAtPoints(pEnumVertex, false, true, -1);
            IGeometryCollection geoColl = pPolyCurve as IGeometryCollection;
            //MessageBox.Show(geoColl.GeometryCount.ToString());
            List <IPoint> ptlist = new List <IPoint>();
            // The results are pathclass
            IPath resultPath;

            for (int i = 0; i < geoColl.GeometryCount; i++)
            {
                object obj = Type.Missing;
                resultPath = new PathClass();
                resultPath = (IPath)geoColl.get_Geometry(i);
                IGeometryCollection lineColl = new PolylineClass();
                lineColl.AddGeometry(resultPath, ref obj, ref obj);
                IPolyline           line         = (IPolyline)lineColl;
                IRelationalOperator pRelOperator = (IRelationalOperator)line;
                if (pRelOperator.Touches(presentCP) || pRelOperator.Contains(presentCP))
                {
                    IPoint temPT1 = resultPath.FromPoint;
                    IPoint temPT2 = resultPath.ToPoint;
                    //pGeometryCollection.AddGeometry(temPT1);
                    //pGeometryCollection.AddGeometry(temPT2);
                    ptlist.Add(temPT1);
                    ptlist.Add(temPT2);
                }
            }
            return(ptlist);
        }
        public void CreatePropertyChildNodes(TreeviewBranchViewModel parentNode, object comObj, Type typ)
        {
            IEnumVertex comEnum = comObj as IEnumVertex;

            foreach (IPoint enumValue in comEnum.Enumerate())
            {
                if ((enumValue != null) && (enumValue.GetType().IsCOMObject))
                {
                    ComObjectViewModel child = new ComObjectViewModel(parentNode, enumValue, typeof(IPoint), ".Next()");
                    parentNode.Children.Add(child);
                }
            }
        }
Example #6
0
        static private StringBuilder aoPolyToWtkHelper(IPointCollection points, bool isPolygon)
        {
            IEnumVertex   vertices = points.EnumVertices;
            StringBuilder sbMain   = new StringBuilder("(");

            IPoint        p;
            IPoint        firstInPart = new PointClass();
            int           pIdx;
            int           vIdx;
            int           pIdxCurr = 0; // The current part index.
            StringBuilder sbPart   = new StringBuilder();

            while ((p = nextPoint(vertices, out pIdx, out vIdx)) != null)
            {
                // Have we gotten a new part?
                // If so, close it out.
                if (pIdx != pIdxCurr)
                {
                    // We need to close this ring if it's a polygon.
                    if (isPolygon)
                    {
                        aoPolyToWktAddPoint(sbPart, firstInPart);
                        replaceLastChar(sbPart, ')');
                    }

                    aoPolyToWktAddPart(sbMain, sbPart);
                    sbMain.Append(",");
                    sbPart   = new StringBuilder();
                    pIdxCurr = pIdx;
                }

                aoPolyToWktAddPoint(sbPart, p);

                // Save the first point in each part to later close polygons.
                if (vIdx == 0)
                {
                    firstInPart.PutCoords(p.X, p.Y);
                }
            }

            // Close the last part of a polygon.
            if (isPolygon)
            {
                aoPolyToWktAddPoint(sbPart, firstInPart);
            }
            aoPolyToWktAddPart(sbMain, sbPart);

            sbMain.Append(")");

            return(sbMain);
        }
        /// <summary>
        /// Converts an Esri enumerable interface to a DotNet IEnumerable.
        /// </summary>
        /// <param name="esriEnum">An enumerable Esri interface.</param>
        /// <returns>The adapted dotnet enumeration.</returns>
        public static IEnumerable <IPoint> Enumerate(this IEnumVertex esriEnum)
        {
            IPoint point;
            int    partIndex;
            int    vertexIndex;

            esriEnum.Reset();
            esriEnum.Next(out point, out partIndex, out vertexIndex);
            while (point != null)
            {
                yield return(point);

                esriEnum.Next(out point, out partIndex, out vertexIndex);
            }
        }
Example #8
0
        public static void AssignZ([NotNull] IPointCollection points,
                                   [NotNull] Plane3D fromPlane)
        {
            Assert.False(points is IMultiPatch,
                         "This method cannot be used on multipatch geometries.");

            IEnumVertex eVertex = points.EnumVertices;
            IPoint      point   = new PointClass();
            int         part;
            int         vertex;

            eVertex.QueryNext(point, out part, out vertex);
            while (part >= 0 && vertex >= 0)
            {
                // This crashes ArcMap (with AccessViolation) if called on multipatch geometry:
                eVertex.put_Z(fromPlane.GetZ(point.X, point.Y));
                eVertex.QueryNext(point, out part, out vertex);
            }
        }
Example #9
0
        public static IEnumerable <LineIntersection> GetIntersections(
            [NotNull] IPolyline polyline1,
            [NotNull] IPolyline polyline2,
            bool is3D)
        {
            const bool  assumeIntersecting = true;
            IMultipoint intersections      =
                IntersectionUtils.GetIntersectionPoints(
                    polyline1, polyline2,
                    assumeIntersecting,
                    IntersectionPointOptions.DisregardLinearIntersections);

            if (intersections.IsEmpty)
            {
                yield break;
            }

            IEnumVertex enumIntersectionPoints =
                ((IPointCollection)intersections).EnumVertices;

            do
            {
                int vertexIndex;
                int outPartIndex;
                enumIntersectionPoints.QueryNext(TemplatePoint1,
                                                 out outPartIndex,
                                                 out vertexIndex);

                if (outPartIndex < 0 || vertexIndex < 0)
                {
                    break;
                }

                var intersection = new LineIntersection(polyline1, polyline2,
                                                        TemplatePoint1, is3D);
                yield return(intersection);
            } while (true);
        }
Example #10
0
        /// <summary>
        /// INTERPOLATE ELEVATION VALUES FOR VERTICES
        /// </summary>
        /// <param name="analysisSurface">Analysis surface</param>
        /// <param name="vertices">Enumeration of vertices</param>
        internal static void InterpolateVertices(AnalysisSurface analysisSurface, IEnumVertex vertices)
        {
            // RESET ENUM
            vertices.Reset();

            // ITERATE VERTICES
            IPoint outVertex;
            int    partIndex;
            int    vertexIndex;

            vertices.Next(out outVertex, out partIndex, out vertexIndex);
            while (outVertex != null)
            {
                // GET ELEVATION AT POINT LOCATION
                double elev = Helper.GetSurfaceElevation(analysisSurface, outVertex);

                // ASSIGN Z USING ELEVATION
                outVertex.Z = elev;

                // GET NEXT VERTEX
                vertices.Next(out outVertex, out partIndex, out vertexIndex);
            }
        }
Example #11
0
        private void processPolygonLayer(LayerProperties layerProps, geFolder folder)
        {
            //I have a polygon layer, and a kml folder :)
            IFeatureClass clasa = (layerProps.Layeru as IFeatureLayer).FeatureClass;
            //get acces to features
            IFeatureCursor featurele = clasa.Search(null, true);
            int            nrFeature = clasa.FeatureCount(null);

            //if I have any features
            Polygon  poligon;
            IFeature currentFeature;

            while ((currentFeature = featurele.NextFeature()) != null)
            {
                poligon = currentFeature.Shape as Polygon;
                //coordinates and vertices
                double      coordLat;
                double      coordLong;
                IEnumVertex colection = poligon.EnumVertices;
                IPoint      polyVertex;

                //create coord system WGS 84 (Google earth)
                IGeographicCoordinateSystem gcs;
                SpatialReferenceEnvironment sre = new SpatialReferenceEnvironment();
                gcs = sre.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
                //create spatial reference
                ISpatialReference pointToSpatialReference;
                pointToSpatialReference = gcs;

                #region add points to polygon
                //create a placemark for the line
                gePlacemark pmPolygon = new gePlacemark();
                pmPolygon.StyleUrl = "#Shape2KMLGeneratedStyle";

                List <geCoordinates> polyCoords = new List <geCoordinates>();
                int index1, index2;
                //iterate points...



                while (!colection.IsLastInPart())
                {
                    //create polygon from vertices
                    colection.Next(out polyVertex, out index1, out index2);
                    //project point and get coordinates
                    polyVertex.Project(pointToSpatialReference);
                    polyVertex.QueryCoords(out coordLong, out coordLat);
                    //add point to line

                    try
                    {
                        //create points for polygon based on altitude mode.
                        switch (layerProps.AltitudeMode)
                        {
                        case AltitudeMode.absolute:
                            if (layerProps.Field == "")
                            {
                                //add point to line
                                polyCoords.Add(new geCoordinates(new geAngle90(coordLat), new geAngle180(coordLong), layerProps.Altitude));
                            }
                            else
                            {
                                int altitude;
                                //if altitude is integer, this should work
                                altitude = (int)currentFeature.get_Value(currentFeature.Fields.FindField(layerProps.Field));

                                //add point to line
                                polyCoords.Add(new geCoordinates(new geAngle90(coordLat), new geAngle180(coordLong), layerProps.Multiplier * altitude));
                            }
                            break;

                        case AltitudeMode.clampToGround:
                            //add point to line
                            polyCoords.Add(new geCoordinates(new geAngle90(coordLat), new geAngle180(coordLong)));
                            break;

                        case AltitudeMode.relativeToGround:
                            if (layerProps.Field == "")
                            {
                                //add point to line
                                polyCoords.Add(new geCoordinates(new geAngle90(coordLat), new geAngle180(coordLong), layerProps.Altitude));
                            }
                            else
                            {
                                float altitude;
                                //if altitude is integer, this should work
                                altitude = (float)currentFeature.get_Value(currentFeature.Fields.FindField(layerProps.Field));

                                //add point to line
                                polyCoords.Add(new geCoordinates(new geAngle90(coordLat), new geAngle180(coordLong), layerProps.Multiplier * altitude));
                            }

                            break;

                        default:
                            break;
                        }
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Altitude field is not a number value");
                        break;
                    }
                }

                //create line from list of coords
                geOuterBoundaryIs outer = new geOuterBoundaryIs(new geLinearRing(polyCoords));
                gePolygon         poly  = new gePolygon(outer);
                //and add it to document

                switch (layerProps.AltitudeMode)
                {
                //set altitude mode...
                case AltitudeMode.absolute:
                    poly.AltitudeMode = geAltitudeModeEnum.absolute;
                    break;

                case AltitudeMode.clampToGround:
                    poly.AltitudeMode = geAltitudeModeEnum.clampToGround;
                    break;

                case AltitudeMode.relativeToGround:
                    poly.AltitudeMode = geAltitudeModeEnum.relativeToGround;
                    break;

                default:
                    break;
                }

                if (layerProps.DescField != "")
                {
                    pmPolygon.Description = currentFeature.get_Value(currentFeature.Fields.FindField(layerProps.DescField)).ToString();
                }

                if (layerProps.NameField != "")
                {
                    pmPolygon.Name = currentFeature.get_Value(currentFeature.Fields.FindField(layerProps.NameField)).ToString();
                }

                pmPolygon.Geometry = poly;
                folder.Features.Add(pmPolygon);

                #endregion
            }
        }
Example #12
0
 private static IPoint nextPoint(IEnumVertex vertices, out int partIndex, out int vertexIndex)
 {
     IPoint p;
     vertices.Next(out p, out partIndex, out vertexIndex);
     return p;
 }
Example #13
0
        //分割线
        public virtual ZhFeature[] SplitPolyline(ZhFeature[] zhFeatures, ZhFeature[] pUsedZHFeatures)
        {
            List <ZhFeature> pMuliFeatures = new List <ZhFeature>();
            List <IGeometry> GeoList       = new List <IGeometry>();

            GeoList.Clear();
            List <IGeometry> CutterGeoList = new List <IGeometry>();
            IPointCollection pMultipoint   = null;

            IGeometry[] cgGeoArray = null;
            //几何对象分割
            foreach (ZhFeature tpByFeat in zhFeatures)
            {
                CutterGeoList.Clear();
                cgGeoArray = null;

                object    obj            = Type.Missing;
                IPolyline cutterPolyline = new PolylineClass();
                pMultipoint = (IPointCollection)cutterPolyline;

                //求相交点的所有集合
                foreach (ZhFeature tpUsedFeat in pUsedZHFeatures)
                {
                    //求相交点集合
                    cgGeoArray = this.MuliCutPolyline(tpByFeat, tpUsedFeat);
                    foreach (IGeometry tGeo in cgGeoArray)
                    {
                        if (((IRelationalOperator)pMultipoint).Contains(tGeo) == false)
                        {
                            pMultipoint.AddPoint((IPoint)tGeo, ref obj, ref obj);
                        }
                    }
                }

                //添加原线端点
                //pMultipoint.AddPointCollection((IPointCollection)tpByFeat.pFeature.ShapeCopy);

                //拓朴化处理  去掉重复点操作
                //ITopologicalOperator pTop = pMultipoint as ITopologicalOperator;
                //pTop.Simplify();
                //pMultipoint = pTop as IPointCollection;

                //清除原对象
                GeoList.Clear();

                //用相交点集合分割线
                if (tpByFeat.pFeature.Shape is IPolycurve2)
                {
                    //IPoint outVertex = null;
                    //IPoint preVertex = null;

                    //int outPartIndex = 0;
                    //int vertexIndex = 0;
                    IPolycurve2 Curve2      = tpByFeat.pFeature.Shape as IPolycurve2;
                    IEnumVertex SplitPoints = pMultipoint.EnumVertices;
                    Curve2.SplitAtPoints(SplitPoints, true, true, -1);
                    IGeometryCollection pcgGeoColl = Curve2 as IGeometryCollection;
                    for (int i = 0; i < pcgGeoColl.GeometryCount; i++)
                    {
                        IGeometry tpcgGeo = pcgGeoColl.get_Geometry(i);

                        IGeometryCollection oGeoCol = new PolylineClass();
                        oGeoCol.AddGeometries(1, ref tpcgGeo);

                        if (((ITopologicalOperator)oGeoCol).IsSimple == false)
                        {
                            ((ITopologicalOperator)oGeoCol).Simplify();
                        }

                        GeoList.Add(oGeoCol as IGeometry);
                    }
                    #region IEnumSplitPoint
                    //IEnumSplitPoint cgEnumPoint=Curve2.SplitAtPoints(SplitPoints,false,false,-1);
                    //cgEnumPoint.Reset();
                    //cgEnumPoint.Next(out outVertex, out outPartIndex, out vertexIndex);
                    //while (outVertex != null && outVertex.IsEmpty != true && cgEnumPoint.IsLastInPart()!=true)
                    //{
                    //    preVertex=outVertex;
                    //    cgEnumPoint.Next(out outVertex, out outPartIndex, out vertexIndex);
                    //    if (preVertex != null && outVertex != null && outVertex.IsEmpty!=true)
                    //    {
                    //        IPolyline pcgPolyline = new PolylineClass();
                    //        (pcgPolyline as IPointCollection).AddPoint(preVertex, ref obj, ref obj);
                    //        (pcgPolyline as IPointCollection).AddPoint(outVertex, ref obj, ref obj);
                    //        if (pcgPolyline.IsEmpty != true)
                    //        {
                    //            GeoList.Add(pcgPolyline);
                    //        }
                    //    }
                    //}
                    #endregion
                }

                //创建分割后对象 ZHFeatureByGeoList
                ZhFeature tpFeat = null;
                foreach (IGeometry pGeo in GeoList)
                {
                    if (pGeo.IsEmpty != true)
                    {
                        tpFeat = this.CreateFeature();
                        //属性拷贝(含GHDM赋码)
                        tpByFeat.CopyField(ref tpFeat);
                        tpFeat.pFeature.Shape = pGeo;
                        //保存
                        //tpFeat.pFeature.Store();
                        pMuliFeatures.Add(tpFeat);
                    }
                }
            }
            return(pMuliFeatures.ToArray());
        }
Example #14
0
            public override IEnumerable <AngleInfo> GetAngles()
            {
                int partIndex;
                int vertexIndex;

                double x2        = 0;
                double y2        = 0;
                double z2        = 0;
                double dx1       = 0;
                double dy1       = 0;
                double dz1       = 0;
                double l12       = 0;
                var    minVertex = 2;

                if (((ICurve)_points).IsClosed)
                {
                    var segments = _points as ISegmentCollection;
                    if (segments != null)
                    {
                        int segmentCount = segments.SegmentCount;
                        if (segmentCount == 1)
                        {
                            ISegment segment = segments.Segment[0];

                            if (IsZeroLength(segment))
                            {
                                // single zero-length segment forming a closed curve, ignore

                                // NOTE: closed elliptic arcs also report length = 0, unable to calculate tangents --> ignored here
                                yield break;
                            }

                            AngleInfo info = AngleInfo.Create(segment, segment, Settings.Is3D);
                            yield return(info);

                            yield break;
                        }

                        if (segmentCount == 2)
                        {
                            ISegment segment0 = segments.Segment[0];
                            ISegment segment1 = segments.Segment[1];

                            if (!(segment0 is ILine) || !(segment1 is ILine))
                            {
                                // two segment closed curve, at least one of the segments is non-linear
                                // --> calculate using tangent
                                // otherwise, linearized segment angles would always be 0, resulting in errors
                                bool segment0IsZeroLength = IsZeroLength(segment0);
                                bool segment1IsZeroLength = IsZeroLength(segment1);

                                if (!segment0IsZeroLength && !segment1IsZeroLength)
                                {
                                    yield return
                                        (AngleInfo.Create(segment0, segment1, Settings.Is3D));

                                    yield return
                                        (AngleInfo.Create(segment1, segment0, Settings.Is3D));
                                }
                                else if (segment0IsZeroLength)
                                {
                                    yield return
                                        (AngleInfo.Create(segment1, segment1, Settings.Is3D));
                                }
                                else
                                {
                                    // segment 1 is zero length
                                    yield return
                                        (AngleInfo.Create(segment0, segment0, Settings.Is3D));
                                }

                                yield break;
                            }
                        }
                    }

                    _points.QueryPoint(_points.PointCount - 2, Settings.QueryPoint);

                    Settings.QueryPoint.QueryCoords(out x2, out y2);
                    z2        = Settings.QueryPoint.Z;
                    minVertex = 1;
                }

                IEnumVertex vertexEnum = _points.EnumVertices;

                vertexEnum.QueryNext(Settings.QueryPoint, out partIndex, out vertexIndex);

                while (partIndex >= 0 && vertexIndex >= 0)
                {
                    double dx0 = dx1;
                    double dy0 = dy1;
                    double l02 = l12;

                    double x1 = x2;
                    double y1 = y2;
                    double z1 = z2;

                    Settings.QueryPoint.QueryCoords(out x2, out y2);
                    z2 = Settings.QueryPoint.Z;

                    dx1 = x2 - x1;
                    dy1 = y2 - y1;

                    l12 = dx1 * dx1 + dy1 * dy1;
                    double prod = dx0 * dx1 + dy0 * dy1;

                    if (Settings.Is3D)
                    {
                        double dz0 = dz1;
                        dz1 = z2 - z1;

                        l12 += dz1 * dz1;

                        prod += dz0 * dz1;
                    }

                    if (vertexIndex < minVertex)
                    {
                        vertexEnum.QueryNext(Settings.QueryPoint, out partIndex, out vertexIndex);
                        continue;
                    }

                    var angleInfo = new AngleInfo(x1, y1, z1, l02, l12, prod);
                    yield return(angleInfo);

                    vertexEnum.QueryNext(Settings.QueryPoint, out partIndex, out vertexIndex);
                }
            }
Example #15
0
        // Execute: Execute the function given the array of the parameters
        public void Execute(IArray paramvalues, ITrackCancel trackcancel, IGPEnvironmentManager envMgr, IGPMessages message)
        {
            IFeatureClass outputFeatureClass = null;

            try
            {
                // get the input feature class
                IGPMultiValue inputFeatureClasses_Parameter = (IGPMultiValue)m_GPUtilities.UnpackGPValue(paramvalues.get_Element(0));
                layer[]       input_featureClasses          = new layer[inputFeatureClasses_Parameter.Count];
                for (int i = 0; i < inputFeatureClasses_Parameter.Count; i++)
                {
                    IGPValue inputFeatureClass_Parameter = inputFeatureClasses_Parameter.get_Value(i);

                    IFeatureClass inputFeatureClass;
                    IQueryFilter  inputQF;

                    m_GPUtilities.DecodeFeatureLayer(inputFeatureClass_Parameter, out inputFeatureClass, out inputQF);

                    input_featureClasses[i] = new layer()
                    {
                        featureclass = inputFeatureClass, qFilter = inputQF
                    };
                }


                if (input_featureClasses.Length == 0 || input_featureClasses.Any(w => w.featureclass == null))
                {
                    message.AddError(2, "Could not open one or more input dataset.");
                    return;
                }

                //IFields additionalFields = new FieldsClass();
                //additionalFields.AddField(FEATURE_SOURCE_FIELD_NAME, esriFieldType.esriFieldTypeString);
                //additionalFields.AddField(FEATURE_ID_FIELD_NAME, esriFieldType.esriFieldTypeInteger);
                //additionalFields.AddField(
                //    input_featureClasses[0].featureclass.Fields.get_Field(
                //    input_featureClasses[0].featureclass.Fields.FindField(
                //    input_featureClasses[0].featureclass.ShapeFieldName)));

                // create the output feature class
                IGPValue outputFeatureClass_Parameter = m_GPUtilities.UnpackGPValue(paramvalues.get_Element(1));
                outputFeatureClass = GPHelperFunctions.CreateFeatureClass(outputFeatureClass_Parameter, envMgr);

                if (outputFeatureClass == null)
                {
                    message.AddError(2, "Could not create output dataset.");
                    return;
                }



                IGPString curveTypeParameter = (IGPString)m_GPUtilities.UnpackGPValue(paramvalues.get_Element(2));
                ArcConstructionMethods method;
                if (!Enum.TryParse <ArcConstructionMethods>(curveTypeParameter.Value, true, out method))
                {
                    message.AddError(2, string.Format("The value {0} is not expected.  Expected values are: {1}.",
                                                      curveTypeParameter.Value,
                                                      string.Join(",", Enum.GetNames(typeof(ArcConstructionMethods)))));
                    return;
                }

                IStepProgressor stepPro = (IStepProgressor)trackcancel;
                GPHelperFunctions.dropSpatialIndex(outputFeatureClass);

                BoostVoronoi bv = new BoostVoronoi(100);

                double          minX = int.MaxValue, minY = int.MaxValue, maxX = int.MinValue, maxY = int.MinValue;
                List <site_key> point_sites   = new List <site_key>();
                List <site_key> segment_sites = new List <site_key>();

                for (short i = 0; i < input_featureClasses.Length; i++)
                {
                    layer l         = input_featureClasses[i];
                    int   featcount = l.featureclass.FeatureCount(l.qFilter);

                    stepPro.MinRange  = 0;
                    stepPro.MaxRange  = featcount;
                    stepPro.StepValue = (1);
                    stepPro.Message   = "Reading features";
                    stepPro.Position  = 0;
                    stepPro.Show();

                    IFeatureCursor cursor = null;
                    IFeature       row    = null;

                    try
                    {
                        cursor = l.featureclass.Search(l.qFilter, false);
                        while ((row = cursor.NextFeature()) != null)
                        {
                            stepPro.Step();
                            IPoint point = row.Shape as IPoint;
                            if (point != null)
                            {
                                double X = point.X;
                                double Y = point.Y;

                                minX = Math.Min(minX, X);
                                maxX = Math.Max(maxX, X);

                                minY = Math.Min(minY, Y);
                                maxY = Math.Max(maxY, Y);

                                bv.AddPoint(point.X, point.Y);
                                point_sites.Add(new site_key(i, row.OID));
                            }

                            IMultipoint multipoint = row.Shape as IMultipoint;
                            if (multipoint != null)
                            {
                                IPointCollection pointCollection = (IPointCollection)multipoint;
                                IEnumVertex      vertices        = pointCollection.EnumVertices;

                                IPoint vertex = null; int part, index;
                                vertices.Next(out vertex, out part, out index);

                                minX = Math.Min(minX, multipoint.Envelope.XMin);
                                maxX = Math.Max(maxX, multipoint.Envelope.XMax);

                                minY = Math.Min(minY, multipoint.Envelope.YMin);
                                maxY = Math.Max(maxY, multipoint.Envelope.YMax);

                                while (vertex != null)
                                {
                                    bv.AddPoint(vertex.X, vertex.Y);
                                    point_sites.Add(new site_key(i, row.OID));

                                    vertices.Next(out vertex, out part, out index);
                                }
                            }

                            IPolyline polyline = row.Shape as IPolyline;
                            if (polyline != null)
                            {
                                double fromX = polyline.FromPoint.X;
                                double fromY = polyline.FromPoint.Y;
                                double toX   = polyline.ToPoint.X;
                                double toY   = polyline.ToPoint.Y;

                                if (toX < fromX)
                                {
                                    minX = Math.Min(minX, toX);
                                    maxX = Math.Max(maxX, fromX);
                                }
                                else
                                {
                                    minX = Math.Min(minX, fromX);
                                    maxX = Math.Max(maxX, toX);
                                }

                                if (toY < fromY)
                                {
                                    minY = Math.Min(minY, toY);
                                    maxY = Math.Max(maxY, fromY);
                                }
                                else
                                {
                                    minY = Math.Min(minY, fromY);
                                    maxY = Math.Max(maxY, toY);
                                }

                                bv.AddSegment(
                                    polyline.FromPoint.X, polyline.FromPoint.Y,
                                    polyline.ToPoint.X, polyline.ToPoint.Y
                                    );


                                segment_sites.Add(new site_key(i, row.OID));
                            }

                            Marshal.ReleaseComObject(row);
                        }
                    }
                    finally
                    {
                        if (row != null)
                        {
                            Marshal.ReleaseComObject(row);
                        }
                        if (cursor != null)
                        {
                            Marshal.ReleaseComObject(cursor);
                        }

                        stepPro.Hide();
                    }
                }

                message.AddMessage(String.Format("{0}, {1} -> {2}, {3}", minX, minY, maxX, maxY));

                int width  = Math.Max((int)((maxX - minX) * 0.1), 1);
                int height = Math.Max((int)((maxY - minY) * 0.1), 1);

                maxX = maxX + width;
                minX = minX - width;
                maxY = maxY + height;
                minY = minY - height;

                message.AddMessage(String.Format("{0}, {1} -> {2}, {3}", minX, minY, maxX, maxY));
                bv.AddSegment(minX, minY, maxX, minY);
                segment_sites.Add(new site_key(-1, -1));
                bv.AddSegment(maxX, minY, maxX, maxY);
                segment_sites.Add(new site_key(-1, -1));
                bv.AddSegment(maxX, maxY, minX, maxY);
                segment_sites.Add(new site_key(-1, -1));
                bv.AddSegment(minX, maxY, minX, minY);
                segment_sites.Add(new site_key(-1, -1));

                stepPro.Message  = "Solve Voronoi";
                stepPro.MaxRange = 0;
                stepPro.MaxRange = 0;
                stepPro.Show();

                bv.Construct();

                stepPro.Hide();

                int featureSourceIndx = outputFeatureClass.Fields.FindField(FEATURE_SOURCE_FIELD_NAME);
                int featureIDIndx     = outputFeatureClass.Fields.FindField(FEATURE_ID_FIELD_NAME);

                IFeatureCursor inserts = null;
                IFeatureBuffer buffer  = null;
                try
                {
                    object            missing          = Type.Missing;
                    ISpatialReference spatialReference = ((IGeoDataset)outputFeatureClass).SpatialReference;
                    inserts = outputFeatureClass.Insert(false);
                    buffer  = outputFeatureClass.CreateFeatureBuffer();

                    List <Cell> cells = bv.Cells;
                    message.AddMessage(string.Format("{0} cells calculated", cells.Count));
                    List <Edge> edges = bv.Edges;
                    message.AddMessage(string.Format("{0} edges calculated", edges.Count));
                    List <Vertex> vertices = bv.Vertices;
                    message.AddMessage(string.Format("{0} vertexes calculated", vertices.Count));

                    stepPro.Message  = "Write cells";
                    stepPro.MaxRange = 0;
                    stepPro.MaxRange = cells.Count;
                    stepPro.Show();


                    for (int cellIndex = 0; cellIndex < cells.Count; cellIndex++)
                    {
                        try
                        {
                            if (cellIndex % 5000 == 0)
                            {
                                message.AddMessage(String.Format("{0}. {1} cells processed.", DateTime.Now, cellIndex));
                            }

                            Cell cell        = cells[cellIndex];
                            int  currentSite = cell.Site;
                            IGeometryCollection geometryCollection = new GeometryBagClass()
                            {
                                SpatialReference = spatialReference
                            };

                            //ignores any sliver cells
                            if (cell.IsOpen || cell.EdgesIndex.Count < 3)
                            {
                                continue;
                            }

                            ISegmentCollection segmentCollection = createSegments(cell, bv, method, spatialReference);

                            if (((IArea)segmentCollection).Area <= 0)
                            {
                                message.AddMessage("A invalid geometry has been detected, try reversing the orientation.");
                                ISegmentCollection reversed_segmentCollection = new PolygonClass()
                                {
                                    SpatialReference = spatialReference
                                };
                                for (int i = segmentCollection.SegmentCount - 1; i >= 0; i--)
                                {
                                    ISegment segment = (ISegment)segmentCollection.get_Segment(i);
                                    segment.ReverseOrientation();
                                    reversed_segmentCollection.AddSegment(segment);
                                }
                                segmentCollection = reversed_segmentCollection;
                            }

                            ((IPolygon)segmentCollection).SpatialReference = spatialReference;
                            if (((IArea)segmentCollection).Area <= 0)
                            {
                                message.AddWarning("An empty shell has been created");

                                for (int i = 0; i < segmentCollection.SegmentCount; i++)
                                {
                                    ISegment segment = (ISegment)segmentCollection.get_Segment(i);
                                    message.AddMessage(String.Format("From {0}, {1} To {2},{3}",
                                                                     segment.FromPoint.X, segment.FromPoint.Y,
                                                                     segment.ToPoint.X, segment.ToPoint.Y));
                                }
                            }


                            //set attributes
                            site_key sk = (currentSite >= point_sites.Count) ? segment_sites[currentSite - point_sites.Count] : point_sites[currentSite];
                            if (!sk.isEmpty)
                            {
                                buffer.set_Value(featureSourceIndx, input_featureClasses[sk.featureClassIndex].featureclass.AliasName);
                                buffer.set_Value(featureIDIndx, sk.objectID);
                            }
                            else
                            {
                                buffer.set_Value(featureSourceIndx, DBNull.Value);
                                buffer.set_Value(featureIDIndx, DBNull.Value);
                            }


                            IPolygon voronoiPolygon = (IPolygon)segmentCollection;
                            buffer.Shape = (IPolygon)voronoiPolygon;
                            inserts.InsertFeature(buffer);
                        }
                        catch (Exception e)
                        {
                            message.AddWarning("Failed to create a cell");
                        }
                    }
                }
                finally
                {
                    if (buffer != null)
                    {
                        Marshal.ReleaseComObject(buffer);
                    }
                    if (inserts != null)
                    {
                        Marshal.ReleaseComObject(inserts);
                    }
                }

                GPHelperFunctions.createSpatialIndex(outputFeatureClass);
            }
            catch (Exception exx)
            {
                message.AddError(2, exx.Message);
                message.AddMessage(exx.ToString());
            }
            finally
            {
                if (outputFeatureClass != null)
                {
                    Marshal.ReleaseComObject(outputFeatureClass);
                }

                ((IProgressor)trackcancel).Hide();
            }
        }
Example #16
0
        private IArray method_2(IGeometry igeometry_0, IGeometry igeometry_1)
        {
            IArray array;

            if (!(igeometry_0 == null ? false : igeometry_1 != null))
            {
                array = null;
            }
            else if (igeometry_0.GeometryType == esriGeometryType.esriGeometryPolyline)
            {
                IGeometry geometry = ((ITopologicalOperator)igeometry_0).Intersect(igeometry_1,
                                                                                   esriGeometryDimension.esriGeometry0Dimension);
                if (geometry != null)
                {
                    ((ITopologicalOperator)geometry).Simplify();
                    IEnumVertex enumVertices = ((IPointCollection)geometry).EnumVertices;
                    if (enumVertices != null)
                    {
                        IPolycurve2 igeometry0 = (IPolycurve2)igeometry_0;
                        if (igeometry0.SplitAtPoints(enumVertices, true, true, -1).SplitHappened)
                        {
                            IGeometryCollection geometryCollection = (IGeometryCollection)igeometry0;
                            IArray arrayClass = new ESRI.ArcGIS.esriSystem.Array();
                            try
                            {
                                bool   zAware = false;
                                bool   mAware = false;
                                double zMin   = 0;
                                try
                                {
                                    zAware = (igeometry_0 as IZAware).ZAware;
                                    zMin   = (igeometry_0 as IZ).ZMin;
                                }
                                catch
                                {
                                }
                                try
                                {
                                    mAware = (igeometry_0 as IMAware).MAware;
                                }
                                catch
                                {
                                }
                                for (int i = 0; i < geometryCollection.GeometryCount; i++)
                                {
                                    IGeometry           geometry1     = geometryCollection.Geometry[i];
                                    IGeometryCollection polylineClass = new Polyline() as IGeometryCollection;
                                    (polylineClass as IZAware).ZAware = zAware;
                                    (polylineClass as IMAware).MAware = mAware;
                                    polylineClass.AddGeometries(1, ref geometry1);
                                    if (zAware)
                                    {
                                        (polylineClass as IZ).SetConstantZ(zMin);
                                    }
                                    (polylineClass as ITopologicalOperator).Simplify();
                                    arrayClass.Add(polylineClass);
                                }
                            }
                            catch (Exception exception)
                            {
                                Trace.WriteLine(exception);
                            }
                            array = arrayClass;
                        }
                        else
                        {
                            array = null;
                        }
                    }
                    else
                    {
                        array = null;
                    }
                }
                else
                {
                    array = null;
                }
            }
            else
            {
                array = null;
            }
            return(array);
        }
Example #17
0
        private int CheckZRange([NotNull] IFeature feature,
                                [NotNull] IPointCollection points)
        {
            IEnumVertex enumPoints = points.EnumVertices;

            enumPoints.Reset();

            var errorPointsBelow = new List <IPoint>();
            var errorPointsAbove = new List <IPoint>();

            IPoint currentPoint;
            int    partIndex;
            int    segmentIndex;

            enumPoints.Next(out currentPoint, out partIndex, out segmentIndex);

            double zMax = double.MinValue;
            double zMin = double.MaxValue;

            while (currentPoint != null)
            {
                double z = currentPoint.Z;

                if (!IsAllowed(z))
                {
                    if (z < _minimumZValue)
                    {
                        errorPointsBelow.Add(GeometryFactory.Clone(currentPoint));
                    }
                    else if (z > _maximumZValue)
                    {
                        errorPointsAbove.Add(GeometryFactory.Clone(currentPoint));
                    }

                    if (z < zMin)
                    {
                        zMin = z;
                    }
                    else if (z > zMax)
                    {
                        zMax = z;
                    }
                }

                enumPoints.Next(out currentPoint, out partIndex, out segmentIndex);
            }

            var errorCount = 0;

            if (errorPointsBelow.Count > 0)
            {
                errorCount += ReportError(GetErrorMessageBelow(errorPointsBelow, zMin),
                                          GetErrorGeometry(errorPointsBelow),
                                          null, _shapeFieldName,
                                          (IRow)feature);
            }

            if (errorPointsAbove.Count > 0)
            {
                string message = GetErrorMessageAbove(errorPointsAbove, zMax);

                errorCount += ReportError(message,
                                          GetErrorGeometry(errorPointsAbove),
                                          null, _shapeFieldName,
                                          (IRow)feature);
            }

            return(errorCount);
        }