You are here: > ESRI Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - ArcObjects 3rd Party IDE (C++, VB, C#, Delphi, etc.) forum

Having difficulty with CreateFeatureClass i...   Skip Cody Mar 29, 2007
Re: Having difficulty with CreateFeatureCla...   Colin Zwicker Mar 30, 2007
Re: Having difficulty with CreateFeatureCla...   Kirk Kuykendall Mar 30, 2007
Re: Having difficulty with CreateFeatureCla...   Skip Cody Apr 03, 2007
Re: Having difficulty with CreateFeatureCla...   Kirk Kuykendall Apr 03, 2007
Re: Having difficulty with CreateFeatureCla...   Petr Sharapov Aug 27, 2007
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Having difficulty with CreateFeatureClass in an InMemoryWorspace .net 
Author Skip Cody 
Date Mar 29, 2007 
Message I am getting an error when the feature class is being created. This same code works if I switch the InMemory workspace with a shape file work space. The error is HRESULT: 0x8004120E. I have tried a bunch of different combinations but I to no avail.

Thanks for looking at it.

This is written in C# and I am using 9.2 Visual Studio 2005
 
 
public void TestMe()
            {

                // Create an InMemory workspace factory.
                InMemoryWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass();

                // Create an InMemory geodatabase.
                ESRI.ArcGIS.Geodatabase.IWorkspaceName workspaceName = workspaceFactory.Create("", "MWspace", null, 0);

                // Cast for IName.
                ESRI.ArcGIS.esriSystem.IName name = (IName)workspaceName;

                //Open a reference to the Access workspace through the name object.
                ESRI.ArcGIS.Geodatabase.IWorkspace inmemWor = (IWorkspace)name.Open();
   

                // get teh IFeatureWorkspace
                IFeatureWorkspace featWork = (IFeatureWorkspace)inmemWor;
                if (featWork == null)
                    throw new ApplicationException("Error getting feautre workspace");

                ISpatialReferenceFactory pSpatialRefFactory = new SpatialReferenceEnvironmentClass();
                IGeographicCoordinateSystem pGeographicCoordSys = pSpatialRefFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_NAD1983);
                ISpatialReference pSpaRef = pGeographicCoordSys;

                IFieldsEdit pFldsEdt = new FieldsClass();
                IFieldEdit pFldEdt = new FieldClass();
                double dGridSize = 1000;

                IGeometryDefEdit pGeoDef;
                pGeoDef = new GeometryDefClass();
                pGeoDef.SpatialReference_2 = pSpaRef;
                pGeoDef.GridCount_2 = 1;
                pGeoDef.set_GridSize(0, dGridSize);

                pFldEdt = new FieldClass();
                pFldEdt.Type_2 = esriFieldType.esriFieldTypeOID;
                pFldEdt.Name_2 = "Id";
                pFldEdt.AliasName_2 = "Id";
                pFldsEdt.AddField(pFldEdt);

                pFldEdt = new FieldClass();
                pFldEdt.Name_2 = "Shape";
                pFldEdt.Type_2 = esriFieldType.esriFieldTypeGeometry;
                pFldEdt.GeometryDef_2 = pGeoDef;
                pFldsEdt.AddField(pFldEdt);

                pFldEdt = new FieldClass();
                pFldEdt.Name_2 = "Oper_Name";
                pFldEdt.Length_2 = 40;
                pFldEdt.Type_2 = esriFieldType.esriFieldTypeString;
                pFldsEdt.AddField(pFldEdt);


                IFeatureClass pFClass = featWork.CreateFeatureClass("Parcel", pFldsEdt, null, null, esriFeatureType.esriFTSimple, "Shape", ""); 
            }
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Having difficulty with CreateFeatureClass in an InMemoryWorspace .net 
Author Colin Zwicker 
Date Mar 30, 2007 
Message Skip,

The Exception from HRESULT: 0x8004120E, Error Code: -2147216882 = FDO_E_INVALID_XY_DOMAIN

In my C# console app I use the code below to help understand the com error codes. I then look then up in fdoError Constants, one of which is found at
http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriGeoDatabase/fdoError.htm

I would suggest looking at the ISpatialReferenceResolution and ISpatialReferenceTolerance interfaces for setting default values as a starting point.

I will continue to look at this issue, and reply if I get any further.

- Colin 
 

catch (COMException ComEx)
{
   Console.WriteLine(String.Format("MyCode errored: {0}, Error Code: {1}", ComEx.Message, ComEx.ErrorCode));
}
             
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Having difficulty with CreateFeatureClass in an InMemoryWorspace .net 
Author Kirk Kuykendall 
Date Mar 30, 2007 
Message try calling SetDomain on the spatial reference.

Code below works, but fails if I comment that line out.

kkeywords inmemoryworkspacefactory 
 
Option Explicit
Sub Test2()
        
    Dim pInMemWS As IFeatureWorkspace
    Set pInMemWS = CreateWorkspace("MyWorkspace4")
    
    Dim pSRF As ISpatialReferenceFactory2
    Set pSRF = New SpatialReferenceEnvironment
