I have been able to connect to an Enterprise GeoDatabase, retrieve features from it and update attributes. However I am having problems accessing and then updating the shape property of a feature. Here is my code (its not production, just test code at the moment) :


            IQueryFilter queryFilter = new QueryFilterClass();
            queryFilter.SubFields = "OBJECTID, Definitive_ID, FL_Id, GIS_ID, SAP_ID, CHECK_Status, CHECK_DateAbandoned, CHECK_Outfall_Ipid, CHECK_Outfall_X";
            queryFilter.WhereClause = "FL_Id = 71444";
            IFeatureClass testFeatureClass = featureWorkspace.OpenFeatureClass("SDE_CSO.DBO.DefinitiveList");

            IQueryFilterDefinition queryFilterDef = (IQueryFilterDefinition)queryFilter;
            queryFilterDef.PostfixClause = "ORDER BY OBJECTID";

            int nameIndex = testFeatureClass.FindField("OBJECTID");
            int defIndex = testFeatureClass.FindField("Definitive_ID");
            int flIndex = testFeatureClass.FindField("FL_Id");
            int GISIndex = testFeatureClass.FindField("GIS_ID");
            int sapIndex = testFeatureClass.FindField("SAP_ID");
            int checkStatusIndex = testFeatureClass.FindField("CHECK_Status");
            int checkDateAbandonedIndex = testFeatureClass.FindField("CHECK_DateAbandoned");
            int checkOutfallIPIndex = testFeatureClass.FindField("CHECK_Outfall_Ipid");
            int checkOutfallXIndex = testFeatureClass.FindField("CHECK_Outfall_X");
            int XLatIndex = testFeatureClass.FindField("XLat");
            int LongIndex = testFeatureClass.FindField("Long");

            using (ComReleaser comReleaser = new ComReleaser())
                IFeatureCursor cursor = testFeatureClass.Search(queryFilter, true);
                IFeature feature = null;
                while ((feature = cursor.NextFeature()) != null)
                    int ObjectID = Convert.ToInt32(feature.get_Value(nameIndex));
                    string Definitive_ID = Convert.ToString(feature.get_Value(defIndex));
                    int FL_ID = Convert.ToInt32(feature.get_Value(flIndex));
                    string GIS_ID = Convert.ToString(feature.get_Value(GISIndex));
                    string SAP_ID = Convert.ToString(feature.get_Value(sapIndex));
                    string CHECK_Status = Convert.ToString(feature.get_Value(checkStatusIndex));
                    string CHECK_DateAbandonedIndex = Convert.ToString(feature.get_Value(checkDateAbandonedIndex));
                    string CHECK_OutfallIPID = Convert.ToString(feature.get_Value(checkOutfallIPIndex));
                    string CHECK_OutfallX = Convert.ToString(feature.get_Value(checkOutfallXIndex));
                    double XLat = Convert.ToDouble(feature.get_Value(XLatIndex));
                    double Long = Convert.ToDouble(feature.get_Value(LongIndex));

                    Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
                    System.Object obj = Activator.CreateInstance(factoryType);
                    ISpatialReferenceFactory3 spacialReferenceFactory3 = obj as ISpatialReferenceFactory3;
                    IGeoTransformation geoTrans = spacialReferenceFactory3.CreateGeoTransformation((int)esriSRGeoTransformationType.esriSRGeoTransformation_OSGB1936_To_WGS1984Petrol) as IGeoTransformation;
                    ISpatialReference fromSpatialReference;
                    ISpatialReference toSpatialReference;
                    geoTrans.GetSpatialReferences(out fromSpatialReference, out toSpatialReference);

                    var wgs84GCS = spacialReferenceFactory3.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
                    var bngPCS = spacialReferenceFactory3.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_BritishNationalGrid);

                    IGeometry geometry = feature.ShapeCopy;
                    IPoint point = geometry as IPoint;
                    point.PutCoords(-3.159875, 51.465615);
                    geometry = point as IGeometry5;
                    geometry.SpatialReference = wgs84GCS;
                    point = new PointClass();
                    point = geometry as PointClass;
                    point.SpatialReference = wgs84GCS;

                    feature.Shape = point;
        catch (Exception ex)
            Log("Problem Connecting to Feature Class or Querying : " + ex.Message);

I am using an IQueryFilter which I thought would allow me to update the feature, however I get an error at the line "IGeometry geomtey = feature.ShapeCopy" - "Error HRESULT E_FAIL has been returned from a call to a COM component"

I am probably doing something incorrectly, please could someone advise how to change the location of an existing Point Feature using C# ArcObjects .NET (Im using v10.1)


The issue was caused because the "Shape" field must be specified in the edit query. I assumed (obviously foolishly) that the Geometry of a feature point would automatically be part of the query - its not.

  • +1 I coulda sworn this wasn't needed in earlier versions. – Kirk Kuykendall Feb 27 '13 at 20:07
  • It may depend on whether the underlying DBMS is SDE, file GDB, etc. – blah238 Feb 27 '13 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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