多边形切割

private void 长方体切割01ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Server svr = new Server();
            //连接数据源
            svr.Connect("MapGISLocal", "", "");
            DataBase db = svr.OpenGDB("sjz3d0330");
            if (db != null)
            {
                //该示例是以Z轴为切割轴实现圆柱体切割功能
                SFeatureCls srcsfcls = new SFeatureCls(db);
                //打开被切割简单要素类
                bool rtn = srcsfcls.Open("钻孔分层点3_Sur_000_Ent", 0);

                if (rtn)
                {
                    //创建结果简单要素类对象,为剖切模型的结果简单要素类1。其中创建的两个结果类必须保存在数据库同一目录下
                    SFeatureCls leftSfcls = new SFeatureCls();
                    int leftClsID = leftSfcls.Create("gdbp://MapGisLocal/sjz3d0330/ds/钻孔分层点3//sfcls/景观_模型_长方体切割cutA2",
                        srcsfcls.GeomType);

                    //创建结果简单要素类对象,为剖切模型的结果简单要素类2
                    SFeatureCls rightSfcls = new SFeatureCls();
                    int rightClsID = rightSfcls.Create("gdbp://MapGisLocal/sjz3d0330/ds/钻孔分层点3/sfcls/景观_模型_长方体切割cutB2",
                        srcsfcls.GeomType);

                    //创建三维模型切割对象
                    G3DModelCut modelCut = new G3DModelCut();
                    //创建三维模型切割对象
                    GeoAnyEntity geometry3D = new GeoAnyEntity();
                    //中心点坐标
                    double x = 75.4300, y = 90.382, z = 0, xmin = 0, xmax = 0, ymin = 0, ymax = 0;
                    double length = 65.5864;
                    double width = 73.1882;
                    float gGeoHeight = 0, fHeightOffSet = 0;

                    xmin = x - length/2;
                    xmax = x + length/2;
                    ymin = y - width/2;
                    ymax = y + width/2;

                    Dots dots = new Dots();
                    //dots.Append(new Dot(xmin, ymin));
                    //dots.Append(new Dot(xmax, ymin));
                    //dots.Append(new Dot(xmax, ymax));
                    //dots.Append(new Dot(xmax - 10, ymax - 5));
                    //dots.Append(new Dot(xmin, ymax));
                    //dots.Append(new Dot(xmin, ymin));

                    dots.Append(new Dot(301679.53, 4190903.00));
                    dots.Append(new Dot(301864.41, 4194845.50));
                    dots.Append(new Dot(300268.69, 4201423.00));
                    dots.Append(new Dot(294296.56, 4195397.50));
                    dots.Append(new Dot(301679.53, 4190903.00));


                    IGeoLine line = new GeoVarLine(dots);
                    GeoLines lines = new GeoLines();
                    lines.Append(line);
                    GeoPolygon polygon = new GeoPolygon();
                    polygon.Append(lines);
                    Rect3D rect3d = srcsfcls.GetRange3D();
                    Rect3D rt3d = new Rect3D();

                    if (rect3d != null)
                    {
                        double xw = rect3d.XMax - rect3d.XMin;
                        double yw = rect3d.YMax - rect3d.YMin;
                        double zw = rect3d.ZMax - rect3d.ZMin;
                        double dxyz = Math.Max(Math.Max(xw, yw), zw);
                        if (dxyz == 0)
                            dxyz = 10;
                        rt3d = rect3d;
                        if (xw == 0)
                            xw = dxyz/10;
                        if (yw == 0)
                            yw = dxyz/10;
                        if (zw == 0)
                            zw = dxyz/10;
                        rt3d.XMin = rect3d.XMin - xw*0.05;
                        rt3d.XMax = rect3d.XMax + xw*0.05;
                        rt3d.YMin = rect3d.YMin - yw*0.05;
                        rt3d.YMax = rect3d.YMax + yw*0.05;
                        rt3d.ZMin = rect3d.ZMin - zw*0.05;
                        rt3d.ZMax = rect3d.ZMax + zw*0.05;
                    }
                    gGeoHeight = (float) (rt3d.ZMax - rt3d.ZMin);
                    fHeightOffSet = (float) rt3d.ZMin;

                    //构建长方体模型
                    GeoModelCommon.CreateClosedSurByReg(geometry3D, polygon, gGeoHeight, fHeightOffSet, null, 1);
                    IGeometry3D geomtry = geometry3D;
                    if (geomtry != null)
                    {
                        List<int> cutMdlClsIDs = new List<int>(); //初始化三维切割模型简单要素类ID列表
                        List<int> cutSectClsIDs = new List<int>(); //初始化三维切割剖面简单要素类ID列表
                        List<int> cutRegClsIDs = new List<int>(); //初始化二维切割剖面简单要素类ID列表

                        // 在列表中添加三维切割模型简单要素类ID
                        cutMdlClsIDs.Add(leftClsID);
                        cutMdlClsIDs.Add(rightClsID);

                        //CutSFClsByGeometry3D方法参数说明:
                        // SFeatureCls sfcls,被切割的源简单要素类,可以是体模型,也可以是面模型;
                        //IGeometry3D cutObj,做切割的实体,如平面、长方体、圆柱体等
                        //DataBase dataBase,目的类所在的数据库
                        //int dsID,目的类所在要素数据集的ID
                        //int saveMdl,是否保存成切割模型的标志,0/1代表否/是
                        //string mdlNamePrefix,三维切割模型的标志名称,随意赋值,无特别意义
                        //ref List<int> mdlClsIDs,三维切割模型简单要素类ID列表
                        //int saveSect,是否保存成三维剖面的标志,0/1代表否/是,其中只有当被切割的模型类型为体模型时有效
                        //string sectNamePrefix,三维剖面的标志名称,随意赋值,无特别意义
                        //ref List<int> sectClsIDs,三维切割剖面简单要素类ID列表
                        //int saveReg,是否保存成二维维剖面的标志,0/1代表否/是,此参数无效,平台暂时无法实现生成二维剖面的功能
                        //string regNamePrefix,二维剖面的标志名称,随意赋值,无特别意义
                        //ref List<int> regClsIDs,二维切割剖面简单要素类ID列表
                        //double dScalX,横向比例尺
                        //double dScalY,纵向比例尺
                        int i = modelCut.CutSFClsByGeometry3D(srcsfcls, geomtry, leftSfcls.GDataBase, leftSfcls.DsID, 1,
                            "长方体切割模型", ref cutMdlClsIDs, 0, "长方体三维切割剖面", ref cutSectClsIDs, 0, "长方体二维切割剖面",
                            ref cutRegClsIDs, 1, 1); //执行切割
                        if (i > 0)
                        {
                            MessageBox.Show("切割成功!");
                        }
                        else
                        {
                            MessageBox.Show("切割失败!");
                        }
                        srcsfcls.Close();
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("打开失败!", "提示");
                    return;
                }

            }

        }

 

posted @ 2022-03-02 15:16  恋上微笑的天使  阅读(92)  评论(0编辑  收藏  举报