阅读:1227回复:2
请教图层新建问题
哪位高手指点一下,用ao如何新建一个图层,要求:图层的参数和当前的工程中的其他图层的参数一样。再平台中arcgis使用arccatclog新建图层在arcmap中添加。怎样在ao中实现这两个功能呀。请高手帮忙,谢谢!!!!!!!!!<img src="images/post/smile/dvbbs/em02.gif" /><img src="images/post/smile/dvbbs/em02.gif" />
|
|
1楼#
发布于:2005-03-25 19:00
<P>自己来解决吧,不知这个方法是否可行</P>
<P>Public Sub newlayer(et As esriGeometryType, dtname As String, lname As String) '图层类型,数据库名,图层名称 Dim pFeatClass As IFeatureClass Dim pLayer As IFeatureLayer Dim player1 As IFeatureLayer Dim pf As IFeatureClass Dim igeofea As IGeoFeatureLayer Set pLayer = New FeatureLayer Set igeofea = New FeatureLayer</P> <P> Set igeofea.SpatialReference = MapControl1.SpatialReference '设置参数 Set pLayer = igeofea pLayer.Name = lname Set pLayer.FeatureClass = CreateShapefile(et, dtname, lname)</P> <P>m_pMapDocument.ActiveView.FocusMap.AddLayer pLayer End Sub </P> <P>Public Function CreateShapefile(et As esriGeometryType, spath As String, sName As String) As IFeatureClass ' Dont include .shp extension ' Open the folder to contain the shapefile as a workspace Dim pFWS As IFeatureWorkspace Dim pWorkspaceFactory As IWorkspaceFactory Set pWorkspaceFactory = New ShapefileWorkspaceFactory Set pFWS = pWorkspaceFactory.OpenFromFile(spath, 0) ' Set up a simple fields collection Dim pFields As IFields Dim pFieldsEdit As IFieldsEdit Set pFields = New Fields Set pFieldsEdit = pFields Dim pField As IField Dim pFieldEdit As IFieldEdit ' Make the shape field ' it will need a geometry definition, with a spatial reference Set pField = New Field Set pFieldEdit = pField pFieldEdit.Name = "Shape" pFieldEdit.Type = esriFieldTypeGeometry Dim pGeomDef As IGeometryDef Dim pGeomDefEdit As IGeometryDefEdit Set pGeomDef = New GeometryDef Set pGeomDefEdit = pGeomDef With pGeomDefEdit .GeometryType = et ' 图层类型 Set .SpatialReference = New UnknownCoordinateSystem End With Set pFieldEdit.GeometryDef = pGeomDef pFieldsEdit.AddField pField</P> <P> ' Add another miscellaneous text field Set pField = New Field Set pFieldEdit = pField With pFieldEdit .Length = 30 .Name = "MiscText" .Type = esriFieldTypeString End With pFieldsEdit.AddField pField ' Create the shapefile ' (some parameters apply to geodatabase options and can be defaulted as Nothing) Dim pFeatClass As IFeatureClass Set pFeatClass = pFWS.CreateFeatureClass(sName, pFields, Nothing, _ Nothing, esriFTSimple, "Shape", "") Set CreateShapefile = pFeatClass End Function</P> |
|
2楼#
发布于:2005-03-26 18:36
我也用的这个方法可以建立新的图层
|
|
|