public void Load(ESRI.ArcGIS.Geodatabase.IWorkspace Workspace, ESRI.ArcGIS.Geodatabase.IFeature Feature, BaseModel BaseModel, ModelProperty Property) { object[] _parametros = { (object)Workspace }; EntityManyToManyFieldAttribute _attribute = (EntityManyToManyFieldAttribute)Property.Attribute; BaseModel _mtmField = (BaseModel)Activator.CreateInstance(_attribute.RelateModelType, _parametros); string _KeyObj = Feature.get_Value(Feature.Fields.FindField(BaseModel.KeyField)).ToString(); Int32 _keyValue = !String.IsNullOrEmpty(_KeyObj) ? Convert.ToInt32(_KeyObj) : 0; if (_keyValue > 0) { var _source = _mtmField.Search(_attribute.FromFieldName + "=" + _keyValue, BaseModel.LoadMethod.Lazy); IList _target = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(_attribute.TargetModelType)); foreach (BaseModel _item in _source) { BaseModel _itemTarget = (BaseModel)Activator.CreateInstance(_attribute.TargetModelType, _parametros); PropertyInfo _entityTarget = _item.ModelProperties.Where(x => { return(_attribute.ToFieldName.Split('.')[1].Equals(((System.Reflection.MemberInfo)x.Property).Name)); }).Single().Property; _itemTarget.Load((int)_entityTarget.GetValue(_item, null)); _target.Add(_itemTarget); } Property.Property.SetValue(BaseModel, _target, null); } }
public void Load(ESRI.ArcGIS.Geodatabase.IWorkspace Workspace, ESRI.ArcGIS.Geodatabase.IRow Row, BaseModel BaseModel, ModelProperty Property, BaseModel.LoadMethod ChooseLoadMethod) { if (BaseModel.LoadMethod.Lazy == ChooseLoadMethod) { return; } this.Load(Workspace, Row, BaseModel, Property); }
/// <summary> /// 创建要素工作空间 /// </summary> /// <param name="MDBPath"></param> /// <returns></returns> public static ESRI.ArcGIS.Geodatabase.IFeatureWorkspace CreateAeWorkspace(string MDBPath) { ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass pwsf = new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass(); string mdbparentPath = System.IO.Path.GetDirectoryName(MDBPath); string mdbName = System.IO.Path.GetFileNameWithoutExtension(MDBPath); pwsf.Create(mdbparentPath, mdbName, null, 0); ESRI.ArcGIS.Geodatabase.IWorkspace targetWorkspace = pwsf.OpenFromFile(MDBPath, 0); System.Runtime.InteropServices.Marshal.ReleaseComObject(pwsf); return(targetWorkspace as ESRI.ArcGIS.Geodatabase.IFeatureWorkspace); }
/// <summary> /// 将workspace 转换为 IWorkspaceName /// </summary> /// <param name="pWs"></param> /// <returns></returns> private static ESRI.ArcGIS.Geodatabase.IWorkspaceName GetWorkspaceName(ESRI.ArcGIS.Geodatabase.IWorkspace pWs) { try { ESRI.ArcGIS.Geodatabase.IDataset pDs = pWs as ESRI.ArcGIS.Geodatabase.IDataset; return((ESRI.ArcGIS.Geodatabase.IWorkspaceName)pDs.FullName);; } catch (Exception ex) { return(null); } }
public void Delete(ESRI.ArcGIS.Geodatabase.IWorkspace Workspace, BaseModel BaseModel, ModelProperty _property) { ModelProperty _mpChaveFromField = BaseModel.ModelProperties.Where(x => x.Attribute is EntityKeyFieldAttribute).First(); int chave = (int)BaseModel.GetType().GetProperty(_mpChaveFromField.Property.Name).GetValue(BaseModel, null); object[] _parametros = { (object)Workspace }; EntityManyToManyFieldAttribute _attribute = (EntityManyToManyFieldAttribute)_property.Attribute; BaseModel _mtmField = (BaseModel)Activator.CreateInstance(_attribute.TargetModelType, _parametros); BaseModel _relateField = (BaseModel)Activator.CreateInstance(_attribute.RelateModelType, _parametros); _relateField.Delete(_attribute.FromFieldName + "=" + chave); }
public override void OnCreate(Plugin.Application.IApplicationRef hook) { _hook = hook as Plugin.Application.IAppFormRef; if (_hook == null) { return; } Plugin.Application.IAppFormRef pAppFormRef = _hook as Plugin.Application.IAppFormRef; ESRI.ArcGIS.Geodatabase.IWorkspace pWks = pAppFormRef.TempWksInfo.Wks; //启动数据更新子系统同时连接数据库(配置) if (ModData.v_SysDataSet == null) { //生成数据库操作对象 ModData.v_SysDataSet = new SysGisDataSet(); ModData.v_SysDataSet.WorkSpace = pWks; ModData.Server = pAppFormRef.TempWksInfo.Server; ModData.Instance = pAppFormRef.TempWksInfo.Service; ModData.Database = pAppFormRef.TempWksInfo.DataBase; ModData.User = pAppFormRef.TempWksInfo.User; ModData.Password = pAppFormRef.TempWksInfo.PassWord; ModData.Version = pAppFormRef.TempWksInfo.Version; ModData.dbType = pAppFormRef.TempWksInfo.DBType; } //权限控制入口 ModData.v_AppGisUpdate = new Plugin.Application.AppGidUpdate(_hook.MainForm, _hook.ControlContainer, _hook.ListUserPrivilegeID, _hook.SystemXml, _hook.DataTreeXml, _hook.DatabaseInfoXml, _hook.ColParsePlugin, _hook.ImageResPath, _hook.ConnUser); //ModData.v_AppGisUpdate = new Plugin.Application.AppGidUpdate(_hook.MainForm, _hook.ControlContainer, _hook.SystemXml, _hook.DataTreeXml, _hook.DatabaseInfoXml, _hook.ColParsePlugin, _hook.ImageResPath, _hook.ConnUser); ModData.v_AppGisUpdate.MyDocument = new System.Drawing.Printing.PrintDocument(); ModData.v_AppGisUpdate.CurWksInfo = pAppFormRef.TempWksInfo; m_TrackCancel = new CancelTrackerClass(); ModData.v_AppGisUpdate.MyDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(MyDocument_PrintPage); _UserControl = new UserControlSMPD(this.Name, this.Caption); _hook.MainForm.Controls.Add(_UserControl); _hook.MainForm.Controls.Add(ModData.v_AppGisUpdate.StatusBar); ModData.v_AppGisUpdate.UserInfo = "当前登录: " + _hook.ConnUser.TrueName; _hook.MainForm.FormClosing += new System.Windows.Forms.FormClosingEventHandler(MainForm_FormClosing); //cyf 20110615 add:添加比例尺窗口事件 ModData.v_AppGisUpdate.RefScaleCmb.SelectedIndexChanged += new EventHandler(RefScaleCmb_SelectedIndexChanged); ModData.v_AppGisUpdate.CurScaleCmb.SelectedIndexChanged += new EventHandler(CurScaleCmb_SelectedIndexChanged); //添加回车事件自定义比例尺 DevComponents.DotNetBar.Controls.ComboBoxEx vComboEx = ModData.v_AppGisUpdate.CurScaleCmb.ComboBoxEx; vComboEx.KeyDown += new KeyEventHandler(vComboEx_KeyDown); }
public ESRI.ArcGIS.Geodatabase.IFeatureClass CreateFeatureClass(string name, ESRI.ArcGIS.Geometry.ISpatialReference spatialReference, string workspacename) { ESRI.ArcGIS.Geodatabase.IWorkspace w = WorkSpace.CreateInMemoryWorkspace(workspacename); ESRI.ArcGIS.Geodatabase.IFeatureWorkspace fw = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)w; ESRI.ArcGIS.Geodatabase.IFields2 fields = CreateFields(spatialReference); ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UID(); ESRI.ArcGIS.Geodatabase.IFeatureClassDescription fcDesc = new ESRI.ArcGIS.Geodatabase.FeatureClassDescriptionClass(); ESRI.ArcGIS.Geodatabase.IObjectClassDescription ocDesc = (ESRI.ArcGIS.Geodatabase.IObjectClassDescription)fcDesc; ESRI.ArcGIS.Geodatabase.IFeatureClass fc = fw.CreateFeatureClass(name, fields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, "Shape", ""); return(fc); }
private void ChooseSource(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { if (dlgSource.ShowDialog() == DialogResult.OK) { try { m_WsSource = (new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass()).OpenFromFile(dlgSource.FileName, 0); txtSource.Text = dlgSource.FileName; } catch { XtraMessageBox.Show("不是正确的PGDB数据库,请重选"); ChooseSource(sender, e); } } }
private void btnDownload_Click(object sender, EventArgs e) { if (!checkInputs()) { MessageBox.Show("You must have a value for all inputs"); return; } mapserviceutility msUtil = new mapserviceutility(); geoDatabaseUtility geoUtil = new geoDatabaseUtility(); IImageServerLayer svLyr = getServerLayer(); ESRI.ArcGIS.Geometry.IEnvelope ext = new ESRI.ArcGIS.Geometry.EnvelopeClass(); if (cmbExtent.Text.ToLower() == "display") { ext = av.Extent; } else { IFeatureLayer ftrLyr = getFeatureLayer(); ext = ((ESRI.ArcGIS.Geodatabase.IGeoDataset)ftrLyr).Extent; } if (svLyr == null) { MessageBox.Show("You must select a Image server layer"); return; } this.Visible = false; ESRI.ArcGIS.Geodatabase.IWorkspace wks = geoUtil.OpenWorkSpace(txtGeoDb.Text); ESRI.ArcGIS.Geodatabase.IRaster rs = null; string msg = msUtil.fillDbRaster(svLyr, wks, ext, svLyr.ServiceInfo.SpatialReference, out rs); IMap mp = (IMap)av; if (rs != null) { IRasterLayer rsLyr = new RasterLayerClass(); rsLyr.CreateFromRaster(rs); rsLyr.Name = svLyr.ServiceInfo.Name; rsLyr.Visible = false; mp.AddLayer((ILayer)rsLyr); } this.Close(); //MessageBox.Show(msg); }
internal static ESRI.ArcGIS.Geodatabase.IWorkspace CreateInMemoryWorkspace(string workspacename) { // Create an in-memory workspace factory. Type factoryType = Type.GetTypeFromProgID( "esriDataSourcesGDB.InMemoryWorkspaceFactory"); ESRI.ArcGIS.Geodatabase.IWorkspaceFactory workspaceFactory = (ESRI.ArcGIS.Geodatabase.IWorkspaceFactory) Activator.CreateInstance(factoryType); // Create an in-memory workspace. ESRI.ArcGIS.Geodatabase.IWorkspaceName workspaceName = workspaceFactory.Create("", workspacename, null, 0); // Cast for IName and open a reference to the in-memory workspace through the name object. ESRI.ArcGIS.esriSystem.IName name = (ESRI.ArcGIS.esriSystem.IName)workspaceName; ESRI.ArcGIS.Geodatabase.IWorkspace workspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)name.Open(); return(workspace); }
protected override bool ImportToBase(ref ESRI.ArcGIS.Geodatabase.IWorkspace wsBase) { // Hy.Common.Utility.Esri.AEAccessFactory.CreateFGDB(this.m_TargetPath, COMMONCONST.DB_Name_Base,ref wsBase); // VctReaderClass vctReader = new VctReaderClass(); // vctReader.VctFile = this.m_Datasource; //// vctReader.SpatialReference = this.m_SpatialReference; // vctReader.ProgressStep += new _IVctReaderEvents_ProgressStepEventHandler(VCTReader_ProgressStep); // //执行转换 // m_ObjectCount = vctReader.LayerCount; // bool isSucceed = vctReader.ConvertToWorkspace(wsBase); // System.Runtime.InteropServices.Marshal.ReleaseComObject(vctReader); // if (!isSucceed) // { // if (m_Messager != null) // m_Messager(enumMessageType.Exception, "转换VCT时出错"); // return false; // } return(true); }
/// <summary> /// 从工作空间下获取到pFeatureClassName对应的 IDatasetName /// </summary> /// <param name="pWs"></param> /// <param name="pFeatureClassName"></param> /// <returns></returns> public static ESRI.ArcGIS.Geodatabase.IDatasetName GetDatasetName(ESRI.ArcGIS.Geodatabase.IWorkspace pWs, string pFeatureClassName) { try { ESRI.ArcGIS.Geodatabase.IEnumDatasetName pDsName = pWs.get_DatasetNames(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTAny); ESRI.ArcGIS.Geodatabase.IDatasetName pDsSetName = pDsName.Next(); while (pDsSetName != null) { //遍历FeatureDataset if (pDsSetName.Type == ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureDataset) { ESRI.ArcGIS.Geodatabase.IEnumDatasetName pDsFtName = pDsSetName.SubsetNames; ESRI.ArcGIS.Geodatabase.IDatasetName pDsSetName1 = pDsFtName.Next(); while (pDsSetName1 != null) { if (pDsSetName1.Name == pFeatureClassName) { System.Runtime.InteropServices.Marshal.ReleaseComObject(pDsName); System.Runtime.InteropServices.Marshal.ReleaseComObject(pDsFtName); return(pDsSetName1); } pDsSetName1 = pDsFtName.Next(); } } else if (pDsSetName.Name == pFeatureClassName) { System.Runtime.InteropServices.Marshal.ReleaseComObject(pDsName); return(pDsSetName); } System.Runtime.InteropServices.Marshal.ReleaseComObject(pDsSetName); pDsSetName = pDsName.Next(); } return(null);//pDsSetName; } catch (Exception ex) { return(null); } }
public string Save(ESRI.ArcGIS.Geodatabase.IWorkspace Workspace, BaseModel BaseModel, ModelProperty Property) { object[] _parametros = { (object)Workspace }; ModelProperty _mpChaveFromField = BaseModel.ModelProperties.Where(x => x.Attribute is EntityKeyFieldAttribute).First(); int chave = (int)BaseModel.GetType().GetProperty(_mpChaveFromField.Property.Name).GetValue(BaseModel, null); EntityManyToManyFieldAttribute _attribute = (EntityManyToManyFieldAttribute)Property.Attribute; BaseModel _mtmField = (BaseModel)Activator.CreateInstance(_attribute.TargetModelType, _parametros); BaseModel _relateField = (BaseModel)Activator.CreateInstance(_attribute.RelateModelType, _parametros); _relateField.Delete(_attribute.FromFieldName + "=" + chave); foreach (ModelProperty _mp in BaseModel.ModelProperties.Where(x => x.Attribute.FieldName.Equals(Property.Attribute.FieldName))) { if (_mp.Property.GetValue(BaseModel, null) != null) { IList _list = (IList)_mp.Property.GetValue(BaseModel, null); foreach (var _item in _list) { ModelProperty _mpChaveToField = BaseModel.ModelProperties.Where(x => x.Attribute is EntityKeyFieldAttribute).First(); int _value = Convert.ToInt32(_item.GetType().GetProperty(_mpChaveToField.Property.Name).GetValue(_item, null).ToString()); var _objFinal = Activator.CreateInstance(_attribute.RelateModelType, _parametros); _objFinal.GetType().GetProperty(_attribute.FromFieldName.Split('.')[1]).SetValue(_objFinal, chave, null); _objFinal.GetType().GetProperty(_attribute.ToFieldName.Split('.')[1]).SetValue(_objFinal, _value, null); ((BaseModel)_objFinal).Save(); } } } return(""); }
/// <summary> /// 重置mxd文档的数据源 /// </summary> /// <param name="pMapDoc"></param> /// <param name="pWs"></param> public static void ChangeMxdDataSource(ESRI.ArcGIS.Carto.IMapDocument pMapDoc, ESRI.ArcGIS.Geodatabase.IWorkspace pWs) { ESRI.ArcGIS.Geodatabase.IWorkspaceName pWsName = GetWorkspaceName(pWs); ESRI.ArcGIS.Carto.IMap pMap = pMapDoc.ActiveView.FocusMap; ESRI.ArcGIS.Carto.ILayer pLayer = null; ESRI.ArcGIS.Carto.IDataLayer pDataLayer = null; ESRI.ArcGIS.Geodatabase.IDatasetName pDataName = null; for (int i = 0; i < pMap.LayerCount; i++) { pLayer = pMap.get_Layer(i); if (pLayer.Valid == false) { if (pLayer is ESRI.ArcGIS.Carto.IDataLayer) { pDataLayer = pLayer as ESRI.ArcGIS.Carto.IDataLayer; try { pDataName = pDataLayer.DataSourceName as ESRI.ArcGIS.Geodatabase.IDatasetName; //获取DatasetName,必须是要替换的工作空间下的 ESRI.ArcGIS.Geodatabase.IDatasetName pDsName = GetDatasetName(pWs, pDataName.Name); if (pDsName == null) { continue; } pDataName = pDataLayer.DataSourceName as ESRI.ArcGIS.Geodatabase.IDatasetName; pDataName.WorkspaceName = pWsName; pDataLayer.Connect(pDsName as ESRI.ArcGIS.esriSystem.IName); System.Runtime.InteropServices.Marshal.ReleaseComObject(pDataName); System.Runtime.InteropServices.Marshal.ReleaseComObject(pDsName); //pDataName = pDataLayer.DataSourceName as ESRI.ArcGIS.Geodatabase.IDatasetName; } catch { } System.Runtime.InteropServices.Marshal.ReleaseComObject(pDataLayer); } } } System.Runtime.InteropServices.Marshal.ReleaseComObject(pWsName); System.Runtime.InteropServices.Marshal.ReleaseComObject(pMap); pMapDoc.Save(true, true); }
public void Save(ESRI.ArcGIS.Geodatabase.IWorkspace Workspace, ESRI.ArcGIS.Geodatabase.IFeature Feature, BaseModel BaseModel, ModelProperty Property) { this.Save(Workspace, BaseModel, Property); }
void OnBeforeRemoveFeature(ISchematicInMemoryFeature inMemoryFeature, ref bool canRemove) { if (State != ESRI.ArcGIS.Desktop.AddIns.ExtensionState.Enabled) { return; } ESRI.ArcGIS.Geodatabase.IDataset esriData = (ESRI.ArcGIS.Geodatabase.IDataset)inMemoryFeature.SchematicDiagram.SchematicDiagramClass.SchematicDataset; // Remove only elements contained in a specific Schematic dataset if (esriData.Name != SampleDatasetName) { return; } // Remove only elements contained in a specific type of diagram if (inMemoryFeature.SchematicDiagram.SchematicDiagramClass.Name != DiagramClassName) { return; } canRemove = false; // can't remove SubStation if (inMemoryFeature.SchematicElementClass.Name == "InsidePlant_SubStation") { return; } ISchematicDiagramClass schemDiagramClass; schemDiagramClass = (ISchematicDiagramClass)inMemoryFeature.SchematicDiagram.SchematicDiagramClass; // For this specific diagram type, we retrieve the datasource // and the tables where the elements are stored ISchematicDataSource schemDataSource = schemDiagramClass.SchematicDataSource; string tableName = ""; switch (inMemoryFeature.SchematicElementClass.SchematicElementType) { case esriSchematicElementType.esriSchematicNodeType: tableName = TableNameNodes; break; case esriSchematicElementType.esriSchematicLinkType: tableName = TableNameLinks; break; case esriSchematicElementType.esriSchematicDrawingType: return; break; } // Retrieve Feature Workspace ESRI.ArcGIS.Geodatabase.IWorkspace esriWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)schemDataSource.Object; ESRI.ArcGIS.Geodatabase.IFeatureWorkspace esriFeatureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)esriWorkspace; // Get Attributes values ISchematicAttributeContainer schemAttribCont = (ISchematicAttributeContainer)inMemoryFeature.SchematicElementClass; ISchematicAttributeContainer schemFatherAttribCont = (ISchematicAttributeContainer)inMemoryFeature.SchematicElementClass.Parent; if ((!(schemAttribCont.GetSchematicAttribute(AttributeNameObjectID, false) == null) || !(schemFatherAttribCont.GetSchematicAttribute(AttributeNameObjectID, false) == null))) { int indField = inMemoryFeature.Fields.FindFieldByAliasName(AttributeNameObjectID); int OID = int.Parse(inMemoryFeature.get_Value(indField).ToString(), System.Globalization.NumberStyles.Integer); //Get table and row ESRI.ArcGIS.Geodatabase.ITable esriTable = esriFeatureWorkspace.OpenTable(tableName); ESRI.ArcGIS.Geodatabase.IRow esriRow = esriTable.GetRow(OID); // When the row is identified in the table, it is deleted and // the CanRemove returns True so that the associated // schematic element is graphically removed from the active diagram if (!(esriRow == null)) { esriRow.Delete(); canRemove = true; } } }