Geographic Coordinate System Corruption in ArcObjects 10.2.2

486
0
06-06-2014 12:56 PM
niroshanshan
New Contributor
Hi,

We just upgrade from ArcObjects 10.1 to 10.2.2 and now we're having a problem where the Geographic Coordinate System (GCS) object gets corrupted after calling the DefineEx (or Define) method a few times (see code sample 1).

I found a workaround by pulling the GCS object from a projection coordinate system object (see code sample 2).

Is there any reason for this behavior and how can I create a Geographic Coordinate System from a factory code?

Thanks,
Niro

Code Sample 1
 
                int numberOfErrors = 0;

                for (int i = 0; i < 1000; i++)
                {
                    var spatialReferenceFactory = new SpatialReferenceEnvironmentClass(); //(ISpatialReferenceFactory4)Activator.CreateInstance(Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment"));
                    var geographicCoordinateSystem = spatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_NAD1983) as IGeographicCoordinateSystem;
//                    var projectedCoordinateSystem = spatialReferenceFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_NAD1983UTM_17N);
//                    var geographicCoordinateSystem = projectedCoordinateSystem.GeographicCoordinateSystem;
                       
                    (geographicCoordinateSystem as IGeographicCoordinateSystemEdit).DefineEx(
                        geographicCoordinateSystem.Name,
                        geographicCoordinateSystem.Alias,
                        geographicCoordinateSystem.Abbreviation,
                        geographicCoordinateSystem.Remarks,
                        geographicCoordinateSystem.Usage,
                        geographicCoordinateSystem.Datum,
                        geographicCoordinateSystem.PrimeMeridian,
                        geographicCoordinateSystem.CoordinateUnit);

                    if (String.IsNullOrEmpty(geographicCoordinateSystem.Name))
                        numberOfErrors++;
                }
              


Code Sample 2
     
                int numberOfErrors = 0;

                for (int i = 0; i < 1000; i++)
                {
                    var spatialReferenceFactory = new SpatialReferenceEnvironmentClass(); //(ISpatialReferenceFactory4)Activator.CreateInstance(Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment"));
//                    var geographicCoordinateSystem = spatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_NAD1983) as IGeographicCoordinateSystem;
                    var projectedCoordinateSystem = spatialReferenceFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_NAD1983UTM_17N);
                    var geographicCoordinateSystem = projectedCoordinateSystem.GeographicCoordinateSystem;
                       
                    (geographicCoordinateSystem as IGeographicCoordinateSystemEdit).DefineEx(
                        geographicCoordinateSystem.Name,
                        geographicCoordinateSystem.Alias,
                        geographicCoordinateSystem.Abbreviation,
                        geographicCoordinateSystem.Remarks,
                        geographicCoordinateSystem.Usage,
                        geographicCoordinateSystem.Datum,
                        geographicCoordinateSystem.PrimeMeridian,
                        geographicCoordinateSystem.CoordinateUnit);

                    if (String.IsNullOrEmpty(geographicCoordinateSystem.Name))
                        numberOfErrors++;
0 Kudos
0 Replies