Beispiel #1
0
        private void InsertValueAndGetPos2(string FieldName)//位置和要素要同时获取,否则值和位置可能不对应
        {
            //try
            //{
            if (fatherform.MFGridView2 != null)
            {
                //添加列
                if (fatherform.MFGridView2.ColumnCount == 0)
                {
                    if (TitleField == "")
                    {
                        fatherform.MFGridView2.Columns.Add("FeatureID", "FeatureID");
                    }
                    else
                    {
                        fatherform.MFGridView2.Columns.Add(TitleField, TitleField);
                    }
                    fatherform.MFGridView2.Columns.Add(FieldName, FieldName);
                }
                else
                {
                    fatherform.MFGridView2.Columns.Add(FieldName, FieldName);
                }
                //添加值
                ILayer61 SlctdLyr    = Program.sgworld.ProjectTree.GetLayer(LayerID);
                string[] ExtractFile = SlctdLyr.DataSourceInfo.ConnectionString.Split(';');
                string   FilePath    = ExtractFile[0].Substring(9);

                IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
                IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(FilePath), 0);
                IFeatureClass     pFeatureClass     = (IFeatureClass)pFeatureWorkspace.OpenFeatureClass(System.IO.Path.GetFileName(FilePath));

                bool   ReProjectOrNot = false;  //标记是否需要重投影
                string LayerCord      = SlctdLyr.CoordinateSystem.WktDescription;
                string TerrainCord    = Program.sgworld.Terrain.CoordinateSystem.WktDescription;
                if (LayerCord != TerrainCord)
                {
                    ReProjectOrNot = true;
                }

                string             AValue    = "";
                IPosition61        cPos      = null;
                List <IPosition61> Positions = new List <IPosition61>();
                double             dXCoord;
                double             dYCoord;
                double             dAltitude         = 0;
                AltitudeTypeCode   eAltitudeTypeCode = AltitudeTypeCode.ATC_ON_TERRAIN;
                double             dYaw      = 0.0;
                double             dPitch    = 0.0;
                double             dRoll     = 0.0;
                double             dDistance = 20000;
                for (int i = 0; i < pFeatureClass.FeatureCount(null); i++)
                {
                    //插入值
                    AValue = pFeatureClass.GetFeature(i).get_Value(pFeatureClass.FindField(FieldName)).ToString();
                    if (fatherform.MFGridView2.ColumnCount == 2)
                    {
                        if (fatherform.MFGridView2.Columns[0].Name == "FeatureID")
                        {
                            this.fatherform.MFGridView2.Rows.Add(pFeatureClass.GetFeature(i).OID, AValue);
                        }
                        else
                        {
                            this.fatherform.MFGridView2.Rows.Add(pFeatureClass.GetFeature(i).get_Value(pFeatureClass.FindField(TitleField)).ToString(), AValue);
                        }
                    }
                    else
                    {
                        if (this.fatherform.MFGridView2.RowCount > 0)
                        {
                            fatherform.MFGridView2.Rows[i].Cells[FieldName].Value = AValue;
                        }
                    }
                    //获取位置
                    ESRI.ArcGIS.Geometry.IGeometry pGeometry = pFeatureClass.GetFeature(i).Shape;
                    if (ReProjectOrNot)
                    {
                        ESRI.ArcGIS.Geometry.ISpatialReferenceFactory    srFactory = new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass();
                        ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem gcs       = srFactory.CreateGeographicCoordinateSystem((int)ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_WGS1984);
                        ESRI.ArcGIS.Geometry.ISpatialReference           sr1       = gcs;
                        pGeometry.Project(sr1);
                    }
                    ESRI.ArcGIS.Geometry.IPoint pPoint = null;
                    switch (pFeatureClass.ShapeType)
                    {
                    case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
                        pPoint = (ESRI.ArcGIS.Geometry.IPoint)pGeometry;

                        break;

                    case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
                        pPoint = ((ESRI.ArcGIS.Geometry.IPolyline)pGeometry).ToPoint;
                        break;

                    case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:
                        pPoint = ((ESRI.ArcGIS.Geometry.IArea)(ESRI.ArcGIS.Geometry.IPolygon) pGeometry).Centroid;
                        break;

                    default:
                        break;
                    }
                    dXCoord = pPoint.X;
                    dYCoord = pPoint.Y;
                    cPos    = Program.sgworld.Creator.CreatePosition(dXCoord, dYCoord, dAltitude, eAltitudeTypeCode, dYaw, dPitch, dRoll, dDistance);
                    Positions.Add(cPos);
                }
                if (Positions != null)
                {
                    fatherform.StaThemePos = Positions;
                }
            }
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show("Unexpected Error:" + ex.Message);
            //}
            /***20130227杨漾(去掉trycatch,抛给上层trycatch处理异常)****/
        }
