gis1117
  • 注册日期
  • 发帖数
  • QQ
  • 铜币
  • 威望
  • 贡献值
  • 银元
阅读:897回复:2

Create New Shapefile in ArcMap

楼主#
更多 发布于:2004-04-13 04:25
Create a macro and then call this code from it.  
  Public Sub CreateShapefile()

  Const strFolder As String = "C:\temp"
  Const strName As String = "MyShapeFile" ' Dont include .shp extension
  Const strShapeFieldName As String = "Shape"
  
  ' 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(strFolder, 0)
  
  ' Set up a simple fields collection
  Dim pFields As IFields
  Dim pFieldsEdit As IFieldsEdit
  Set pFields = New esriCore.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 esriCore.Field
  Set pFieldEdit = pField
  pFieldEdit.Name = strShapeFieldName
  pFieldEdit.Type = esriFieldTypeGeometry
  
'########This Creates the Shape type point line or polygon ###############
  Dim pGeomDef As IGeometryDef
  Dim pGeomDefEdit As IGeometryDefEdit
  Set pGeomDef = New GeometryDef
  Set pGeomDefEdit = pGeomDef
  With pGeomDefEdit
    .GeometryType = esriGeometryPolygon '##Or esriGeometryPoint Or esriGeometryLine ####
    Set .SpatialReference = New UnknownCoordinateSystem
  End With
  Set pFieldEdit.GeometryDef = pGeomDef
  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(strName, pFields, Nothing, _
                                           Nothing, esriFTSimple, strShapeFieldName, "")
 
喜欢0 评分0
游客

返回顶部