Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have the code below, which is supposed to create a new featureclass in memory then add the FC to the map, but I get a Automation error when I use the createfeatureclass method

Set pFC = pFeatWS.CreateFeatureClass("NewBus", pFields, Nothing, Nothing, esriFTSimple, "Shape", " ")

Here' s the full code

Public Sub InMemoryWorkspace()

'Create Workspace factory
Dim pWorkspaceFactory As IWorkspaceFactory2
Set pWorkspaceFactory = New InMemoryWorkspaceFactory

'Create workspace
Dim pWorkspaceName As IWorkspaceName2
Set pWorkspaceName = pWorkspaceFactory.Create("", "MyInMemoryworkspace", Nothing, 0)

'Get a handle on Name
Dim PName As IName
Set PName = pWorkspaceName

'Get handle on Featureworkspace
Dim pFeatWS As IFeatureWorkspace
Set pFeatWS = PName.Open

'Create field object and set number of fields
Dim pFields As IFields
Set pFields = New Fields
Dim pFieldsEdit As IFieldsEdit
Set pFieldsEdit = pFields
pFieldsEdit.FieldCount = 3

'Create objectID field
Dim pField As IField
Set pField = New Field
Dim pFieldEdit As IFieldEdit
Set pFieldEdit = pField
With pFieldEdit
    .Name = "OBJECTID"
    .Type = esriFieldTypeOID
End With
Set pFieldsEdit.Field(0) = pField

'Create postcode field

Set pField = New Field

Set pFieldEdit = pField
With pFieldEdit
    .Name = "POSTCODE"
    .Type = esriFieldTypeString
End With
Set pFieldsEdit.Field(1) = pField

'Create Shape field
Set pField = New Field
Set pFieldEdit = pField
With pFieldEdit
    .Name = "SHAPE"
    .Type = esriFieldTypeGeometry
End With
Set pFieldsEdit.Field(2) = pField


Dim pGeomDef As IGeometryDef
Dim pGeomDefEdit As IGeometryDefEdit
Set pGeomDef = New GeometryDef
Set pGeomDefEdit = pGeomDef
With pGeomDefEdit
  .GeometryType = esriGeometryPolygon
  Set .SpatialReference = New UnknownCoordinateSystem
End With
Set pFieldEdit.GeometryDef = pGeomDef
pFieldsEdit.AddField pField

' Create featureclass
 Dim pFC As IFeatureClass
 Set pFC = pFeatWS.CreateFeatureClass("NewBus", pFields, Nothing, Nothing, esriFTSimple, "Shape", " ")

 Dim pmemLayer As IFeatureLayer
 Set pmemLayer.featureClass = pFC

 Dim pmxdoc As IMxDocument
 Set pmxdoc = ThisDocument
 Dim pmap As IMap
 Set pmap = pmxdoc.FocusMap

 pmap.AddLayer pFC

Can someone explain where I am going wrong.

Cheers

share|improve this question
    
I'm wanting to do something similar to this using Python/ArcPy but it looks like my only hope will an enhancement in a future version: gis.stackexchange.com/questions/20329/… –  PolyGeo Mar 22 '12 at 5:13

1 Answer 1

up vote 2 down vote accepted

Try calling SetDomain on the spatial reference. See code here.

share|improve this answer
    
Thanks Kirk, that helped. –  Halil Siddique Mar 22 '12 at 10:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.