'
    Dim pSR As ISpatialReference
    Set pSR = pSRF.CreateGeographicCoordinateSystem(esriSRGeoCSType.esriSRGeoCS_NAD1983)
    ' won't work if I comment out next line
    pSR.SetDomain -200, 200, -200, 200
    
    Dim pGeoDefEdit As IGeometryDefEdit
    Set pGeoDefEdit = New GeometryDef
    With pGeoDefEdit
        Set .SpatialReference = pSR
        .GeometryType = esriGeometryType.esriGeometryPolyline
        .GridCount = 1
        .GridSize(0) = 1000
    End With
    
    Dim pFldsEdit As IFieldsEdit
    Set pFldsEdit = New esriGeoDatabase.Fields
    
    pFldsEdit.AddField MakeField("ObjectID", esriFieldTypeOID)
    pFldsEdit.AddField MakeField("Shape", esriFieldTypeGeometry, 0, pGeoDefEdit)
    
    Dim pFWS As IFeatureWorkspace
    Set pFWS = pInMemWS
    
    Dim pUID As New UID
    pUID.Value = "esriGeodatabase.Feature"
    
    Dim pLineFC As IFeatureClass
    Set pLineFC = pFWS.CreateFeatureClass("mylines2", pFldsEdit, pUID, Nothing, esriFTSimple, "Shape", "")
    
    
End Sub

Function CreateWorkspace(ByVal sName As String) As IWorkspace
    Dim pWSF As IWorkspaceFactory
    Set pWSF = New InMemoryWorkspaceFactory
    Dim pName As IName
    Set pName = pWSF.Create("", sName, Nothing, 0)
    Set CreateWorkspace = pName.Open
End Function

Function MakeField(sName As String, lType As esriFieldType, _
                   Optional lLen As Long, _
                   Optional pGeomDef As IGeometryDef) As IField
    Dim pFldEdit As IFieldEdit
    Set pFldEdit = New esriGeoDatabase.Field
    pFldEdit.Name = sName
    pFldEdit.Type = lType
    If Not pGeomDef Is Nothing Then
        Set pFldEdit.GeometryDef = pGeomDef
    End If
    If lLen > 0 Then
        pFldEdit.Length = lLen
    End If
    Set MakeField = pFldEdit
End Function

 
  Kirk Kuykendall
AmberGIS Programming Services & Sales
http://www.ambergis.com
Now Answering questions at:
http://gis.stackexchange.com/


 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Having difficulty with CreateFeatureClass in an InMemoryWorspace .net 
Author Skip Cody 
Date Apr 03, 2007 
Message Thank you Kurt.

Making this change in C# fixed the current error but is raising another error (I will repost with the new error). Taking your code and putting it in VB.net and making the 9.2 _2 changes works great.

Thanks for the Error tip Colin this will help a lot in the future
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Having difficulty with CreateFeatureClass in an InMemoryWorspace .net 
Author Kirk Kuykendall 
Date Apr 03, 2007 
Message see http://forums.esri.com/Thread.asp?c=93&f=1170&t=218190&mc=2#660740 
  Kirk Kuykendall
AmberGIS Programming Services & Sales
http://www.ambergis.com
Now Answering questions at:
http://gis.stackexchange.com/


 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Having difficulty with CreateFeatureClass in an InMemoryWorspace .net 
Author Petr Sharapov 
Date Aug 27, 2007 
Message It seems problem could be solved using code like: 
 
public static IFeatureWorkspace CreateFeatureWorkspace(string workspaceNameString)
		{
			
			IWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass();
			// Create an InMemory geodatabase.
			IWorkspaceName workspaceName = workspaceFactory.Create("", workspaceNameString, null, 0);

			// Cast for IName.
			IName name = (IName)workspaceName;

			IWorkspace inmemWor = (IWorkspace)name.Open();

			IFeatureWorkspace featWork = (IFeatureWorkspace)inmemWor;
			Assert.IsNotNull(featWork, "Error getting feautre workspace");
			
			return featWork;
		}

		public static IFeatureClass CreateFeatureClass(IFeatureWorkspace featWorkspace, string name)
		{
			ISpatialReferenceFactory pSpatialRefFactory = new SpatialReferenceEnvironmentClass();
			IGeographicCoordinateSystem pGeographicCoordSys = pSpatialRefFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
			ISpatialReference pSpaRef = pGeographicCoordSys;
			pSpaRef.SetDomain(-180, 180, -90, 90);
			
			IFieldsEdit pFldsEdt = new FieldsClass();
			IFieldEdit pFldEdt = new FieldClass();

			pFldEdt = new FieldClass();
			pFldEdt.Type_2 = esriFieldType.esriFieldTypeOID;
			pFldEdt.Name_2 = "OBJECTID";
			pFldEdt.AliasName_2 = "OBJECTID";
			pFldsEdt.AddField(pFldEdt);
			
			double dGridSize = 1000;

			IGeometryDefEdit pGeoDef;
			pGeoDef = new GeometryDefClass();
			pGeoDef.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
			pGeoDef.SpatialReference_2 = pSpaRef;
			pGeoDef.GridCount_2 = 1;
			pGeoDef.set_GridSize(0, dGridSize);
			pGeoDef.AvgNumPoints_2 = 0;
			pGeoDef.HasM_2 = false;
			pGeoDef.HasZ_2 = false;
			
			pFldEdt = new FieldClass();
			pFldEdt.Name_2 = "SHAPE";
			pFldEdt.AliasName_2 = "SHAPE";
			pFldEdt.Type_2 = esriFieldType.esriFieldTypeGeometry;
			pFldEdt.GeometryDef_2 = pGeoDef;
			pFldsEdt.AddField(pFldEdt);

			IFeatureClass pFClass = featWorkspace.CreateFeatureClass(name, pFldsEdt, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
			return pFClass;
		}