コード例 #1
1
    private void SetPINValue()
    {
      //The Theory.
      //Select polygons that intersect the sketch.
      //Construct one polyline from the boundaries and intersect with sketch.
      //Sort resulting intersection locations (multipoint) by distance of the intersect
      // from the start of the sketch and create new ordered multipoint.
      //Loop through new ordered multipoint, select underlying parcel and calc pin.

      IFeatureLayer featLayer = m_editLayers.CurrentLayer;
      m_curve = m_edSketch.Geometry as IPolyline;

      //Search parcel polys by graphic to get feature cursor
      ISpatialFilter spatialFilter = new SpatialFilter();
      spatialFilter.Geometry = m_curve;
      spatialFilter.GeometryField = m_editLayers.CurrentLayer.FeatureClass.ShapeFieldName;
      spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;

      IFeatureCursor featCursor = featLayer.Search(spatialFilter,true);
      IFeature feature = featCursor.NextFeature();

      //If we have no intersects then exit
      if (feature == null)
        return;
  
      //Make a GeomBag of the polygons boundaries (polylines)
      IGeometryCollection geomBag = new GeometryBagClass();
      object missing = Type.Missing;
      while (feature != null)
      {
        ITopologicalOperator poly = feature.Shape as ITopologicalOperator;
        geomBag.AddGeometry(poly.Boundary,ref missing,ref missing);
        feature = featCursor.NextFeature();
      }

      //Make one polyline from the boundaries
      IPolyline polyLineU = new PolylineClass();
      ITopologicalOperator topoOp = polyLineU as ITopologicalOperator;
      topoOp.ConstructUnion(geomBag as IEnumGeometry);

      //Get the intersections of the boundaries and the curve
      IPointCollection pointCol = topoOp.Intersect(m_curve, esriGeometryDimension.esriGeometry0Dimension) as IPointCollection;

      //The point collection is not ordered by distance along the curve so
      //need to create a new collection with this info

      int[] pointOrder = new int[pointCol.PointCount];
      double dac = 0, dfc = 0;
      bool bRS = false;

      for (int i = 0; i < pointCol.PointCount; i++)
      {
        IPoint queryPoint = new PointClass();
        pointCol.QueryPoint(i, queryPoint);
        m_curve.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, queryPoint, false, null,ref dac,ref dfc,ref bRS);
        pointOrder[i] = (int)dac;
      }

      //use built in bubble sort
      System.Array.Sort(pointOrder);

      //Loop through the sorted array and calc midpoint between parcel boundaries
      IPointCollection midPoints = new MultipointClass();

      for (int i = 0; i < pointOrder.Length -1; i++)
      {
        //Get the midpoint distance
        double midPointDist = (pointOrder[i] + pointOrder[i + 1]) / 2;
        
        //create a point at the distance and store in point collection
        IPoint queryPoint = new PointClass();
        m_curve.QueryPoint(esriSegmentExtension.esriNoExtension, midPointDist, false, queryPoint);
        midPoints.AddPoint(queryPoint,ref missing,ref missing);
      }

      //If ends of sketch are included then add them as points
      if (chkEnds.Checked)
      {
        object before = 0 as object;
        midPoints.AddPoint(m_curve.FromPoint, ref before, ref missing);
        midPoints.AddPoint(m_curve.ToPoint, ref missing, ref missing);
      }

      m_editor.StartOperation();

      //Loop through calculated midpoints, select polygon and calc pin
      for (int i = 0; i < midPoints.PointCount; i++)
      {
        IPoint midPoint = midPoints.get_Point(i);
        spatialFilter = new SpatialFilter();
        spatialFilter.Geometry = midPoint;
        spatialFilter.GeometryField = m_editLayers.CurrentLayer.FeatureClass.ShapeFieldName;
        spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin;

        featCursor = featLayer.Search(spatialFilter, false);
        while ((feature = featCursor.NextFeature()) != null)
        {
          feature.set_Value(feature.Fields.FindField(cmbPINField.Text), m_lotNum);
          feature.Store();
          m_lotNum += int.Parse(txtlotinc.Text);
        }
      }
      m_editor.StopOperation("ViperPIN");
      txtlot.Text = m_lotNum.ToString();
    }
コード例 #2
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            // TODO:  Add RouteQuery.OnMouseDown implementation
            if (networkanalasia == true)
            {
                IPointCollection m_ipPoints;//输入点集合
                IPoint           ipNew;
                m_ipPoints = new MultipointClass();
                ipNew      = axMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
                object o = Type.Missing;
                m_ipPoints.AddPoint(ipNew, ref o, ref o);
                CreateFeature(inputFClass, m_ipPoints);//获取用鼠标点击最近点
                //把最近的点显示出来
                IElement     element;
                ITextElement textelement = new TextElementClass();
                element = textelement as IElement;
                ITextSymbol textSymbol = new ESRI.ArcGIS.Display.TextSymbol();

                textelement.Symbol = textSymbol;
                clickedcount++;
                textelement.Text = clickedcount.ToString();
                element.Geometry = m_ipActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
                PGC.AddElement(element, 0);

                m_ipActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            }
        }
