在featureDataset和workspace下創建featureclass
生活随笔
收集整理的這篇文章主要介紹了
在featureDataset和workspace下創建featureclass
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在featureDataset里創建新的featureclass
Public?Function?createDatasetFeatureClass()Function?createDatasetFeatureClass(pFDS?As?IFeatureDataset,?_??????????????????????????????????????????Name?As?String,?featType?As?esriFeatureType,?_?
??????????????????????????????????????????Optional?geomType?As?esriGeometryType?=?esriGeometryPoint,?_??
??????????????????????????????????????????Optional?pfields?As?IFields,?_
??????????????????????????????????????????Optional?pCLSID?As?UID,?_
??????????????????????????????????????????Optional?pCLSEXT?As?UID,?_?
??????????????????????????????????????????Optional?ConfigWord?As?String?=?""?_
??????????????????????????????????????????)?As?IFeatureClass
??
''?createDatasetFeatureClass:?simple?helper?to?create?a?featureclass?in?a?geodatabase?Dataset.
''?NOTE:?when?creating?a?feature?class?in?a?dataset?the?spatial?reference?is?inherited?
''?from?the?dataset?object
''
??Dim?pFieldsEdit?As?IFieldsEdit
??Dim?pGeomDef?As?IGeometryDef
??Dim?pGeomDefEdit?As?IGeometryDefEdit
??Dim?pField?As?IField
??Dim?pFieldEdit?As?IFieldEdit
??Dim?strShapeFld?As?String
??Dim?j?As?Integer
??
??On?Error?GoTo?EH
??
??Set?createDatasetFeatureClass?=?Nothing
??If?pFDS?Is?Nothing?Then?Exit?Function
??If?Name?=?""?Then?Exit?Function
??
??If?(pCLSID?Is?Nothing)?Or?IsMissing(pCLSID)?Then
????Set?pCLSID?=?Nothing
????Set?pCLSID?=?New?UID
????
????''?determine?the?appropriate?geometry?type?corresponding?the?the?feature?type
????Select?Case?featType
??????Case?esriFTSimple
????????pCLSID.Value?=?"esriGeoDatabase.Feature"
??????Case?esriFTSimpleJunction
????????geomType?=?esriGeometryPoint
????????pCLSID.Value?=?"esriGeoDatabase.SimpleJunctionFeature"
??????Case?esriFTComplexJunction
????????pCLSID.Value?=?"esriGeoDatabase.ComplexJunctionFeature"
??????Case?esriFTSimpleEdge
????????geomType?=?esriGeometryPolyline
????????pCLSID.Value?=?"esriGeoDatabase.SimpleEdgeFeature"
??????Case?esriFTComplexEdge
????????geomType?=?esriGeometryPolyline
????????pCLSID.Value?=?"esriGeoDatabase.ComplexEdgeFeature"
??????Case?esriFTAnnotation
????????Exit?Function
????End?Select
??End?If
??
??'?establish?a?fields?collection
??If?(pfields?Is?Nothing)?Or?IsMissing(pfields)?Then
????Set?pFieldsEdit?=?New?Fields
????''
????''?create?the?geometry?field
????Set?pGeomDef?=?New?GeometryDef
????Set?pGeomDefEdit?=?pGeomDef
????
????''?assign?the?geometry?definiton?properties.
????With?pGeomDefEdit
??????.GeometryType?=?geomType
??????.GridCount?=?1
??????.gridSize(0)?=?10
??????.AvgNumPoints?=?2
??????.hasM?=?False
??????.hasZ?=?False
????End?With
????
????Set?pField?=?New?Field
????Set?pFieldEdit?=?pField
????
????pFieldEdit.Name?=?"shape"
????pFieldEdit.AliasName?=?"geometry"
????pFieldEdit.Type?=?esriFieldTypeGeometry
????Set?pFieldEdit.GeometryDef?=?pGeomDef
????pFieldsEdit.addField?pField
????''?create?the?object?id?field
????Set?pField?=?New?Field
????Set?pFieldEdit?=?pField
????pFieldEdit.Name?=?"OBJECTID"
????pFieldEdit.AliasName?=?"object?identifier"
????pFieldEdit.Type?=?esriFieldTypeOID
????pFieldsEdit.addField?pField
????Set?pfields?=?pFieldsEdit
??End?If
??
??'?establish?the?class?extension
??If?(pCLSEXT?Is?Nothing)?Or?IsMissing(pCLSEXT)?Then
????Set?pCLSEXT?=?Nothing
??End?If
??
??'?locate?the?shape?field
??For?j?=?0?To?pfields.FieldCount?-?1
????If?pfields.Field(j).Type?=?esriFieldTypeGeometry?Then
??????strShapeFld?=?pfields.Field(j).Name
????End?If
??Next
??
??Set?createDatasetFeatureClass?=?pFDS.CreateFeatureClass(Name,?pfields,?pCLSID,?pCLSEXT,?featType,?strShapeFld,?ConfigWord)
??
??Exit?Function
EH:
????MsgBox?Err.Description,?vbInformation,?"createDatasetFeatureClass"
End?Function
?
?在工作區間(Workspace)創建新的featureclass
Public?Function?createWorkspaceFeatureClass()Function?createWorkspaceFeatureClass(featWorkspace?As?IFeatureWorkspace,?_????????????????????????????????????????????Name?As?String,?_
????????????????????????????????????????????featType?As?esriFeatureType,?_
????????????????????????????????????????????Optional?geomType?As?esriGeometryType?=?esriGeometryPoint,?_
????????????????????????????????????????????Optional?pfields?As?IFields,?_
????????????????????????????????????????????Optional?pCLSID?As?UID,?_
????????????????????????????????????????????Optional?pCLSEXT?As?UID,?_
????????????????????????????????????????????Optional?ConfigWord?As?String?=?""?_
????????????????????????????????????????????)?As?IFeatureClass
??
??On?Error?GoTo?EH
??
??Set?createWorkspaceFeatureClass?=?Nothing
??If?featWorkspace?Is?Nothing?Then?Exit?Function
??If?Name?=?""?Then?Exit?Function
??
??If?(pCLSID?Is?Nothing)?Or?IsMissing(pCLSID)?Then
????Set?pCLSID?=?Nothing
????Set?pCLSID?=?New?UID
????
????''?determine?the?appropriate?geometry?type?corresponding?the?the?feature?type
????Select?Case?featType
??????Case?esriFTSimple
????????pCLSID.Value?=?"esricore.Feature"
????????If?geomType?=?esriGeometryLine?Then?geomType?=?esriGeometryPolyline
??????Case?esriFTSimpleJunction
????????geomType?=?esriGeometryPoint
????????pCLSID.Value?=?"esricore.SimpleJunctionFeature"
??????Case?esriFTComplexJunction
????????pCLSID.Value?=?"esricore.ComplexJunctionFeature"
??????Case?esriFTSimpleEdge
????????geomType?=?esriGeometryPolyline
????????pCLSID.Value?=?"esricore.SimpleEdgeFeature"
??????Case?esriFTComplexEdge
????????geomType?=?esriGeometryPolyline
????????pCLSID.Value?=?"esricore.ComplexEdgeFeature"
??????Case?esriFTAnnotation
????????Exit?Function
????End?Select
??End?If
??
??'?establish?a?fields?collection
??If?(pfields?Is?Nothing)?Or?IsMissing(pfields)?Then
????Dim?pFieldsEdit?As?esriCore.IFieldsEdit
????Set?pFieldsEdit?=?New?esriCore.Fields
????
????''
????''?create?the?geometry?field
????''
????Dim?pGeomDef?As?IGeometryDef
????Set?pGeomDef?=?New?GeometryDef
????Dim?pGeomDefEdit?As?IGeometryDefEdit
????Set?pGeomDefEdit?=?pGeomDef
????
????'?assign?the?spatial?reference
????Dim?pSR?As?ISpatialReference
????Set?pSR?=?New?esriCore.UnknownCoordinateSystem
????pSR.SetDomain?0,?21474.83645,?0,?21474.83645
????pSR.SetFalseOriginAndUnits?0,?0,?100000
????
????''?assign?the?geometry?definiton?properties.
????With?pGeomDefEdit
??????.GeometryType?=?geomType
??????.GridCount?=?1
??????.gridSize(0)?=?10
??????.AvgNumPoints?=?2
??????.hasM?=?False
??????.hasZ?=?False
??????Set?.SpatialReference?=?pSR
????End?With
????
????Dim?pField?As?IField
????Dim?pFieldEdit?As?IFieldEdit
????Set?pField?=?New?Field
????Set?pFieldEdit?=?pField
????
????pFieldEdit.Name?=?"shape"
????pFieldEdit.AliasName?=?"geometry"
????pFieldEdit.Type?=?esriFieldTypeGeometry
????Set?pFieldEdit.GeometryDef?=?pGeomDef
????pFieldsEdit.addField?pField
????
????''
????''?create?the?object?id?field
????''
????Set?pField?=?New?Field
????Set?pFieldEdit?=?pField
????pFieldEdit.Name?=?"OBJECTID"
????pFieldEdit.AliasName?=?"object?identifier"
????pFieldEdit.Type?=?esriFieldTypeOID
????pFieldsEdit.addField?pField
????Set?pfields?=?pFieldsEdit
??End?If
??
??'?establish?the?class?extension
??If?(pCLSEXT?Is?Nothing)?Or?IsMissing(pCLSEXT)?Then
????Set?pCLSEXT?=?Nothing
??End?If
??
??'?locate?the?shape?field
??Dim?strShapeFld?As?String
??Dim?j?As?Integer
??For?j?=?0?To?pfields.FieldCount?-?1
????If?pfields.Field(j).Type?=?esriFieldTypeGeometry?Then
??????strShapeFld?=?pfields.Field(j).Name
????End?If
??Next
??
??Set?createWorkspaceFeatureClass?=?featWorkspace.CreateFeatureClass(Name,?pfields,?pCLSID,?_
?????????????????????????????pCLSEXT,?featType,?strShapeFld,?ConfigWord)
??
??Exit?Function
EH:
????MsgBox?Err.Description,?vbInformation,?"createWorkspaceFeatureClass"
End?Function
?
轉載于:https://www.cnblogs.com/iswszheng/archive/2009/03/18/1415116.html
總結
以上是生活随笔為你收集整理的在featureDataset和workspace下創建featureclass的全部內容,希望文章能夠幫你解決所遇到的問題。