Exemplo n.º 1
0
        public ESRI.ArcGIS.Geometry.IEnvelope DrawRectangle(ESRI.ArcGIS.Carto.IActiveView activeView)
        {
            if (activeView == null)
            {
                return(null);
            }
            else
            {
                ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = activeView.ScreenDisplay;

                // Constant
                screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit Cast
                //ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
                //rgbColor.Red = 255;

                //ESRI.ArcGIS.Display.IColor color = rgbColor; // Implicit Cast
                ESRI.ArcGIS.Display.ISimpleFillSymbol simpleFillSymbol = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
                //simpleFillSymbol.Color = color;
                simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSHollow;

                ESRI.ArcGIS.Display.ISymbol     symbol     = simpleFillSymbol as ESRI.ArcGIS.Display.ISymbol; // Dynamic Cast
                ESRI.ArcGIS.Display.IRubberBand rubberBand = new ESRI.ArcGIS.Display.RubberEnvelopeClass();
                ESRI.ArcGIS.Geometry.IGeometry  geometry   = rubberBand.TrackNew(screenDisplay, symbol);
                screenDisplay.SetSymbol(symbol);
                ESRI.ArcGIS.Geometry.IEnvelope pEnvelope = geometry as ESRI.ArcGIS.Geometry.IEnvelope;
                screenDisplay.DrawRectangle(pEnvelope); // Dynamic Cast
                screenDisplay.FinishDrawing();

                return(pEnvelope);
            }
        }