コード例 #3
0
ファイル: ModPublic.cs プロジェクト: siszoey/geosufan
        // 端点捕捉
        private static void GetPortPntCollection(List <IFeature> listFeats, IFeatureClass pFeatureClass, IProximityOperator pProximity, double dSearchDist)
        {
            IPointCollection pPntColTemp = new MultipointClass();

            for (int i = 0; i < listFeats.Count; i++)
            {
                IFeature pFeature = listFeats[i];
                //判断该Feature图层
                if (pFeature.Class.ObjectClassID != pFeatureClass.ObjectClassID)
                {
                    continue;
                }

                if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline || pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                {
                    double dScreenSearchDist = pProximity.ReturnDistance(pFeature.Shape);
                    if (dScreenSearchDist < 1.5 * dSearchDist)
                    {
                        IGeometryCollection pGeoCollection = pFeature.Shape as IGeometryCollection;
                        for (int j = 0; j < pGeoCollection.GeometryCount; j++)
                        {
                            IGeometry        pGeom   = pGeoCollection.get_Geometry(j);
                            IPointCollection pPntCol = pGeom as IPointCollection;
                            m_PointCollection.AddPointCollection(pPntCol);
                            pPntColTemp.AddPointCollection(pPntCol);
                        }
                    }
                }
            }

            m_dicPointCollection.Add(pPntColTemp, "PortPnt");
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: XYT1033/csdn_download
        //构造切线点
        private void button5_Click(object sender, EventArgs e)
        {
            delFeature("point");
            IPoint[] points = new IPoint[4];
            for (int i = 0; i < 4; i++)
            {
                points[i] = new PointClass();
            }

            points[0].PutCoords(15, 10);
            points[1].PutCoords(20, 60);
            points[2].PutCoords(40, 60);
            points[3].PutCoords(45, 10);
            addFeature("point", points[0]);
            addFeature("point", points[1]);
            addFeature("point", points[2]);
            addFeature("point", points[3]);

            IBezierCurveGEN bezierCurve = new BezierCurveClass();

            bezierCurve.PutCoords(ref points);
            IConstructMultipoint constructMultipoint = new MultipointClass();

            constructMultipoint.ConstructTangent(bezierCurve as ICurve, points[1]);
            IMultipoint      multipoint      = constructMultipoint as IMultipoint;
            IPointCollection pointCollection = multipoint as IPointCollection;

            for (int i = 0; i < pointCollection.PointCount; i++)
            {
                addFeature("point", pointCollection.get_Point(i));
            }
            axMapControl1.Refresh();
        }
コード例 #5
0
        /// <summary>
        /// 得到Feature与 FeatureList所有的交点
        /// </summary>
        /// <param name="vNewFeature"></param>
        /// <param name="vFeatureCol"></param>
        /// <returns></returns>
        private IPointCollection GetAllIntersect(IFeature OneOfFeature, List <IFeature> list_AllFeatures)
        {
            IPolyline        tempLine   = new PolylineClass();
            IPointCollection pPointColl = tempLine as IPointCollection;

            pPointColl.AddPointCollection(OneOfFeature.Shape as IPointCollection);

            IPointCollection vItersectCol = new MultipointClass();


            IMultipoint vIntersectPnt = new MultipointClass();

            IFeature vFeature;

            for (int i = 0; i < list_AllFeatures.Count; i++)
            {
                vFeature = list_AllFeatures[i];
                if (vFeature != OneOfFeature)
                {
                    vIntersectPnt = GetIntersection(vFeature.Shape, tempLine as IPolyline) as IMultipoint;
                    if (vIntersectPnt != null)
                    {
                        vItersectCol.AddPointCollection(vIntersectPnt as IPointCollection);
                    }
                }
            }

            return(vItersectCol);
        }
コード例 #6
0
ファイル: Form1.cs プロジェクト: XYT1033/csdn_download
        //构造等长点
        private void button3_Click(object sender, EventArgs e)
        {
            delFeature("point");
            IPoint centerPoint = new PointClass();

            centerPoint.PutCoords(10, 0);
            IPoint fromPoint = new PointClass();

            fromPoint.PutCoords(0, 0);
            IPoint toPoint = new PointClass();

            toPoint.PutCoords(0, 20);
            ICircularArc circularArcConstruction = new CircularArcClass();

            circularArcConstruction.PutCoords(centerPoint, fromPoint, toPoint, esriArcOrientation.esriArcClockwise);
            IConstructMultipoint constructMultipoint = new MultipointClass();

            constructMultipoint.ConstructDivideLength(circularArcConstruction as ICurve, 10);
            IPointCollection pointCollection = constructMultipoint as IPointCollection;

            for (int i = 0; i < pointCollection.PointCount; i++)
            {
                addFeature("point", pointCollection.get_Point(i));
            }

            axMapControl1.Refresh();
        }
コード例 #7
0
ファイル: Form1.cs プロジェクト: XYT1033/csdn_download
        //构造圆弧点
        private void button1_Click(object sender, EventArgs e)
        {
            delFeature("point");
            //构造一段圆弧
            IPoint centerPoint = new PointClass();

            centerPoint.PutCoords(10, 0);
            IPoint fromPoint = new PointClass();

            fromPoint.PutCoords(0, 0);
            IPoint toPoint = new PointClass();

            toPoint.PutCoords(0, 20);
            IConstructCircularArc circularArcConstruction = new CircularArcClass();

            circularArcConstruction.ConstructThreePoints(fromPoint, centerPoint, toPoint, false);
            //构造圆弧点
            IConstructMultipoint constructMultipoint = new MultipointClass();

            constructMultipoint.ConstructArcPoints(circularArcConstruction as ICircularArc);
            IPointCollection pointCollection = constructMultipoint as IPointCollection;

            for (int i = 0; i < pointCollection.PointCount; i++)
            {
                addFeature("point", pointCollection.get_Point(i));
            }

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

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

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

                IFeature feature = featureClass.CreateFeature();

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

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

                IEnvelope envelop = feature.Shape.Envelope;
                DataEditCommon.g_pMyMapCtrl.ActiveView.Extent = envelop;
                DataEditCommon.g_pMyMapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null);
            }
            else
            {
                MessageBox.Show(@"��ѡ����ͼ�㡣", "��ʾ", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            //}
            //catch
            //{
            //    return;
            //}
        }
コード例 #9
0
ファイル: ModPublic.cs プロジェクト: siszoey/geosufan
        //相交点捕捉
        private static void GetIntersectPntCollection(List <IFeature> listFeats, IFeatureClass pFeatureClass, IProximityOperator pProximity, double dSearchDist)
        {
            IPointCollection pPntColTemp = new MultipointClass();

            List <IFeature> listFeatsTemp = new List <IFeature>();

            for (int i = 0; i < listFeats.Count; i++)
            {
                IFeature pFeature = listFeats[i];
                if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline || pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                {
                    double dScreenSearchDist = pProximity.ReturnDistance(pFeature.Shape);
                    if (dScreenSearchDist < 1.5 * dSearchDist)
                    {
                        listFeatsTemp.Add(pFeature);
                    }
                }
            }

            //收集线两两相交点,收集的交点有重复,但是不影响结果
            foreach (IFeature pFeat in listFeatsTemp)
            {
                IPointCollection pPntCol = GetAllIntersect(pFeat, listFeatsTemp);
                m_PointCollection.AddPointCollection(pPntCol);
                pPntColTemp.AddPointCollection(pPntCol);
            }

            m_dicPointCollection.Add(pPntColTemp, "IntersectPnt");
        }
コード例 #10
0
        public IPointCollection4 ToPointCollection(IGeometry geometry, out int nrPoints)
        {
            IPointCollection4 result = null;

            nrPoints = 0;

            if (geometry != null)
            {
                result = geometry as IPointCollection4;
                TypeOfLayer typeOfLayer = GetTypeOfLayer(geometry);

                if ((!geometry.IsEmpty) && (typeOfLayer == TypeOfLayer.Point) && (result == null) && IsPointMeasurement)
                {
                    var pointc = geometry as IPoint;
                    result = new MultipointClass();
                    result.AddPoint(pointc);
                }

                if (result != null)
                {
                    nrPoints = result.PointCount;

                    if ((nrPoints >= 2) && (typeOfLayer == TypeOfLayer.Polygon))
                    {
                        IPoint point1 = result.Point[0];
                        IPoint point2 = result.Point[nrPoints - 1];
                        nrPoints = (point1.Compare(point2) == 0) ? (nrPoints - 1) : nrPoints;
                    }
                }
            }

            return(result);
        }
コード例 #11
0
        private IFeature Convert_Point2MultiPoint_Class(IFeatureClass PointFeatureClass)
        {
            IWorkspaceFactory contourWSF   = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace contourFWS   = (IFeatureWorkspace)contourWSF.OpenFromFile(WorkSpaceName, 0);
            IFields           pFields      = CreateShapeFields(esriGeometryType.esriGeometryMultipoint);
            string            filename     = PointFeatureClass.AliasName + "_muilti";
            string            filename_shp = WorkSpaceName + @"/" + filename + ".shp";

            if (System.IO.File.Exists(filename_shp))
            {
                System.IO.File.Delete(filename_shp);
                System.IO.File.Delete(System.IO.Path.ChangeExtension(filename_shp, ".dbf"));
                System.IO.File.Delete(System.IO.Path.ChangeExtension(filename_shp, ".shx"));
            }
            contourFWS.CreateFeatureClass(filename, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", null);
            IFeatureClass    MultiFeatureClass = contourFWS.OpenFeatureClass(filename);
            IPointCollection pPointCollection  = new MultipointClass();

            for (int i = 0; i < PointFeatureClass.FeatureCount(null); i++)
            {
                IFeature pFeature = PointFeatureClass.GetFeature(i);
                IPoint   pPoint   = pFeature.Shape as IPoint;
                pPointCollection.AddPoint(pPoint);
            }
            IFeature MultiFeature = MultiFeatureClass.CreateFeature();

            MultiFeature.Shape = pPointCollection as IGeometry;
            MultiFeature.Store();
            return(MultiFeature);
        }
コード例 #12
0
ファイル: Extentions.cs プロジェクト: DemonScarlett/DPP
        public static void ReadPolugon(this ImportSentinelData importProduct)
        {
            if (string.IsNullOrWhiteSpace(importProduct.Footprint))
            {
                return;
            }

            string text = importProduct.Footprint;

            //"<gml:Polygon srsName=\"http://www.opengis.net/gml/srs/epsg.xml#4326\" xmlns:gml=\"http://www.opengis.net/gml\"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>45.308281,24.306789 45.711151,21.006590 47.207355,21.359417 46.803715,24.750584 45.308281,24.306789</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon>";


            var doc  = XDocument.Parse(text);
            var elem = doc.Descendants(XName.Get("coordinates", "http://www.opengis.net/gml")).Select(node =>
            {
                var pointCollection = new MultipointClass();
                node.Value.Split(' ').Select(p =>
                {
                    var coords = p.Split(','); return(new Point {
                        X = coords[1].ParceToDouble(), Y = coords[0].ParceToDouble(), SpatialReference = EsriTools.Wgs84Spatialreference
                    });
                }).ToList().ForEach(p => pointCollection.AddPoint(p));

                return(EsriTools.GetPolygonByPointCollection(pointCollection));
            });

            importProduct.FootprintPoly = elem.FirstOrDefault();
        }
コード例 #13
0
        /// <summary>
        /// 通过簇的点集计算簇的凸包
        /// </summary>
        /// <returns></returns>
        public void CreateConvexHull(ISpatialReference spatialReference)
        {
            //少于3个点就不做
            if (m_pointsList.Count < 3)
            {
                return;
            }
            IGeometryCollection geometryCollection = new MultipointClass();

            for (int i = 0; i < m_pointsList.Count; i++)
            {
                geometryCollection.AddGeometry(m_pointsList[i] as IGeometry);
            }
            ITopologicalOperator pTopological = geometryCollection as ITopologicalOperator;
            IGeometry            g            = pTopological.ConvexHull();

            if (g.GeometryType != esriGeometryType.esriGeometryPolygon)
            {
                return;
            }
            IPolygon convexHull = g as IPolygon;

            convexHull.SpatialReference = spatialReference;
            m_convexHull = convexHull;
        }
コード例 #14
0
ファイル: MeasureArea.cs プロジェクト: zhongshuiyuan/gews
        /// <summary>
        /// 计算面积
        /// </summary>
        /// <param name="CurPoint"></param>
        /// <returns></returns>
        private double CaculateArea(IPoint CurPoint)
        {
            IPointCollection tempCollection = new MultipointClass();

            object missing = Type.Missing;

            for (int i = 0; i < m_ptCollection.PointCount; i++)
            {
                IPoint dPoint = m_ptCollection.get_Point(i);
                tempCollection.AddPoint(dPoint, ref missing, ref missing);
            }

            tempCollection.AddPoint(CurPoint, ref missing, ref missing);
            tempCollection.AddPoint(tempCollection.get_Point(0), ref missing, ref missing);
            int Count = tempCollection.PointCount;

            double x1, x2, y1, y2;
            double tempArea = 0.0;

            for (int i = 0; i < Count - 1; i++)
            {
                x1        = Convert.ToDouble(tempCollection.get_Point(i).X);
                y1        = Convert.ToDouble(tempCollection.get_Point(i).Y);
                x2        = Convert.ToDouble(tempCollection.get_Point(i + 1).X);
                y2        = Convert.ToDouble(tempCollection.get_Point(i + 1).Y);
                tempArea += (x1 * y2 - x2 * y1);
            }

            tempArea = Math.Abs(tempArea) / 2;
            return(tempArea);
        }
コード例 #15
0
ファイル: helpers.cs プロジェクト: BGCX261/ziggis-svn-to-git
        static void createWkbMultiLineString(byte[] wkb, ref int startIndex, BitConversion bitConversion, out IGeometry geometry)
        {
            geometry = new PolylineClass();
            IPointCollection mp = (IPointCollection)geometry;

            // Get the number of line strings.
            UInt32 lineStringCnt;

            getWkbUInt32(wkb, ref startIndex, bitConversion, out lineStringCnt);

            UInt32 pointCnt;
            double x, y;
            object missing = Type.Missing;

            // Loop through each LineString.
            for (int i = 0; i < lineStringCnt; i++)
            {
                startIndex += 5;  // Jump past useless header stuff.
                getWkbUInt32(wkb, ref startIndex, bitConversion, out pointCnt);

                IPointCollection tempPc = new MultipointClass();
                // Loop through each point.
                for (int j = 0; j < pointCnt; j++)
                {
                    getWkbDouble(wkb, ref startIndex, bitConversion, out x);
                    getWkbDouble(wkb, ref startIndex, bitConversion, out y);
                    tempPc.AddPoint(createAoPoint(x, y), ref missing, ref missing);
                }
                mp.AddPointCollection(tempPc);
            }
        }
コード例 #16
0
ファイル: ModPublic.cs プロジェクト: siszoey/geosufan
        //节点捕捉
        private static void GetNodeCollection(List <IFeature> listFeats, IFeatureClass pFeatureClass, IProximityOperator pProximity, double dSearchDist)
        {
            IPointCollection pPntColTemp = new MultipointClass();

            for (int i = 0; i < listFeats.Count; i++)
            {
                IFeature pFeature = listFeats[i];
                //判断该Feature图层
                if (pFeature.Class.ObjectClassID != pFeatureClass.ObjectClassID)
                {
                    continue;
                }

                double dScreenSearchDist = pProximity.ReturnDistance(pFeature.Shape);
                if (dScreenSearchDist < 1.5 * dSearchDist)
                {
                    if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                    {
                        IPoint pPoint = pFeature.Shape as IPoint;
                        object befor  = Type.Missing;
                        object after  = Type.Missing;
                        m_PointCollection.AddPoint(pPoint, ref befor, ref after);
                        pPntColTemp.AddPoint(pPoint, ref befor, ref after);
                    }
                    else
                    {
                        IPointCollection pTempPtcln = pFeature.Shape as IPointCollection;
                        m_PointCollection.AddPointCollection(pTempPtcln);
                        pPntColTemp.AddPointCollection(pTempPtcln);
                    }
                }
            }

            m_dicPointCollection.Add(pPntColTemp, "Node");
        }
コード例 #17
0
        private static IGeometry GetErrorGeometry([NotNull] List <WKSPointZ> errPoints)
        {
            IGeometry result = new MultipointClass();

            WKSPointZ[] errArray = errPoints.ToArray();
            GeometryUtils.SetWKSPointZs((IPointCollection4)result, errArray);

            return(result);
        }
コード例 #18
0
        public static MultipointClass CreateMultipoint <T>(
            [NotNull] IEnumerable <T> templateEnum)
            where T : IGeometry
        {
            var multiPoint = new MultipointClass();

            AdaptAware(multiPoint, templateEnum);
            return(multiPoint);
        }
コード例 #19
0
        public void AddZToSketch(IEditSketch3 sketch)
        {
            var    editor  = ArcUtils.Editor;
            var    editorZ = editor as IEditorZ;
            IPoint point   = sketch.LastPoint;

            if ((editorZ != null) && (point != null) && sketch.ZAware)
            {
                double z = GetHeight(point.X, point.Y);
                editorZ.UseZOffset = true;
                editorZ.ZOffset    = z;

                IGeometry         geometry = sketch.Geometry;
                var               ptColl   = geometry as IPointCollection4;
                ISketchOperation2 sketchOp = new SketchOperationClass();
                sketchOp.Start(editor);
                IPoint pointc = null;

                if ((!geometry.IsEmpty) && (geometry is IPoint) && (ptColl == null))
                {
                    pointc = geometry as IPoint;
                    ptColl = new MultipointClass();
                    ptColl.AddPoint(pointc);
                }

                if (ptColl != null)
                {
                    int nrPoints = ptColl.PointCount;

                    for (int i = 0; i < nrPoints; i++)
                    {
                        IPoint pointC = ptColl.Point[i];
                        // ReSharper disable CompareOfFloatsByEqualityOperator

                        if (pointC.Z == 0)
                        {
                            IPoint newPoint = new PointClass {
                                X = pointC.X, Y = pointC.Y, Z = z
                            };
                            ptColl.UpdatePoint(i, newPoint);
                        }

                        // ReSharper restore CompareOfFloatsByEqualityOperator
                    }
                }

                sketch.Geometry = pointc ?? (ptColl as IGeometry);
                geometry        = sketch.Geometry;

                if (geometry != null)
                {
                    sketchOp.Finish(geometry.Envelope, esriSketchOperationType.esriSketchOperationGeneral, geometry);
                }
            }
        }
コード例 #20
0
ファイル: Form1.cs プロジェクト: XYT1033/csdn_download
        //构造交点
        private void button4_Click(object sender, EventArgs e)
        {
            delFeature("point");
            IPoint[] points = new IPoint[4];
            for (int i = 0; i < 4; i++)
            {
                points[i] = new PointClass();
            }

            points[0].PutCoords(15, 10);
            points[1].PutCoords(20, 60);
            points[2].PutCoords(40, 60);
            points[3].PutCoords(45, 10);
            addFeature("point", points[0]);
            addFeature("point", points[1]);
            addFeature("point", points[2]);
            addFeature("point", points[3]);
            //构造Bezier曲线
            IBezierCurveGEN bezierCurve = new BezierCurveClass();

            bezierCurve.PutCoords(ref points);
            IPoint centerPoint = new PointClass();

            centerPoint.PutCoords(30, 30);
            IPoint fromPoint = new PointClass();

            fromPoint.PutCoords(10, 10);
            IPoint toPoint = new PointClass();

            toPoint.PutCoords(50, 10);
            //构造圆弧
            IConstructCircularArc circularArcConstruction = new CircularArcClass();

            circularArcConstruction.ConstructThreePoints(fromPoint, centerPoint, toPoint, false);


            object param0;
            object param1;
            object isTangentPoint;
            IConstructMultipoint constructMultipoint = new MultipointClass();

            constructMultipoint.ConstructIntersection(circularArcConstruction as ISegment, esriSegmentExtension.esriNoExtension, bezierCurve as ISegment, esriSegmentExtension.esriNoExtension, out param0, out param1, out isTangentPoint);
            IMultipoint      multipoint      = constructMultipoint as IMultipoint;
            IPointCollection pointCollection = multipoint as IPointCollection;

            for (int i = 0; i < pointCollection.PointCount; i++)
            {
                addFeature("point", pointCollection.get_Point(i));
            }

            axMapControl1.Extent = multipoint.Envelope;
            axMapControl1.Refresh();
        }
コード例 #21
0
ファイル: ArcEngineAPI.cs プロジェクト: xkang8902/AEWinForm
        /// <summary>
        /// 获得一个Geometry的所有顶点
        /// </summary>
        /// <param name="sourceGeom"></param>
        /// <returns></returns>
        public static IMultipoint GetVertices(IGeometry pGeometry)
        {
            if (pGeometry == null)
            {
                return(null);
            }

            IPointCollection pPointCollection = new MultipointClass();

            object obj = null;

            if (pGeometry is IPoint)
            {
                pPointCollection.AddPoint(pGeometry as IPoint, ref obj, ref obj);
                return(pPointCollection as IMultipoint);
            }
            else if (pGeometry is ISegment)
            {
                ISegment pSegment = pGeometry as ISegment;
                pPointCollection.AddPoint(pSegment.FromPoint, ref obj, ref obj);
                pPointCollection.AddPoint(pSegment.ToPoint, ref obj, ref obj);
            }
            else if (pGeometry is IEnvelope)
            {
                IEnvelope pEnvelope = pGeometry as IEnvelope;
                pPointCollection.AddPoint(pEnvelope.UpperLeft, ref obj, ref obj);
                pPointCollection.AddPoint(pEnvelope.UpperRight, ref obj, ref obj);
                pPointCollection.AddPoint(pEnvelope.LowerLeft, ref obj, ref obj);
                pPointCollection.AddPoint(pEnvelope.LowerRight, ref obj, ref obj);
            }
            else if (pGeometry is IGeometryCollection)
            {
                IGeometryCollection pGeometryCollection = pGeometry as IGeometryCollection;
                for (int i = 0; i < pGeometryCollection.GeometryCount; i++)
                {
                    IGeometry        pSubGeo             = pGeometryCollection.get_Geometry(i);
                    IPointCollection pSubPointCollection = GetVertices(pSubGeo) as IPointCollection;
                    if (pSubPointCollection != null)
                    {
                        pPointCollection.AddPointCollection(pSubPointCollection);
                    }
                }
            }

            if (pPointCollection.PointCount == 0)
            {
                return(null);
            }
            else
            {
                return(pPointCollection as IMultipoint);
            }
        }
コード例 #22
0
        private IPointCollection Convert_Point2MultiPoint(IFeatureClass PointFeatureClass)
        {
            IPointCollection pPointCollection = new MultipointClass();

            for (int i = 0; i < PointFeatureClass.FeatureCount(null); i++)
            {
                IFeature pFeature = PointFeatureClass.GetFeature(i);
                IPoint   pPoint   = pFeature.Shape as IPoint;
                pPointCollection.AddPoint(pPoint);
            }
            return(pPointCollection);
        }
コード例 #23
0
        private int ReportPointErrors(
            [NotNull] IDictionary <int, List <int> > pointIndexesById,
            int maxPointsId,
            [NotNull] Rings rings,
            [NotNull] IRow row)
        {
            object missing = Type.Missing;

            IPointCollection points = new MultipointClass();

            GeometryUtils.EnsureSpatialReference((IGeometry)points,
                                                 rings.SpatialReference);

            foreach (KeyValuePair <int, List <int> > pair in pointIndexesById)
            {
                int id = pair.Key;
                if (id == maxPointsId)
                {
                    continue;
                }

                List <int> pointIndexes = pair.Value;

                foreach (int pointIndex in pointIndexes)
                {
                    IPoint point = rings.get_Point(pointIndex);
                    points.AddPoint(point, ref missing, ref missing);
                }
            }

            string description;

            if (rings.RingsCount > 1)
            {
                description = string.Format(
                    "The point ids of these points differ from the most frequent point id {0} " +
                    "({1} occurrences) in the rings (outer ring = {2}. patch in multipatch)",
                    maxPointsId, pointIndexesById[maxPointsId].Count,
                    rings.FirstPatchIndex + 1);
            }
            else
            {
                description = string.Format(
                    "The point ids of these points differ from the most frequent point id {0} " +
                    "({1} occurrences) in the ring ({2}. patch in Multipatch)",
                    maxPointsId, pointIndexesById[maxPointsId].Count,
                    rings.FirstPatchIndex + 1);
            }

            return(ReportError(description, (IGeometry)points, Codes[Code.DifferentIdInRing],
                               TestUtils.GetShapeFieldName(row), row));
        }
コード例 #24
0
        public IGeometry GetMultipointGeometry()
        {
            const double MultipointPointCount = 25;

            IPointCollection pPointCollection = new MultipointClass();

            for (int i = 0; i < MultipointPointCount; i++)
            {
                pPointCollection.AddPoint(GetPoint(), ref pMissing, ref pMissing);
            }

            return pPointCollection as IGeometry;
        }
コード例 #25
0
ファイル: QaBorderSense.cs プロジェクト: sungaoyong/ProSuite
        private static IMultipoint CreateUnclosedErrorGeometry([NotNull] LineList <DirectedRow> list)
        {
            IMultipoint result = new MultipointClass();

            var points = (IPointCollection)result;

            object missing = Type.Missing;

            points.AddPoint(GeometryFactory.Clone(list.FromPoint), ref missing, ref missing);
            points.AddPoint(GeometryFactory.Clone(list.ToPoint), ref missing, ref missing);

            return(result);
        }
コード例 #26
0
        public IGeometry GetMultipointGeometry()
        {
            const double MultipointPointCount = 25;

            IPointCollection pPointCollection = new MultipointClass();

            for (int i = 0; i < MultipointPointCount; i++)
            {
                pPointCollection.AddPoint(GetPoint(), ref pMissing, ref pMissing);
            }

            return(pPointCollection as IGeometry);
        }
コード例 #27
0
ファイル: QaCentroids.cs プロジェクト: sungaoyong/ProSuite
        private static IGeometry GetErrorGeometry([NotNull] LineListPolygon poly)
        {
            object missing = Type.Missing;

            IPointCollection multiPoint = new MultipointClass();

            foreach (IRow pointRow in poly.Centroids)
            {
                multiPoint.AddPoint(((IFeature)pointRow).Shape as Point, ref missing,
                                    ref missing);
            }

            return((IGeometry)multiPoint);
        }
コード例 #28
0
        private void UpdateFeature(IFeature selectedFeature, IPointCollection4 polylinePoints)
        {
            IPointCollection4 geometry;
            esriGeometryType  geometryType = selectedFeature.Shape.GeometryType;

            switch (geometryType)
            {
            case esriGeometryType.esriGeometryMultipoint:
                geometry = new MultipointClass();
                break;

            case esriGeometryType.esriGeometryPolyline:
                geometry = new PolylineClass();
                break;

            case esriGeometryType.esriGeometryPolygon:
                geometry = new PolygonClass();
                break;

            default:
                geometry = null;
                break;
            }
            if (geometry == null)
            {
                return;
            }
            geometry.AddPointCollection(polylinePoints);
            IFeatureClass  featureClass  = selectedFeature.Class as IFeatureClass;
            IDataset       dataset       = featureClass as IDataset;
            IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit;

            if (!(workspaceEdit.IsBeingEdited()))
            {
                return;
            }

            try
            {
                workspaceEdit.StartEditOperation();
                selectedFeature.Shape = geometry as IGeometry;
                selectedFeature.Store();
                workspaceEdit.StopEditOperation();
            }
            catch (Exception ex)
            {
                workspaceEdit.AbortEditOperation();
                MessageBox.Show("移动要素顶点失败!!" + ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
コード例 #29
0
        //根据创建的点要素做tin
        public void CreatTINs()
        {
            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);

            Workspace = workspaceFactory.OpenFromFile(workspacepath, 0);
            IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)Workspace;

            //new tin 的范围
            tin = new TinClass();
            tin.Init(tinpath);
            IEnvelope EnvO = tin.Extent;
            IEnvelope Env  = new EnvelopeClass();

            Env.XMax = EnvO.XMax + 10;
            Env.YMax = EnvO.YMax + 10;
            Env.ZMax = EnvO.ZMax + 100;
            Env.XMin = EnvO.XMin + 10;
            Env.YMin = EnvO.YMin + 10;
            Env.ZMin = EnvO.ZMin + 100;

            // Instantiate a new empty TIN.
            ITinEdit[] TinEdit   = new ITinEdit[SurfaceCount + 1];
            object     overwrite = true;

            for (int i = 0; i < SurfaceCount + 1; i++)
            {
                TinEdit[i] = new TinClass();
                TinEdit[i].InitNew(Env);
                TinEdit[i].SaveAs(OutTinPath + "_" + i, ref overwrite);
            }

            IFeatureClass[] ISOpointFeatureClass = new IFeatureClass[SurfaceCount + 1];
            for (int i = 0; i < SurfaceCount + 1; i++)
            {
                ISOpointFeatureClass[i] = featureWorkspace.OpenFeatureClass("Node_" + i);
                IGeometryCollection MultipointGeometryCollection = new MultipointClass();
                MakeZAware(MultipointGeometryCollection as IGeometry);
                for (int p = 0; p < NodeCount - 4; p++)
                {
                    IPoint onePoint = ISOpointFeatureClass[i].GetFeature(p + 1).Shape as IPoint;
                    MakeZAware(onePoint);
                    MultipointGeometryCollection.AddGeometry(onePoint);
                }
                (TinEdit[i] as ITinEdit2).SetToConstrainedDelaunay();
                TinEdit[i].AddShapeZ(MultipointGeometryCollection as IGeometry, esriTinSurfaceType.esriTinMassPoint, 0, _missing);
                TinEdit[i].Save();
            }
        }
コード例 #30
0
ファイル: GeometryUtility.cs プロジェクト: koson/CodeLab
 /// <summary>
 /// 点集合转换为多点
 /// </summary>
 /// <param name="pointCollection">点集合</param>
 /// <returns>多点</returns>
 public static IMultipoint PointCollectionToMultiPoint(IPointCollection pointCollection)
 {
     if (pointCollection != null)
     {
         IMultipoint points = new MultipointClass();
         if (pointCollection.PointCount > 0)
         {
             (points as IPointCollection).AddPointCollection(pointCollection);
         }
         return(points);
     }
     else
     {
         return(null);
     }
 }
コード例 #31
0
        private IPolygon buildHomeRangePolygon(Animal inAnimal, double stretchFactor)
        {
            const int        numberOfPoints = 30;
            IPointCollection boundaryPoints = new PolygonClass();
            IPointCollection myPoints       = new MultipointClass();

            double[]      anglesList = new double[numberOfPoints];
            RandomNumbers rn         = RandomNumbers.getInstance();
            IGeometry     geom       = null;
            double        angle      = 0;
            double        radius     = 0;
            IPoint        tempPoint;
            object        missing = Type.Missing;
            IPolygon      returnPoly;


            try
            {
                geom = (IGeometry)boundaryPoints;

                mLog.Debug("inside buildHomeRangePolygon for animal " + inAnimal.IdNum.ToString());
                for (int i = 0; i < numberOfPoints; i++)
                {
                    anglesList[i] = (rn.getUniformRandomNum() * Math.PI * 2);
                }
                System.Array.Sort(anglesList);
                //go backwards to get clockwise polygon for external ring
                for (int i = numberOfPoints - 1; i >= 0; i--)
                {
                    tempPoint = new PointClass();
                    angle     = anglesList[i];
                    //radius is slightly larger than needed for home range to compensate for not being a circle
                    radius      = Math.Sqrt(1000000 * inAnimal.HomeRangeCriteria.Area / Math.PI) * rn.getPositiveNormalRandomNum(1.2, .1) * stretchFactor;
                    tempPoint.X = inAnimal.HomeRangeCenter.X + radius * Math.Cos(angle);
                    tempPoint.Y = inAnimal.HomeRangeCenter.Y + radius * Math.Sin(angle);
                    boundaryPoints.AddPoint(tempPoint, ref missing, ref missing);
                }
            }
            catch (Exception ex)
            {
                eLog.Debug(ex);
            }
            returnPoly = boundaryPoints as PolygonClass;
            returnPoly.Close();
            mLog.Debug("leaving buildHomeRangePolygon");
            return(returnPoly);
        }
コード例 #32
0
        public static IPolygon GetPolygon([NotNull] IEnumerable <WKSPointVA> points)
        {
            Assert.ArgumentNotNull(points, nameof(points));

            IPointCollection5 mps = new MultipointClass();

            foreach (WKSPointVA point in points)
            {
                WKSPointVA p = point;
                mps.InsertWKSPointVA(0, 1, ref p);
            }

            IPointCollection poly = new PolygonClass();

            poly.AddPointCollection(mps);
            return((IPolygon)poly);
        }
コード例 #33
0
        private void btnDeleteLink_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedRowCollection rowCollection = this.dataGridViewX1.SelectedRows;
            int nCount    = rowCollection.Count;
            int nOriCount = m_OriginPoints.PointCount;

            IPointCollection tmpPointCollectionOri = new MultipointClass();
            IPointCollection tmpPointCollectionDst = new MultipointClass();

            for (int i = 0; i < nOriCount; i++)
            {
                bool bFlag = false;
                for (int j = 0; j < nCount; j++)
                {
                    if (i == rowCollection[j].Index)
                    {
                        bFlag = true;
                        break;
                    }
                }

                if (bFlag == false)
                {
                    tmpPointCollectionOri.AddPoint(m_OriginPoints.get_Point(i));
                    tmpPointCollectionDst.AddPoint(m_TargetPoints.get_Point(i));
                }
            }

            m_OriginPoints.RemovePoints(0, m_OriginPoints.PointCount);
            m_TargetPoints.RemovePoints(0, m_TargetPoints.PointCount);
            for (int i = 0; i < tmpPointCollectionDst.PointCount; i++)
            {
                m_OriginPoints.AddPoint(tmpPointCollectionOri.get_Point(i));
                m_TargetPoints.AddPoint(tmpPointCollectionDst.get_Point(i));
            }

            RefreshDataTable();

            //m_pMapCtr.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            //m_pMapCtr.RefreshLayer();
            //if (refreshLayer != null)
            //{
            //    refreshLayer();
            //}
        }
コード例 #34
0
 /// <summary>
 /// 通过簇的点集计算簇的凸包
 /// </summary>
 /// <returns></returns>
 public void CreateConvexHull(ISpatialReference spatialReference)
 {
     //少于3个点就不做
     if (m_pointsList.Count < 3)
         return;
     IGeometryCollection geometryCollection = new MultipointClass();
     for (int i = 0; i < m_pointsList.Count; i++)
     {
         geometryCollection.AddGeometry(m_pointsList[i] as IGeometry);
     }
     ITopologicalOperator pTopological = geometryCollection as ITopologicalOperator;
     IGeometry g = pTopological.ConvexHull();
     if (g.GeometryType != esriGeometryType.esriGeometryPolygon)
         return;
     IPolygon convexHull = g as IPolygon;
     convexHull.SpatialReference = spatialReference;
     m_convexHull = convexHull;
 }
コード例 #35
0
        private void zoom2selBtn_Click(object sender, EventArgs e)
        {
            if (resultGrid.SelectedRows.Count == 0) return;

            IPointCollection points = new MultipointClass();
            try
            {
                for (int i = 0; i < resultGrid.SelectedRows.Count; i++)
                {
                    DataGridViewRow row = resultGrid.SelectedRows[i];
                    int id = (int)row.Cells[0].Value;

                    List<datacontract.poiLocation> qry = (from n in poiData.pois
                                                          where n.id == id
                                                          select n.location).ToList<datacontract.poiLocation>();
                    if (qry.Count == 0) break;
                    if (qry[0].points == null || qry[0].points.Count == 0) break;

                    datacontract.geojsonPoint jsonPt = qry[0].points[0].Point;
                    IPoint wgsPt = geopuntHelper.geojson2esriPoint(jsonPt, 4326);
                    IPoint prjPt = (IPoint)geopuntHelper.Transform((IGeometry)wgsPt, map.SpatialReference);

                    points.AddPoint(prjPt, Type.Missing, Type.Missing);
                }
                if (points.PointCount == 0)
                {
                    return;
                }
                else if (points.PointCount == 1)
                {
                    IPoint xy = points.get_Point(0);
                    geopuntHelper.ZoomByRatioAndRecenter(view, 1, xy.X, xy.Y);
                    map.MapScale = 1000;
                }
                else
                {
                    IEnvelope extent = ((IGeometry)points).Envelope;
                    view.Extent = extent;
                }
                view.Refresh();
            }
            catch (WebException wex)
            {
                if (wex.Status == WebExceptionStatus.Timeout)
                    MessageBox.Show("De connectie werd afgebroken." +
                        " Het duurde te lang voor de server een resultaat terug gaf.\n" +
                        "U kunt via de instellingen de 'timout'-tijd optrekken.", wex.Message);
                else if (wex.Response != null)
                {
                    string resp = new StreamReader(wex.Response.GetResponseStream()).ReadToEnd();
                    MessageBox.Show(resp, wex.Message);
                }
                else
                    MessageBox.Show(wex.Message, "Error");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ": " + ex.StackTrace);
            }
        }
コード例 #36
0
ファイル: GraphicToFeatureCmd.cs プロジェクト: EAWCS1/SUITT
        public static IGeometry get_GraphicShape(IEnumElement theElements, int a_Dimensionality, bool multipart)
        {
            IGeometry theReturn = null;
            IGeometryCollection theGeomColl = null;
            object missing = Type.Missing;

            if (theElements != null)
            {
                theElements.Reset();
                IElement theElement = theElements.Next();
                while (theElement != null)
                {
                    if (theGeomColl == null)
                        theGeomColl = new GeometryBagClass();

                    IGeometry theShape = null;
                    if (theElement is IGroupElement)
                    {
                        theShape = get_GraphicShape(((IGroupElement)theElement).Elements, a_Dimensionality, multipart);
                    }
                    else if (theElement is ICircleElement
                        || theElement is IPolygonElement
                        || theElement is IRectangleElement
                        || theElement is IEllipseElement
                        || theElement is ILineElement
                        || theElement is IMarkerElement)
                        theShape = theElement.Geometry;

                    if (theShape != null)
                        theGeomColl.AddGeometry(theShape, ref missing, ref missing);

                    theElement = theElements.Next();
                }
            }

            if (theGeomColl != null && theGeomColl.GeometryCount > 0)
            {
                ITopologicalOperator theTopoOp = null;

                switch (a_Dimensionality)
                {
                    case 0:
                        if (multipart)
                        {
                            theTopoOp = new MultipointClass();
                            theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl);
                        }
                        else
                            theTopoOp = theGeomColl.get_Geometry(0) as ITopologicalOperator;
                        break;
                    case 1:
                        theTopoOp = new PolylineClass();
                        theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl);
                        break;
                    case 2:
                        theTopoOp = new PolygonClass();
                        theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl);
                        break;
                }

                theReturn = theTopoOp as IGeometry;
            }
            return theReturn;
        }
