I'm trying to create a Feature class. It shows the error

X Y domain on the spatial reference system is not set or in valid

Here is my code attempt:

      IWorkspaceFactory wsf = new  FileGDBWorkspaceFactory();
      IWorkspace ws = wsf.OpenFromFile(@"D:\ARC OBJECTS\Newgdb.gdb", 
      IFeatureWorkspace fws = ws as IFeatureWorkspace;
      IFields flds = new FieldsClass();
      IFieldsEdit fldsedit = flds as IFieldsEdit;
      IField fld = new FieldClass();
      IFieldEdit fldedit = fld as IFieldEdit;
      fldedit.AliasName_2 = "Shape";
      fldedit.IsNullable_2 = false;
      fldedit.Name_2 = "Shape";
      fldedit.Type_2 = esriFieldType.esriFieldTypeGeometry;
      IGeometryDef gdef = new GeometryDefClass();
      IGeometryDefEdit gdedit = gdef as IGeometryDefEdit;
      gdedit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
      gdedit.SpatialReference_2 = new UnknownCoordinateSystemClass();
      fldedit.GeometryDef_2 = gdedit;
      IFeatureClass feacls= fws.CreateFeatureClass("Error", flds, null,
                          null,esriFeatureType.esriFTSimple, "shape", "");

Where did I go wrong?


1 Answer 1


With a EPSG as parameter I work with this:

IGeometryDefEdit geometryDefEdit = new GeometryDefClass();
geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
ISpatialReference spatialReference = 
spatialReferenceFactory.CreateProjectedCoordinateSystem(EPSG); //or CreateGeographicCoordinateSystem
geometryDefEdit.SpatialReference_2 = spatialReference;

Then, when I define the field "Shape" I use:

IFieldsEdit fields = new FieldsClass();    
field = new FieldClass();
field.Name_2 = "Shape";
field.Type_2 = esriFieldType.esriFieldTypeGeometry;
field.GeometryDef_2 = geometryDefEdit as IGeometryDef;

Finally you have to add all the other fields...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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