using DevExpress.XtraEditors; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.DataSourcesRaster; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.Geometry; using KGIS.Framework.OpenData.Filter; using KGIS.Framework.OpenData.InterFace; using KGIS.Framework.Utils.Helper; using KGIS.Plugin.LayerProperty.Interface; using KGIS.Plugin.LayerProperty.Model; using System; using System.Text; namespace KGIS.Plugin.LayerProperty.View.UC_Controls { public partial class UCDataSourceProperty : XtraUserControl, IUCPropertyPageEx, IPropertyPage { private ILayer m_Layer; private string SRName; private int SRType; private ISpatialReference m_SpatialReference; private IRasterProperty m_RasterProperty; private IRasterDataset m_RasterDataset; private IFeatureClass SelectFC; private IRasterDataset selectRasterDs; private bool isDirty; public IUCPropertyPageEx ucFieldsPropertyPage; public UCDataSourceProperty() { InitializeComponent(); } public int Priority { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public string Title { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public bool IsPageDirty { get { return this.isDirty; } set { this.isDirty = value; } } public event System.EventHandler EditorChanged; public int Activate() { throw new NotImplementedException(); } public void Cancel() { throw new NotImplementedException(); } public bool CanWrite2Prop() { return true; } public void Deactivate() { throw new NotImplementedException(); } public void SetDefaultValue(object value) { } public void InitUC(object layerProperty) { try { if (layerProperty is ILayer) { this.m_Layer = (layerProperty as ILayer); } IGeoDataset geoDataset = this.m_Layer as IGeoDataset; if (geoDataset is IFeatureLayer) { this.groupControl1.Visible = false; SetMemCoordinateSysText((this.m_Layer as IFeatureLayer).FeatureClass); //this.GetGeoDatasetInfo(this.m_Layer as IGeoDataset); } else { if (this.m_Layer is IRasterLayer) { this.groupControl1.Visible = true; this.InitForm(((this.m_Layer as IRasterLayer).Raster as IRaster2).RasterDataset); } else { this.groupControl1.Visible = false; //this.GetGeoDatasetInfo(geoDataset); } } } catch (Exception ex) { //RdbUtil.AddException(ex); } } public void Write2Prop() { if (SelectFC != null) { (this.m_Layer as IFeatureLayer).FeatureClass = SelectFC; } if (selectRasterDs != null && this.m_Layer is IRasterLayer) { (m_Layer as IRasterLayer).CreateFromDataset(selectRasterDs); } } private StringBuilder GetDataSourceInfoByFC(IFeatureClass featureClass) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("数据类型:".PadRight(15) + (featureClass as FeatureClass).Category); if ((featureClass as FeatureClass).Workspace != null) { if ((featureClass as FeatureClass).Workspace.WorkspaceFactory.WorkspaceType == esriWorkspaceType.esriRemoteDatabaseWorkspace) { stringBuilder.AppendLine("服务器:".PadRight(16) + (featureClass as FeatureClass).Workspace.ConnectionProperties.GetProperty("Server".ToString())); stringBuilder.AppendLine("用户名:".PadRight(16) + (featureClass as FeatureClass).Workspace.ConnectionProperties.GetProperty("User".ToString())); stringBuilder.AppendLine("实例名:".PadRight(16) + (featureClass as FeatureClass).Workspace.ConnectionProperties.GetProperty("Instance".ToString())); stringBuilder.AppendLine("版本:".PadRight(17) + (featureClass as FeatureClass).Workspace.ConnectionProperties.GetProperty("Version".ToString())); } else { stringBuilder.AppendLine("数据位置:".PadRight(15) + (featureClass as FeatureClass).Workspace.PathName); } } if (featureClass.FeatureDataset != null) { stringBuilder.AppendLine("要素集:".PadRight(16) + featureClass.FeatureDataset.Name); } stringBuilder.AppendLine("数据要素类:".PadRight(14) + (featureClass as FeatureClass).Name); stringBuilder.AppendLine("要素类型:".PadRight(15) + featureClass.FeatureType.ToString().Substring(6)); stringBuilder.AppendLine("几何类型:".PadRight(15) + featureClass.ShapeType.ToString().Substring(12)); stringBuilder.AppendLine(""); return stringBuilder; } private void SetMemCoordinateSysText(IFeatureClass featureClass) { try { m_SpatialReference = (featureClass as IGeoDataset).SpatialReference; IEnvelope extent = (featureClass as IGeoDataset).Extent; //double xmin = 0; //double xmax = 0; //double ymin = 0; //double ymax = 0; //m_SpatialReference.GetDomain(out xmin, out xmax, out ymin, out ymax); //extent.XMin = xmin; //extent.XMax = xmax; //extent.YMin = ymin; //extent.YMax = ymax; this.ucExtentSet1.SetEnvelope(extent, true); } catch { } StringBuilder dataSourceInfo = GetDataSourceInfoByFC(featureClass); StringBuilder coordinateSystemInfo = Utils.Util.GetCoordinateSystemInfo(m_SpatialReference); dataSourceInfo.Append(coordinateSystemInfo); this.memCoordinateSys.Text = dataSourceInfo.ToString(); } private void InvokeEditValueChanged(object sender, System.EventArgs e) { if (this.EditorChanged != null) { this.EditorChanged(sender, e); } this.isDirty = true; } /// /// 设置数据源 /// /// /// private void BtnSetDataSource_Click(object sender, System.EventArgs e) { try { object obj = GetGisFileSource(); if (obj == null) return; if (obj is IFeatureClass) { SelectFC = obj as IFeatureClass; if (SelectFC != null && (SelectFC as IGeoDataset) != null) { if (!KGIS.Framework.AE.GeoDBAPI.SpatialReferenceCompare2((SelectFC as IGeoDataset).SpatialReference, null)) { MessageHelper.ShowTips("选择要素类与当前工程坐标参考不一致!"); return; } SetMemCoordinateSysText(SelectFC); InvokeEditValueChanged(sender, e); if (ucFieldsPropertyPage != null && ucFieldsPropertyPage is UCFieldsPropertyPage) { (ucFieldsPropertyPage as UCFieldsPropertyPage).InitFields(SelectFC.Fields); } } } else if (obj is IRasterDataset) { //修改人:李进营 修改时间:2018-09-19 增加栅格图层设置数据源无效问题 selectRasterDs = (obj as IRasterDataset); this.InitForm(selectRasterDs); InvokeEditValueChanged(sender, e); } } catch (Exception ex) { //RdbUtil.AddException(ex); } } private object GetGisFileSource() { try { KGIS.Framework.OpenData.Control.OpenDataDialog pDialog = new KGIS.Framework.OpenData.Control.OpenDataDialog(); ISpatialDataObjectFilter pOFilter; pOFilter = new FilterDatasetsAndLayers(); pDialog.AddFilter(pOFilter, true); pDialog.Title = "选择矢量图层数据"; pDialog.AllowMultiSelect = false; pDialog.RestoreLocation = true; pDialog.StartLocation = pDialog.FinalLocation; if (pDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK && pDialog.Selection.Count != 0) { foreach (ISpatialDataObject distObj in pDialog.Selection) { //修改人:李进营 修改时间:2018-09-19 修复栅格数据选区无效问题 if (distObj.DatasetType == esriDatasetType.esriDTFeatureClass || distObj.DatasetType == esriDatasetType.esriDTRasterDataset) { return (distObj.DatasetName as ESRI.ArcGIS.esriSystem.IName).Open(); } } } return null; } catch (Exception) { return null; } } private void InitForm(IRasterDataset pRasterDataset) { try { if (pRasterDataset != null) { this.m_RasterDataset = pRasterDataset; IDataset dataset = (IDataset)this.m_RasterDataset; ESRI.ArcGIS.Geodatabase.IWorkspace workspace = dataset.Workspace; if (workspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace) { this.m_RasterProperty = new RemoteRasterPropetry(this.m_RasterDataset); } else { this.m_RasterProperty = new LocalRasterPropetry(this.m_RasterDataset); } this.propertyRaster.SelectedObject = this.m_RasterProperty; this.propertyRaster.RetrieveFields(); } } catch (Exception) { } } } }