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;
}
}