コード例 #37
0
 public static IPoint Snapping(IActiveView activeView, esriGeometryHitPartType geometryHitPartType, IPoint queryPoint, double searchRaius)
 {
     IPoint vetexPoint = null;
     IPoint hitPoint = new PointClass();
     IHitTest hitTest = null;
     IPointCollection pointCollection = new MultipointClass();
     IProximityOperator proximityOperator = null;
     double hitDistance = 0;
     int hitPartIndex = 0, hitSegmentIndex = 0;
     Boolean rightSide = false;
     IFeatureCache2 featureCache = new FeatureCacheClass();
     featureCache.Initialize(queryPoint, searchRaius);  //初始化缓存
     for (int i = 0; i < activeView.FocusMap.LayerCount; i++)
     {
         //只有点、线、面并且可视的图层才加入缓存
         IFeatureLayer featLayer = (IFeatureLayer)activeView.FocusMap.get_Layer(i);
         if (featLayer != null && featLayer.Visible == true &&
             (featLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline ||
             featLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon ||
             featLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint))                
         {
             featureCache.AddFeatures(featLayer.FeatureClass, null);
             for (int j = 0; j < featureCache.Count; j++)
             {
                 IFeature feature = featureCache.get_Feature(j);
                 hitTest = (IHitTest)feature.Shape;
                 //捕捉节点,另外可以设置esriGeometryHitPartType,捕捉边线点,中间点等。
                 if (hitTest.HitTest(queryPoint, searchRaius, geometryHitPartType, hitPoint, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref rightSide))
                 {
                     object obj = Type.Missing;
                     pointCollection.AddPoint(hitPoint, ref obj, ref obj);
                     break;
                 }
             }
         }
     }
     proximityOperator = (IProximityOperator)queryPoint;
     double minDistance = 0, distance = 0;
     for (int i = 0; i < pointCollection.PointCount; i++)
     {
         IPoint tmpPoint = pointCollection.get_Point(i);
         distance = proximityOperator.ReturnDistance(tmpPoint);
         if (i == 0)
         {
             minDistance = distance;
             vetexPoint = tmpPoint;
         }
         else
         {
             if (distance < minDistance)
             {
                 minDistance = distance;
                 vetexPoint = tmpPoint;
             }
         }
     }
     return vetexPoint;            
 }
