阅读:1421回复:1
怎样在arcMap里用程序创建一个新层啊?
<P>在arcMap里用程序创建一个层,并把这个层保存为一个新的层文件?</P>
<P>用程序怎么实现?</P> |
|
|
1楼#
发布于:2005-07-08 15:13
<P>Public Function CreateShapefile(strFolder As String, strName As String, _<BR> geomType As esriGeometryType) As esriGeoDatabase.IFeatureClass</P>
<P>'' 在目录里建立一个shp图层.<BR>'' 注意: shapefile的名字不包括 .shp 扩展名<BR>'' 作者:<BR>'' 修改时间</P> <P> Const strShapeFieldName As String = "Shape"</P> <P> On Error GoTo EH<BR> Set CreateShapefile = Nothing<BR> If strFolder = "" Then Exit Function</P> <P> ' Open the folder to contain the shapefile as a workspace<BR> Dim pFWS As esriGeoDatabase.IFeatureWorkspace<BR> Dim pWorkspaceFactory As esriGeoDatabase.IWorkspaceFactory<BR> Set pWorkspaceFactory = New esriDataSourcesFile.ShapefileWorkspaceFactory<BR> Set pFWS = pWorkspaceFactory.OpenFromFile(strFolder, 0)</P> <P> ' Set up a simple fields collection<BR> Dim pFields As esriGeoDatabase.IFields<BR> Dim pFieldsEdit As esriGeoDatabase.IFieldsEdit<BR> Set pFields = New esriGeoDatabase.Fields<BR> Set pFieldsEdit = pFields</P> <P> Dim pField As esriGeoDatabase.IField<BR> Dim pFieldEdit As esriGeoDatabase.IFieldEdit</P> <P> ' Make the shape field<BR> ' it will need a geometry definition, with a spatial reference<BR> Set pField = New esriGeoDatabase.Field<BR> Set pFieldEdit = pField<BR> pFieldEdit.Name = strShapeFieldName<BR> pFieldEdit.Type = esriFieldTypeGeometry</P> <P> Dim pGeomDef As esriGeoDatabase.IGeometryDef<BR> Dim pGeomDefEdit As esriGeoDatabase.IGeometryDefEdit<BR> Set pGeomDef = New esriGeoDatabase.GeometryDef<BR> Set pGeomDefEdit = pGeomDef<BR> With pGeomDefEdit<BR> .GeometryType = geomType<BR> Set .SpatialReference = New esriGeometry.UnknownCoordinateSystem<BR> End With<BR> Set pFieldEdit.GeometryDef = pGeomDef<BR> pFieldsEdit.AddField pField</P> <P> ' Create the shapefile<BR> ' (some parameters apply to geodatabase options and can be defaulted as Nothing)</P> <P> Set CreateShapefile = pFWS.CreateFeatureClass(strName, pFields, Nothing, _<BR> Nothing, esriFTSimple, strShapeFieldName, "")<BR> Exit Function<BR>EH:<BR> MsgBox Err.Description, vbInformation, "createShapefile"<BR>End Function</P> |
|
|