コード例 #1
0
ファイル: MainForm.cs プロジェクト: batuZ/Samples
        private void dataGridView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            int           featureId       = int.Parse((sender as DataGridView).CurrentRow.Cells[0].Value.ToString());
            IFeatureClass curFeatureClass = null;

            foreach (IFeatureClass fc in fcMap.Keys)
            {
                curFeatureClass = fc;
                IRowBuffer fdeRow = curFeatureClass.GetRow(featureId);
                if (fdeRow != null)
                {
                    int nPos = fdeRow.FieldIndex("Geometry");
                    if (nPos != -1 && !fdeRow.IsNull(nPos))
                    {
                        IPOI   mp  = fdeRow.GetValue(nPos) as IPOI; // 从库中读取值
                        IPoint pos = new GeometryFactory().CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                        pos.Position   = mp.Position;
                        pos.SpatialCRS = mp.SpatialCRS;
                        IEulerAngle angle = new EulerAngle();
                        angle.Heading = 0;
                        angle.Tilt    = -60;
                        angle.Roll    = 0;
                        this.axRenderControl1.Camera.LookAt2(pos, 3000, angle);
                        this.axRenderControl1.FeatureManager.UnhighlightAll();
                        this.axRenderControl1.FeatureManager.HighlightFeature(curFeatureClass, int.Parse(fdeRow.GetValue(0).ToString()), System.Drawing.Color.Yellow);

                        mp.ImageName = (strMediaPath + @"\png\lan.png");
                        IRenderPOI rpoi = this.axRenderControl1.ObjectManager.CreateRenderPOI(mp);
                        rpoi.Highlight(System.Drawing.Color.Red);
                        this.axRenderControl1.ObjectManager.DelayDelete(rpoi.Guid, 60000);
                    }
                }
            }
        }
コード例 #2
0
        private IModelPoint GetModel(IFeatureClass fc, string geoFieldName, int oid)
        {
            IModelPoint result = null;
            IRowBuffer  row    = fc.GetRow(oid);
            int         num    = row.FieldIndex(geoFieldName);

            if (num != -1)
            {
                result = (row.GetValue(num) as IModelPoint);
            }
            return(result);
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: batuZ/Samples
        private void tsb_Update_Click(object sender, EventArgs e)
        {
            this.cmdManager.StartCommand();

            //获取当前选中要素,将其放大一倍,作为新的行进行更新
            IRowBuffer row = curSelectFc.GetRow(curSelectFid);
            int geoPos = curSelectFc.GetFields().IndexOf("Geometry");
            if (geoPos != -1)
            {
                IModelPoint geo = row.GetValue(geoPos) as IModelPoint;
                geo.SelfScale(2, 2, 2);
                row.SetValue(geoPos, geo);
            }

            this.cmdManager.UpdateFeature(curSelectFc as IObjectClass, row);
            this.axRenderControl1.FeatureManager.EditFeature(curSelectFc, row);

            this.tsb_Redo.Enabled = this.cmdManager.CanRedo;
            this.tsb_Undo.Enabled = this.cmdManager.CanUndo;
            this.tsb_Update.Enabled = false;
        }
コード例 #4
0
        private void UpdateAttribute(EditParameters paramter)
        {
            DF3DApplication app = DF3DApplication.Application;

            if (app == null || app.Current3DMapControl == null)
            {
                return;
            }
            string featureClassGuid = paramter.featureClassGuid;

            if (string.IsNullOrEmpty(featureClassGuid))
            {
                return;
            }
            DF3DFeatureClass featureClassInfo = DF3DFeatureClassManager.Instance.GetFeatureClassByID(featureClassGuid);

            if (featureClassInfo == null)
            {
                return;
            }
            IFeatureClass        featureClass        = featureClassInfo.GetFeatureClass();
            IRowBufferCollection rowBufferCollection = new RowBufferCollectionClass();

            if (featureClass.HasTemporal() && CommonUtils.Instance().EnableTemproalEdit)
            {
                ITemporalManager temporalManager = featureClass.TemporalManager;
                ITemporalCursor  temporalCursor  = temporalManager.Search(new TemporalFilterClass
                {
                    IdsFilter = paramter.fidList
                });
                while (temporalCursor.MoveNext())
                {
                    bool       flag      = false;
                    int        currentId = temporalCursor.CurrentId;
                    IRowBuffer row       = featureClass.GetRow(currentId);
                    base.UpdateRowBuffer(ref row, paramter.colName, paramter.regexDataList);
                    rowBufferCollection.Add(row);
                    ITemporalInstanceCursor temporalInstances = temporalCursor.GetTemporalInstances(false);
                    TemporalInstance        temporalInstance;
                    while ((temporalInstance = temporalInstances.NextInstance()) != null)
                    {
                        if (temporalInstance.StartDatetime == paramter.TemproalTime)
                        {
                            flag = true;
                            temporalInstances.Update(row);
                            break;
                        }
                    }
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalInstances);
                    if (!flag)
                    {
                        temporalCursor.Insert(paramter.TemproalTime, row);
                    }
                }
                app.Current3DMapControl.FeatureManager.RefreshFeatureClass(featureClass);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalCursor);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalManager);
            }
            else
            {
                CommandManagerServices.Instance().StartCommand();
                FDECommand cmd = new FDECommand(false, true);
                for (int i = 0; i < paramter.fidList.Length; i++)
                {
                    int        id   = paramter.fidList[i];
                    IRowBuffer row2 = featureClass.GetRow(id);
                    if (row2 != null)
                    {
                        base.UpdateRowBuffer(ref row2, paramter.colName, paramter.regexDataList);
                        rowBufferCollection.Add(row2);
                    }
                }
                CommonUtils.Instance().FdeUndoRedoManager.UpdateFeatures(featureClass, rowBufferCollection);
                app.Current3DMapControl.FeatureManager.EditFeatures(featureClass, rowBufferCollection);
                CommandManagerServices.Instance().CallCommand(cmd);
                app.Workbench.UpdateMenu();
            }
            CommonUtils.Instance().Update(featureClassInfo, rowBufferCollection);
        }