コード例 #38
0
ファイル: helpers.cs プロジェクト: BGCX261/ziggis-svn-to-git
        static void createWkbMultiLineString(byte[] wkb, ref int startIndex, BitConversion bitConversion, out IGeometry geometry)
        {
            geometry = new PolylineClass();
            IPointCollection mp = (IPointCollection)geometry;

            // Get the number of line strings.
            UInt32 lineStringCnt;
            getWkbUInt32(wkb, ref startIndex, bitConversion, out lineStringCnt);

            UInt32 pointCnt;
            double x, y;
            object missing = Type.Missing;
            // Loop through each LineString.
            for (int i = 0; i < lineStringCnt; i++)
            {
                startIndex += 5;  // Jump past useless header stuff.
                getWkbUInt32(wkb, ref startIndex, bitConversion, out pointCnt);

                IPointCollection tempPc = new MultipointClass();
                // Loop through each point.
                for (int j = 0; j < pointCnt; j++)
                {
                    getWkbDouble(wkb, ref startIndex, bitConversion, out x);
                    getWkbDouble(wkb, ref startIndex, bitConversion, out y);
                    tempPc.AddPoint(createAoPoint(x, y), ref missing, ref missing);
                }
                mp.AddPointCollection(tempPc);
            }
        }
コード例 #39
0
        ///方法1:根据点要素直接生产线要素,《参考绘制巷道》
        /// <summary>
        /// 根据点集坐标绘制线要素
        /// </summary>
        /// <params name="featureLayer"></params>
        /// <params name="lstPoint"></params>
        public static void CreateLine(IFeatureLayer featureLayer, List<IPoint> lstPoint, string ID)
        {
            try
            {
                IFeatureClass featureClass = featureLayer.FeatureClass;
                if (featureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                {
                    IPointCollection multipoint = new MultipointClass();
                    if (lstPoint.Count < 2)
                    {
                        MessageBox.Show(@"请选择两个及两个以上点数。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    ISegmentCollection pPath = new PathClass();
                    ILine pLine;
                    ISegment pSegment;
                    object o = Type.Missing;
                    for (int i = 0; i < lstPoint.Count - 1; i++)
                    {
                        pLine = new LineClass();
                        pLine.PutCoords(lstPoint[i], lstPoint[i + 1]);
                        pSegment = pLine as ISegment;
                        pPath.AddSegment(pSegment, ref o, ref o);
                    }
                    IGeometryCollection pPolyline = new PolylineClass();
                    pPolyline.AddGeometry(pPath as IGeometry, ref o, ref o);

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

                    IFeature feature = featureClass.CreateFeature();

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

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

                    //DataEditCommon.g_pMyMapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null);
                }
                else
                {
                    MessageBox.Show(@"请选择线图层。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch
            {
                return;
            }
        }
コード例 #40
0
        private KeyValuePair<IGeoDataset, IGeoDataset> computeWatershed(IPoint pour_point, IEnvelope analysisExtent)
        {
            try
            {
                //bodge the input point into its nasty shell of arcobjects junk for analysis
                IHydrologyOp pHydrologyOp = new RasterHydrologyOp() as IHydrologyOp;
                IPointCollection3 tPointCollection = new MultipointClass();
                object tPointlessMissingObject = Type.Missing;
                tPointCollection.AddPoint(pour_point, ref tPointlessMissingObject, ref tPointlessMissingObject);

                // open the accumulation and direction datasets, hardcoded
                //IGeoDataset tAccum = OpenRasterDataset(data_path, accum_name) as IGeoDataset;
                //IGeoDataset tDirection = OpenRasterDataset(data_path, dir_name) as IGeoDataset;
                //bodge the input extent into its nasty shell of arcobjects junk
                IRasterAnalysisEnvironment tRasterAnalysisEnvironment = new RasterAnalysisClass();
                if (analysisExtent != null)
                {
                    IRelationalOperator tCheckRequestedExtent = analysisExtent as IRelationalOperator;
                    if (tCheckRequestedExtent != null && tCheckRequestedExtent.Contains(pour_point))
                    {
                        // can anyone explain why these things have to be objects? Why can't there be interfaces
                        // for AnalysisExtentProvider and SnapObject that the datasets implement?
                        object tAnalysisEnvelopePointlesslyCastedToObject = (System.Object)analysisExtent;
                        object tAnotherPointlessMissingObject = Type.Missing;
                        //object tSnapObject = (System.Object)tDirection;
                        object tSnapObject = (System.Object)m_FlowDirDataset;
                        tRasterAnalysisEnvironment.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue,
                            ref tAnalysisEnvelopePointlesslyCastedToObject, ref tSnapObject);
                        tRasterAnalysisEnvironment.SetAsNewDefaultEnvironment();
                    }
                    else
                    {
                        logger.LogMessage(ServerLogger.msgType.warning, "create watershed", 8000,
                            "Input point was not within requested analysis extent. Analysis extent will be ignored (may be slow)!");
                    }
                }
                else
                {
                    logger.LogMessage(ServerLogger.msgType.warning, "create watershed", 8000,
                        "No analysis extent requested. Full extent will be used (may be slow)!");

                }
                IExtractionOp tExtractionOp = new RasterExtractionOpClass();

                // Do the work: snap the point to a snapped-pour-point grid and use it to calcualte the watershed
                //IGeoDataset tPourPointGrid = tExtractionOp.Points(tDirection, tPointCollection, true);
                IGeoDataset tPourPointGrid = tExtractionOp.Points(m_FlowDirDataset, tPointCollection, true);
                //IGeoDataset snapRaster = pHydrologyOp.SnapPourPoint(tPourPointGrid, tAccum, 100);
                IGeoDataset snapRaster = pHydrologyOp.SnapPourPoint(tPourPointGrid, m_FlowAccDataset, 100);
                // check the snapping worked..?
                // calculate the watershed!
                //IGeoDataset watershedRaster = pHydrologyOp.Watershed(tDirection, snapRaster);
                IGeoDataset watershedRaster = pHydrologyOp.Watershed(m_FlowDirDataset, snapRaster);
                //  restore previous default analysis extent if we changed it (should = whole dataset)
                if (analysisExtent != null)
                {
                    tRasterAnalysisEnvironment.RestoreToPreviousDefaultEnvironment();
                }
                // change it to a polygon feature (will have the area added) and return it
                IGeoDataset tWatershedPolygonGDS = ConvertAndUnionWatershed(watershedRaster);
                KeyValuePair<IGeoDataset, IGeoDataset> tRasterPolyPair = new KeyValuePair<IGeoDataset, IGeoDataset>(watershedRaster, tWatershedPolygonGDS);
                return tRasterPolyPair;
            }
            catch (Exception e)
            {
                logger.LogMessage(ServerLogger.msgType.infoStandard, "Compute watershed error: ", 8000, e.Message);
                logger.LogMessage(ServerLogger.msgType.infoStandard, "Compute watershed error: ", 8000, e.ToString());
                logger.LogMessage(ServerLogger.msgType.infoStandard, "Compute watershed error: ", 8000, e.TargetSite.Name);
                logger.LogMessage(ServerLogger.msgType.infoStandard, "Compute watershed error: ", 8000, e.StackTrace);
            }
            return new KeyValuePair<IGeoDataset, IGeoDataset>();
        }
コード例 #41
0
        /// <summary>
        /// �������
        /// </summary>
        /// <params name="CurPoint"></params>
        /// <returns></returns>
        private double CaculateArea(IPoint CurPoint)
        {
            IPointCollection tempCollection = new MultipointClass();

            object missing = Type.Missing;
            for (int i = 0; i < m_ptCollection.PointCount; i++)
            {
                IPoint dPoint = m_ptCollection.get_Point(i);
                tempCollection.AddPoint(dPoint, ref  missing, ref  missing);
            }

            tempCollection.AddPoint(CurPoint, ref missing, ref missing);
            tempCollection.AddPoint(tempCollection.get_Point(0), ref missing, ref  missing);
            int Count = tempCollection.PointCount;

            double x1, x2, y1, y2;
            double tempArea = 0.0;
            for (int i = 0; i < Count - 1; i++)
            {
                x1 = Convert.ToDouble(tempCollection.get_Point(i).X);
                y1 = Convert.ToDouble(tempCollection.get_Point(i).Y);
                x2 = Convert.ToDouble(tempCollection.get_Point(i + 1).X);
                y2 = Convert.ToDouble(tempCollection.get_Point(i + 1).Y);
                tempArea += (x1 * y2 - x2 * y1);
            }

            tempArea = Math.Abs(tempArea) / 2;
            return tempArea;
        }
コード例 #42
0
ファイル: CompilationLogCmd.cs プロジェクト: EAWCS1/SUITT
        private static IGeometry get_GraphicShape(IEnumElement theElements, int a_Dimensionality, bool multipart, ref IElementCollection elemCollection)
        {
            IGeometry theReturn = null;
            IGeometryCollection theGeomColl = null;
            object missing = Type.Missing;

            try
            {
                elemCollection.Clear();

                if (theElements != null)
                {
                    theElements.Reset();
                    IElement theElement = theElements.Next();
                    while (theElement != null)
                    {
                        if (theGeomColl == null)
                            theGeomColl = new GeometryBagClass();

                        IGeometry theShape = null;
                        if (theElement is IGroupElement)
                        {
                            theShape = get_GraphicShape(((IGroupElement)theElement).Elements, a_Dimensionality, multipart,ref elemCollection);
                        }
                        else if (theElement is ICircleElement
                            || theElement is IPolygonElement
                            || theElement is IRectangleElement
                            || theElement is IEllipseElement
                            || theElement is ILineElement
                            || theElement is IMarkerElement)
                            theShape = theElement.Geometry;

                        if (theShape != null)
                            theGeomColl.AddGeometry(theShape, ref missing, ref missing);

                        elemCollection.Add(theElement,-1);

                        theElement = theElements.Next();
                    }
                }

                if (theGeomColl != null && theGeomColl.GeometryCount > 0)
                {
                    ITopologicalOperator theTopoOp = null;

                    switch (a_Dimensionality)
                    {
                        case 0:
                            if (multipart)
                            {
                                theTopoOp = new MultipointClass();
                                theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl);
                            }
                            else
                                theTopoOp = theGeomColl.get_Geometry(0) as ITopologicalOperator;
                            break;
                        case 1:
                            theTopoOp = new PolylineClass();
                            theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl);
                            break;
                        case 2:
                            theTopoOp = new PolygonClass();
                            theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl);
                            break;
                    }

                    theReturn = theTopoOp as IGeometry;
                }
            }
            catch(Exception ex)
            {
                util.Logger.Write(" Descrip  : Finding elements with a specific dimensionality. " +
                    "\n Message  : " + ex.Message +
                    "\n StackTrc : " + ex.StackTrace,util.Logger.LogLevel.Debug);

            }
            return theReturn;
        }
コード例 #43
0
ファイル: GeometryVoronoi.cs プロジェクト: nicogis/Voronoi
        /// <summary>
        /// Calculate diagram voronoi from list of points
        /// </summary>
        /// <param name="points">list of points</param>
        /// <returns>list of polygons</returns>
        public static IList<IGeometry> GeometryVoronoi(List<IPoint> points)
        {
            // Check valid input
            if (points.Count < 3)
            {
                throw new ArgumentException("Input must be a MultiPoint containing at least three points");
            }

            // Initialise a list of vertices
            List<SimplePoint> vertices = new List<SimplePoint>();

            // Add all the original supplied points
            for (int i = 0; i < points.Count; i++)
            {
                SimplePoint point = new SimplePoint(points[i].X, points[i].Y);

                // MultiPoints can contain the same point twice, but this messes up Delaunay
                if (!vertices.Contains(point))
                {
                    vertices.Add(point);
                }
            }

            // Important - count the number of points in the array as some duplicate points
            // may have been removed
            int numPoints = vertices.Count;

            // Check valid input
            if (numPoints < 3)
            {
                throw new ArgumentException("Input must be a list of points containing at least three points");
            }

            // Important! Sort the list so that points sweep from left - right
            vertices.Sort();

            IPointCollection pointCollection = new MultipointClass();
            foreach (SimplePoint p in vertices)
            {
                pointCollection.AddPoint(new PointClass() { X = p.X, Y = p.Y });
            }

            // Calculate the "supertriangle" that encompasses the pointset
            IEnvelope envelope = (pointCollection as IGeometry).Envelope;

            // Width
            double dx = envelope.Width;

            // Height
            double dy = envelope.Height;

            // Maximum dimension
            double dmax = (dx > dy) ? dx : dy;

            // Centre
            double avgx = ((envelope.XMax - envelope.XMin) / 2) + envelope.XMin;
            double avgy = ((envelope.YMax - envelope.YMin) / 2) + envelope.YMin;

            // Create the points at corners of the supertriangle
            SimplePoint a = new SimplePoint(avgx - (2 * dmax), avgy - dmax);
            SimplePoint b = new SimplePoint(avgx + (2 * dmax), avgy - dmax);
            SimplePoint c = new SimplePoint(avgx, avgy + (2 * dmax));

            // Add the supertriangle vertices to the end of the vertex array
            vertices.Add(a);
            vertices.Add(b);
            vertices.Add(c);

            double radius;
            SimplePoint circumcentre;
            Triangulation.CalculateCircumcircle(a, b, c, out circumcentre, out radius);

            // Create a triangle from the vertices
            SimpleTriangle superTriangle = new SimpleTriangle(numPoints, numPoints + 1, numPoints + 2, circumcentre, radius);

            // Add the supertriangle to the list of triangles
            List<SimpleTriangle> triangles = new List<SimpleTriangle>();
            triangles.Add(superTriangle);

            List<SimpleTriangle> completedTriangles = new List<SimpleTriangle>();

            // Loop through each point
            for (int i = 0; i < numPoints; i++)
            {
                // Initialise the edge buffer
                List<int[]> edges = new List<int[]>();

                // Loop through each triangle
                for (int j = triangles.Count - 1; j >= 0; j--)
                {
                    // If the point lies within the circumcircle of this triangle
                    if (Distance(triangles[j].CircumCentre, vertices[i]) < triangles[j].Radius)
                    {
                        // Add the triangle edges to the edge buffer
                        edges.Add(new int[] { triangles[j].A, triangles[j].B });
                        edges.Add(new int[] { triangles[j].B, triangles[j].C });
                        edges.Add(new int[] { triangles[j].C, triangles[j].A });

                        // Remove this triangle from the list
                        triangles.RemoveAt(j);
                    }
                    else if (vertices[i].X > triangles[j].CircumCentre.X + triangles[j].Radius)
                    {
                        // If this triangle is complete
                        {
                            completedTriangles.Add(triangles[j]);
                        }

                        triangles.RemoveAt(j);
                    }
                }

                // Remove duplicate edges
                for (int j = edges.Count - 1; j > 0; j--)
                {
                    for (int k = j - 1; k >= 0; k--)
                    {
                        // Compare if this edge match in either direction
                        if (edges[j][0].Equals(edges[k][1]) && edges[j][1].Equals(edges[k][0]))
                        {
                            // Remove both duplicates
                            edges.RemoveAt(j);
                            edges.RemoveAt(k);

                            // We've removed an item from lower down the list than where j is now, so update j
                            j--;
                            break;
                        }
                    }
                }

                // Create new triangles for the current point
                for (int j = 0; j < edges.Count; j++)
                {
                    Triangulation.CalculateCircumcircle(vertices[edges[j][0]], vertices[edges[j][1]], vertices[i], out circumcentre, out radius);
                    SimpleTriangle t = new SimpleTriangle(edges[j][0], edges[j][1], i, circumcentre, radius);
                    triangles.Add(t);
                }
            }

            // We've finished triangulation. Move any remaining triangles onto the completed list
            completedTriangles.AddRange(triangles);

            IList<IGeometry> voronoiPolygon = new List<IGeometry>();
            for (var i = 0; i < vertices.Count; i++)
            {
                // Initiliase a new geometry to hold the voronoi polygon
                IPointCollection mp = new MultipointClass();

                // Look through each triangle
                foreach (SimpleTriangle tri in completedTriangles)
                {
                    // If the triangle intersects this point
                    if (tri.A == i || tri.B == i || tri.C == i)
                    {
                        mp.AddPoint(new PointClass() { X = tri.CircumCentre.X, Y = tri.CircumCentre.Y });
                    }
                }

                // Create the voronoi polygon from the convex hull of the circumcentres of intersecting triangles
                ITopologicalOperator topologicalOperator = mp as ITopologicalOperator;
                IGeometry polygon = topologicalOperator.ConvexHull();
                topologicalOperator = polygon as ITopologicalOperator;
                IGeometry result = topologicalOperator.Intersect(envelope, esriGeometryDimension.esriGeometry2Dimension);
                if ((result != null) && (!result.IsEmpty))
                {
                    voronoiPolygon.Add(result);
                }
            }

            return voronoiPolygon;
        }
コード例 #44
0
        private void zoom2selBtn_Click(object sender, EventArgs e)
        {
            if (mouseCmd == null || csvDataGrid.SelectedRows.Count == 0) return;

            int maxCount = 30;
            int i = 0;

            try
            {
                clearGraphics();

                IPointCollection points = new MultipointClass();

                foreach (DataGridViewRow row in csvDataGrid.SelectedRows)
                {
                    if (row.Cells["validAdres"].Value == null || row.Cells["validAdres"].Value.ToString() == "")
                        continue;

                    if( i > maxCount ) break;
                    i++;

                    string adres = row.Cells["validAdres"].Value.ToString();

                    string[] xy = adres.Split(new string[] {"|"}, StringSplitOptions.RemoveEmptyEntries);

                    double x; double y;
                    string adresType = "Manueel";
                    if (xy.Count() == 2)
                    {
                        bool xBool = Double.TryParse(xy[0], out x);
                        bool yBool = Double.TryParse(xy[1], out y);

                        if (!xBool || !yBool)
                        {
                            List<datacontract.locationResult> locs = loc.getAdresLocation(adres, 1);
                            if (locs.Count == 0) continue;
                            x = locs[0].Location.X_Lambert72;
                            y = locs[0].Location.Y_Lambert72;
                            adresType = locs[0].LocationType;
                        }
                    }
                    else
                    {
                        List<datacontract.locationResult> locs = loc.getAdresLocation(adres, 1);
                        if (locs.Count == 0) continue;
                        x = locs[0].Location.X_Lambert72;
                        y = locs[0].Location.Y_Lambert72;
                        adresType = locs[0].LocationType;
                    }

                    IPoint pt = new PointClass() { X = x, Y = y, SpatialReference = lam72 };
                    IPoint prjPt = geopuntHelper.Transform(pt, map.SpatialReference) as IPoint;
                    points.AddPoint(prjPt);

                    IRgbColor rgb = new RgbColorClass() { Red = 0, Blue = 255, Green = 255 };
                    IRgbColor black = new RgbColorClass() { Red = 0, Green = 0, Blue = 0 };
                    IElement grp = geopuntHelper.AddGraphicToMap(map, (IGeometry)prjPt, rgb, black, 5, true);
                    graphics.Add(grp);
                }

                if (points.PointCount == 0)
                {
                    return;
                }
                else if (points.PointCount == 1)
                {
                    IPoint xy = points.get_Point(0);
                    geopuntHelper.ZoomByRatioAndRecenter(view, 1, xy.X, xy.Y);
                    map.MapScale = 1000;
                    view.Refresh();
                }
                else
                {
                    IEnvelope extent = ((IGeometry)points).Envelope;
                    view.Extent = extent;
                    view.Refresh();
                }
            }
            catch (WebException wex)
            {
                if (wex.Status == WebExceptionStatus.Timeout)
                    MessageBox.Show("De connectie werd afgebroken." +
                        " Het duurde te lang voor de server een resultaat terug gaf.\n" +
                        "U kunt via de instellingen de 'timout'-tijd optrekken.", wex.Message);
                else if (wex.Response != null)
                {
                    string resp = new StreamReader(wex.Response.GetResponseStream()).ReadToEnd();
                    MessageBox.Show(resp, wex.Message);
                }
                else
                    MessageBox.Show(wex.Message, "Error");
            }
            catch (Exception ex)
            {
                 MessageBox.Show( ex.Message +" : "+ ex.StackTrace );
            }
        }