// 公共方法 void FeatureLayerVisualize(IConnectionInfo ci, bool needfly, string sourceName, ITextRender textRender, IGeometryRender geoRender) { IDataSourceFactory dsFactory = null; IDataSource ds = null; IFeatureDataSet dataset = null; try { dsFactory = new DataSourceFactory(); ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } dataset = ds.OpenFeatureDataset(setnames[0]); crs = dataset.SpatialReference; string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = new Hashtable(fcnames.Length); 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); } // CreateFeautureLayer bool hasfly = !needfly; foreach (IFeatureClass fcInMap in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fcInMap]; foreach (string geoName in geoNames) { IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fcInMap, geoName, textRender, geoRender, rootId); // 添加节点到界面控件上 object[] registeredFields = GetRegisteredRenderIndexFields(fcInMap); myListNode item = new myListNode(string.Format("{0}_{1}_{2}", sourceName, fcInMap.Name, featureLayer.MaxVisibleDistance.ToString()), featureLayer, registeredFields); item.Checked = true; listView1.Items.Add(item); layerFcMap.Add(featureLayer, fcInMap); IFieldInfoCollection fieldinfos = fcInMap.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; layerEnvelopeMap.Add(featureLayer, env); 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; } // 相机飞入 if (!hasfly) { angle.Set(0, -20, 0); IPoint pos = (new GeometryFactory()).CreatePoint(gviVertexAttribute.gviVertexAttributeZ); pos.SpatialCRS = crs; pos.Position = env.Center; this.axRenderControl1.Camera.LookAt2(pos, 1000, angle); } hasfly = true; } } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } catch (System.Exception e) { System.Diagnostics.Trace.WriteLine(e.Message); return; } finally { if (ds != null) { ds.Dispose(); ds = null; } if (dataset != null) { dataset.Dispose(); dataset = null; } //if (fc != null) //{ // fc.Dispose(); // fc = null; //} } }