Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            string      path   = textBox5.Text;
            string      s1     = textBox1.Text;
            string      s2     = textBox2.Text;
            string      s3     = textBox3.Text;
            string      s4     = textBox4.Text;
            string      mes    = String.Empty;
            IPosition61 dztpos = null;

            TECoClass      = new TerraExplorerClass();
            ITerraExplorer = (ITerraExplorer5)TECoClass;
            IInfoTree      = (IInformationTree5)TECoClass;
            IObjectManager = (IObjectManager5)TECoClass;
            try
            {
                double           dxcoord  = double.Parse(s1);
                double           dycoord  = double.Parse(s2);
                double           altitude = double.Parse(s3);
                AltitudeTypeCode ealit    = AltitudeTypeCode.ATC_TERRAIN_RELATIVE;
                dztpos = MainForm.sgworld.Creator.CreatePosition(dxcoord, dycoord, altitude, ealit, 0, 90, 100.0, 1000);
                dzt    = MainForm.sgworld.Creator.CreateModel(dztpos, path, 1, ModelTypeCode.MT_NORMAL, 0, s4);
            }
            catch (Exception ex)
            {
                mes = String.Format("CreateLabelButton_Click Exception :{0}", ex.Message);
                Log4NetHelper.WriteLog(typeof(AddgeologicbodyForm), ex);
                MessageBox.Show(mes);
            }
        }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string              s1    = textBox1.Text;
            string              s2    = textBox2.Text;
            string              s3    = textBox3.Text;
            string              s4    = textBox4.Text;
            string              mes   = String.Empty;
            IPosition61         cpos  = null;
            ITerrain3DRegBase61 drill = null;

            try
            {
                double           dxcoord  = double.Parse(s1);
                double           dycoord  = double.Parse(s2);
                double           altitude = double.Parse(s3);
                AltitudeTypeCode ealit    = AltitudeTypeCode.ATC_TERRAIN_RELATIVE;
                cpos = MainForm.sgworld.Creator.CreatePosition(dxcoord, dycoord, altitude, ealit, -90, -30, 180, 1000);
                {
                    drill = MainForm.sgworld.Creator.CreateCone(cpos, 10, 50, nrgb, nrgb, -1, 0, s4);
                    MainForm.sgworld.Navigate.FlyTo(cpos, ActionCode.AC_FLYTO);
                }
            }
            catch (Exception ex)
            {
                mes = String.Format("CreateLabelButton_Click Exception :{0}", ex.Message);
                Log4NetHelper.WriteLog(typeof(AdddrillForm), ex);
                MessageBox.Show(mes);
            }
        }
