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


Create Low Precision Spatial Reference Snippet (ArcObjects .NET 10.4 SDK)
ArcObjects Library Reference

Create Low Precision Spatial Reference Snippet

Creates a low precision spatial reference given an enumeration value and domain in the form of an IEnvelope.

[C#]
///<summary>Creates a low precision spatial reference given an enumeration value and domain in the form of an IEnvelope.</summary>
///  
///<param name="spatialReferenceEnum">A System.Int32 that comes from an ESRI.ArcGIS.Geometry.esriSRGeoCS3Type enumeration. Example: (System.Int32)ESRI.ArcGIS.Geometry.esriSRProjCS3Type.esriSRProjCS_Sphere_Aitoff</param>
///<param name="envelope">An  IEnvelope interface for the area that defines the spatial reference.</param>
///   
///<remarks>
///Passing in both an ESRI enumeration as an interger and a the domain extents you wish your spatial reference to cover in the form of an ESRI IEnvelope. 
///   
///It is possible to either type in the actual number or type out the enumeration with (int) in front of it.
///  
///A Spatial reference will be returned with the Domain set to equal your envelope values and XYResolution (which is the inverse of Precision) set. 
///  
///It is possible to reset the XYResoltion after the spatial reference has been returned using the ISpatialReferenceResolution interface.
///</remarks>
public static ESRI.ArcGIS.Geometry.ISpatialReference CreateLowPrecisionSpatialReference(System.Int32 spatialReferenceEnum, ESRI.ArcGIS.Geometry.IEnvelope envelope)
{
  // Create a Projected or Geographic Coordinate System interface then set it equal to a call to the method
  // CreateingLowPrecisionSR cast as the respective interface you have created. 
  // Examples:
  //  Dim projSRset As ESRI.ArcGIS.Geometry.IProjectedCoordinateSystem=CType((CreateingLowPrecisionSR(CType(ESRI.ArcGIS.Geometry.esriSRProjCS3Type.esriSRProjCS_Sphere_Aitoff, System.Int32), True, True)), ESRI.ArcGIS.Geometry.IProjectedCoordinateSystem)
  //  Dim geoSRset As ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem=CType((CreateingLowPrecisionSR(CType(ESRI.ArcGIS.Geometry.esriSRGeoCS3Type.esriSRGeoCS_TheMoon, System.Int32), True, False)), ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem)

  ESRI.ArcGIS.Geometry.ISpatialReferenceFactory3 spatialReferenceFactory3=new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass();
  ESRI.ArcGIS.Geometry.IControlPrecision2 controlPrecision2;
  ESRI.ArcGIS.Geometry.ISpatialReferenceResolution spatialReferenceResolution;

  try
  {
    // Create the spatial reference
    ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem geographicCoordinateSystem=spatialReferenceFactory3.CreateGeographicCoordinateSystem(spatialReferenceEnum);

    controlPrecision2=geographicCoordinateSystem as ESRI.ArcGIS.Geometry.IControlPrecision2; // Dynamic Cast

    // Make the spatial reference low precision
    controlPrecision2.IsHighPrecision=false;

    // Use of provided envelope to set the domain of the spatial reference
    geographicCoordinateSystem.SetDomain(envelope.XMin, envelope.XMax, envelope.YMin, envelope.YMax);

    spatialReferenceResolution=geographicCoordinateSystem as ESRI.ArcGIS.Geometry.ISpatialReferenceResolution; // Dynamic Cast

    // Set the defualt XY resolution
    spatialReferenceResolution.SetDefaultXYResolution();

    return geographicCoordinateSystem;
  }

  catch (System.ArgumentException)
  {
    // Create the spatial reference
    ESRI.ArcGIS.Geometry.IProjectedCoordinateSystem projectedCoordinateSystem=spatialReferenceFactory3.CreateProjectedCoordinateSystem(spatialReferenceEnum);

    controlPrecision2=projectedCoordinateSystem as ESRI.ArcGIS.Geometry.IControlPrecision2; // Dynamic Cast

    // Make the spatial reference low precision
    controlPrecision2.IsHighPrecision=false;

    // Use of provided envelope to set the domain of the spatial reference
    projectedCoordinateSystem.SetDomain(envelope.XMin, envelope.XMax, envelope.YMin, envelope.YMax);

    spatialReferenceResolution=projectedCoordinateSystem as ESRI.ArcGIS.Geometry.ISpatialReferenceResolution; // Dynamic Cast

    // Set the defualt XY resolution
    spatialReferenceResolution.SetDefaultXYResolution();

    return projectedCoordinateSystem;
  }
}
[Visual Basic .NET]
'''<summary>Creates a low precision spatial reference given an enumeration value and domain in the form of an IEnvelope.</summary>
'''  
'''<param name="spatialReferenceEnum">A System.Int32 that comes from an ESRI.ArcGIS.Geometry.esriSRGeoCS3Type enumeration. Example: (System.Int32)ESRI.ArcGIS.Geometry.esriSRProjCS3Type.esriSRProjCS_Sphere_Aitoff</param>
'''<param name="envelope">An  IEnvelope interface for the area that defines the spatial reference.</param>
'''   
'''<remarks>
'''Passing in both an ESRI enumeration as an interger and a the domain extents you wish your spatial reference to cover in the form of an ESRI IEnvelope. 
'''   
'''It is possible to either type in the actual number or type out the enumeration with (int) in front of it.
'''  
'''A Spatial reference will be returned with the Domain set to equal your envelope values and XYResolution (which is the inverse of Precision) set. 
'''  
'''It is possible to reset the XYResoltion after the spatial reference has been returned using the ISpatialReferenceResolution interface.
'''</remarks>
Public Function CreateLowPrecisionSpatialReference(ByVal spatialReferenceEnum As System.Int32, ByVal envelope As ESRI.ArcGIS.Geometry.IEnvelope) As ESRI.ArcGIS.Geometry.ISpatialReference

  ' Create a Projected or Geographic Coordinate System interface then set it equal to a call to the method
  ' CreateingLowPrecisionSR cast as the respective interface you have created. 
  ' Examples:
  '  Dim projSRset As ESRI.ArcGIS.Geometry.IProjectedCoordinateSystem=CType((CreateingLowPrecisionSR(CType(ESRI.ArcGIS.Geometry.esriSRProjCS3Type.esriSRProjCS_Sphere_Aitoff, System.Int32), True, True)), ESRI.ArcGIS.Geometry.IProjectedCoordinateSystem)
  '  Dim geoSRset As ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem=CType((CreateingLowPrecisionSR(CType(ESRI.ArcGIS.Geometry.esriSRGeoCS3Type.esriSRGeoCS_TheMoon, System.Int32), True, False)), ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem)

  Dim spatialReferenceFactory3 As ESRI.ArcGIS.Geometry.ISpatialReferenceFactory3=New ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass
  Dim controlPrecision2 As ESRI.ArcGIS.Geometry.IControlPrecision2
  Dim spatialReferenceResolution As ESRI.ArcGIS.Geometry.ISpatialReferenceResolution

  Try

    ' Create the spatial reference
    Dim geographicCoordinateSystem As ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem=spatialReferenceFactory3.CreateGeographicCoordinateSystem(spatialReferenceEnum)
    controlPrecision2=CType(geographicCoordinateSystem, ESRI.ArcGIS.Geometry.IControlPrecision2) ' Explicit Cast

    ' Make the spatial reference low precision
    controlPrecision2.IsHighPrecision=False

    ' use of provided envelope to set the domain of the spatial reference
    geographicCoordinateSystem.SetDomain(envelope.XMin, envelope.XMax, envelope.YMin, envelope.YMax)
    spatialReferenceResolution=CType(geographicCoordinateSystem, ESRI.ArcGIS.Geometry.ISpatialReferenceResolution) ' Explicit Cast

    ' set the defualt XY resolution
    spatialReferenceResolution.SetDefaultXYResolution()

    Return geographicCoordinateSystem

  Catch generatedExceptionVariable0 As System.ArgumentException

    ' Create the spatial reference
    Dim projectedCoordinateSystem As ESRI.ArcGIS.Geometry.IProjectedCoordinateSystem=spatialReferenceFactory3.CreateProjectedCoordinateSystem(spatialReferenceEnum)
    controlPrecision2=CType(projectedCoordinateSystem, ESRI.ArcGIS.Geometry.IControlPrecision2) ' Explict Cast

    ' Make the spatial reference low precision
    controlPrecision2.IsHighPrecision=False

    ' use of provided envelope to set the domain of the spatial reference
    projectedCoordinateSystem.SetDomain(envelope.XMin, envelope.XMax, envelope.YMin, envelope.YMax)
    spatialReferenceResolution=CType(projectedCoordinateSystem, ESRI.ArcGIS.Geometry.ISpatialReferenceResolution)

    ' set the defualt XY resolution
    spatialReferenceResolution.SetDefaultXYResolution()

    Return projectedCoordinateSystem

  End Try

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