Exemplo n.º 2
0
        ///<summary>Flash geometry on the display. The geometry type could be polygon, polyline, point, or multipoint.</summary>
        ///
        ///<param name="geometry"> An IGeometry interface</param>
        ///<param name="color">An IRgbColor interface</param>
        ///<param name="display">An IDisplay interface</param>
        ///<param name="delay">A System.Int32 that is the time im milliseconds to wait.</param>
        ///
        ///<remarks></remarks>
        public void FlashGeometry(ESRI.ArcGIS.Geometry.IGeometry geometry, ESRI.ArcGIS.Display.IRgbColor color, ESRI.ArcGIS.Display.IDisplay display, System.Int32 delay)
        {
            if (geometry == null || color == null || display == null)
            {
                return;
            }

            display.StartDrawing(display.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit Cast


            switch (geometry.GeometryType)
            {
            case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
            {
                //Set the flash geometry's symbol.
                ESRI.ArcGIS.Display.ISimpleMarkerSymbol simpleMarkerSymbol = new ESRI.ArcGIS.Display.SimpleMarkerSymbol();
                simpleMarkerSymbol.Style = ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle;
                simpleMarkerSymbol.Size  = 12;
                simpleMarkerSymbol.Color = color;
                ESRI.ArcGIS.Display.ISymbol symbol = simpleMarkerSymbol as ESRI.ArcGIS.Display.ISymbol;         // Dynamic Cast
                symbol.ROP2 = ESRI.ArcGIS.Display.esriRasterOpCode.esriROPNotXOrPen;

                //Flash the input point geometry.
                display.SetSymbol(symbol);
                display.DrawPoint(geometry);
                System.Threading.Thread.Sleep(delay);
                display.DrawPoint(geometry);
                break;
            }
            }
            display.FinishDrawing();
        }
Exemplo n.º 3
0
 private void frmAreaStatistics_FormClosing(object sender, FormClosingEventArgs e)
 {
     this.ucArea1.CurGeometry = null;
     this.ucArea1.boolok      = true;
     ///ZQ  2011 1129  ÒƳýÌí¼ÓµÄʼþ
     SysCommon.ScreenDraw.list.Remove(this.ucArea1.UcAreaAfterDraw);
     (m_pMap.ActiveView).PartialRefresh(esriViewDrawPhase.esriViewForeground, null, null);
 }
Exemplo n.º 4
0
        public void CreateLineFeature(IFeatureClass featureClass, IFeature sourceF, ESRI.ArcGIS.Geometry.IGeometry shape, string value1, string value2, string value3, string value4, string value5)
        {
            try
            {
                double angle = Convert.ToDouble(ConfigUtil.GetConfigValue("Angle"));
                // Build the feature.
                ESRI.ArcGIS.Geometry.IPoint pOriginPoint = shape as ESRI.ArcGIS.Geometry.IPoint;
                double dbPi = 4 * Math.Atan(1);
                ESRI.ArcGIS.Geometry.IPoint pEndPoint = new ESRI.ArcGIS.Geometry.PointClass();
                //MessageBox.Show(pOriginPoint.X.ToString() + pOriginPoint.Y.ToString());
                pEndPoint.X = pOriginPoint.X - (Math.Cos(((angle) * (dbPi / 180))) * 6);
                pEndPoint.Y = pOriginPoint.Y - (Math.Sin(((angle) * (dbPi / 180))) * 6);


                ESRI.ArcGIS.Geometry.IPointCollection pCollection = new ESRI.ArcGIS.Geometry.PolylineClass();
                pCollection.AddPoint(pOriginPoint);
                pCollection.AddPoint(pEndPoint);

                IFeature feature = featureClass.CreateFeature();
                feature.Shape = pCollection as ESRI.ArcGIS.Geometry.IPolyline;

                // Update the value on a string field that indicates who installed the feature.
                int contractorFieldIndex = featureClass.FindField("DIAMETER");
                feature.set_Value(contractorFieldIndex, Convert.ToInt16(value2));

                int diaFieldIndex = featureClass.FindField("OWNEDBY");
                feature.set_Value(diaFieldIndex, value4);

                int matFieldIndex = featureClass.FindField("SERVICELENGTHBAND");
                feature.set_Value(matFieldIndex, value3);


                int ownedbyFieldIndex = featureClass.FindField("SERVICESIDE");
                feature.set_Value(ownedbyFieldIndex, value1);

                int JBPFieldIndex = featureClass.FindField("JPNUM");
                feature.set_Value(featureClass.FindField("LENGTH"), 6);
                feature.set_Value(JBPFieldIndex, value5);
                feature.set_Value(featureClass.FindField("LOCATION"), sourceF.get_Value(sourceF.Fields.FindField(ConfigUtil.GetConfigValue("LOCATION"))));
                feature.set_Value(featureClass.FindField("LOCATIONDESCRIPTION"), ConfigUtil.GetConfigValue("LOCATIONDESCRIPTION"));
                feature.set_Value(featureClass.FindField("FACILITYID"), GenerateID(ConfigUtil.GetConfigValue("GenIDNWL")));


                // Commit the new feature to the geodatabase.
                feature.Store();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message + e.StackTrace);
            }
        }