Exemple #3
0
 //左键单击
 bool sgworld_OnLButtonDown(int Flags, int X, int Y)
 {
     try
     {
         if (pbhander == "modify")
         {
             LClickCount++;
             //点击三个点以前画线,三个点以后画面
             double longitude, latitude, height;
             (this.TerraExplorer as IRender5).ScreenToTerrain(X, Y, out longitude, out latitude, out height);
             IPosition61 pIPosition = this.SgWorld.Navigate.GetPosition(AltitudeTypeCode.ATC_TERRAIN_RELATIVE);
             if (LClickCount < 3)
             {
                 this.pITerrainPolyline.AddVertex(longitude, height, latitude, 0);
                 ListVerticsArray.Add(longitude);
                 ListVerticsArray.Add(latitude);
                 ListVerticsArray.Add(pIPosition.Distance);
             }
             else
             {
                 if (LClickCount == 3)
                 {
                     ListVerticsArray.Add(longitude);
                     ListVerticsArray.Add(latitude);
                     ListVerticsArray.Add(pIPosition.Distance);
                     double[] tripletArray = new double[ListVerticsArray.Count];
                     ListVerticsArray.CopyTo(tripletArray, 0);
                     IColor61         LineColor         = this.SgWorld.Creator.CreateColor(Color.Red.R, Color.Red.G, Color.Red.B, Color.Red.A);
                     IColor61         FillColor         = this.SgWorld.Creator.CreateColor(Color.Red.R, Color.Red.G, Color.Red.B, 0);
                     AltitudeTypeCode eAltitudeTypeCode = AltitudeTypeCode.ATC_TERRAIN_RELATIVE;
                     pITerrainPolygon = this.SgWorld.Creator.CreatePolygonFromArray(tripletArray, LineColor, FillColor, eAltitudeTypeCode, GroupID, "TempPolygon");
                     this.SgWorld.ProjectTree.DeleteItem(this.pITerrainPolyline.InfoTreeItemID);
                 }
                 else
                 {
                     if (pITerrainPolygon != null)
                     {
                         IPolygon pPolygon = pITerrainPolygon.Geometry as IPolygon;
                         pPolygon.StartEdit();
                         foreach (ILinearRing r in pPolygon.Rings)
                         {
                             r.Points.AddPoint(longitude, latitude, pIPosition.Distance);
                         }
                         pITerrainPolygon.Geometry = pPolygon.EndEdit();
                     }
                 }
             }
         }
     }
     catch
     {
         MessageBox.Show("地形调整范围绘制失败!");
     }
     return(true);
 }
        /// <summary>
        /// 创建位置
        /// </summary>
        /// <returns></returns>
        private IPosition66 CreatePosition()
        {
            double           dXCoord           = 116.35;
            double           dYCoord           = 27.98;
            double           dAltitude         = 0;
            AltitudeTypeCode eAltitudeTypeCode = AltitudeTypeCode.ATC_TERRAIN_RELATIVE;
            double           dYaw      = 0.0;
            double           dPitch    = 0.0;
            double           dRoll     = 0.0;
            double           dDistance = 500;
            var cPos = this.sgWorld.Creator.CreatePosition(dXCoord, dYCoord, dAltitude, eAltitudeTypeCode, dYaw, dPitch, dRoll, dDistance);

            return(cPos);
        }
        /// <summary>
        /// 创建Polyline
        /// </summary>
        private void CreatePolyline()
        {
            double[] cVerticesArray = null;
            cVerticesArray = new double[] { 114.35, 36.01659, 0, 116.35, 36.15498, 0, 115.35, 34.05090, 0 };
            // geometry creator can work on WKT, WKB or array of x,z,y coordinates
            var geometry = this.sgWorld.Creator.GeometryCreator.CreateLineStringGeometry(cVerticesArray);
            var color    = this.sgWorld.Creator.CreateColor(255, 0, 0, 0);
            // 2 in AltitudeTypeCode means on terrain, 0 means add to root
            AltitudeTypeCode eAltitudeTypeCode = AltitudeTypeCode.ATC_ON_TERRAIN;
            var line = this.sgWorld.Creator.CreatePolyline(geometry, color, eAltitudeTypeCode, string.Empty, "my poly on terrain");

            line.LineStyle.Width   = 15000;    // 15000m (15km)
            line.Position.Distance = 600000.0; // set max viewing distance in meters
            this.sgWorld.Navigate.FlyTo(line);
        }
