This document is archived and information here might be outdated.  Recommended version.


Convert Spatial Reference From High To Low Precision Snippet (ArcObjects .NET 10.5 SDK)
ArcObjects Library Reference

Convert Spatial Reference From High To Low Precision Snippet

Converts an existing high precision spatial reference and returns a new low precision spatial reference.

[C#]
///<summary>Converts an existing high precision spatial reference and returns a new low precision spatial reference.</summary>
///  
///<param name="highSpatialReference">An ISpatialReference interface that is a high precision spatial reference.</param>
///<param name="envelope">An IEnvelope that is the area covering the extent of the new low precision spatial reference.</param>
///   
///<returns>An ISpatialReference interface that is the new low precision spatial reference.</returns>
///   
///<remarks></remarks>
public ESRI.ArcGIS.Geometry.ISpatialReference ConvertSpatialReferenceFromHighToLowPrecision(ESRI.ArcGIS.Geometry.ISpatialReference highSpatialReference, ESRI.ArcGIS.Geometry.IEnvelope envelope)
{
  ESRI.ArcGIS.Geometry.IControlPrecision2 controlPrecision2=highSpatialReference as ESRI.ArcGIS.Geometry.IControlPrecision2; // Dynamic Cast
  ESRI.ArcGIS.Geometry.ISpatialReference lowSpatialReference=null;
  if (controlPrecision2.IsHighPrecision)
  {
    ESRI.ArcGIS.Geometry.ISpatialReferenceFactory3 spatialReferenceFactory3=new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass();
    try
    {
      lowSpatialReference=spatialReferenceFactory3.ConstructLowPrecisionSpatialReference(true, highSpatialReference, envelope);
    }

    catch (System.Runtime.InteropServices.COMException ex)
    {
      if (ex.ErrorCode == -2147220986)
      {
        lowSpatialReference=spatialReferenceFactory3.ConstructLowPrecisionSpatialReference(false, highSpatialReference, envelope);
      }
    }

    return lowSpatialReference;
  }

  return null;
}
[Visual Basic .NET]
'''<summary>Converts an existing high precision spatial reference and returns a new low precision spatial reference.</summary>
'''  
'''<param name="highSpatialReference">An ISpatialReference interface that is a high precision spatial reference.</param>
'''<param name="envelope">An IEnvelope that is the area covering the extent of the new low precision spatial reference.</param>
'''   
'''<returns>An ISpatialReference interface that is the new low precision spatial reference.</returns>
'''   
'''<remarks></remarks>
Public Function ConvertSpatialReferenceFromHighToLowPrecision(ByVal highSpatialReference As ESRI.ArcGIS.Geometry.ISpatialReference, ByVal envelope As ESRI.ArcGIS.Geometry.IEnvelope) As ESRI.ArcGIS.Geometry.ISpatialReference

  Dim controlPrecision2 As ESRI.ArcGIS.Geometry.IControlPrecision2=CType(highSpatialReference, ESRI.ArcGIS.Geometry.IControlPrecision2) ' Explicit Cast
  Dim lowSpatialReference As ESRI.ArcGIS.Geometry.ISpatialReference=Nothing

  If controlPrecision2.IsHighPrecision Then

    Dim spatialReferenceFactory3 As ESRI.ArcGIS.Geometry.ISpatialReferenceFactory3=New ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass

    Try

      lowSpatialReference=spatialReferenceFactory3.ConstructLowPrecisionSpatialReference(True, highSpatialReference, envelope)

    Catch ex As System.Runtime.InteropServices.COMException

      If ex.ErrorCode=-2147220986 Then

        lowSpatialReference=spatialReferenceFactory3.ConstructLowPrecisionSpatialReference(False, highSpatialReference, envelope)

      End If

    End Try

    Return lowSpatialReference

  End If

  Return Nothing

End Function

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.Geometry
  • ESRI.ArcGIS.System