public int TryCeateFeatureDataSet(IDataSource ds, string Name, ISpatialCRS SpatialCRS, out IFeatureDataSet dataset) { dataset = null; if (((ds == null) || string.IsNullOrEmpty(Name)) || (SpatialCRS == null)) { return(-1); } try { string[] featureDatasetNames = ds.GetFeatureDatasetNames(); if ((featureDatasetNames != null) && (Array.IndexOf <string>(featureDatasetNames, Name) != -1)) { dataset = ds.OpenFeatureDataset(Name); return(0); } dataset = ds.CreateFeatureDataset(Name, SpatialCRS); if (dataset == null) { return(-1); } return(1); } catch (Exception exception) { return(-1); } }
public void SetI3dObjectType() { crs = new CRSFactory().CreateFromWKT(_axRenderControl.GetCurrentCrsWKT()) as ISpatialCRS; //if (crs.CrsType == i3dCoordinateReferenceSystemType.i3dCrsGeographic) // TYPE = i3dObjectType.i3dObjectTerrain; //else if (crs.CrsType == i3dCoordinateReferenceSystemType.i3dCrsProject || crs.CrsType == i3dCoordinateReferenceSystemType.i3dCrsUnknown) // TYPE = i3dObjectType.i3dObjectReferencePlane; }
private void LoadLocalData() { try { ConnectionInfo ci = new ConnectionInfo { ConnectionType = i3dConnectionType.i3dConnectionFireBird2x }; string rootPath = Path.GetFullPath(@"..//..//.."); string tmpFDBPath = Path.Combine(rootPath, "data\\3dm\\1.3DM"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]); datasetCRS = dataset.SpatialReference; string[] fcnames = (string[])dataset.GetNamesByType(i3dDataSetType.i3dDataSetFeatureClassTable); 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); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } }
//public event Action<(string, NotationType)> SelectNotationFinished; public MapOperation() { _axRenderControl = new AxRenderControl(); _featureClassMapping = new Dictionary <IFeatureClass, List <string> >(); _featureLayerMaps = new List <FeatureLayerMap>(); _spatialCRS = new CRSFactory().CreateFromWKT(WKT) as ISpatialCRS; _geoFactory = new GeometryFactoryClass(); px = _geoFactory.CreatePoint(i3dVertexAttribute.i3dVertexAttributeZ); px.SpatialCRS = _spatialCRS; sb = new StringBuilder(); }
public MapOperation(AxRenderControl axRenderControl, string i3dmPath) { _axRenderControl = axRenderControl; _i3dmPath = i3dmPath; _spatialCRS = new CRSFactory().CreateFromWKT(WKT) as ISpatialCRS; gfactory = new GeometryFactory(); textAttribute = new TextAttribute() { TextColor = 0xffffff00, TextSize = 12, Underline = true, Font = "楷体" }; textSymbol = new TextSymbol() { TextAttribute = textAttribute, VerticalOffset = 10, DrawLine = true, MarginColor = 0x8800ffff }; }
/// <summary> /// 重投影 /// </summary> /// <param name="tagWKT"></param> bool ProjectCoord(IPoint p, string tagWKT) { ISpatialCRS tagCRS = (ISpatialCRS) new CRSFactory().CreateFromWKT(tagWKT); return(p.Project(tagCRS)); }
/// <summary> /// 初始化 /// </summary> private void init() { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); // Unknown this.axRenderControl1.Initialize(true, ps); rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 平面坐标系 //string wkt = @"PROJCS['Beijing_1954_3_Degree_GK_CM_102E',GEOGCS['GCS_Beijing_1954',DATUM['D_Beijing_1954',SPHEROID['Krasovsky_1940',6378245.0,298.3]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Gauss_Kruger'],PARAMETER['False_Easting',500000],PARAMETER['False_Northing',0],PARAMETER['Central_Meridian',102],PARAMETER['Scale_Factor',1],PARAMETER['Latitude_Of_Origin',0],UNIT['metre',1]]"; //this.axRenderControl1.Initialize2(wkt, ps); // 球面1 //this.axRenderControl1.Initialize(false, ps); // 球面2 //IGeographicCRS crs = new CRSFactory().CreateWGS84(); //this.axRenderControl1.Initialize2(crs.AsWKT(), ps); // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } #region 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]); datasetCRS = 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); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer 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.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; 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; } angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle); } hasfly = true; } } #endregion 加载FDB场景 this.axRenderControl1.Camera.FlyTime = 0; { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "ParticleEffect.html"; } }
public bool InitTemplateLib(IDataSource ds) { IFeatureDataSet dataset = null; IObjectClass oc = null; IFieldInfoCollection fields = null; string[] arrDBIndex = null; ICRSFactory o = null; ISpatialCRS spatialCRS = null; bool flag; string wKT = "UNKNOWNCS[\"unnamed\"]"; if (ds == null) { return(false); } try { o = new CRSFactoryClass(); spatialCRS = o.CreateFromWKT(wKT) as ISpatialCRS; if (spatialCRS != null) { if (DataProvider.Instance.TryCeateFeatureDataSet(ds, "DataSet_BIZ", spatialCRS, out dataset) == -1) { return(false); } Marshal.ReleaseComObject(dataset); if (!DataProvider.Instance.TryOpenFeatureDataSet(ds, "DataSet_BIZ", out dataset)) { return(false); } fields = DataModel.GetDataModel("OC_Catalog", out arrDBIndex); if (fields != null) { try { try { switch (DataProvider.Instance.TryCeateObjectClass(dataset, "OC_Catalog", fields, arrDBIndex, out oc)) { case -1: return(false); case 1: oc.AliasName = "设施类分类表"; Marshal.ReleaseComObject(oc); break; } } catch (Exception exception) { return(false); } goto Label_012C; } finally { Marshal.ReleaseComObject(fields); fields = null; } } } return(false); Label_012C: fields = DataModel.GetDataModel("OC_FieldConfig", out arrDBIndex); if (fields != null) { try { try { switch (DataProvider.Instance.TryCeateObjectClass(dataset, "OC_FieldConfig", fields, arrDBIndex, out oc)) { case -1: return(false); case 1: oc.AliasName = "设施类字段配置表"; Marshal.ReleaseComObject(oc); break; } } catch (Exception exception2) { return(false); } goto Label_01BE; } finally { Marshal.ReleaseComObject(fields); fields = null; } } return(false); Label_01BE: fields = DataModel.GetDataModel("OC_TopoManage", out arrDBIndex); if (fields != null) { try { try { switch (DataProvider.Instance.TryCeateObjectClass(dataset, "OC_TopoManage", fields, arrDBIndex, out oc)) { case -1: return(false); case 1: oc.AliasName = "拓扑管理表"; Marshal.ReleaseComObject(oc); break; } } catch (Exception exception3) { return(false); } goto Label_0250; } finally { Marshal.ReleaseComObject(fields); fields = null; } } return(false); Label_0250: fields = DataModel.GetDataModel("OC_FacilityStyle", out arrDBIndex); if (fields != null) { try { try { switch (DataProvider.Instance.TryCeateObjectClass(dataset, "OC_FacilityStyle", fields, arrDBIndex, out oc)) { case -1: return(false); case 1: oc.AliasName = "设施风格管理表"; Marshal.ReleaseComObject(oc); break; } } catch (Exception exception4) { return(false); } goto Label_02E2; } finally { Marshal.ReleaseComObject(fields); fields = null; } } return(false); Label_02E2: fields = DataModel.GetDataModel("OC_ModelInfo", out arrDBIndex); if (fields != null) { try { try { switch (DataProvider.Instance.TryCeateObjectClass(dataset, "OC_ModelInfo", fields, arrDBIndex, out oc)) { case -1: return(false); case 1: oc.AliasName = "模型管理表"; Marshal.ReleaseComObject(oc); break; } } catch (Exception exception5) { return(false); } goto Label_0374; } finally { Marshal.ReleaseComObject(fields); fields = null; } } return(false); Label_0374: fields = DataModel.GetDataModel("OC_ColorInfo", out arrDBIndex); if (fields != null) { try { try { switch (DataProvider.Instance.TryCeateObjectClass(dataset, "OC_ColorInfo", fields, arrDBIndex, out oc)) { case -1: return(false); case 1: oc.AliasName = "颜色管理表"; Marshal.ReleaseComObject(oc); break; } } catch (Exception exception6) { return(false); } goto Label_0406; } finally { Marshal.ReleaseComObject(fields); fields = null; } } return(false); Label_0406: fields = DataModel.GetDataModel("OC_TextureInfo", out arrDBIndex); if (fields != null) { try { try { switch (DataProvider.Instance.TryCeateObjectClass(dataset, "OC_TextureInfo", fields, arrDBIndex, out oc)) { case -1: return(false); case 1: oc.AliasName = "材质管理表"; Marshal.ReleaseComObject(oc); break; } } catch (Exception exception7) { return(false); } goto Label_0524; } finally { Marshal.ReleaseComObject(fields); fields = null; } } return(false); Label_0524: flag = true; } catch (Exception exception9) { flag = false; } finally { if (o != null) { Marshal.ReleaseComObject(o); o = null; } } return(flag); }
public bool InitPipeLib(IDataSource ds) { if (ds == null) { return(false); } IFeatureDataSet dataset = null; IObjectClass oc = null; IFieldInfoCollection fields = null; string[] arrDBIndex = null; try { //IDomainFactory o = null; //ICodedValueDomain domain = null; //string[] array = null; //o = new DomainFactoryClass(); //CRSFactoryClass crsFactory = new CRSFactoryClass(); //array = ds.GetDomainNames(); //if ((array == null) || (Array.IndexOf<string>(array, "Domain_GroupInfo") == -1)) //{ // domain = o.CreateCodedValueDomain("Domain_GroupInfo", gviFieldType.gviFieldInt32); // domain.Description = "逻辑图层分组"; // ds.AddDomain(domain); //} //Marshal.ReleaseComObject(o); CRSFactoryClass crsFactory = new CRSFactoryClass(); string wKT = "UNKNOWNCS[\"unnamed\"]"; ISpatialCRS spatialCRS = crsFactory.CreateFromWKT(wKT) as ISpatialCRS; if (spatialCRS != null) { if (DataProvider.Instance.TryCeateFeatureDataSet(ds, "DataSet_BIZ", spatialCRS, out dataset) == -1) { return(false); } dataset.Alias = "业务数据集"; Marshal.ReleaseComObject(dataset); if (DataProvider.Instance.TryCeateFeatureDataSet(ds, "DataSet_GEO_Actuality", spatialCRS, out dataset) == -1) { return(false); } dataset.Alias = "现状空间数据集"; Marshal.ReleaseComObject(dataset); if (!DataProvider.Instance.TryOpenFeatureDataSet(ds, "DataSet_BIZ".ToString(), out dataset)) { return(false); } fields = DataModel.GetDataModel("OC_FacilityClass", out arrDBIndex); if (fields != null) { switch (DataProvider.Instance.TryCeateObjectClass(dataset, "OC_FacilityClass", fields, arrDBIndex, out oc)) { case -1: return(false); case 1: oc.AliasName = "设施类注册表"; Marshal.ReleaseComObject(oc); return(true); } } } return(false); } catch (Exception exception4) { return(false); } }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } #region 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\MultiSpatialColumns.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]); projectCRS = dataset.SpatialReference as IProjectedCRS; string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = new Hashtable(fcnames.Length); fcGUIDMap = new Hashtable(fcnames.Length); foreach (string name in fcnames) { IFeatureClass fc = dataset.OpenFeatureClass(name); fcGUIDMap.Add(fc.Guid, fc); // 找到空间列字段 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); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer 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.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; 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 p = geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); p.Position = env.Center; p.SpatialCRS = fc.FeatureDataSet.SpatialReference; this.axRenderControl1.Camera.LookAt2(p, 1000, angle); } hasfly = true; } } #endregion if (crsFactory == null) { crsFactory = new CRSFactory(); } currentCRS = crsFactory.CreateFromWKT(this.axRenderControl1.GetCurrentCrsWKT()) as ISpatialCRS; this.axRenderControl1.HighlightHelper.VisibleMask = 1; }
private void DrawEnvelope(IEnvelope env, ISpatialCRS crs, out ArrayList rPolylineList) { rPolylineList = new ArrayList(); IPolyline polyline = new GeometryFactory().CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline; polyline.SpatialCRS = crs; IPoint point = new GeometryFactory().CreatePoint(gviVertexAttribute.gviVertexAttributeZ); point.SpatialCRS = crs; ISimplePointSymbol psy = new SimplePointSymbol(); psy.FillColor = System.Drawing.Color.Yellow; psy.Size = 10; ICurveSymbol cSymbol = new CurveSymbol(); cSymbol.Color = System.Drawing.Color.Yellow; cSymbol.Width = 2; point.SetCoords(env.MinX, env.MinY, env.MinZ, 0, 0); //0 //this.axRenderControl1.ObjectManager.CreateRenderPoint(point, psy); polyline.AppendPoint(point); point.SetCoords(env.MaxX, env.MinY, env.MinZ, 0, 1); //1 //this.axRenderControl1.ObjectManager.CreateRenderPoint(point, psy); polyline.AppendPoint(point); point.SetCoords(env.MaxX, env.MaxY, env.MinZ, 0, 2); //2 //this.axRenderControl1.ObjectManager.CreateRenderPoint(point, psy); polyline.AppendPoint(point); point.SetCoords(env.MinX, env.MaxY, env.MinZ, 0, 3); //3 //this.axRenderControl1.ObjectManager.CreateRenderPoint(point, psy); polyline.AppendPoint(point); point.SetCoords(env.MinX, env.MinY, env.MinZ, 0, 4); //0 polyline.AppendPoint(point); //close rPolylineList.Add(this.axRenderControl1.ObjectManager.CreateRenderPolyline(polyline, cSymbol, rootId)); polyline.SetEmpty(); point.SetCoords(env.MinX, env.MaxY, env.MaxZ, 0, 0); //4 //this.axRenderControl1.ObjectManager.CreateRenderPoint(point, psy); polyline.AppendPoint(point); point.SetCoords(env.MaxX, env.MaxY, env.MaxZ, 0, 0); //5 //this.axRenderControl1.ObjectManager.CreateRenderPoint(point, psy); polyline.AppendPoint(point); point.SetCoords(env.MaxX, env.MinY, env.MaxZ, 0, 0); //6 //this.axRenderControl1.ObjectManager.CreateRenderPoint(point, psy); polyline.AppendPoint(point); point.SetCoords(env.MinX, env.MinY, env.MaxZ, 0, 0); //7 //this.axRenderControl1.ObjectManager.CreateRenderPoint(point, psy); polyline.AppendPoint(point); point.SetCoords(env.MinX, env.MaxY, env.MaxZ, 0, 0); //4 polyline.AppendPoint(point); //close rPolylineList.Add(this.axRenderControl1.ObjectManager.CreateRenderPolyline(polyline, cSymbol, rootId)); polyline.SetEmpty(); point.SetCoords(env.MinX, env.MinY, env.MinZ, 0, 0); //0 polyline.AppendPoint(point); point.SetCoords(env.MinX, env.MinY, env.MaxZ, 0, 0); //7 polyline.AppendPoint(point); rPolylineList.Add(this.axRenderControl1.ObjectManager.CreateRenderPolyline(polyline, cSymbol, rootId)); polyline.SetEmpty(); point.SetCoords(env.MaxX, env.MinY, env.MinZ, 0, 0); //1 polyline.AppendPoint(point); point.SetCoords(env.MaxX, env.MinY, env.MaxZ, 0, 0); //6 polyline.AppendPoint(point); rPolylineList.Add(this.axRenderControl1.ObjectManager.CreateRenderPolyline(polyline, cSymbol, rootId)); polyline.SetEmpty(); point.SetCoords(env.MaxX, env.MaxY, env.MinZ, 0, 0); //2 polyline.AppendPoint(point); point.SetCoords(env.MaxX, env.MaxY, env.MaxZ, 0, 0); //5 polyline.AppendPoint(point); rPolylineList.Add(this.axRenderControl1.ObjectManager.CreateRenderPolyline(polyline, cSymbol, rootId)); polyline.SetEmpty(); point.SetCoords(env.MinX, env.MaxY, env.MinZ, 0, 0); //3 polyline.AppendPoint(point); point.SetCoords(env.MinX, env.MaxY, env.MaxZ, 0, 0); //4 polyline.AppendPoint(point); rPolylineList.Add(this.axRenderControl1.ObjectManager.CreateRenderPolyline(polyline, cSymbol, rootId)); }
// 公共方法 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; //} } }
private bool InitTempLib(IDataSource ds) { if (ds == null) { return(false); } IFieldInfoCollection fields = null; IFieldInfo newVal = null; ISpatialCRS spatialCRS = null; ITable o = null; IFeatureDataSet set = null; try { fields = new FieldInfoCollectionClass(); newVal = new FieldInfoClass { Name = "ID", Alias = "编号", FieldType = gviFieldType.gviFieldFID }; fields.Add(newVal); newVal = new FieldInfoClass { Name = "LayerName", Alias = "图层名称", FieldType = gviFieldType.gviFieldString, Length = 50 }; fields.Add(newVal); newVal = new FieldInfoClass { Name = "DataSetName", Alias = "数据集名称", FieldType = gviFieldType.gviFieldString, Length = 100 }; fields.Add(newVal); newVal = new FieldInfoClass { Name = "FCName", Alias = "要素类名称", FieldType = gviFieldType.gviFieldString, Length = 100 }; fields.Add(newVal); newVal = new FieldInfoClass { Name = "FCGuid", Alias = "要素类GUID", FieldType = gviFieldType.gviFieldString, Length = 100 }; fields.Add(newVal); newVal = new FieldInfoClass { Name = "GeoType", Alias = "空间列几何类型", FieldType = gviFieldType.gviFieldString, Length = 50 }; fields.Add(newVal); newVal = new FieldInfoClass { Name = "RenderStyle", Alias = "图层渲染样式", FieldType = gviFieldType.gviFieldBlob }; fields.Add(newVal); newVal = new FieldInfoClass { Name = "SourceFile", Alias = "数据来源", FieldType = gviFieldType.gviFieldString, Length = 150 }; fields.Add(newVal); newVal = new FieldInfoClass { Name = "GroupId", Alias = "逻辑组ID", FieldType = gviFieldType.gviFieldInt32 }; fields.Add(newVal); newVal = new FieldInfoClass { Name = "SourceType", Alias = "数据来源类型", FieldType = gviFieldType.gviFieldString, Length = 50 }; fields.Add(newVal); newVal = new FieldInfoClass { Name = "CreateDate", Alias = "创建日期", FieldType = gviFieldType.gviFieldDate }; fields.Add(newVal); o = ds.CreateTable("Tb_TemporaryMgr", "ID", fields); if (o != null) { IDbIndexInfo index = null; index = new DbIndexInfoClass { Name = string.Format("{0}_{1}", "Tb_TemporaryMgr", "LayerName") }; index.AppendFieldDefine("LayerName", false); o.AddDbIndex(index); index = new DbIndexInfoClass { Name = string.Format("{0}_{1}", "Tb_TemporaryMgr", "DatasetName") }; index.AppendFieldDefine("DatasetName", false); o.AddDbIndex(index); index = new DbIndexInfoClass { Name = string.Format("{0}_{1}", "Tb_TemporaryMgr", "FCName") }; index.AppendFieldDefine("FCName", false); o.AddDbIndex(index); index = new DbIndexInfoClass { Name = string.Format("{0}_{1}", "Tb_TemporaryMgr", "FCGuid") }; index.AppendFieldDefine("FCGuid", false); o.AddDbIndex(index); index = new DbIndexInfoClass { Name = string.Format("{0}_{1}", "Tb_TemporaryMgr", "GeoType") }; index.AppendFieldDefine("GeoType", false); o.AddDbIndex(index); index = new DbIndexInfoClass { Name = string.Format("{0}_{1}", "Tb_TemporaryMgr", "GroupId") }; index.AppendFieldDefine("GroupId", false); o.AddDbIndex(index); index = new DbIndexInfoClass { Name = string.Format("{0}_{1}", "Tb_TemporaryMgr", "SourceType") }; index.AppendFieldDefine("SourceType", false); o.AddDbIndex(index); Marshal.ReleaseComObject(o); } CRSFactory factory = new CRSFactoryClass(); spatialCRS = factory.CreateFromWKT("UNKNOWNCS[\"unnamed\"]") as ISpatialCRS; set = ds.CreateFeatureDataset("FeatureDataSet", spatialCRS); if (set != null) { Marshal.ReleaseComObject(set); } return(true); } catch (Exception exception) { return(false); } }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; ICRSFactory crsfac = new CRSFactory(); _currentCRS = (crsfac.CreateFromWKT(this.axRenderControl1.GetCurrentCrsWKT())) as ISpatialCRS; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } this.axRenderControl1.Camera.FlyTime = 0; // 加载瓦片图层 string tilelayerString = (strMediaPath + @"\sdk.tdb"); I3DTileLayer layer = this.axRenderControl1.ObjectManager.Create3DTileLayer(tilelayerString, "", rootId); this.axRenderControl1.Camera.FlyToObject(layer.Guid, gviActionCode.gviActionFlyTo); // 添加节点到界面控件上 myListNode item = new myListNode("tilelayer", TreeNodeType.NT_TiltedLAYER, layer); item.Checked = true; listView1.Items.Add(item); #region 加载FDB try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]); _datasetCRS = dataset.SpatialReference; //遍历FeatureClass string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = new Hashtable(fcnames.Length); fcuidMap = 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; } if (geometryDef.GeometryColumnType == gviGeometryColumnType.gviGeometryColumnPolygon) { geoNames.Add(fieldinfo.Name); } } fcMap.Add(fc, geoNames); fcuidMap.Add(fc.Guid, fc); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } #endregion //CreateFeautureLayer for 矢量贴地 foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; if (geoNames.Count == 0) { continue; } #region 定义几何物体渲染风格 ICurveSymbol cs = new CurveSymbol(); cs.Color = System.Drawing.Color.Empty; //防止贴瓦片时出现绿色竖边 IValueMapGeometryRender geoRender = new ValueMapGeometryRender(); { IRangeRenderRule rangeRule = new RangeRenderRule(); rangeRule.LookUpField = "oid"; rangeRule.MaxValue = 1100; rangeRule.MinValue = 1000; rangeRule.IncludeMin = false; ISurfaceSymbol geoSymbol = new SurfaceSymbol(); geoSymbol.Color = System.Drawing.Color.Yellow; geoSymbol.BoundarySymbol = cs; IGeometryRenderScheme grs = new GeometryRenderScheme(); grs.AddRule(rangeRule); grs.Symbol = geoSymbol; geoRender.AddScheme(grs); } { IRangeRenderRule rangeRule = new RangeRenderRule(); rangeRule.LookUpField = "oid"; rangeRule.MaxValue = 1200; rangeRule.MinValue = 1100; rangeRule.IncludeMin = false; ISurfaceSymbol geoSymbol = new SurfaceSymbol(); geoSymbol.Color = System.Drawing.Color.Blue; geoSymbol.BoundarySymbol = cs; IGeometryRenderScheme grs = new GeometryRenderScheme(); grs.AddRule(rangeRule); grs.Symbol = geoSymbol; geoRender.AddScheme(grs); } { IRangeRenderRule rangeRule = new RangeRenderRule(); rangeRule.LookUpField = "oid"; rangeRule.MaxValue = 1300; rangeRule.MinValue = 1200; rangeRule.IncludeMin = false; ISurfaceSymbol geoSymbol = new SurfaceSymbol(); geoSymbol.Color = System.Drawing.Color.Green; geoSymbol.BoundarySymbol = cs; IGeometryRenderScheme grs = new GeometryRenderScheme(); grs.AddRule(rangeRule); grs.Symbol = geoSymbol; geoRender.AddScheme(grs); } { IRangeRenderRule rangeRule = new RangeRenderRule(); rangeRule.LookUpField = "oid"; rangeRule.MaxValue = 1400; rangeRule.MinValue = 1300; rangeRule.IncludeMin = false; ISurfaceSymbol geoSymbol = new SurfaceSymbol(); geoSymbol.Color = System.Drawing.Color.Goldenrod; geoSymbol.BoundarySymbol = cs; IGeometryRenderScheme grs = new GeometryRenderScheme(); grs.AddRule(rangeRule); grs.Symbol = geoSymbol; geoRender.AddScheme(grs); } { ISurfaceSymbol geoSymbol = new SurfaceSymbol(); geoSymbol.Color = System.Drawing.Color.Fuchsia; geoSymbol.BoundarySymbol = cs; IGeometryRenderScheme geoSchemeOther = new GeometryRenderScheme(); geoSchemeOther.Symbol = geoSymbol; geoRender.AddScheme(geoSchemeOther); } #endregion geoRender.HeightStyle = gviHeightStyle.gviHeightOnEverything; IFeatureLayer fcLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoNames[0], null, geoRender, rootId); if (fcLayer != null) { fcLayer.VisibleMask = gviViewportMask.gviViewNone; // 添加节点到界面控件上 myListNode item2 = new myListNode(fc.Name + "_" + geoNames[0], TreeNodeType.NT_FeatureLayer, fcLayer); item.Checked = false; listView1.Items.Add(item2); } else { MessageBox.Show("Create FeatureLayer Failed! " + this.axRenderControl1.GetLastError().ToString()); } } // 注册事件 this.axRenderControl1.RcMouseClickSelect += new Gvitech.CityMaker.Controls._IRenderControlEvents_RcMouseClickSelectEventHandler(axRenderControl1_RcMouseClickSelect); //设置highlight可用 this.axRenderControl1.HighlightHelper.VisibleMask = 1; { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "TileHole.html"; } }
private void DrawBox() { try { IPolyline line = this._drawTool.GetGeo() as IPolyline; if (line == null || line.PointCount != 2) { return; } DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } if (this._renderBox != null) { app.Current3DMapControl.ObjectManager.DeleteObject(this._renderBox.Guid); this._renderBox = null; } if (this._renderPolygon != null) { app.Current3DMapControl.ObjectManager.DeleteObject(this._renderPolygon.Guid); this._renderPolygon = null; } double middleZ = (line.StartPoint.Z + line.EndPoint.Z) / 2; double minZ = middleZ + (double)this.seMinHeight.Value; double maxZ = middleZ + (double)this.seMaxHeight.Value; IPoint startPoint = line.StartPoint; IPoint endPoint = line.EndPoint; IEulerAngle ang = app.Current3DMapControl.Camera.GetAimingAngles2(startPoint, endPoint); IEulerAngle angcz = new EulerAngle(); angcz.Set(ang.Heading - 90, ang.Tilt, ang.Roll); IPoint pt1 = app.Current3DMapControl.Camera.GetAimingPoint2(startPoint, angcz, this.tbcClipDis.Value); IPoint pt2 = app.Current3DMapControl.Camera.GetAimingPoint2(endPoint, angcz, this.tbcClipDis.Value); ICRSFactory crsFact = new CRSFactory(); ISpatialCRS crs = crsFact.CreateFromWKT(app.Current3DMapControl.GetCurrentCrsWKT()) as ISpatialCRS; IGeometryFactory geoFact = new GeometryFactoryClass(); IPoint pointb1 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); pointb1.SpatialCRS = crs; pointb1.SetCoords(startPoint.X, startPoint.Y, minZ, 0, 0); IPoint pointb2 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); pointb2.SpatialCRS = crs; pointb2.SetCoords(endPoint.X, endPoint.Y, minZ, 0, 0); IPoint pointb3 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); pointb3.SpatialCRS = crs; pointb3.SetCoords(pt2.X, pt2.Y, minZ, 0, 0); IPoint pointb4 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); pointb1.SpatialCRS = crs; pointb4.SetCoords(pt1.X, pt1.Y, minZ, 0, 0); IPolygon polygonBottom = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon; polygonBottom.SpatialCRS = crs; polygonBottom.ExteriorRing.AppendPoint(pointb1); polygonBottom.ExteriorRing.AppendPoint(pointb2); polygonBottom.ExteriorRing.AppendPoint(pointb3); polygonBottom.ExteriorRing.AppendPoint(pointb4); IPoint pointt1 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); pointt1.SpatialCRS = crs; pointt1.SetCoords(startPoint.X, startPoint.Y, maxZ, 0, 0); IPoint pointt2 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); pointt2.SpatialCRS = crs; pointt2.SetCoords(endPoint.X, endPoint.Y, maxZ, 0, 0); IPoint pointt3 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); pointt3.SpatialCRS = crs; pointt3.SetCoords(pt2.X, pt2.Y, maxZ, 0, 0); IPoint pointt4 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); pointt4.SpatialCRS = crs; pointt4.SetCoords(pt1.X, pt1.Y, maxZ, 0, 0); IPolygon polygonTop = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon; polygonTop.SpatialCRS = crs; polygonTop.ExteriorRing.AppendPoint(pointt1); polygonTop.ExteriorRing.AppendPoint(pointt2); polygonTop.ExteriorRing.AppendPoint(pointt3); polygonTop.ExteriorRing.AppendPoint(pointt4); IPolygon polygon1 = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon; polygon1.SpatialCRS = crs; polygon1.ExteriorRing.AppendPoint(pointb1); polygon1.ExteriorRing.AppendPoint(pointb2); polygon1.ExteriorRing.AppendPoint(pointt2); polygon1.ExteriorRing.AppendPoint(pointt1); IPolygon polygon2 = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon; polygon2.SpatialCRS = crs; polygon2.ExteriorRing.AppendPoint(pointb1); polygon2.ExteriorRing.AppendPoint(pointb4); polygon2.ExteriorRing.AppendPoint(pointt4); polygon2.ExteriorRing.AppendPoint(pointt1); IPolygon polygon3 = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon; polygon3.SpatialCRS = crs; polygon3.ExteriorRing.AppendPoint(pointb2); polygon3.ExteriorRing.AppendPoint(pointb3); polygon3.ExteriorRing.AppendPoint(pointt3); polygon3.ExteriorRing.AppendPoint(pointt2); IPolygon polygon4 = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon; polygon4.SpatialCRS = crs; polygon4.ExteriorRing.AppendPoint(pointb3); polygon4.ExteriorRing.AppendPoint(pointb4); polygon4.ExteriorRing.AppendPoint(pointt4); polygon4.ExteriorRing.AppendPoint(pointt3); IMultiPolygon multiPolygon = geoFact.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon; multiPolygon.SpatialCRS = crs; multiPolygon.AddPolygon(polygonBottom); multiPolygon.AddPolygon(polygonTop); //multiPolygon.AddPolygon(polygon1); multiPolygon.AddPolygon(polygon2); multiPolygon.AddPolygon(polygon3); multiPolygon.AddPolygon(polygon4); ISurfaceSymbol ss = new SurfaceSymbolClass(); ss.Color = 0x550000AA; ICurveSymbol cs = new CurveSymbolClass(); cs.Color = 0xff0000AA; ss.BoundarySymbol = cs; this._renderPolygon = app.Current3DMapControl.ObjectManager.CreateRenderPolygon(polygon1, ss, app.Current3DMapControl.ProjectTree.RootID); ISurfaceSymbol ss1 = new SurfaceSymbolClass(); ss1.Color = 0x88FFFFFF; ICurveSymbol cs1 = new CurveSymbolClass(); cs1.Color = 0xffffffff; ss1.BoundarySymbol = cs1; this._renderBox = app.Current3DMapControl.ObjectManager.CreateRenderMultiPolygon(multiPolygon, ss1, app.Current3DMapControl.ProjectTree.RootID); _env = null; _ang = null; _center = null; _env = new EnvelopeClass(); double xdis = Math.Sqrt((pointb1.X - pointb2.X) * (pointb1.X - pointb2.X) + (pointb1.Y - pointb2.Y) * (pointb1.Y - pointb2.Y)) / 2; double ydis = Math.Sqrt((pointb1.X - pointb4.X) * (pointb1.X - pointb4.X) + (pointb1.Y - pointb4.Y) * (pointb1.Y - pointb4.Y)) / 2; _env.MinZ = -ydis; _env.MaxZ = ydis; _env.MinX = -xdis; _env.MaxX = xdis; _env.MinY = -(maxZ - minZ) / 2.0; _env.MaxY = (maxZ - minZ) / 2.0; _center = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); _center.SpatialCRS = crs; _center.X = polygonBottom.Centroid.X; _center.Y = polygonBottom.Centroid.Y; _center.Z = polygon1.Centroid.Z; _ang = new EulerAngleClass(); _ang.Set(angcz.Heading, 0, 0); } catch (Exception ex) { } }
/// <summary> /// 初始化 /// </summary> private void init() { IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; axRenderControl1.Camera.FlyTime = 1; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); skybox = this.axRenderControl1.ObjectManager.GetSkyBox(1); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\2_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\2_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\2_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\2_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\2_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\2_UP.jpg"); skybox = this.axRenderControl1.ObjectManager.GetSkyBox(2); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\04_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\04_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\04_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\04_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\04_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\04_UP.jpg"); skybox = this.axRenderControl1.ObjectManager.GetSkyBox(3); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\9_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\9_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\9_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\9_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\9_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\9_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } #region 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]); _datasetCRS = 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); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer 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.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; 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); IPoint point = new GeometryFactory().CreatePoint(gviVertexAttribute.gviVertexAttributeZ); point.SpatialCRS = _datasetCRS; point.SetCoords(env.Center.X, env.Center.Y, env.Center.Z, 0, 0); this.axRenderControl1.Camera.LookAt2(point, 500, angle); } hasfly = true; } } #endregion 加载FDB场景 { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "MultipleScreen.html"; } }
/// <summary> /// 初始化 /// </summary> private void init() { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(false, ps); rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; this.axRenderControl1.Camera.FlyTime = 1; #region 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]); datasetCRS = 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); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer 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.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); featureLayer.MouseSelectMask = gviViewportMask.gviViewNone; if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; 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.axRenderControl1.Camera.LookAt2(pos, 1000, angle); } hasfly = true; } } #endregion 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionShapeFile; string tmpShpPath = (strMediaPath + @"\shp\Singapore\BCA_EXISTING_BUILDING.shp"); ci.Database = tmpShpPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]); shpCRS = dataset.SpatialReference; string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } IFeatureClass fc = dataset.OpenFeatureClass(fcnames[0]); this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, "Geometry", null, null, rootId); } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } this.axRenderControl1.InteractMode = gviInteractMode.gviInteractSelect; this.axRenderControl1.MouseSelectObjectMask = gviMouseSelectObjectMask.gviSelectFeatureLayer; this.axRenderControl1.MouseSelectMode = gviMouseSelectMode.gviMouseSelectClick; this.axRenderControl1.RcMouseClickSelect += new _IRenderControlEvents_RcMouseClickSelectEventHandler(axRenderControl1_RcMouseClickSelect); { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "SpatialQuery.html"; } }