Exemple #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            string          s1          = textBox1.Text;
            string          s2          = textBox2.Text;
            string          s3          = textBox3.Text;
            string          s4          = textBox4.Text;
            string          s5          = textBox4.Text + "\r\n" + textBox5.Text;
            string          mes         = String.Empty;
            IPosition61     cpos        = null;
            ILabelStyle61   clabelstyle = null;
            ITerrainLabel61 ctextlabel  = null;

            try
            {
                double           dxcoord  = double.Parse(s1);
                double           dycoord  = double.Parse(s2);
                double           altitude = double.Parse(s3);
                AltitudeTypeCode ealit    = AltitudeTypeCode.ATC_TERRAIN_RELATIVE;
                cpos = MainForm.sgworld.Creator.CreatePosition(dxcoord, dycoord, altitude, ealit, -30, -30, 0.0, 10000);
                {
                    SGLabelStyle elabelstyle = SGLabelStyle.LS_DEFAULT;
                    clabelstyle = MainForm.sgworld.Creator.CreateLabelStyle(elabelstyle);
                    {
                        double   alpha       = 0.5;
                        IColor61 cbackground = clabelstyle.BackgroundColor;
                        cbackground.FromBGRColor(nrgb);
                        cbackground.SetAlpha(alpha);
                        clabelstyle.FontName = "Arial";
                        clabelstyle.FontSize = 50;
                        clabelstyle.TextColor.FromABGRColor(nrgb);
                        clabelstyle.Italic = true;
                        clabelstyle.Scale  = 3;
                        ctextlabel         = MainForm.sgworld.Creator.CreateTextLabel(cpos, s5, clabelstyle, 0, s4);
                        IPosition61 cflypos = cpos.Copy();
                        cflypos.Pitch = -30.0;
                        MainForm.sgworld.Navigate.FlyTo(cflypos, ActionCode.AC_FLYTO);
                    }
                }
            }
            catch (Exception ex)
            {
                mes = String.Format("CreateLabelButton_Click Exception :{0}", ex.Message);
                Log4NetHelper.WriteLog(typeof(LabelForm), ex);
                MessageBox.Show(mes);
            }
        }
Exemple #7
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处理异常)****/
        }
Exemple #8
0
        bool sgworld_OnLButtonDown(int Flags, int X, int Y)
        {
            if (pbhander == "modify")
            {
                LClickCount++;
                IWorldPointInfo61 pIWPInfo   = this.SgWorld.Window.PixelToWorld(X, Y, WorldPointType.WPT_TERRAIN);
                IPosition61       pIPosition = this.SgWorld.Navigate.GetPosition(AltitudeTypeCode.ATC_TERRAIN_RELATIVE);

                if (pITerrainPolygon == null)
                {
                    try
                    {
                        ILinearRing cRing          = null;
                        double[]    cVerticesArray = null;
                        cVerticesArray = new double[] {
                            pIPosition.X, pIPosition.Y, 0,
                            pIWPInfo.Position.X, pIWPInfo.Position.Y, 0,
                            pIWPInfo.Position.X, pIWPInfo.Position.Y, 0,
                        };
                        cRing = this.SgWorld.Creator.GeometryCreator.CreateLinearRingGeometry(cVerticesArray);

                        uint             nLineColor        = 0xFF00FF00;
                        uint             nFillColor        = 0x7FFF0000;
                        AltitudeTypeCode eAltitudeTypeCode = AltitudeTypeCode.ATC_TERRAIN_RELATIVE;
                        pITerrainPolygon = this.SgWorld.Creator.CreatePolygon(cRing, nLineColor, nFillColor, eAltitudeTypeCode, 0, "Polygon");

                        IPolygon polygonGeometry = pITerrainPolygon.Geometry as IPolygon;
                        polygonGeometry.StartEdit();
                        foreach (ILinearRing ring in polygonGeometry.Rings)
                        {
                            double dx = pIWPInfo.Position.X;
                            double dy = pIWPInfo.Position.Y;
                            double dh = pIWPInfo.Position.Distance;
                            ring.Points.AddPoint(dx, dy, dh);
                            ring.Points.DeletePoint(0);
                        }
                        IGeometry editedGeometry = polygonGeometry.EndEdit();
                        pITerrainPolygon.Geometry = editedGeometry;
                    }
                    catch (Exception)
                    {
                    }
                }
                else
                {
                    try
                    {
                        IPolygon polygonGeometry = pITerrainPolygon.Geometry as IPolygon;
                        polygonGeometry.StartEdit();
                        foreach (ILinearRing ring in polygonGeometry.Rings)
                        {
                            double dx = pIWPInfo.Position.X;
                            double dy = pIWPInfo.Position.Y;
                            double dh = pIWPInfo.Position.Distance;
                            ring.Points.AddPoint(dx, dy, dh);
                        }
                        IGeometry editedGeometry = polygonGeometry.EndEdit();
                        pITerrainPolygon.Geometry = editedGeometry;
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            return(false);
        }