伟景行Citymaker三维Gis加载FDB数据

FDB是伟景行平台数据存储的格式,可以保存在本地也可以存储在后台数据库中,本代码是从本地加载FDB文件。

            // 连接信息对象,用于数据源的创建或打
             IConnectionInfo ci = new ConnectionInfo();
                       //指定数据源连接类型
                        ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                        string tmpFDBPath = ConfigurationManager.AppSettings["fdbFile"];//获取FDB文件路径
                         ci.Database = tmpFDBPath;
                        //数据源工厂, 负责数据源的打开
                        IDataSourceFactory dsFactory = new DataSourceFactory();
                        //打开数据源
                        IDataSource ds = dsFactory.OpenDataSource(ci);
                        // 获取数据集名集合
                        string[] setnames = (string[])ds.GetFeatureDatasetNames();
                        if (setnames.Length == 0)
                            return;
                        fcMap = new Hashtable();
                        for (int j = 0; j < setnames.Length; j++)
                        {
                            IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[j]);
                            datasetCRS = dataset.SpatialReference;
          string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                            if (fcnames.Length == 0)
                                return;
                             foreach (string name in fcnames)
                            {
                                IFeatureClass fc = dataset.OpenFeatureClass(name);
                                // 找到空间列字段
                                List<string> geoNames = new List<string>();
                                IFieldInfoCollection fieldinfos = fc.GetFields();
                                 for (int i = 0; i < fieldinfos.Count; i++)
                                {
                                    IFieldInfo fieldinfo = fieldinfos.Get(i);
                                    if (null == fieldinfo)
                                        continue;
                                    IGeometryDef geometryDef = fieldinfo.GeometryDef;
                                    if (null == geometryDef)
                                        continue;
                                    geoNames.Add(fieldinfo.Name);
                                }
                                fcMap.Add(fc, geoNames);
                              }
                        }
                        
                  
                   
                    bool hasfly = false;
                    foreach (IFeatureClass fc in fcMap.Keys)
                    {
                        List<string> geoNames = (List<string>)fcMap[fc];
                        foreach (string geoName in geoNames)
                        {
                            if (!geoName.Equals("Geometry"))
                                continue;
                            IFeatureLayer featureLayer = this.axRenderControl.ObjectManager.CreateFeatureLayer(
                            fc, geoName, null, null, rootId);
                             IFieldInfoCollection fieldinfos = fc.GetFields();
                            IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                            IGeometryDef geometryDef = fieldinfo.GeometryDef;
                            env = geometryDef.Envelope;
                          //定位到元素
                            if (!hasfly)
                            {
                                
                                if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                    env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                                    continue;
                                IEulerAngle angle = new EulerAngle();
                                angle.Set(0, -20, 0);
                                if (geoFactory == null)
                                    geoFactory = new GeometryFactory();
                                IPoint pos = geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                                pos.SpatialCRS = datasetCRS;
                                pos.Position = env.Center;
                                this.axRenderControl.Camera.LookAt2(pos, 200, angle);
                            }
                            hasfly = true;
                        }

                    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

凡梦_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值