Beispiel #2
0
        ///刘宇

        private string Geometry2Json(IGeometry pGeo)
        {
            int wkid = pGeo.SpatialReference.FactoryCode;

            ESRI.ArcGIS.Geometry.IPoint           pPoint = null;
            ESRI.ArcGIS.Geometry.IPointCollection pPoints = null;
            double        x, y;
            StringBuilder sb = new StringBuilder("{");

            sb.Append(@"""geometries""" + ":{");

            switch (pGeo.GeometryType)
            {
                #region Point2Json
            case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
                pPoint = pGeo as ESRI.ArcGIS.Geometry.IPoint;
                pPoint.QueryCoords(out x, out y);
                string json = @"{""x"":" + x + @",""y"":" + y + @",""spatialReference"":" + @"{""wkid"":" + wkid + "}";
                sb.Append(@"""point"":" + json);

                break;
                #endregion

                #region Polyline2Json
            case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
                pPoints = pGeo as ESRI.ArcGIS.Geometry.IPointCollection;

                IPolyline pPolyline = pGeo as IPolyline;

                IGeometryCollection pGeoetryCollection = pPolyline as IGeometryCollection;

                if (pGeoetryCollection.GeometryCount >= 1)
                {
                    sb.Append(@"""paths"":[");
                    for (int i = 0; i < pGeoetryCollection.GeometryCount; i++)
                    {
                        //paths可能有多个path,而每一个path是多个点,用两个for循环
                        if (pGeoetryCollection.get_Geometry(i) is IPath)
                        {
                            sb.Append("[");
                            pPoints = pGeoetryCollection.get_Geometry(i) as IPointCollection;

                            for (int j = 0; j < pPoints.PointCount; j++)
                            {
                                pPoint = pPoints.get_Point(j);
                                pPoint.QueryCoords(out x, out y);
                                sb.Append("[" + x + "," + y + "],");
                            }
                            sb.Remove(sb.Length - 1, 1);
                            sb.Append("]");
                        }
                    }
                    sb.Append("]" + @",""spatialReference"":" + @"{""wkid"":" + wkid + "}");
                }
                //else
                //{
                //     sb.Append(@"""paths"":[[");
                //for (int i = 0; i < pPoints.PointCount; i++)
                //{
                //    pPoint = pPoints.get_Point(i);
                //    pPoint.QueryCoords(out x, out y);
                //    sb.Append("[" + x + "," + y + "],");
                //}
                //sb.Remove(sb.Length - 1, 1);
                //sb.Append("]]" + @",""spatialReference"":" + @"{""wkid"":" + wkid + "}");
                //}


                break;

                #endregion

                #region Polygon2Json
            case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:
                pPoints = pGeo as ESRI.ArcGIS.Geometry.IPointCollection;



                IPolygon pPolygon = pGeo as IPolygon;

                //外环和内环?面的构造比较复杂



                IGeometryCollection pGeoetryCollection1 = pPolygon as IGeometryCollection;

                if (pGeoetryCollection1.GeometryCount >= 1)
                {
                    sb.Append(@"""rings"":[");
                    for (int i = 0; i < pGeoetryCollection1.GeometryCount; i++)
                    {
                        if (pGeoetryCollection1.get_Geometry(i) is IRing)
                        {
                            sb.Append("[");
                            pPoints = pGeoetryCollection1.get_Geometry(i) as IPointCollection;
                            for (int j = 0; j < pPoints.PointCount; j++)
                            {
                                pPoint = pPoints.get_Point(j);
                                pPoint.QueryCoords(out x, out y);
                                sb.Append("[" + x + "," + y + "],");
                            }

                            sb.Remove(sb.Length - 1, 1);
                            sb.Append("]");
                        }
                    }
                    sb.Append("]" + @",""spatialReference"":" + @"{""wkid"":" + wkid + "}");
                }
                //else
                //{
                //    sb.Append(@"""rings"":[[");
                //    for (int i = 0; i < pPoints.PointCount; i++)
                //    {
                //        pPoint = pPoints.get_Point(i);
                //        pPoint.QueryCoords(out x, out y);
                //        sb.Append("[" + x + "," + y + "],");
                //    }
                //    sb.Remove(sb.Length - 1, 1);
                //    sb.Append("]]" + @",""spatialReference"":" + @"{""wkid"":" + wkid + "}");
                //}


                break;
                #endregion
            }

            sb.Append("}");

            //添加Geometry

            sb.Append("}");

            return(sb.ToString());
        }
        // The following CreateXMLLNodeElt private procedure is used to create all the expected
        // XML items for a XML NodeFeature related to a Station or Feeder simple junction feature
        private void CreateXMLNodeElt(ESRI.ArcGIS.Geodatabase.IFeature inFeature, ref MSXML2.DOMDocument outDOMDoc, ref MSXML2.IXMLDOMElement outXMLElements, string inNodeTypeName)
        {
            if (!inFeature.HasOID)
            {
                MessageBox.Show("No OID");
                return;
            }

            MSXML2.IXMLDOMElement xmlNode;
            MSXML2.IXMLDOMElement xmlNode_XCoord;
            MSXML2.IXMLDOMElement xmlNode_YCoord;
            MSXML2.IXMLDOMElement xmlNode_RelatedContainerID;
            bool relatedContainer;

            MSXML2.IXMLDOMNodeList xmlNodeList;
            MSXML2.IXMLDOMElement  xmlDrawing;
            MSXML2.IXMLDOMElement  xmlDrawing_EltTypeName;
            MSXML2.IXMLDOMElement  xmlDrawing_ExternalUID;

            //-------- Feature Section START related to the "infeature" --------
            // Creating the NodeFeature element
            xmlNode = outDOMDoc.createElement("NodeFeature");
            outXMLElements.appendChild(xmlNode);
            // Specifying basic XML items for this NodeFeature
            CreateBasicXMLItemsForSchematicElt(inFeature, ref outDOMDoc, ref xmlNode, inNodeTypeName);

            // Specifying its X && Y when they exist
            if ((inFeature.Fields.FindField("X") > 0) && (inFeature.Fields.FindField("Y") > 0))
            {
                // Specifying InitialX
                xmlNode_XCoord = outDOMDoc.createElement("InitialX");
                xmlNode.appendChild(xmlNode_XCoord);
                xmlNode_XCoord.nodeTypedValue = inFeature.get_Value(inFeature.Fields.FindField("X"));
                // Specifying InitialY
                xmlNode_YCoord = outDOMDoc.createElement("InitialY");
                xmlNode.appendChild(xmlNode_YCoord);
                xmlNode_YCoord.nodeTypedValue = inFeature.get_Value(inFeature.Fields.FindField("Y"));
            }
            else
            {
                // Retrieving initial position from Geometry
                ESRI.ArcGIS.Geometry.IPoint oPoint = (ESRI.ArcGIS.Geometry.IPoint)inFeature.ShapeCopy;

                if (oPoint != null)
                {
                    // Specifying InitialX
                    xmlNode_XCoord = outDOMDoc.createElement("InitialX");
                    xmlNode.appendChild(xmlNode_XCoord);
                    xmlNode_XCoord.nodeTypedValue = oPoint.X;
                    // Specifying InitialY
                    xmlNode_YCoord = outDOMDoc.createElement("InitialY");
                    xmlNode.appendChild(xmlNode_YCoord);
                    xmlNode_YCoord.nodeTypedValue = oPoint.Y;
                }
            }

            xmlNode_RelatedContainerID = outDOMDoc.createElement("RelatedContainerID");
            xmlNode.appendChild(xmlNode_RelatedContainerID);

            // Specifying its properties
            switch (inFeature.Class.AliasName)
            {
            case "Station":
            {
                xmlNode_RelatedContainerID.nodeTypedValue = "Container-" + System.Convert.ToString(inFeature.get_Value(inFeature.Fields.FindField("Feeder")));
                // For Station feature, the field contained in the StationsPropertiesArray will be exported
                CompleteXMLEltByProperties(inFeature, ref outDOMDoc, ref xmlNode, m_stationsPropertiesArray);
                break;
            }

            case "Feeder":
            {
                xmlNode_RelatedContainerID.nodeTypedValue = "Container-" + inFeature.OID.ToString();
                // For Feeder feature, the field contained in the StationsPropertiesArray will be exported
                CompleteXMLEltByProperties(inFeature, ref outDOMDoc, ref xmlNode, m_feedersPropertiesArray);
                break;
            }
            }
            //-------- Feature Section END related to the "infeature" --------

            // Checking the existence of the related container
            xmlNodeList      = outXMLElements.selectNodes("NodeFeature/ExternalUniqueID");
            relatedContainer = false;

            foreach (MSXML2.IXMLDOMNode node in xmlNodeList)
            {
                if (node.text == xmlNode_RelatedContainerID.nodeTypedValue.ToString())
                {
                    relatedContainer = true;
                    break;
                }
            }             // pNode

            // Creating the related container when it doesn//t already exist
            if (!relatedContainer)
            {
                xmlDrawing = outDOMDoc.createElement("NodeFeature");
                outXMLElements.appendChild(xmlDrawing);
                // Specifying its FeatureClassName
                xmlDrawing_EltTypeName = outDOMDoc.createElement("FeatureClassName");
                xmlDrawing.appendChild(xmlDrawing_EltTypeName);
                xmlDrawing_EltTypeName.nodeTypedValue = "Containers";
                // Specifying its ExternalUniqueID
                xmlDrawing_ExternalUID = outDOMDoc.createElement("ExternalUniqueID");
                xmlDrawing.appendChild(xmlDrawing_ExternalUID);
                xmlDrawing_ExternalUID.nodeTypedValue = xmlNode_RelatedContainerID.nodeTypedValue;
            }
        }
        void EventListener_OnVertexDeleted(ESRI.ArcGIS.Geometry.IPoint point)
        {
            EditorEventArgs e = new EditorEventArgs("OnVertexDeleted");

            OnChanged(e);
        }
        protected override void OnMouseDown(MouseEventArgs arg)
        {
            ESRI.ArcGIS.Geometry.IPoint point = ArcMap.Document.CurrentLocation;//ArcMap.Document.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);

            GeometryTools.SplitLinesAtClick(ArcMap.Application, ConfigUtil.GetConfigValue("SplitLinesSuspendAA", "true"), ConfigUtil.GetConfigValue("SplitLinesAtLocation_Snap", 10.0), ConfigUtil.GetConfigValue("SplitLines_SkipDistance", .5), point, true, false, true);
        }
Beispiel #6
0
        private void simpleButton2_Click(object sender, EventArgs e)
        {
            if (this.pPath == null || this.pPath == "")
            {
                MessageBox.Show("请添加数据!", "SUNZ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            try
            {
                IWorkspaceFactory pShpWorkspaceFactory = new ShapefileWorkspaceFactoryClass();

                if (pShpWorkspaceFactory.IsWorkspace(System.IO.Path.GetDirectoryName(this.pPath)))
                {
                    IWorkspace        pWorkspace        = pShpWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(this.pPath), 0);
                    IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
                    IFeatureClass     pFeatureClass     = pFeatureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(this.pPath));
                    if (pFeatureClass.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon)
                    {
                        MessageBox.Show("请导入面图层!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    int GroupID = SgWorld.ProjectTree.FindItem("区域挖开");
                    if (GroupID == 0)
                    {
                        GroupID = SgWorld.ProjectTree.CreateGroup("区域挖开", 0);
                    }
                    IFeatureCursor fc       = pFeatureClass.Search(null, false);
                    IFeature       pFeature = fc.NextFeature();
                    while (pFeature != null)
                    {
                        int sq = 0;
                        ESRI.ArcGIS.Geometry.IGeometry        geo = pFeature.Shape;
                        ESRI.ArcGIS.Geometry.IPointCollection pPointCollection = geo as ESRI.ArcGIS.Geometry.IPointCollection;
                        this.cVerticesArray = new double[(pPointCollection.PointCount - 1) * 3];
                        for (int i = 0; i < pPointCollection.PointCount - 1; i++)
                        {
                            ESRI.ArcGIS.Geometry.IPoint pPoint = pPointCollection.get_Point(i);
                            cVerticesArray[sq] = pPoint.X;
                            sq++;
                            cVerticesArray[sq] = pPoint.Y;
                            sq++;
                            // cVerticesArray[sq] = item[2];
                            cVerticesArray[sq] = 0.1;
                            sq++;
                        }
                        ILinearRing cRing            = SgWorld.Creator.GeometryCreator.CreateLinearRingGeometry(cVerticesArray);
                        IPolygon    cPolygonGeometry = SgWorld.Creator.GeometryCreator.CreatePolygonGeometry(cRing, null);

                        IGeometry geoX = cPolygonGeometry as IGeometry;
                        Creator.CreateHoleOnTerrain(geoX, GroupID, "Hole" + System.Guid.NewGuid().ToString().Substring(0, 6).ToUpper());
                        pFeature = fc.NextFeature();

                        this.Hide();
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Beispiel #7
0
        void EventListener_OnVertexMoved(ESRI.ArcGIS.Geometry.IPoint point)
        {
            EditorEventArgs e = new EditorEventArgs(EditorEventEnum.OnVertexMoved);

            OnChanged(e);
        }
Beispiel #8
0
 /// <summary>
 /// PointsToSegment - Takes to/from points to form a line segment
 /// </summary>
 /// <param name="frompoint"></param>
 /// <param name="topoint"></param>
 /// <returns>Segment</returns>
 internal static ESRI.ArcGIS.Geometry.ISegment PointsToSegment(ESRI.ArcGIS.Geometry.IPoint frompoint, ESRI.ArcGIS.Geometry.IPoint topoint)
 {
     ESRI.ArcGIS.Geometry.ISegment segment = null;
     ESRI.ArcGIS.Geometry.ILine    line    = new ESRI.ArcGIS.Geometry.Line();
     if (frompoint != null && topoint != null)
     {
         line.FromPoint = frompoint;
         line.ToPoint   = topoint;
         segment        = line as ESRI.ArcGIS.Geometry.ISegment;
     }
     return(segment);
 }
Beispiel #9
0
 private void AddASCFile_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     this.openFileDialog1.Title  = "加载路线数据";
     this.openFileDialog1.Filter = "My file(*.txt)|*.txt|ShapeFile(*.shp)|*.shp";
     if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         this.gridControl1.DataSource = null;
         if (this.PointsDt.Rows.Count != 0)
         {
             this.PointsDt.Clear();
         }
         // int rCount = this.PointsDt.Rows.Count;
         if (this.openFileDialog1.FileName.ToLower().Contains(".txt"))
         {
             string[] CoorPoint = File.ReadAllLines(this.openFileDialog1.FileName, Encoding.ASCII);
             try
             {
                 for (int j = 0; j < CoorPoint.Length; j++)
                 {
                     if (CoorPoint[j] != "" && CoorPoint[j] != null)
                     {
                         DataRow  dr        = PointsDt.NewRow();
                         string[] newStrArr = new string[2];
                         newStrArr = CoorPoint[j].Split(',');
                         dr["X"]   = newStrArr[0];
                         dr["Y"]   = newStrArr[1];
                         PointsDt.Rows.Add(dr);
                     }
                 }
                 this.gridControl1.DataSource = PointsDt;
             }
             catch (Exception ex)
             {
                 MessageBox.Show("加载文件格式不正确!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 //throw;
             }
         }
         else if (this.openFileDialog1.FileName.ToLower().Contains(".shp"))
         {
             try
             {
                 IWorkspaceFactory pShpWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
                 IWorkspace        pWorkspace           = pShpWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(this.openFileDialog1.FileName), 0);
                 IFeatureWorkspace pFeatureWorkspace    = pWorkspace as IFeatureWorkspace;
                 IFeatureClass     pFeatureClass        = pFeatureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(this.openFileDialog1.FileName));
                 if (pFeatureClass.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline)
                 {
                     MessageBox.Show("请导入线图层!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                     return;
                 }
                 IFeatureCursor fc       = pFeatureClass.Search(null, false);
                 IFeature       pFeature = fc.NextFeature();
                 if (pFeature != null)
                 {
                     int sq = 0;
                     ESRI.ArcGIS.Geometry.IGeometry        geo = pFeature.Shape;
                     ESRI.ArcGIS.Geometry.IPointCollection pPointCollection = geo as ESRI.ArcGIS.Geometry.IPointCollection;
                     for (int i = 0; i < pPointCollection.PointCount; i++)
                     {
                         ESRI.ArcGIS.Geometry.IPoint pPoint = pPointCollection.get_Point(i);
                         DataRow dr = PointsDt.NewRow();
                         dr["X"] = pPoint.X;
                         dr["Y"] = pPoint.Y;
                         PointsDt.Rows.Add(dr);
                     }
                 }
             }
             catch (Exception)
             {
             }
             if (PointsDt != null)
             {
                 this.gridControl1.DataSource = PointsDt;
             }
         }
         else
         {
             return;
         }
     }
 }
Beispiel #10
0
        public void UpdateFeature(string featureClasses,
                                  List <FeatureValues> featureValues,
                                  double[] Coordinates,
                                  string sID,
                                  string sFieldName)
        {
            bool          bError = false;
            IFeatureClass fc     = GetFeatureClass(featureClasses);

            IWorkspaceEdit ipWksEdit = ((IDataset)fc).Workspace as IWorkspaceEdit;

            if (null != ipWksEdit)
            {
                try
                {
                    ipWksEdit.StartEditing(true);
                    ipWksEdit.StartEditOperation();
                }
                catch
                {
                    bError = true;
                    return;
                }
            }

            // the meat to update the feature
            foreach (FeatureValues featureValue in featureValues)
            {
                featureValue.Index = fc.Fields.FindField(featureValue.Name);
            }

            IQueryFilter pQueryFilter = (IQueryFilter)_serverContext.CreateObject("esriGeoDatabase.QueryFilter");

            pQueryFilter.WhereClause = sFieldName + "='" + sID + "'";
            IFeatureCursor cursor = fc.Update(pQueryFilter, false);
            IFeature       pFeature;

            while ((pFeature = cursor.NextFeature()) != null)
            {
                if (Coordinates != null && Coordinates.Length == 2)
                {
                    double[] points = Coordinates;
                    ESRI.ArcGIS.Geometry.IPoint pt = (ESRI.ArcGIS.Geometry.IPoint)_serverContext.CreateObject("esriGeometry.Point");
                    pt.PutCoords(points[0], points[1]);

                    pFeature.Shape = pt as ESRI.ArcGIS.Geometry.IPoint;
                }
                else if (Coordinates != null && Coordinates.Length > 2)
                {
                    ESRI.ArcGIS.Geometry.IPointCollection pPointCol = _serverContext.CreateObject("esriGeometry.Polygon") as ESRI.ArcGIS.Geometry.IPointCollection;
                    for (int i = 0; i < Coordinates.Length; i += 2)
                    {
                        ESRI.ArcGIS.Geometry.IPoint pt = (ESRI.ArcGIS.Geometry.IPoint)_serverContext.CreateObject("esriGeometry.Point");
                        pt.PutCoords(Coordinates[i], Coordinates[i + 1]);
                        pPointCol.AddPoints(1, ref pt);
                    }

                    pFeature.Shape = pPointCol as ESRI.ArcGIS.Geometry.IPolygon;
                }
                break;
            }

            pFeature.Store();

            if (null != ipWksEdit)
            {
                try
                {
                    if (bError)
                    {
                        //rollback
                        ipWksEdit.UndoEditOperation();
                        ipWksEdit.StopEditing(false);
                    }
                    else
                    {
                        //commit
                        ipWksEdit.StopEditOperation();
                        ipWksEdit.StopEditing(true);
                    }
                }
                catch
                {
                }
                finally
                {
                    Marshal.ReleaseComObject(ipWksEdit);
                    ipWksEdit = null;
                }
            }
        }
Beispiel #11
0
        /// <summary>
        /// Returns all features from a given feature class that have a vertex or endpoint coincident with a given point
        /// </summary>
        /// <param name="point">IPoint to use as the spatial filter</param>
        /// <param name="searchFtClass">IFeatureClass to search in</param>
        /// <param name="linearEndpointsOnly">Flag to use only the endpoints of a line instead of all vertices</param>
        /// <param name="buffer">Search geometry buffer in map units</param>
        /// <returns>List of IFeature</returns>
        public static List <ESRI.ArcGIS.Geodatabase.IFeature> GetFeaturesWithCoincidentVertices(ESRI.ArcGIS.Geometry.IPoint point, ESRI.ArcGIS.Geodatabase.IFeatureClass searchFtClass, bool linearEndpointsOnly, double buffer)
        {
            List <ESRI.ArcGIS.Geodatabase.IFeature> result = new List <ESRI.ArcGIS.Geodatabase.IFeature>();

            using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser())
            {
                ESRI.ArcGIS.Geodatabase.ISpatialFilter filter = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();
                releaser.ManageLifetime(filter);

                ESRI.ArcGIS.Geometry.IEnvelope filterGeometry = point.Envelope;
                if (0 < buffer)
                {
                    filterGeometry.Expand(buffer, buffer, false);
                }

                filter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelIntersects;
                filter.Geometry   = filterGeometry;

                ESRI.ArcGIS.Geodatabase.IFeatureCursor fts = searchFtClass.Search(filter, false);
                releaser.ManageLifetime(fts);

                ESRI.ArcGIS.Geodatabase.IFeature ft = fts.NextFeature();
                while (null != ft)
                {
                    if (searchFtClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint)
                    {
                        result.Add(ft);
                    }
                    else if (searchFtClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline && linearEndpointsOnly)
                    {
                        ESRI.ArcGIS.Geometry.IPolyline           polyline  = (ESRI.ArcGIS.Geometry.IPolyline)ft.Shape;
                        ESRI.ArcGIS.Geometry.IRelationalOperator fromPoint = polyline.FromPoint as ESRI.ArcGIS.Geometry.IRelationalOperator;
                        ESRI.ArcGIS.Geometry.IRelationalOperator toPoint   = polyline.ToPoint as ESRI.ArcGIS.Geometry.IRelationalOperator;

                        if (fromPoint.Equals(point) || toPoint.Equals(point))
                        {
                            result.Add(ft);
                        }
                    }
                    else
                    {
                        ESRI.ArcGIS.Geometry.IPointCollection pointCollection = ft.Shape as ESRI.ArcGIS.Geometry.IPointCollection;
                        if (null != pointCollection)
                        {
                            for (int i = 0; i < pointCollection.PointCount; i++)
                            {
                                ESRI.ArcGIS.Geometry.IRelationalOperator testPoint = pointCollection.get_Point(i) as ESRI.ArcGIS.Geometry.IRelationalOperator;
                                if (testPoint.Equals(point))
                                {
                                    result.Add(ft);
                                    break;
                                }
                            }
                        }
                    }

                    ft = fts.NextFeature();
                }
            }

            return(result);
        }
Beispiel #12
0
 /// <summary>
 /// Returns all features from a given feature class that have a vertex or endpoint coincident with a given point
 /// </summary>
 /// <param name="point">IPoint to use as the spatial filter</param>
 /// <param name="searchFtClass">IFeatureClass to search in</param>
 /// <param name="linearEndpointsOnly">Flag to use only the endpoints of a line instead of all vertices</param>
 /// <param name="buffer">Search geometry buffer in map units</param>
 /// <returns>List of IFeature</returns>
 public static List <ESRI.ArcGIS.Geodatabase.IFeature> GetLinearsWithCoincidentEndpoints(ESRI.ArcGIS.Geometry.IPoint point, ESRI.ArcGIS.Geodatabase.IFeatureClass searchFtClass, double buffer)
 {
     return(GetFeaturesWithCoincidentVertices(point, searchFtClass, true, buffer));
 }
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            // TODO:  Add PolygonsDifference.OnMouseDown implementation
            if (Button != (int)Keys.LButton)
            {
                return;
            }
            ILayer layer = m_engineEditor.TargetLayer;

            if (layer == null)
            {
                return;
            }
            m_activeView = m_hookHelper.ActiveView;
            m_map        = m_hookHelper.FocusMap;
            ESRI.ArcGIS.Geometry.IPoint pPoint = m_activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
            ISelectionEnvironment       pSelectionEnvironment = new SelectionEnvironmentClass(); pSelectionEnvironment.PointSelectionMethod = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelWithin;

            m_map.SelectByShape(pPoint as ESRI.ArcGIS.Geometry.IGeometry, pSelectionEnvironment, false);
            //if (m_map.SelectionCount != 2)
            //{
            //    MessageBox.Show("选择的多边形个数应该为2!!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    return;
            //}
            m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, m_activeView.Extent);
            ESRI.ArcGIS.Geodatabase.IEnumFeature pEnumFeature  = m_map.FeatureSelection as ESRI.ArcGIS.Geodatabase.IEnumFeature;
            ESRI.ArcGIS.Geodatabase.IFeature     firstFeature  = pEnumFeature.Next();
            ESRI.ArcGIS.Geodatabase.IFeature     secondFeature = pEnumFeature.Next();
            bool firstPolygonIsLarge = false;

            ESRI.ArcGIS.Geometry.IGeometry            pGeometry            = null;
            ESRI.ArcGIS.Geometry.IRelationalOperator  pRelOp1              = firstFeature.Shape as ESRI.ArcGIS.Geometry.IRelationalOperator;
            ESRI.ArcGIS.Geometry.IRelationalOperator  pRelOp2              = secondFeature.Shape as ESRI.ArcGIS.Geometry.IRelationalOperator;
            ESRI.ArcGIS.Geometry.ITopologicalOperator pTopologicalOperator = null;
            if (pRelOp1.Contains(secondFeature.Shape))
            {
                pTopologicalOperator = firstFeature.Shape as ESRI.ArcGIS.Geometry.ITopologicalOperator;
                pGeometry            = pTopologicalOperator.Difference(secondFeature.Shape);
                firstPolygonIsLarge  = true;
            }
            else if (pRelOp2.Contains(firstFeature.Shape))
            {
                pTopologicalOperator = secondFeature.Shape as ESRI.ArcGIS.Geometry.ITopologicalOperator;
                pGeometry            = pTopologicalOperator.Difference(firstFeature.Shape);
                firstPolygonIsLarge  = false;
            }
            else
            {
                return;
            }
            bool         deleteInteriorPolygon = false;
            DialogResult pDialogResult         = MessageBox.Show("是否要删除内多边形?", "操作提示", MessageBoxButtons.YesNo);

            if (pDialogResult == DialogResult.Yes)
            {
                deleteInteriorPolygon = true;
            }
            ESRI.ArcGIS.Geodatabase.IFeatureClass  featureClass  = firstFeature.Class as ESRI.ArcGIS.Geodatabase.IFeatureClass;
            ESRI.ArcGIS.Geodatabase.IDataset       dataset       = featureClass as ESRI.ArcGIS.Geodatabase.IDataset;
            ESRI.ArcGIS.Geodatabase.IWorkspaceEdit workspaceEdit = dataset.Workspace as ESRI.ArcGIS.Geodatabase.IWorkspaceEdit;
            if (!(workspaceEdit.IsBeingEdited()))
            {
                return;
            }
            workspaceEdit.StartEditOperation();
            if (firstPolygonIsLarge)
            {
                firstFeature.Shape = pGeometry;
                firstFeature.Store();
                if (deleteInteriorPolygon)
                {
                    secondFeature.Delete();
                }
            }
            else
            {
                secondFeature.Shape = pGeometry;
                secondFeature.Store();
                if (deleteInteriorPolygon)
                {
                    firstFeature.Delete();
                }
            }
            workspaceEdit.StopEditOperation();
            m_map.ClearSelection();
            m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_activeView.Extent);
            m_Mapcontrol.CurrentTool = null;
        }
        public BetterMarker(ESRI.ArcGIS.Geometry.IPoint mapPoint, string Text, double MapScale)
        {
            _Callout = new BalloonCallout();

            _Callout.AnchorPoint = mapPoint;

            ITextElement         pTextElement = new TextElementClass();
            IElement             pElement;
            IFillSymbol          pFill        = new SimpleFillSymbolClass();
            ILineSymbol          pLine        = new SimpleLineSymbolClass();
            IFormattedTextSymbol pLabelSymbol = new TextSymbolClass();

            IRgbColor c = new RgbColorClass();

            c.Red   = 0;
            c.Green = 0;
            c.Blue  = 0;

            IRgbColor d = new RgbColorClass();

            d.Red   = 255;
            d.Green = 255;
            d.Blue  = 255;

            IRgbColor e = new RgbColorClass();

            e.Red   = 205;
            e.Green = 192;
            e.Blue  = 176;

            pLine.Color   = c;
            pFill.Color   = d;
            pFill.Outline = pLine;

            this._Callout.Symbol = pFill;
            this._Callout.Style  = esriBalloonCalloutStyle.esriBCSRoundedRectangle;


            pLabelSymbol.Background    = this._Callout as ITextBackground;
            pLabelSymbol.Size          = 10.5d;
            pLabelSymbol.ShadowColor   = e;
            pLabelSymbol.ShadowXOffset = 1.0d;
            pLabelSymbol.ShadowYOffset = 1.0d;

            pTextElement.Text   = Text;
            pTextElement.Symbol = pLabelSymbol as ITextSymbol;

            pElement = pTextElement as IElement;
            double delta = (.1 * MapScale) / 2;

            //switch (mMap.MapScale)
            //{
            //    case
            //}

            ESRI.ArcGIS.Geometry.IPoint p1 = new ESRI.ArcGIS.Geometry.PointClass();
            p1.X = mapPoint.X + delta;
            p1.Y = mapPoint.Y + delta;


            pElement.Geometry = p1;

            this._Element = pElement;
        }