コード例 #5
0
        void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender)
        {
            try
            {
                if (PickResult != null)
                {
                    if (PickResult.Type == gviObjectType.gviObjectFeatureLayer)
                    {
                        IFeatureLayerPickResult flpr = PickResult as IFeatureLayerPickResult;
                        int fid = flpr.FeatureId;
                        this.axRenderControl1.FeatureManager.HighlightFeature(_featureClass, fid, System.Drawing.Color.Yellow);

                        //////////////////////////////////////////////////////////////////////////
                        //
                        //  GeometryConvert的代码添加在这里
                        //
                        //////////////////////////////////////////////////////////////////////////
                        fidList.Clear();
                        fidList.Add(fid);
                        IRowBuffer rowGC = _featureClass.GetRow(fidList[0]);

                        int nPose = rowGC.FieldIndex("Geometry");
                        if (nPose == -1)
                        {
                            MessageBox.Show("不存在Geometry列");
                            return;
                        }

                        // 获取polygon
                        IPolyline polylineGC = null;
                        if (rowGC != null)
                        {
                            nPose = rowGC.FieldIndex("Geometry");
                            IGeometry geo = rowGC.GetValue(nPose) as IGeometry;
                            if (geo.GeometryType == gviGeometryType.gviGeometryPolyline)
                            {
                                polylineGC = geo as IPolyline;
                            }
                        }

                        if (polylineGC != null)
                        {
                            this.Text = "拾取成功";
                        }
                        else
                        {
                            this.Text = "拾取失败";
                        }

                        param = new PropertySet();

                        if (this.tabControl1.SelectedIndex == 0)
                        {
                            // 1.调接口构造模型
                            double innerRadius = double.Parse(this.numInnerRadius.Value.ToString());
                            param.SetProperty("InnerRadius", innerRadius);
                            double outerRadius = double.Parse(this.numOuterRadius.Value.ToString());
                            param.SetProperty("OuterRadius", outerRadius);
                            double deflection = double.Parse(this.numDeflection.Value.ToString());
                            param.SetProperty("Deflection", deflection);

                            Color difColor = Color.FromArgb(Convert.ToInt32(DifColorBox.Text, 16));
                            param.SetProperty("DiffuseColor", difColor);
                            Color speColor = Color.FromArgb(Convert.ToInt32(SpeColorBox.Text, 16));
                            param.SetProperty("SpecularColor", speColor);


                            IModelPoint mp    = null;
                            IModel      model = null;
                            if (!paraModel.PolylineToPipeLine(polylineGC, param, out mp, out model))
                            {
                                MessageBox.Show("拉管线出错!");
                                return;
                            }

                            //2、将模型及贴图写入osg文件
                            string modelName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".osg");//输出osg文件路径
                            model.WriteFile(modelName, null);

                            //3、测试显示模型
                            mp.ModelName = modelName;
                            IRenderModelPoint rmp = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(mp, null, rootId);
                            rmp.MouseSelectMask    = gviViewportMask.gviViewNone;
                            rmp.MaxVisibleDistance = 100000;
                            this.axRenderControl1.Camera.LookAtEnvelope(mp.Envelope);//飞入
                            mpList.Add(rmp);
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                if (ex.GetType().Name.Equals("UnauthorizedAccessException"))
                {
                    MessageBox.Show("需要标准runtime授权");
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
コード例 #6
0
        private void InitialView()
        {
            try
            {
                IRowBuffer           myRow      = fc.GetRow(fid);
                IFieldInfoCollection fieldinfos = fc.GetFields();
                for (int i = 0; i < fieldinfos.Count; i++)
                {
                    int        iRowIndex = -1;
                    IFieldInfo fieldinfo = fieldinfos.Get(i);
                    if (null == fieldinfo)
                    {
                        continue;
                    }
                    if (fieldinfo.FieldType == gviFieldType.gviFieldGeometry)
                    {
                        if (myRow.IsNull(i))
                        {
                            iRowIndex = this.dgv_FieldValue.Rows.Add(new object[] { fieldinfo.Name, null });
                            continue;
                        }
                        IGeometry geo      = myRow.GetValue(i) as IGeometry;
                        string    geoValue = null;
                        if (geo != null)
                        {
                            switch (geo.GeometryType)
                            {
                            case gviGeometryType.gviGeometryModelPoint:
                                geoValue = "ModelPoint";
                                break;

                            case gviGeometryType.gviGeometryPoint:
                                geoValue = "Point";
                                break;

                            case gviGeometryType.gviGeometryMultiPoint:
                                geoValue = "MultiPoint";
                                break;

                            case gviGeometryType.gviGeometryPolyline:
                                geoValue = "Polyline";
                                break;

                            case gviGeometryType.gviGeometryMultiPolyline:
                                geoValue = "MultiPolyline";
                                break;

                            case gviGeometryType.gviGeometryPolygon:
                                geoValue = "Polygon";
                                break;

                            case gviGeometryType.gviGeometryMultiPolygon:
                                geoValue = "MultiPolygon";
                                break;
                            }
                        }
                        iRowIndex = this.dgv_FieldValue.Rows.Add(new object[] { fieldinfo.Name, geoValue });
                    }
                    else if (fieldinfo.FieldType == gviFieldType.gviFieldFID)
                    {
                        iRowIndex = this.dgv_FieldValue.Rows.Add(new object[] { fieldinfo.Name, myRow.GetValue(i) });
                    }
                    else
                    {
                        IDomain fieldDomain = fieldinfo.Domain;
                        if (fieldDomain != null && fieldDomain.DomainType == gviDomainType.gviDomainCodedValue)
                        {
                            DataGridViewComboBoxCell comCell = new DataGridViewComboBoxCell();
                            comCell.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
                            comCell.Items.Clear();
                            comCell.Items.Add("");
                            Dictionary <object, string> codeValue = this.GetDomainCodeValuePair(fieldDomain);
                            comCell.Items.AddRange(codeValue.Values.ToArray());
                            iRowIndex = this.dgv_FieldValue.Rows.Add();
                            DataGridViewRow myViewRow = this.dgv_FieldValue.Rows[iRowIndex];
                            myViewRow.Cells[1] = comCell;
                            object oCodeValue = myRow.GetValue(i);
                            if (codeValue.ContainsKey(oCodeValue))
                            {
                                myViewRow.SetValues(new object[] { fieldinfo.Name, codeValue[oCodeValue] });
                            }
                            else
                            {
                                myViewRow.SetValues(new object[] { fieldinfo.Name, oCodeValue });
                            }
                        }
                        else
                        {
                            iRowIndex = this.dgv_FieldValue.Rows.Add(new object[] { fieldinfo.Name, myRow.GetValue(i) });
                        }
                    }
                    this.dgv_FieldValue.Rows[iRowIndex].Tag = new EditField(fieldinfo, i);
                }
                this.dgv_FieldValue.Tag = myRow;
            }
            catch (COMException comEx)
            {
                MessageBox.Show(comEx.Message);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
            }
        }
コード例 #7
0
        void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender)
        {
            try
            {
                this.axRenderControl1.FeatureManager.UnhighlightAll();
                if (PickResult != null)
                {
                    if (PickResult.Type == gviObjectType.gviObjectFeatureLayer)
                    {
                        IFeatureLayerPickResult flpr = PickResult as IFeatureLayerPickResult;
                        int fid = flpr.FeatureId;
                        this.axRenderControl1.FeatureManager.HighlightFeature(_featureClass, fid, System.Drawing.Color.Yellow);

                        //////////////////////////////////////////////////////////////////////////
                        //
                        //  GeometryConvert的代码添加在这里
                        //
                        //////////////////////////////////////////////////////////////////////////
                        fidList.Clear();
                        fidList.Add(fid);
                        IRowBuffer rowGC = _featureClass.GetRow(fidList[0]);

                        int nPose = rowGC.FieldIndex("Geometry");
                        if (nPose == -1)
                        {
                            MessageBox.Show("不存在Geometry列");
                            return;
                        }

                        // 获取ModelPoint
                        IModelPoint modelPointGC = null;
                        if (rowGC != null)
                        {
                            nPose = rowGC.FieldIndex("Geometry");
                            IGeometry geo = rowGC.GetValue(nPose) as IGeometry;
                            if (geo.GeometryType == gviGeometryType.gviGeometryModelPoint)
                            {
                                modelPointGC = geo as IModelPoint;
                            }
                        }

                        this.Text = "拾取成功";

                        // 获取Model
                        string modelName = modelPointGC.ModelName;
                        IModel modelGC   = (_featureClass.FeatureDataSet as IResourceManager).GetModel(modelName);

                        // 1、获取MultiTriMesh
                        IGeometryConvertor gc      = new GeometryConvertor();
                        IMultiTriMesh      multiTM = gc.ModelPointToTriMesh(modelGC, modelPointGC, false);
                        this.Text = "ModelToTriMesh完成";

                        if (this.cbCreateRenderTriMesh.Checked)
                        {
                            // 创建RenderTriMesh在三维上显示
                            for (int i = 0; i < multiTM.GeometryCount; i++)
                            {
                                ITriMesh       tm  = multiTM.GetGeometry(i) as ITriMesh;
                                IRenderTriMesh rtm = this.axRenderControl1.ObjectManager.CreateRenderTriMesh(tm, null, rootId);

                                //随机颜色填充TriMesh
                                Random         randObj = new Random(i);
                                int            aColor  = randObj.Next(0, 255);
                                int            gColor  = randObj.Next(0, 255);
                                int            rColor  = randObj.Next(0, 255);
                                ISurfaceSymbol ss      = new SurfaceSymbol();
                                ss.Color   = System.Drawing.Color.FromArgb(rColor, gColor, aColor);
                                rtm.Symbol = ss;
                                rTMeshList.Add(rtm);
                            }
                        }

                        if (this.cbCreateRenderPolygon.Checked)
                        {
                            // 2、获取投影MultiPolygon
                            IMultiPolygon multiPolygon = gc.ProjectTriMeshToPolygon(multiTM, 1.0);
                            this.Text = "MultiTriMeshToFootprint完成。面积:" + multiPolygon.GetArea();

                            // 创建RenderPolygon在三维上显示
                            for (int i = 0; i < multiPolygon.GeometryCount; i++)
                            {
                                IPolygon       polygon  = multiPolygon.GetGeometry(i) as IPolygon;
                                IRenderPolygon rpolygon = this.axRenderControl1.ObjectManager.CreateRenderPolygon(polygon, null, rootId);
                                rPolygonList.Add(rpolygon);
                            }
                        }

                        if (this.cbCreateRenderPolygon2.Checked)
                        {
                            // 3、获取切割MultiPolygon
                            double heightSpec = 0.0, heightIntersect = 0.0;
                            Double.TryParse(IntersectPoint.Z.ToString(), out heightIntersect);
                            fidList.Clear();
                            fidList.Add(fid);
                            IEnvelope box = _featureClass.GetFeaturesEnvelope(fidList.ToArray(), "Geometry");
                            heightSpec = System.Math.Abs(heightIntersect - box.MinZ);
                            // 注意:CutTriMeshToPolygon方法的第三个参数为空间分辨率,应该选择合适值。
                            // 值过大会导致结果不精确,值过小会导致转换时间过长。使用时应设置大小合适的值来平衡精度和效率问题。
                            IMultiPolygon multiPolygon2 = gc.CutTriMeshToPolygon(multiTM, heightSpec, 0.5);
                            this.Text = "MultiTriMeshToFootprint2完成。面积:" + multiPolygon2.GetArea();

                            // 创建RenderPolygon在三维上显示
                            for (int i = 0; i < multiPolygon2.GeometryCount; i++)
                            {
                                IPolygon       polygon2  = multiPolygon2.GetGeometry(i) as IPolygon;
                                IRenderPolygon rpolygon2 = this.axRenderControl1.ObjectManager.CreateRenderPolygon(polygon2, null, rootId);
                                rPolygonList2.Add(rpolygon2);
                            }
                        }

                        if (this.cbCreateRenderMulPoint.Checked)
                        {
                            // 4、获取MultiPoint
                            IMultiPoint multiPoint = gc.MultiTriMeshToMultiPoint(multiTM, 3.0);
                            this.Text = "MultiTriMeshToMultiPoint完成。MultiPoint个数为:" + multiPoint.GeometryCount;

                            //创建RenderPoint在三维上显示
                            IRenderMultiPoint rpoint = this.axRenderControl1.ObjectManager.CreateRenderMultiPoint(multiPoint, null, rootId);
                            rPointList.Add(rpoint);
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                if (ex.GetType().Name.Equals("UnauthorizedAccessException"))
                {
                    MessageBox.Show("需要标准runtime授权");
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
コード例 #8
0
ファイル: AttributeFrm.cs プロジェクト: batuZ/Samples
        private void toolStripButtonEditFeature_Click(object sender, EventArgs e)
        {
            this.dataGridView1.EndEdit();  //强制提交
            if (dsFactory == null)
            {
                dsFactory = new DataSourceFactory();
            }

            IDataSource     ds      = null;
            IFeatureDataSet dataset = null;
            IFeatureClass   fc      = null;
            IFdeCursor      cursor  = null;
            IFieldInfo      field   = null;

            try
            {
                if (dataGridView1.SelectedRows.Count == 1)
                {
                    ds      = dsFactory.OpenDataSource(Info.ci);
                    dataset = ds.OpenFeatureDataset(Info.datasetName);
                    fc      = dataset.OpenFeatureClass(Info.featureclassName);

                    // 比较是否修改了记录
                    int        oid    = int.Parse(dataGridView1.SelectedRows[0].Cells["oid"].Value.ToString());
                    IRowBuffer fdeRow = fc.GetRow(oid);

                    bool isChanged = false;
                    for (int i = 0; i < AttriTable.Columns.Count; ++i)
                    {
                        string strColName = AttriTable.Columns[i].ColumnName;
                        int    nPos       = fdeRow.FieldIndex(strColName);
                        if (nPos != -1)
                        {
                            field = fdeRow.Fields.Get(nPos);
                        }
                        if (nPos != -1 && strColName != "oid" && strColName != "GroupName" && field.FieldType != gviFieldType.gviFieldGeometry)
                        {
                            if (fdeRow.GetValue(nPos) == null || (!dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[i].EditedFormattedValue.Equals(fdeRow.GetValue(nPos).ToString())))
                            {
                                isChanged = true;
                                break;
                            }
                        }
                    }
                    if (!isChanged)
                    {
                        MessageBox.Show("该条记录无改动");
                        return;
                    }

                    for (int j = 0; j < AttriTable.Columns.Count; ++j)
                    {
                        string strColName = AttriTable.Columns[j].ColumnName;
                        int    nPos       = fdeRow.FieldIndex(strColName);
                        if (nPos != -1)
                        {
                            field = fdeRow.Fields.Get(nPos);
                        }
                        if (nPos != -1 && strColName != "oid" && strColName != "GroupName" && field.FieldType != gviFieldType.gviFieldGeometry)
                        {
                            fdeRow.SetValue(nPos, dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[j].EditedFormattedValue);   //插入字段值
                        }
                    }

                    // 修改数据库中记录
                    IRowBufferCollection col = new RowBufferCollection();
                    col.Add(fdeRow);
                    fc.UpdateRows(col, false);
                    MessageBox.Show("修改成功");
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            finally
            {
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
                if (dataset != null)
                {
                    //Marshal.ReleaseComObject(dataset);
                    dataset = null;
                }
                if (fc != null)
                {
                    //Marshal.ReleaseComObject(fc);
                    fc = null;
                }
                if (cursor != null)
                {
                    //Marshal.ReleaseComObject(cursor);
                    cursor = null;
                }
            }
        }
コード例 #9
0
        void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender)
        {
            try
            {
                if (PickResult != null)
                {
                    if (PickResult.Type == gviObjectType.gviObjectFeatureLayer)
                    {
                        IFeatureLayerPickResult flpr = PickResult as IFeatureLayerPickResult;
                        int fid = flpr.FeatureId;
                        this.axRenderControl1.FeatureManager.HighlightFeature(_featureClass, fid, System.Drawing.Color.Red);

                        //////////////////////////////////////////////////////////////////////////
                        //
                        //  GeometryConvert的代码添加在这里
                        //
                        //////////////////////////////////////////////////////////////////////////
                        fidList.Clear();
                        fidList.Add(fid);
                        IRowBuffer rowGC = _featureClass.GetRow(fidList[0]);

                        int nPose = rowGC.FieldIndex("Geometry");
                        if (nPose == -1)
                        {
                            MessageBox.Show("不存在Geometry列");
                            return;
                        }

                        // 获取polygon
                        IPolygon polygonGC = null;
                        if (rowGC != null)
                        {
                            nPose = rowGC.FieldIndex("Geometry");
                            IGeometry geo = rowGC.GetValue(nPose) as IGeometry;
                            if (geo.GeometryType == gviGeometryType.gviGeometryPolygon)
                            {
                                polygonGC = geo as IPolygon;
                            }
                        }

                        this.Text = "拾取成功";

                        param = new PropertySet();

                        //第一个Tab页:PolygonToBuilding
                        if (this.tabControl1.SelectedIndex == 0)
                        {
                            // 1.调接口构造模型
                            double floorNum = double.Parse(this.numFloorNumber.Value.ToString());
                            param.SetProperty("FloorNumber", floorNum);
                            double floorHgt = double.Parse(this.numFloorHeight.Value.ToString());
                            param.SetProperty("FloorHeight", floorHgt);
                            double interiorOffset = double.Parse(this.numInteriorOffset.Value.ToString());
                            param.SetProperty("InteriorOffset", interiorOffset);
                            double exteriorOffset = double.Parse(this.numExteriorOffset.Value.ToString());
                            param.SetProperty("ExteriorOffset", exteriorOffset);
                            double heightOffset = double.Parse(this.numHeightOffset.Value.ToString());
                            param.SetProperty("HeightOffset", heightOffset);

                            string imgPath = (strMediaPath + @"\dds");
                            string roof    = this.comboBoxRoofTexture.Text;
                            string facade  = this.comboBoxFacadeTexture.Text;
                            param.SetProperty("FacadeTexture", roof);
                            param.SetProperty("RoofTexture", facade);

                            IModelPoint mp    = null;
                            IModel      model = null;
                            if (!paraModel.PolygonToBuilding(polygonGC, param, out mp, out model))
                            {
                                MessageBox.Show("拉体块出错!");
                                return;
                            }

                            //2、将模型及贴图写入osg文件
                            string           modelName  = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".osg");//输出osg文件路径
                            IResourceFactory resFactory = new ResourceFactory();
                            string[]         imageNames = model.GetImageNames();
                            IPropertySet     ps         = new PropertySet();
                            for (int i = 0; i < imageNames.Length; i++)
                            {
                                string imgName = imageNames[i];
                                IImage img     = resFactory.CreateImageFromFile(string.Format(@"{0}\{1}", imgPath + @"\facade", imgName));
                                if (img == null)
                                {
                                    img = resFactory.CreateImageFromFile(string.Format(@"{0}\{1}", imgPath + @"\roof", imgName));
                                }
                                ps.SetProperty(imgName, img);
                            }
                            model.WriteFile(modelName, ps);

                            //3、测试显示模型
                            mp.ModelName = modelName;
                            IRenderModelPoint rmp = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(mp, null, rootId);
                            rmp.MouseSelectMask    = gviViewportMask.gviViewNone;
                            rmp.MaxVisibleDistance = 100000;
                            this.axRenderControl1.Camera.LookAtEnvelope(mp.Envelope);//飞入
                            mpList.Add(rmp);
                        }
                        //第二个tab页:ExtrudePolygonToTriMesh
                        else
                        {
                            // 1.调接口构造模型
                            double floorNum = double.Parse(this.numFloorNumber.Value.ToString());
                            param.SetProperty("FloorNumber", floorNum);
                            double floorHgt = double.Parse(this.numFloorHeight.Value.ToString());
                            param.SetProperty("FloorHeight", floorHgt);
                            double interiorOffset = double.Parse(this.numInteriorOffset.Value.ToString());
                            param.SetProperty("InteriorOffset", interiorOffset);
                            double exteriorOffset = double.Parse(this.numExteriorOffset.Value.ToString());
                            param.SetProperty("ExteriorOffset", exteriorOffset);
                            double heightOffset = double.Parse(this.numHeightOffset.Value.ToString());
                            param.SetProperty("HeightOffset", heightOffset);

                            double buildingHeight = double.Parse(this.numBuildingHeight.Value.ToString());
                            param.SetProperty("BuildingHeight", buildingHeight);
                            double buildingXScale = double.Parse(this.numBuildingXScale.Value.ToString());
                            param.SetProperty("BuildingXScale", buildingXScale);
                            double buildingYScale = double.Parse(this.numBuildingYScale.Value.ToString());
                            param.SetProperty("BuildingYScale", buildingYScale);

                            string imgPath = (strMediaPath + @"\dds");
                            string roof    = this.comboBoxRoofTexture.Text;
                            string facade  = this.comboBoxFacadeTexture.Text;
                            param.SetProperty("FacadeTexture", roof);
                            param.SetProperty("RoofTexture", facade);

                            IModelPoint mp    = null;
                            IModel      model = null;
                            if (!paraModel.PolygonToBuilding(polygonGC, param, out mp, out model))
                            {
                                MessageBox.Show("拉体块出错!");
                                return;
                            }

                            //2、将模型及贴图写入osg文件
                            string           modelName  = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".osg");//输出osg文件路径
                            IResourceFactory resFactory = new ResourceFactory();
                            string[]         imageNames = model.GetImageNames();
                            IPropertySet     ps         = new PropertySet();
                            for (int i = 0; i < imageNames.Length; i++)
                            {
                                string imgName = imageNames[i];
                                IImage img     = resFactory.CreateImageFromFile(string.Format(@"{0}\{1}", imgPath + @"\facade", imgName));
                                if (img == null)
                                {
                                    img = resFactory.CreateImageFromFile(string.Format(@"{0}\{1}", imgPath + @"\roof", imgName));
                                }
                                ps.SetProperty(imgName, img);
                            }
                            model.WriteFile(modelName, ps);

                            //3、测试显示模型
                            mp.ModelName = modelName;
                            IRenderModelPoint rmp = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(mp, null, rootId);
                            rmp.MouseSelectMask    = gviViewportMask.gviViewNone;
                            rmp.MaxVisibleDistance = 100000;
                            this.axRenderControl1.Camera.LookAtEnvelope(mp.Envelope);//飞入
                            mpList.Add(rmp);
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                if (ex.GetType().Name.Equals("UnauthorizedAccessException"))
                {
                    MessageBox.Show("需要标准runtime授权");
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// 在要素类里创建要素
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButtonInsertFeature_Click(object sender, EventArgs e)
        {
            if (dsFactory == null)
            {
                dsFactory = new DataSourceFactory();
            }

            IDataSource     ds      = null;
            IFeatureDataSet dataset = null;
            IFeatureClass   fc      = null;
            IFdeCursor      cursor  = null;

            try
            {
                ds      = dsFactory.OpenDataSource(Info.ci);
                dataset = ds.OpenFeatureDataset(Info.datasetName);
                fc      = dataset.OpenFeatureClass(Info.featureclassName);

                DataRow          dr  = AttriTable.NewRow();;
                RowBufferFactory rbf = new RowBufferFactory();
                IRowBuffer       rb  = rbf.CreateRowBuffer(fc.GetFields());

                // 构造待插入的数据:暂时用最后一行的数据进行插入
                int        lastOid = int.Parse(dataGridView1.Rows[AttriTable.Rows.Count - 1].Cells["oid"].Value.ToString());
                IRowBuffer lastRow = fc.GetRow(lastOid);
                for (int i = 0; i < fc.GetFields().Count; ++i)
                {
                    string strColName = fc.GetFields().Get(i).Name;
                    int    nPos       = rb.FieldIndex(strColName);
                    if (fc.GetFields().Get(i).Name != "oid")
                    {
                        rb.SetValue(nPos, lastRow.GetValue(nPos));   //插入字段值
                    }
                }
                // 构造界面显示数据
                for (int j = 0; j < AttriTable.Columns.Count; ++j)
                {
                    string strColName = AttriTable.Columns[j].ColumnName;
                    int    nPos       = rb.FieldIndex(strColName);
                    if (nPos != -1 && strColName != "oid")
                    {
                        if (lastRow.GetValue(nPos) != null)
                        {
                            dr[j] = lastRow.GetValue(nPos).ToString();
                        }
                    }

                    if ("GroupName" == strColName)
                    {
                        dr[j] = this.dataGridView1.Rows[AttriTable.Rows.Count - 1].Cells["GroupName"].Value.ToString();
                    }
                }

                // 往数据库中增加
                cursor = fc.Insert();
                cursor.InsertRow(rb);

                // 往界面DataTable上增加
                dr["oid"] = cursor.LastInsertId;  //获取插入后oid值在界面显示
                AttriTable.Rows.Add(dr);
                this.dataGridView1.Refresh();
                this.dataGridView1.Rows[AttriTable.Rows.Count - 1].Selected = true;
                this.dataGridView1.FirstDisplayedScrollingRowIndex          = AttriTable.Rows.Count - 1;
                MessageBox.Show("增加记录成功");

                // 更新表头文字
                if (FilterWhereClause.Equals(""))
                {
                    this.Text = "Attributes of " + Info.featureclassName + "  [Total records: " + fc.GetCount(null).ToString() + "]";
                }
                else
                {
                    this.Text = "Attributes of " + Info.featureclassName + "  [Total records: " + AttriTable.Rows.Count.ToString() + "]" + "  Filter: " + FilterWhereClause;
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            finally
            {
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
                if (dataset != null)
                {
                    //Marshal.ReleaseComObject(dataset);
                    dataset = null;
                }
                if (fc != null)
                {
                    //Marshal.ReleaseComObject(fc);
                    fc = null;
                }
                if (cursor != null)
                {
                    //Marshal.ReleaseComObject(cursor);
                    cursor = null;
                }
            }
        }
コード例 #11
0
        private void sbtn_Split_Click(object sender, System.EventArgs e)
        {
            DF3DApplication app = DF3DApplication.Application;

            if (app == null || app.Current3DMapControl == null)
            {
                return;
            }
            if (System.Windows.Forms.DialogResult.No != XtraMessageBox.Show("模型拆分不支持撤销操作,是否继续?", "询问", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Exclamation))
            {
                IFeatureClass featureClass = null;
                IFdeCursor    fdeCursor    = null;
                app.Current3DMapControl.PauseRendering(false);
                WaitDialogForm waitDialogForm = null;
                try
                {
                    int count = SelectCollection.Instance().GetCount(true);
                    if (count <= 0)
                    {
                        XtraMessageBox.Show("未选中要拆分的模型!");
                    }
                    else
                    {
                        if (this._renderGeo == null || this._renderGeo.GetFdeGeometry() == null)
                        {
                            XtraMessageBox.Show("请先绘制或选择拆分多边形!");
                        }
                        else
                        {
                            IMultiPolygon multiPolygon = null;
                            if (this.radioGroup1.SelectedIndex == 1)
                            {
                                IGeometryFactory geometryFactory = new GeometryFactoryClass();
                                multiPolygon = (geometryFactory.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon);
                                multiPolygon.AddPolygon(this._renderGeo.GetFdeGeometry() as IPolygon);
                            }
                            else
                            {
                                if (this.radioGroup1.SelectedIndex == 0)
                                {
                                    multiPolygon = (this._renderGeo.GetFdeGeometry() as IMultiPolygon);
                                }
                            }
                            if (multiPolygon == null)
                            {
                                XtraMessageBox.Show("获取裁剪多边形失败!");
                            }
                            else
                            {
                                waitDialogForm = new WaitDialogForm(string.Empty, "正在拆分模型,请稍后...");
                                HashMap featureClassInfoMap            = SelectCollection.Instance().FeatureClassInfoMap;
                                System.Collections.Hashtable hashtable = new System.Collections.Hashtable();
                                foreach (DF3DFeatureClass featureClassInfo in featureClassInfoMap.Keys)
                                {
                                    if (featureClassInfo.GetFeatureLayer().GeometryType == gviGeometryColumnType.gviGeometryColumnModelPoint)
                                    {
                                        System.Collections.Generic.List <int> list  = new System.Collections.Generic.List <int>();
                                        System.Collections.Generic.List <int> list2 = new System.Collections.Generic.List <int>();
                                        IRowBufferCollection rowBufferCollection    = new RowBufferCollectionClass();
                                        IRowBufferCollection rowBufferCollection2   = new RowBufferCollectionClass();
                                        ResultSetInfo        resultSetInfo          = featureClassInfoMap[featureClassInfo] as ResultSetInfo;
                                        DataTable            resultSetTable         = resultSetInfo.ResultSetTable;
                                        if (resultSetTable.Rows.Count >= 1)
                                        {
                                            featureClass = featureClassInfo.GetFeatureClass();
                                            IResourceManager resourceManager = featureClass.FeatureDataSet as IResourceManager;
                                            string           fidFieldName    = featureClass.FidFieldName;
                                            int num = featureClass.GetFields().IndexOf(fidFieldName);
                                            foreach (DataRow dataRow in resultSetTable.Rows)
                                            {
                                                int         num2       = int.Parse(dataRow[fidFieldName].ToString());
                                                IRowBuffer  row        = featureClass.GetRow(num2);
                                                int         position   = row.FieldIndex(featureClassInfo.GetFeatureLayer().GeometryFieldName);
                                                IModelPoint modelPoint = row.GetValue(position) as IModelPoint;
                                                if (modelPoint != null)
                                                {
                                                    Gvitech.CityMaker.Resource.IModel model  = resourceManager.GetModel(modelPoint.ModelName);
                                                    IGeometryConvertor geometryConvertor     = new GeometryConvertorClass();
                                                    Gvitech.CityMaker.Resource.IModel model2 = null;
                                                    Gvitech.CityMaker.Resource.IModel model3 = null;
                                                    IModelPoint modelPoint2 = null;
                                                    IModelPoint modelPoint3 = null;
                                                    bool        flag        = geometryConvertor.SplitModelPointByPolygon2D(multiPolygon, model, modelPoint, out model2, out modelPoint2, out model3, out modelPoint3);
                                                    if (flag && model2 != null && !model2.IsEmpty && modelPoint2 != null && model3 != null && !model3.IsEmpty && modelPoint3 != null)
                                                    {
                                                        System.Guid guid = System.Guid.NewGuid();
                                                        string      text = guid.ToString();
                                                        resourceManager.AddModel(text, model2, null);
                                                        resourceManager.RebuildSimplifiedModel(text);
                                                        guid = System.Guid.NewGuid();
                                                        string text2 = guid.ToString();
                                                        resourceManager.AddModel(text2, model3, null);
                                                        resourceManager.RebuildSimplifiedModel(text2);
                                                        modelPoint3.ModelName = text2;
                                                        row.SetValue(position, modelPoint3);
                                                        rowBufferCollection.Add(row);
                                                        list.Add(num2);
                                                        modelPoint2.ModelName = text;
                                                        IRowBuffer rowBuffer = row.Clone(false);
                                                        rowBuffer.SetNull(num);
                                                        rowBuffer.SetValue(position, modelPoint2);
                                                        fdeCursor = featureClass.Insert();
                                                        fdeCursor.InsertRow(rowBuffer);
                                                        int lastInsertId = fdeCursor.LastInsertId;
                                                        rowBuffer.SetValue(num, lastInsertId);
                                                        rowBufferCollection2.Add(rowBuffer);
                                                        list2.Add(lastInsertId);
                                                        System.Runtime.InteropServices.Marshal.ReleaseComObject(fdeCursor);
                                                        fdeCursor = null;
                                                    }
                                                }
                                            }
                                            featureClass.UpdateRows(rowBufferCollection, false);
                                            app.Current3DMapControl.FeatureManager.EditFeatures(featureClass, rowBufferCollection);
                                            app.Current3DMapControl.FeatureManager.CreateFeatures(featureClass, rowBufferCollection2);
                                            hashtable[featureClassInfo] = list2;
                                            //System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass);
                                            featureClass = null;
                                            System.Runtime.InteropServices.Marshal.ReleaseComObject(resourceManager);
                                            resourceManager = null;
                                        }
                                    }
                                }
                                SelectCollection.Instance().UpdateSelection(hashtable);
                                base.Close();
                                base.DialogResult = System.Windows.Forms.DialogResult.OK;
                            }
                        }
                    }
                }
                catch (System.Runtime.InteropServices.COMException ex)
                {
                    XtraMessageBox.Show(ex.Message);
                }
                catch (System.UnauthorizedAccessException var_35_4EC)
                {
                    XtraMessageBox.Show("拒绝访问");
                }
                catch (System.Exception ex2)
                {
                    XtraMessageBox.Show(ex2.Message);
                }
                finally
                {
                    if (waitDialogForm != null)
                    {
                        waitDialogForm.Close();
                    }
                    if (fdeCursor != null)
                    {
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(fdeCursor);
                        fdeCursor = null;
                    }
                    //if (featureClass != null && System.Runtime.InteropServices.Marshal.IsComObject(featureClass))
                    //{
                    //    System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass);
                    //    featureClass = null;
                    //}
                    app.Current3DMapControl.ResumeRendering();
                }
            }
        }
コード例 #12
0
ファイル: MiddleDataEdit.cs プロジェクト: wwcc19870805/DIFGIS
        private void UpdateAttribute(object param)
        {
            DF3DApplication app = DF3DApplication.Application;

            if (app == null || app.Current3DMapControl == null)
            {
                return;
            }
            EditParameters editParameters = (EditParameters)param;

            if (editParameters == null)
            {
                return;
            }
            string           featureClassGuid = editParameters.featureClassGuid;
            DF3DFeatureClass featureClassInfo = DF3DFeatureClassManager.Instance.GetFeatureClassByID(featureClassGuid);

            if (featureClassInfo == null)
            {
                return;
            }
            CommandManagerServices.Instance().StartCommand();
            FDECommand cmd         = new FDECommand(false, true);
            int        nTotalCount = editParameters.nTotalCount;
            int        num         = 0;

            if (featureClassInfo.GetFeatureClass().HasTemporal() && CommonUtils.Instance().EnableTemproalEdit)
            {
                IConnectionInfo connectionInfo = new ConnectionInfoClass();
                connectionInfo.FromConnectionString(featureClassInfo.GetFeatureClass().DataSource.ConnectionInfo.ToConnectionString());
                IDataSource      dataSource      = ((IDataSourceFactory) new DataSourceFactoryClass()).OpenDataSource(connectionInfo);
                IFeatureDataSet  featureDataSet  = dataSource.OpenFeatureDataset(CommonUtils.Instance().GetCurrentFeatureDataset().Name);
                IFeatureClass    featureClass    = featureDataSet.OpenFeatureClass(featureClassInfo.GetFeatureClass().Name);
                ITemporalManager temporalManager = featureClass.TemporalManager;
                ITemporalCursor  temporalCursor  = temporalManager.Search(new TemporalFilterClass
                {
                    IdsFilter = editParameters.fidList
                });
                while (temporalCursor.MoveNext())
                {
                    this._manualResult.WaitOne();
                    num++;
                    string userState       = string.Format(StringParser.Parse("${res:feature_progress_finished}"), num, nTotalCount);
                    int    percentProgress = num * 100 / nTotalCount;
                    this._bgWorker.ReportProgress(percentProgress, userState);
                    bool       flag      = false;
                    int        currentId = temporalCursor.CurrentId;
                    IRowBuffer row       = featureClass.GetRow(currentId);
                    base.UpdateRowBuffer(ref row, editParameters.colName, editParameters.regexDataList);
                    ITemporalInstanceCursor temporalInstances = temporalCursor.GetTemporalInstances(false);
                    TemporalInstance        temporalInstance;
                    while ((temporalInstance = temporalInstances.NextInstance()) != null)
                    {
                        if (temporalInstance.StartDatetime == editParameters.TemproalTime)
                        {
                            flag = true;
                            temporalInstances.Update(row);
                            break;
                        }
                    }
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalInstances);
                    if (!flag)
                    {
                        temporalCursor.Insert(editParameters.TemproalTime, row);
                    }
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalCursor);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalManager);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(featureDataSet);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(dataSource);
            }
            else
            {
                IFeatureClass featureClass2 = featureClassInfo.GetFeatureClass();
                System.Collections.Generic.Dictionary <int, string> dictionary = new System.Collections.Generic.Dictionary <int, string>();
                IRowBufferCollection rowBufferCollection  = new RowBufferCollectionClass();
                IRowBufferCollection rowBufferCollection2 = new RowBufferCollectionClass();
                for (int i = 0; i < editParameters.fidList.Length; i++)
                {
                    if (this._bgWorker.CancellationPending)
                    {
                        CommonUtils.Instance().FdeUndoRedoManager.UpdateFeatures(featureClass2, rowBufferCollection2);
                        break;
                    }
                    this._manualResult.WaitOne();
                    System.Threading.Thread.Sleep(1);
                    int        num2 = editParameters.fidList[i];
                    IRowBuffer row2 = featureClass2.GetRow(num2);
                    if (row2 != null)
                    {
                        string value = base.UpdateRowBuffer(ref row2, editParameters.colName, editParameters.regexDataList);
                        rowBufferCollection.Add(row2);
                        rowBufferCollection2.Add(row2);
                        dictionary[num2] = value;
                        num++;
                        string userState2       = string.Format(StringParser.Parse("${res:feature_progress_finished}"), num, nTotalCount);
                        int    percentProgress2 = num * 100 / nTotalCount;
                        this._bgWorker.ReportProgress(percentProgress2, userState2);
                    }
                }
                if (dictionary.Count > 0)
                {
                    CommonUtils.Instance().FdeUndoRedoManager.UpdateFeatures(featureClass2, rowBufferCollection2);
                    object[] args = new object[]
                    {
                        featureClassInfo,
                        editParameters.colName,
                        dictionary
                    };
                    //System.IAsyncResult asyncResult = MainFrmService.ResultSetPanel.BeginInvoke(this._updateSelection, args);
                    //MainFrmService.ResultSetPanel.EndInvoke(asyncResult);
                }
            }
            CommandManagerServices.Instance().CallCommand(cmd);
            app.Workbench.UpdateMenu();
        }
コード例 #13
0
ファイル: MainForm.cs プロジェクト: batuZ/Samples
        void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender)
        {
            try
            {
                if (PickResult != null)
                {
                    if (PickResult.Type == gviObjectType.gviObjectFeatureLayer)
                    {
                        IFeatureLayerPickResult flpr = PickResult as IFeatureLayerPickResult;
                        int fid = flpr.FeatureId;
                        this.axRenderControl1.FeatureManager.HighlightFeature(_featureClass, fid, System.Drawing.Color.Yellow);

                        //////////////////////////////////////////////////////////////////////////
                        //
                        //  GeometryConvert的代码添加在这里
                        //
                        //////////////////////////////////////////////////////////////////////////
                        fidList.Clear();
                        fidList.Add(fid);
                        IRowBuffer rowGC = _featureClass.GetRow(fidList[0]);

                        int nPose = rowGC.FieldIndex("Geometry");
                        if (nPose == -1)
                        {
                            MessageBox.Show("不存在Geometry列");
                            return;
                        }

                        // 获取polygon
                        IPolygon polygonGC = null;
                        if (rowGC != null)
                        {
                            nPose = rowGC.FieldIndex("Geometry");
                            IGeometry geo = rowGC.GetValue(nPose) as IGeometry;
                            if (geo.GeometryType == gviGeometryType.gviGeometryPolygon)
                            {
                                polygonGC = geo as IPolygon;
                            }
                        }

                        this.Text = "拾取成功";

                        //第一个Tab页:ExtrudePolygonToModel
                        if (this.tabControl1.SelectedIndex == 0)
                        {
                            // 1.调接口构造模型
                            IGeometryConvertor gc       = new GeometryConvertor();
                            gviRoofType        rooftype = gviRoofType.gviRoofFlat;
                            switch (this.comboxRoofType.Text)
                            {
                            case "Flat":
                                rooftype = gviRoofType.gviRoofFlat;
                                break;

                            case "Gable":
                                rooftype = gviRoofType.gviRoofGable;
                                break;

                            case "Hip":
                                rooftype = gviRoofType.gviRoofHip;
                                break;
                            }
                            string      imgPath = (strMediaPath + @"\dds");
                            string      roof    = this.comboBoxRoofTexture.Text;
                            string      facade  = this.comboBoxFacadeTexture.Text;
                            IModelPoint mp      = null;
                            IModel      model   = null;
                            if (!gc.ExtrudePolygonToModel(polygonGC, int.Parse(this.numFloorNumber.Value.ToString()), double.Parse(this.numFloorHeight.Value.ToString()), double.Parse(this.numSlopeAngle.Value.ToString()),
                                                          rooftype, facade, roof, out mp, out model))
                            {
                                MessageBox.Show("拉体块出错!");
                                return;
                            }

                            //2、将模型及贴图写入osg文件
                            string           modelName  = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".osg");//输出osg文件路径
                            IResourceFactory resFactory = new ResourceFactory();
                            string[]         imageNames = model.GetImageNames();
                            IPropertySet     ps         = new PropertySet();
                            for (int i = 0; i < imageNames.Length; i++)
                            {
                                string imgName = imageNames[i];
                                IImage img     = resFactory.CreateImageFromFile(string.Format(@"{0}\{1}", imgPath + @"\facade", imgName));
                                if (img == null)
                                {
                                    img = resFactory.CreateImageFromFile(string.Format(@"{0}\{1}", imgPath + @"\roof", imgName));
                                }
                                ps.SetProperty(imgName, img);
                            }
                            model.WriteFile(modelName, ps);

                            //3、测试显示模型
                            mp.ModelName = modelName;
                            IRenderModelPoint rmp = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(mp, null, rootId);
                            rmp.MouseSelectMask    = gviViewportMask.gviViewNone;
                            rmp.MaxVisibleDistance = 100000;
                            this.axRenderControl1.Camera.LookAtEnvelope(mp.Envelope);//飞入
                            mpList.Add(rmp);
                        }
                        //第二个tab页:ExtrudePolygonToTriMesh
                        else
                        {
                            // 1.调接口构造模型
                            IGeometryConvertor gc = new GeometryConvertor();
                            ITriMesh           tm = gc.ExtrudePolygonToTriMesh(polygonGC, double.Parse(this.numHeight.Value.ToString()), true);
                            if (tm == null)
                            {
                                MessageBox.Show("拉体块出错!");
                                return;
                            }

                            //2、显示三角面
                            //---- 渲染样式不是必须的 -----
                            ISurfaceSymbol surfaceSym = new SurfaceSymbol();
                            surfaceSym.Color       = System.Drawing.Color.Red;
                            surfaceSym.EnableLight = true;
                            ICurveSymbol curveSym = new CurveSymbol();
                            curveSym.Color            = System.Drawing.Color.Yellow;
                            curveSym.Width            = 10;
                            surfaceSym.BoundarySymbol = curveSym;
                            //---- ------------------ -----
                            IRenderTriMesh rmp = this.axRenderControl1.ObjectManager.CreateRenderTriMesh(tm, surfaceSym, rootId);
                            rmp.MouseSelectMask    = gviViewportMask.gviViewNone;
                            rmp.MaxVisibleDistance = 100000;
                            this.axRenderControl1.Camera.LookAtEnvelope(rmp.Envelope);//飞入
                            tmList.Add(rmp);
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                if (ex.GetType().Name.Equals("UnauthorizedAccessException"))
                {
                    MessageBox.Show("需要标准runtime授权");
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
コード例 #14
0
ファイル: LarageDataEdit.cs プロジェクト: wwcc19870805/DIFGIS
        private void UpdateAttribute(object param)
        {
            IFeatureClass featureClass = null;

            try
            {
                EditParameters editParameters = (EditParameters)param;
                if (editParameters != null)
                {
                    DF3DFeatureClass featureClassInfo = DF3DFeatureClassManager.Instance.GetFeatureClassByID(editParameters.featureClassGuid);
                    IDataSource      dataSource       = ((IDataSourceFactory) new DataSourceFactoryClass()).OpenDataSourceByString(editParameters.connectionInfo);
                    IFeatureDataSet  featureDataSet   = dataSource.OpenFeatureDataset(editParameters.datasetName);
                    featureClass = featureDataSet.OpenFeatureClass(editParameters.fcName);
                    int nTotalCount = editParameters.nTotalCount;
                    int num         = 0;
                    if (featureClass.HasTemporal() && CommonUtils.Instance().EnableTemproalEdit)
                    {
                        ITemporalManager temporalManager = featureClass.TemporalManager;
                        ITemporalCursor  temporalCursor  = temporalManager.Search(new TemporalFilterClass
                        {
                            IdsFilter = editParameters.fidList
                        });
                        while (temporalCursor.MoveNext())
                        {
                            this._manualResult.WaitOne();
                            num++;
                            string userState       = string.Format(StringParser.Parse("${res:feature_progress_finished}"), num, nTotalCount);
                            int    percentProgress = num * 100 / nTotalCount;
                            this._bgWorker.ReportProgress(percentProgress, userState);
                            bool       flag      = false;
                            int        currentId = temporalCursor.CurrentId;
                            IRowBuffer row       = featureClass.GetRow(currentId);
                            base.UpdateRowBuffer(ref row, editParameters.colName, editParameters.regexDataList);
                            ITemporalInstanceCursor temporalInstances = temporalCursor.GetTemporalInstances(false);
                            TemporalInstance        temporalInstance;
                            while ((temporalInstance = temporalInstances.NextInstance()) != null)
                            {
                                if (temporalInstance.StartDatetime == editParameters.TemproalTime)
                                {
                                    flag = true;
                                    temporalInstances.Update(row);
                                    break;
                                }
                            }
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalInstances);
                            if (!flag)
                            {
                                temporalCursor.Insert(editParameters.TemproalTime, row);
                            }
                        }
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalCursor);
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalManager);
                    }
                    else
                    {
                        featureClass.FeatureDataSet.DataSource.StartEditing();
                        IFdeCursor fdeCursor = featureClass.Update(new QueryFilterClass
                        {
                            IdsFilter = editParameters.fidList
                        });
                        IRowBuffer rowBuffer = null;
                        System.Collections.Generic.Dictionary <int, string> dictionary = new System.Collections.Generic.Dictionary <int, string>();
                        while ((rowBuffer = fdeCursor.NextRow()) != null && !this._bgWorker.CancellationPending)
                        {
                            int    position = rowBuffer.FieldIndex(featureClass.FidFieldName);
                            int    key      = int.Parse(rowBuffer.GetValue(position).ToString());
                            string value    = base.UpdateRowBuffer(ref rowBuffer, editParameters.colName, editParameters.regexDataList);
                            fdeCursor.UpdateRow(rowBuffer);
                            num++;
                            dictionary[key] = value;
                            string userState2       = string.Format(StringParser.Parse("${res:feature_progress_finished}"), num, nTotalCount);
                            int    percentProgress2 = num * 100 / nTotalCount;
                            this._bgWorker.ReportProgress(percentProgress2, userState2);
                        }
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(fdeCursor);
                        featureClass.FeatureDataSet.DataSource.StopEditing(true);
                        object[] args = new object[]
                        {
                            featureClassInfo,
                            editParameters.colName,
                            dictionary
                        };
                        //System.IAsyncResult asyncResult = MainFrmService.ResultSetPanel.BeginInvoke(this._updateSelection, args);
                        //MainFrmService.ResultSetPanel.EndInvoke(asyncResult);
                    }
                    //System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(featureDataSet);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(dataSource);
                }
            }
            catch (System.Exception)
            {
                if (featureClass != null)
                {
                    featureClass.FeatureDataSet.DataSource.StopEditing(true);
                }
            }
        }
コード例 #15
0
ファイル: MainForm.cs プロジェクト: batuZ/Samples
        void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender)
        {
            if (PickResult == null)
            {
                return;
            }

            this.dataGridView1.Rows.Clear();
            this.axRenderControl1.FeatureManager.UnhighlightAll();
            rowMap.Clear();

            IPickResult pr = PickResult;

            if (pr.Type != gviObjectType.gviObjectFeatureLayer)
            {
                return;
            }
            IFeatureLayerPickResult fpr   = pr as IFeatureLayerPickResult;
            IFeatureLayer           layer = fpr.FeatureLayer;
            IFeatureClassInfo       cinfo = layer.FeatureClassInfo;

            if (cinfo.DataSourceConnectionString.Contains("FireBird2x"))
            {
                return;
            }
            IDataSource     ds       = (new DataSourceFactory()).OpenDataSourceByString(cinfo.DataSourceConnectionString);
            IFeatureDataSet dset     = ds.OpenFeatureDataset(cinfo.DataSetName);
            IFeatureClass   shpfc    = dset.OpenFeatureClass(cinfo.FeatureClassName);
            IRowBuffer      shprow   = shpfc.GetRow(fpr.FeatureId);
            int             shpindex = shprow.FieldIndex("Geometry");
            IPolygon        polygon  = shprow.GetValue(shpindex) as IPolygon;

            if (polygon == null)
            {
                return;
            }

            IFdeCursor cursor = null;

            try
            {
                foreach (IFeatureClass fc in fcMap.Keys)
                {
                    IRowBuffer        row  = null;
                    List <IRowBuffer> list = new List <IRowBuffer>();

                    ISpatialFilter filter = new SpatialFilter();
                    filter.Geometry      = polygon;
                    filter.SpatialRel    = gviSpatialRel.gviSpatialRelEnvelope;
                    filter.GeometryField = "Geometry";
                    cursor = fc.Search(filter, false);
                    while ((row = cursor.NextRow()) != null)
                    {
                        list.Add(row);
                    }

                    foreach (IRowBuffer r in list)
                    {
                        int geometryIndex = -1;
                        geometryIndex = r.FieldIndex("Geometry");
                        if (geometryIndex != -1)
                        {
                            int oid = int.Parse(r.GetValue(0).ToString());
                            this.axRenderControl1.FeatureManager.HighlightFeature(fc, oid, System.Drawing.Color.Red);

                            string    fid = "";
                            IEnvelope env = null;
                            for (int i = 0; i < r.FieldCount; i++)
                            {
                                string fieldName = r.Fields.Get(i).Name;
                                if (r.Fields.Get(i).Name == "oid")
                                {
                                    fid = r.GetValue(i).ToString();
                                }
                                else if (r.Fields.Get(i).Name == "Geometry")
                                {
                                    IGeometry geometry = r.GetValue(i) as IModelPoint;
                                    env = geometry.Envelope;
                                }
                            }
                            RowObject ro = new RowObject()
                            {
                                FID = fid, FCGUID = fc.Guid.ToString(), FCName = fc.Name, FeatureClass = fc, Envelop = env
                            };
                            if (!rowMap.ContainsKey(ro.FID + "/" + ro.FCGUID))
                            {
                                rowMap.Add(ro.FID + "/" + ro.FCGUID, ro);
                            }
                        }
                    } // end of foreach (IRowBuffer r in list)
                }     // end of foreach (IFeatureClass fc in fcMap.Keys)
                this.Text = "分析完成!";
                LoadGridView();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (cursor != null)
                {
                    cursor.Dispose();
                    cursor = null;
                }
            }
        }