Exemplo n.º 5
0
        ///<summary>Draw a specified graphic on the map using the supplied colors.</summary>
        ///
        ///<param name="map">An IMap interface.</param>
        ///<param name="geometry">An IGeometry interface. It can be of the geometry type: esriGeometryPoint, esriGeometryPolyline, or esriGeometryPolygon.</param>
        ///<param name="rgbColor">An IRgbColor interface. The color to draw the geometry.</param>
        ///<param name="outlineRgbColor">An IRgbColor interface. For those geometry's with an outline it will be this color.</param>
        ///
        ///<remarks>Calling this function will not automatically make the graphics appear in the map area. Refresh the map area after after calling this function with Methods like IActiveView.Refresh or IActiveView.PartialRefresh.</remarks>
        public void AddGraphicToMap(ESRI.ArcGIS.Carto.IMap map, ESRI.ArcGIS.Geometry.IGeometry geometry, ESRI.ArcGIS.Display.IRgbColor rgbColor, ESRI.ArcGIS.Display.IRgbColor outlineRgbColor)
        {
            ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = (ESRI.ArcGIS.Carto.IGraphicsContainer)map; // Explicit Cast
            ESRI.ArcGIS.Carto.IElement           element           = null;
            if ((geometry.GeometryType) == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint)
            {
                // Marker symbols
                ESRI.ArcGIS.Display.ISimpleMarkerSymbol simpleMarkerSymbol = new ESRI.ArcGIS.Display.SimpleMarkerSymbol();
                simpleMarkerSymbol.Color        = rgbColor;
                simpleMarkerSymbol.Outline      = true;
                simpleMarkerSymbol.OutlineColor = outlineRgbColor;
                simpleMarkerSymbol.Size         = 15;
                simpleMarkerSymbol.Style        = ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle;

                ESRI.ArcGIS.Carto.IMarkerElement markerElement = new ESRI.ArcGIS.Carto.MarkerElement() as ESRI.ArcGIS.Carto.IMarkerElement;
                markerElement.Symbol = simpleMarkerSymbol;
                element = (ESRI.ArcGIS.Carto.IElement)markerElement; // Explicit Cast
            }
            else if ((geometry.GeometryType) == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline)
            {
                //  Line elements
                ESRI.ArcGIS.Display.ISimpleLineSymbol simpleLineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbol();
                simpleLineSymbol.Color = rgbColor;
                simpleLineSymbol.Style = ESRI.ArcGIS.Display.esriSimpleLineStyle.esriSLSSolid;
                simpleLineSymbol.Width = 5;

                ESRI.ArcGIS.Carto.ILineElement lineElement = new ESRI.ArcGIS.Carto.LineElement() as ESRI.ArcGIS.Carto.ILineElement;
                lineElement.Symbol = simpleLineSymbol;
                element            = (ESRI.ArcGIS.Carto.IElement)lineElement; // Explicit Cast
            }
            else if ((geometry.GeometryType) == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon)
            {
                // Polygon elements
                ESRI.ArcGIS.Display.ISimpleFillSymbol simpleFillSymbol = new ESRI.ArcGIS.Display.SimpleFillSymbol();
                simpleFillSymbol.Color = rgbColor;
                simpleFillSymbol.Style = ESRI.ArcGIS.Display.esriSimpleFillStyle.esriSFSForwardDiagonal;
                ESRI.ArcGIS.Carto.IFillShapeElement fillShapeElement = new ESRI.ArcGIS.Carto.PolygonElement() as ESRI.ArcGIS.Carto.IFillShapeElement;
                fillShapeElement.Symbol = simpleFillSymbol;
                element = (ESRI.ArcGIS.Carto.IElement)fillShapeElement; // Explicit Cast
            }
            if (!(element == null))
            {
                element.Geometry = geometry;
                graphicsContainer.AddElement(element, 0);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Determines the coincident ends of the given edges and returns the junction's shape as IPoint
        /// </summary>
        /// <param name="featureA">One edge feature</param>
        /// <param name="featureB">Another edge feature</param>
        /// <returns>IPoint</returns>
        public static ESRI.ArcGIS.Geometry.IPoint GetJunctionPoint(ESRI.ArcGIS.Geodatabase.IEdgeFeature featureA, ESRI.ArcGIS.Geodatabase.IEdgeFeature featureB)
        {
            #region Validation

            if (null == featureA)
            {
                throw new ArgumentNullException("featureA");
            }

            if (null == featureB)
            {
                throw new ArgumentNullException("featureB");
            }

            #endregion

            int aFromEid = featureA.FromJunctionEID;
            int aToEid   = featureA.ToJunctionEID;
            int bFromEid = featureB.FromJunctionEID;
            int bToEid   = featureB.ToJunctionEID;

            ESRI.ArcGIS.Geodatabase.IJunctionFeature junctionFt = null;
            if (aFromEid == bFromEid || aFromEid == bToEid)
            {
                junctionFt = featureA.FromJunctionFeature;
            }
            else if (aToEid == bFromEid || aToEid == bToEid)
            {
                junctionFt = featureA.ToJunctionFeature;
            }

            if (null == junctionFt)
            {
                throw new Exception("Unable to find junction feature for provided edges.");
            }

            ESRI.ArcGIS.Geometry.IGeometry geometry = ((ESRI.ArcGIS.Geodatabase.IFeature)junctionFt).ShapeCopy;
            if (geometry.GeometryType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint)
            {
                throw new Exception("Junction feature's geometry is not a point.");
            }

            return(geometry as ESRI.ArcGIS.Geometry.IPoint);
        }
Exemplo n.º 7
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            if (m_hookHelper.Hook == null)
            {
                return;
            }
            IMapControl2 pMapCtl = m_hookHelper.Hook as IMapControl2;

            ESRI.ArcGIS.Geometry.IGeometry pGeometry = pMapCtl.TrackRectangle();
            if (pGeometry == null)
            {
                return;
            }

            ESRI.ArcGIS.Carto.IMap pMap = m_hookHelper.FocusMap;
            frmExport frm = new frmExport(pMap, pGeometry);

            frm.ShowDialog();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Occurs when this tool is clicked
        /// </summary>
        public override void OnClick()
        {
            if (m_hookHelper.Hook == null)
            {
                return;
            }
            IMapControl2 pMapCtl = m_hookHelper.Hook as IMapControl2;

            ESRI.ArcGIS.Geometry.IGeometry pGeometry = pMapCtl.Extent;
            if (pGeometry == null)
            {
                return;
            }

            ESRI.ArcGIS.Carto.IMap pMap = m_hookHelper.FocusMap;
            frmExport frm = new frmExport(pMap, pGeometry);

            frm.ShowDialog();
        }
Exemplo n.º 9
0
 public void AddErr(List <ErrorEntity> pErrEntity, ErrType pTy, string idname)
 {
     try
     {
         if (_table != null)
         {
             if ((pErrEntity == null) || (pErrEntity.Count < 1))
             {
                 this.ClearTable(idname);
             }
             else if (this.ClearTable(idname))
             {
                 string str = ((int)pErrEntity[0].ErrType).ToString();
                 foreach (ErrorEntity entity in pErrEntity)
                 {
                     ESRI.ArcGIS.Geometry.IGeometry geo = entity.ErrGeo as ESRI.ArcGIS.Geometry.IGeometry;
                     DataRow row = _table.NewRow();
                     row["ID"]        = entity.idname;
                     row["FeatureID"] = entity.FeatureID;
                     row["ErrDes"]    = entity.ErrMsg;
                     row["ErrPos"]    = entity.ErrPos;
                     row["ErrType"]   = str;
                     if (pTy == ErrType.SelfIntersect)
                     {
                         row["Geometry"] = geo.SpatialReference;
                     }
                     else
                     {
                         row["Geometry"] = geo;
                     }
                     _table.Rows.Add(row);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         LogHelper.WriteLog(typeof(ErrorTable), ex);
         Console.WriteLine("MyException Throw:" + ex.Message);
     }
 }
Exemplo n.º 10
0
 public void SelectByShape(ESRI.ArcGIS.Geometry.IGeometry Shape, ISelectionEnvironment env, bool justOne)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 11
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处理异常)****/
        }
Exemplo n.º 12
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)
            {
            }
        }
Exemplo n.º 13
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;
         }
     }
 }
