zoukankan      html  css  js  c++  java
  • 创建内存图层不成功的问题

    http://bbs.esrichina-bj.cn/ESRI/thread-47516-1-1.html 注意:创建图层时坐标系统不能为Unknow 我想把一图层中选中要素复制到一个新的图层中,故要先创建一个图层。目前网上有个创建内存图层的方法如下: /// <summary> /// 在内存中创建图层 /// </summary> /// <param name="DataSetName">数据集名称(所建图层名称)</param> /// <param name="AliaseName">别名</param> /// <param name="SpatialRef">空间参考</param> /// <param name="GeometryType">几何类型</param> /// <param name="PropertyFields">属性字段集合</param> /// <returns>IfeatureLayer</returns> public static IFeatureLayer CreateFeatureLayerInmemeory(string DataSetName, string AliaseName, ISpatialReference SpatialRef, esriGeometryType GeometryType, IFields PropertyFields) { IWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass(); ESRI.ArcGIS.Geodatabase.IWorkspaceName workspaceName = workspaceFactory.Create("", "MyWorkspace", null, 0); ESRI.ArcGIS.esriSystem.IName name = (IName)workspaceName; ESRI.ArcGIS.Geodatabase.IWorkspace inmemWor = (IWorkspace)name.Open(); IField oField = new FieldClass(); IFields oFields = new FieldsClass(); IFieldsEdit oFieldsEdit = null; IFieldEdit oFieldEdit = null; IFeatureClass oFeatureClass = null; IFeatureLayer oFeatureLayer = null; try { oFieldsEdit = oFields as IFieldsEdit; oFieldEdit = oField as IFieldEdit; for (int i = 0; i < PropertyFields.FieldCount; i++) { oFieldsEdit.AddField(PropertyFields.get_Field(i)); } //IGeometryDef Interface Provides access to members that return information about the geometry definition IGeometryDef geometryDef = new GeometryDefClass(); //IGeometryDefEdit Provides access to members that modify the geometry definition IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef; geometryDefEdit.AvgNumPoints_2 = 5; geometryDefEdit.GeometryType_2 = GeometryType; geometryDefEdit.GridCount_2 = 1; geometryDefEdit.HasM_2 = false; geometryDefEdit.HasZ_2 = false; geometryDefEdit.SpatialReference_2 = SpatialRef; oFieldEdit.Name_2 = "SHAPE"; oFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; oFieldEdit.GeometryDef_2 = geometryDef; oFieldEdit.IsNullable_2 = true; oFieldEdit.Required_2 = true; oFieldsEdit.AddField(oField); oFeatureClass = (inmemWor asIFeatureWorkspace).CreateFeatureClass(DataSetName, oFields, null, null,esriFeatureType.esriFTSimple, "SHAPE", ""); (oFeatureClass as IDataset).BrowseName = DataSetName; oFeatureLayer = new FeatureLayerClass(); oFeatureLayer.Name = AliaseName; oFeatureLayer.FeatureClass = oFeatureClass; } catch { MessageBox.Show("Error on Create FeatureLayer!"); } finally { try { System.Runtime.InteropServices.Marshal.ReleaseComObject(oField); System.Runtime.InteropServices.Marshal.ReleaseComObject(oFields); System.Runtime.InteropServices.Marshal.ReleaseComObject(oFieldsEdit); System.Runtime.InteropServices.Marshal.ReleaseComObject(oFieldEdit); System.Runtime.InteropServices.Marshal.ReleaseComObject(name); System.Runtime.InteropServices.Marshal.ReleaseComObject(workspaceFactory); System.Runtime.InteropServices.Marshal.ReleaseComObject(workspaceName); System.Runtime.InteropServices.Marshal.ReleaseComObject(inmemWor); System.Runtime.InteropServices.Marshal.ReleaseComObject(oFeatureClass); } catch { } GC.Collect(); } return oFeatureLayer; }复制代码 创建字段组的方法如下: //Create fileds public IFields CreateFields() { IFields fields = new FieldsClass(); // if (fields == null) //{ fields = new FieldsClass(); // create the fields using the required fields method IObjectClassDescription objectClassDescription = new ObjectClassDescriptionClass(); fields = objectClassDescription.RequiredFields; ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast ESRI.ArcGIS.Geodatabase.IField field = new ESRI.ArcGIS.Geodatabase.FieldClass(); // create a user defined text field ESRI.ArcGIS.Geodatabase.IFieldEdit fieldEdit = (ESRI.ArcGIS.Geodatabase.IFieldEdit)field; // Explicit Cast // setup field properties fieldEdit.Name_2 = "SampleField"; fieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString; fieldEdit.IsNullable_2 = true; fieldEdit.AliasName_2 = "Sample Field Column"; fieldEdit.DefaultValue_2 = "test"; fieldEdit.Editable_2 = true; fieldEdit.Length_2 = 100; // add field to field collection fieldsEdit.AddField(field); fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast return fields; //} //return null; } 复制代码 我采用如下代码进行图层的创建: IFields pField = CreateFields(); ISpatialReference pSparef = new UnknownCoordinateSystemClass(); IFeatureLayer pFeatLyr =CreateFeatureLayerInmemeory("Hello", "Hello", pSparef,esriGeometryType.esriGeometryPoint, pField); this.m_mainForm.m_mapCtrl.Map.AddLayer(pFeatLyr); this.m_mainForm.m_mapCtrl.ActiveView.Refresh();复制代码 但调试的时候,图层创建失败,即返回的IFeatureLayer是null。 //这个地方出错 IFeatureLayer pFeatLyr = CreateFeatureLayerInmemeory("Hello", "Hello", pSparef, esriGeometryType.esriGeometryPoint, pField);复制代码 希望能够得到大家的帮助,非常感谢!
  • 相关阅读:
    AIMS 2013中的性能报告工具不能运行的解决办法
    读懂AIMS 2013中的性能分析报告
    在线研讨会网络视频讲座 方案设计利器Autodesk Infrastructure Modeler 2013
    Using New Profiling API to Analyze Performance of AIMS 2013
    Map 3D 2013 新功能和新API WebCast视频下载
    为Autodesk Infrastructure Map Server(AIMS) Mobile Viewer创建自定义控件
    ADN新开了云计算Cloud和移动计算Mobile相关技术的博客
    JavaScript修改css样式style
    文本编辑神器awk
    jquery 开发总结1
  • 原文地址:https://www.cnblogs.com/adodo1/p/4327950.html
Copyright © 2011-2022 走看看