ArcGIS Engine 10.0 / updated feature not saving new spatial reference

950
7
Jump to solution
06-26-2012 02:23 PM
GlennNead
New Contributor
I am using a feature cursor to reproject each feature in a feature layer to a different datum. The ProjectEx() conversion works and the stored feature has the new location (ie, underlying Point.X, Point.Y), but the new spatial reference is not saved along with it.  If I loop through checking for the old spatial reference a second time, I end up with a double projection rather than skipping it.

...
// geo has new SpatialReference and new X, Y
feature.set_Value(shapeIdx, geo as object)
feature.store();
geo = feature.get_value(shapeIdx) as IGeometry5;
// geo has original Spatial reference, but new X, Y.
0 Kudos
1 Solution

Accepted Solutions
NeilClemmons
Regular Contributor III
As mentioned in the developer help, you can't use IFieldsEdit or IGeometryDefEdit to alter an existing feature class.  In order to change the spatial reference of an existing feature class you should use IGeoDatasetSchemaEdit2.AlterSpatialReference.

View solution in original post

0 Kudos
7 Replies
NeilClemmons
Regular Contributor III
The spatial reference of a feature is determined by the feature class in which it is stored.  If you get a feature out of a feature class and project its geometry into another coordinate system, you will change the coordinates and spatial reference of that geometry object.  However, if you set the feature's geometry back to the projected geometry and store it, the feature will have updated coordinates but the spatial reference will remain that of the feature class.  If you want to change the spatial reference of all of the features in the feature class, then you will also need to change the spatial reference of the feature class after you've projected them.
0 Kudos
GlennNead
New Contributor
Hi Neil,

Thank you for your response, but I am still having some difficulty.

The FeatureClass's SR now gets updated within the program, but not the SRs of the features.  I had thought it was due to the fact that I was working with the FeatureClass associated with the layer, hoping not the change the original data.  I then tried to work directly with the featureClass from the gdb.  The text fields and coordinates update in the gdb and the SR of the class while in memory updates, but the SR of the features stubbornly remain the original SR as well as the SR of the class when looked at by ArcCatalog.

Do I need to update somehow with the FeatureWorkspaceFactory or otherwise commit?


                                IFields fields = fc.Fields;
                                IFieldsEdit fieldsEdit = fields as IFieldsEdit;
                                int fcShapeIdx = fields.FindField("shape");
                                IField field = fields.Field[fcShapeIdx];
                                IFieldEdit fieldEdit = field as IFieldEdit;

                                IGeometryDef geometryDef = field.GeometryDef;

                                IGeometryDefEdit ge = geometryDef as IGeometryDefEdit;
                                Debug.Print("class ge.SR = " + ge.SpatialReference.Name);
                                ge.SpatialReference_2 = newSR;
                                fieldEdit.GeometryDef_2 = ge;
                                fieldsEdit.set_Field(fcShapeIdx, field);
                                fLayer.FeatureClass = fc;
0 Kudos
NeilClemmons
Regular Contributor III
As mentioned in the developer help, you can't use IFieldsEdit or IGeometryDefEdit to alter an existing feature class.  In order to change the spatial reference of an existing feature class you should use IGeoDatasetSchemaEdit2.AlterSpatialReference.
0 Kudos
GlennNead
New Contributor
Neil,

It took a bit, but I finally found the reference you mentioned in the ArcObjects SDK Microsoft .NET Framework Concepts & Examples.  I greatly appreciate your assistance!

-- Glenn
0 Kudos
GlennNead
New Contributor
Neil,

Are you aware of any issues with NAD 1983?  When changing to or from it, the coordinates change as expected, but the feature will not update.  I do not have the problem with other datums, eg between WGS1984 and WGS1972.  If multistep projections are used, eg ProjectEx WGS1984 to NAD1983,  then to NAD1927 NADCON, then update the feature, the coordinates save correctly.

     -- Glenn
0 Kudos
NeilClemmons
Regular Contributor III
I've never noticed any problems.  In fact, most of the coordinates systems I work with regularly are based on NAD 83 or WGS 84.  I don't do a lot of projecting though.
0 Kudos
GlennNead
New Contributor
Okay, thanks Neil.

I've modified my application to use NAD1983 as a bridge to various NAD1927s from/to WGS1984, but not "land" on it.  Works as expected that way.


[INDENT]-- Glenn[/INDENT]
0 Kudos