Exemplo n.º 14
0
        public void CreateFeature(IFeatureClass featureClass, IFeature sourceF, ESRI.ArcGIS.Geometry.IGeometry shape, string value1, string value2, string value3, string value4, string value5)
        {
            // Ensure the feature class contains points.
            if (featureClass.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint)
            {
                return;
            }
            IFeature feature = featureClass.CreateFeature();

            feature.Shape = shape;

            if (featureClass.AliasName == ConfigUtil.GetConfigValue("ServiceWorksPoint"))
            {
                // Build the feature.

                // Update the value on a string field that indicates who installed the feature.
                int contractorFieldIndex = featureClass.FindField("SERVICEWORKSTYPE");
                feature.set_Value(contractorFieldIndex, value1);

                int diaFieldIndex = featureClass.FindField("PIPEDIAMETER");
                feature.set_Value(diaFieldIndex, Convert.ToInt16(value2));

                int matFieldIndex = featureClass.FindField("MATERIAL");
                feature.set_Value(matFieldIndex, value3);


                int ownedbyFieldIndex = featureClass.FindField("OWNEDBY");
                feature.set_Value(ownedbyFieldIndex, value4);

                int JBPFieldIndex = featureClass.FindField("JPNUM");
                feature.set_Value(JBPFieldIndex, value5);

                feature.set_Value(featureClass.FindField("LOCATION"), sourceF.get_Value(sourceF.Fields.FindField(ConfigUtil.GetConfigValue("LOCATION"))));
                feature.set_Value(featureClass.FindField("LOCATIONDESCRIPTION"), ConfigUtil.GetConfigValue("LOCATIONDESCRIPTION"));
                feature.set_Value(featureClass.FindField("FACILITYID"), GenerateID(ConfigUtil.GetConfigValue("GenIDNWM")));
            }
            else if (featureClass.AliasName == ConfigUtil.GetConfigValue("CustomerMeter"))
            {
                int contractorFieldIndex = featureClass.FindField("METERFITTYPE");
                feature.set_Value(contractorFieldIndex, value1);

                int diaFieldIndex = featureClass.FindField("METERTYPE");
                feature.set_Value(diaFieldIndex, value2);

                int matFieldIndex = featureClass.FindField("METERSIZE");
                feature.set_Value(matFieldIndex, value3);


                int ownedbyFieldIndex = featureClass.FindField("CUSTOMERTYPE");
                feature.set_Value(ownedbyFieldIndex, Convert.ToInt16(value4));

                int JBPFieldIndex = featureClass.FindField("JPNUM");
                feature.set_Value(JBPFieldIndex, value5);
                feature.set_Value(featureClass.FindField("LOCATION"), sourceF.get_Value(sourceF.Fields.FindField(ConfigUtil.GetConfigValue("LOCATION"))));
                feature.set_Value(featureClass.FindField("LOCATIONDESCRIPTION"), ConfigUtil.GetConfigValue("LOCATIONDESCRIPTION"));
                feature.set_Value(featureClass.FindField("FACILITYID"), GenerateID(ConfigUtil.GetConfigValue("GenIDNCM")));
            }


            // Commit the new feature to the geodatabase.
            feature.Store();
        }
