Is it possible to change spatialreference by arcobjects?

2142
3
07-04-2010 09:38 PM
SongWendong
New Contributor
I used IGeometryDefEdit.SpatialReference, but it did not work.

I will change every coordinates by code.
0 Kudos
3 Replies
AlexanderGray
Occasional Contributor III
The answer is it depends on what specifically you are trying to do.  If you are trying to change the spatial reference of a feature class, the answer is no.  Typically you would create a new featureclass with the other spatial reference and copy all the features over (which will project them.)  If you are trying to change the spatialreference of a geometry, you can call the project method.
0 Kudos
NeilClemmons
Regular Contributor III
You can change the spatial reference of a feature class, however it must be inside of a feature dataset.  Use IGeoDatasetSchemaEdit2::AlterSpatialReference to change the spatial reference of the feature dataset.  This will change the spatial reference of any feature classes inside the feature dataset.  As Alex mentioned, this will not project the features inside the feature class.  If you need to do that, then you will need to loop through all of the features and project the geometries.  I don't know that there's any way to change the spatial reference of a standalone feature class.
0 Kudos
WilliamBuerger
Occasional Contributor
Resurrecting an old thread here.  But I was looking to do the same thing as the OP and there isn't much that comes up from it.  The problem with the project tool is that it creates new feature classes/datasets.  I would expect new OIDs could come out of that but I know that things like relationships and such get messed up.  Not to mention you then have to copy over all the tables and other things that don't have spatial references and don't get copied.  What would be nicer would be to have the Project tool update the projection of the feature class or dataset and then update all the features with the new coordinates without creating any new objects.  I was able to do just that but it took a bit of work.  Not 100% sure it will work right with annotation either.  Need to test that still.  So it can be done.

One note is that the IGeoDatasetSchemaEdit2::AlterSpatialReference is the method needed to change the spatial reference.  The SDK seems to suggest it's only for FeatureDataset objects.  But it would appear to be implemented on FeatureClass objects as well as it worked for me.
0 Kudos