Exemplo n.º 15
0
        private void LampAnalysis()
        {
            try
            {
                if (m_Model == null)
                {
                    MessageBox.Show("请先安放信号灯!");
                    return;
                }

                this.txtResult.Clear();
                Application.DoEvents();

                SendMessage("正在获取路口信息...");

                string lyr   = ConfigurationManager.AppSettings["CrossLayer"];
                int    lyrID = m_Hook.ProjectTree.FindItem(lyr);
                if (lyrID < 0)
                {
                    MessageBox.Show("您的配置有问题或者路口图层没有加载");
                    return;
                }

                ILayer61 teLayer = m_Hook.ProjectTree.GetLayer(lyrID);
                if (teLayer == null)
                {
                    return;
                }
                //IFeature61 tefCurrent = teLayer.FeatureGroups.Point[0] as IFeature61;

                // 严格来说要根据所点的位置来确定是哪个路口
                // 取第一个作为路口信息

                // 先直接从数据库中读取,模拟计算
                string   strOld = teLayer.DataSourceInfo.ConnectionString;
                string[] strs   = strOld.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                strOld = strs[0];
                strOld = strOld.Substring(strOld.IndexOf("=") + 1);
                string strFolder = System.IO.Path.GetDirectoryName(strOld);
                string strName   = System.IO.Path.GetFileNameWithoutExtension(strOld);

                IWorkspaceFactory wsf    = new ShapefileWorkspaceFactoryClass();
                IWorkspace        wsShp  = wsf.OpenFromFile(strFolder, 0);
                IFeatureClass     fClass = (wsShp as IFeatureWorkspace).OpenFeatureClass(strName);

                IPosition61 position = m_Model.Position;
                ESRI.ArcGIS.Geometry.IPoint pModel = new ESRI.ArcGIS.Geometry.PointClass();
                pModel.SpatialReference = (fClass as IGeoDataset).SpatialReference;
                pModel.PutCoords(position.X, position.Y);

                ESRI.ArcGIS.Geometry.ITopologicalOperator topoOperator = pModel as ESRI.ArcGIS.Geometry.ITopologicalOperator;
                ESRI.ArcGIS.Geometry.IGeometry            geoModel     = topoOperator.Buffer(50);

                ISpatialFilter qFilter = new SpatialFilterClass();
                qFilter.Geometry   = geoModel;
                qFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                IFeatureCursor fCursor = fClass.Search(qFilter, false);
                IFeature       fCross  = fCursor.NextFeature();
                if (fCross == null)
                {
                    SendMessage("在当前位置的50米范围内没有找到路口信息。");
                    SendMessage("若您的路口信息是全面的,则您所安放的位置偏离了路口过多,理论上不适合安放信号灯!");
                    SendMessage("分析结束");
                    return;
                }

                double lampHeight       = (double)spinEdit1.Value;
                double carHeight        = (double)spinEdit2.Value;
                double setHeight        = (double)spinEdit3.Value;
                double carLength        = (double)spinEdit4.Value;
                double lampMustDistance = (double)spinEdit5.Value;
                double roadWidth        = 30;

                roadWidth = Convert.ToDouble(fCross.get_Value(fClass.FindField("NorthWidth")));

                System.Threading.Thread.Sleep(1000);
                SendMessage("正在计算有大车情况下是否能在规定的最小必须可见距离内看到信号灯...");
                System.Threading.Thread.Sleep(1000);
                double lampMustHeight = (carHeight - setHeight) * lampMustDistance / (carLength + roadWidth) + setHeight;
                if (lampHeight < lampMustHeight)
                {
                    SendMessage(string.Format("  信号灯在有大车情况下不能在规定的最小距离内看到信号灯,必须在路对面增加辅助信号灯。"));
                    SendMessage("当前位置不合适安放信号灯或必须添加辅助信号灯!");
                    SendMessage("分析结束。");
                    return;
                }

                SendMessage("正在计算是否会因为建筑物及绿化带等引起信号灯盲区...");

                //int tempGroup = this.m_Hook.ProjectTree.FindItem(m_TempGroup);
                //if (tempGroup < 0)
                //{
                //    tempGroup = this.m_Hook.ProjectTree.CreateGroup(m_TempGroup);
                //}

                //IPosition61 position = m_Model.Position;
                //m_Hook.CoordServices.MoveCoordEx(ref position, 0, 0, lampHeight);
                //int analysisGroup = m_Hook.Analysis.CreateViewshed(position, 360, 1, roadWidth + lampMustDistance, setHeight, null, null, tempGroup, m_TempAnalysisName);
                //int invisibleItem = m_Hook.ProjectTree.FindItem(string.Format(@"{0}\{1}\Invisible Area",m_TempGroup,m_TempAnalysisName));
                //object obj = m_Hook.ProjectTree.GetObject(invisibleItem);

                System.Threading.Thread.Sleep(5000);
                if (Convert.ToInt32(fCross.get_Value(fClass.FindField("Flag"))) > 0)
                {
                    SendMessage("   由于建筑物及绿化带等将引起信号灯盲区,必须在路对面增加辅助信号灯.");
                    SendMessage("当前位置不合适安放信号灯或必须添加辅助信号灯!");
                    SendMessage("分析结束。");
                    return;
                }

                SendMessage("当前位置安放信号灯后不需要添加辅助信号灯!");
                SendMessage("分析结束。");
            }
            catch
            {
                SendMessage("分析过程出错了,分析结束");
            }
        }
        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;
        }
Exemplo n.º 17
0
 public void InitFrm()
 {
     this.ucArea1.CurGeometry = m_pGeometry;
     this.ucArea1.CurMap      = m_pMap;
     this.ucArea1.InitLayers();
 }