This document is archived and information here might be outdated. Recommended version. |
ArcObjects Help for .NET developers > ESRI.ArcGIS.Snippets > Snippets > Create High Precision Spatial Reference Snippet (ArcObjects .NET 10.4 SDK) |
Creates a high precision spatial reference given an enumeration value and two boolean values to dictate if the spatial reference should have M and Z values.
///<summary>Creates a high precision spatial reference given an enumeration value and two boolean values to dictate if the spatial reference should have M and Z values.</summary> /// ///<param name="spatialRefEnum">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="hasMs">A System.Boolean that allows initializing of the resolution for the M value. false=initialize the M value using the ISpatialReferenceResolution interface.</param> ///<param name="hasZs">A System.Boolean that that allows initializing of the resolution for the Z value. false=initialize the Z value using the ISpatialReferenceResolution interface.</param> /// ///<remarks> ///Notes: ///Pass in a ESRI enumeration as an integer. It is possible to either type in the actual number or type out the enumeration with (int) in front of it. /// ///You have the option of also initializing the M and Z default Resolutions by passing true values for the other two ///operands in the method call. It is possible to set the Resolution for M and Z to user defined values. To do this ///set the two boolean values to false and then use a ISpatialReferenceResolution interface to set the values. /// ///Setting the defualt Resolutions will set all the Tolerances to twice the default resolution value. ///To set the defualt Tolerance values it will be necessary to create a ISpatialReferenceTolerance interface and set it equal to your completed ///spatial reference and call the SetDefaultXYTolerance, SetDefaultZTolerance, and SetDefaultMTolerance methods. ///</remarks> /// ///<returns>An ISpatialReference interface will be returned with the Horizons set and XYResolution set to its default value.</returns> /// /// Return geographicCoordinateSystem /// /// Catch generatedExceptionVariable0 As System.ArgumentException /// /// ' Create the spatial reference /// Dim projectedCoordinateSystem As ESRI.ArcGIS.Geometry.IProjectedCoordinateSystem=spatialReferenceFactory3.CreateProjectedCoordinateSystem(CType(spatialRefEnum, System.Int32)) ' Explicit Cast /// /// controlPrecision2=CType(projectedCoordinateSystem, ESRI.ArcGIS.Geometry.IControlPrecision2) ' Explict Cast /// /// ' Make the spatial reference high precision /// controlPrecision2.IsHighPrecision=True /// /// spatialReferenceResolution=CType(projectedCoordinateSystem, ESRI.ArcGIS.Geometry.ISpatialReferenceResolution) ' Explict Cast /// spatialReferenceResolution.ConstructFromHorizon() /// spatialReferenceResolution.SetDefaultXYResolution() /// /// If hasMs Then /// spatialReferenceResolution.SetDefaultMResolution() /// End If /// /// If hasZs Then /// spatialReferenceResolution.SetDefaultZResolution() /// End If /// /// Return projectedCoordinateSystem /// /// End Try /// ///End Function ///#End Region public static ESRI.ArcGIS.Geometry.ISpatialReference CreateHighPrecisionSpatialReference(System.Int32 spatialRefEnum, System.Boolean hasMs, System.Boolean hasZs) { // Create a Projected or Geographic Coordinate System interface then set it equal to a call to the method // CreateHighPrecisionSR cast as the respective interface you have created. // Examples: // ESRI.ArcGIS.Geometry.IProjectedCoordinateSystem projSRset=CreateHighPrecisionSR((System.Int32)ESRI.ArcGIS.Geometry.esriSRProjCS3Type.esriSRProjCS_Sphere_Aitoff, true, true) as ESRI.ArcGIS.Geometry.IProjectedCoordinateSystem; // ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem geoSRset=CreateHighPrecisionSR((System.int32)ESRI.ArcGIS.Geometry.esriSRGeoCS3Type.esriSRGeoCS_TheMoon, true, false) as ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem; ESRI.ArcGIS.Geometry.ISpatialReferenceFactory3 spatialReferenceFactory3=new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass(); ESRI.ArcGIS.Geometry.ISpatialReferenceResolution spatialReferenceResolution; ESRI.ArcGIS.Geometry.IControlPrecision2 controlPrecision2; try { // Create the spatial reference ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem geographicCoordinateSystem=spatialReferenceFactory3.CreateGeographicCoordinateSystem(spatialRefEnum); controlPrecision2=geographicCoordinateSystem as ESRI.ArcGIS.Geometry.IControlPrecision2; // Dynamic Cast // Make the spatial reference high precision controlPrecision2.IsHighPrecision=true; spatialReferenceResolution=geographicCoordinateSystem as ESRI.ArcGIS.Geometry.ISpatialReferenceResolution; // Dynamic Cast spatialReferenceResolution.ConstructFromHorizon(); spatialReferenceResolution.SetDefaultXYResolution(); if (hasMs) spatialReferenceResolution.SetDefaultMResolution(); if (hasZs) spatialReferenceResolution.SetDefaultZResolution(); return geographicCoordinateSystem; } catch (System.ArgumentException) { // Create the spatial reference ESRI.ArcGIS.Geometry.IProjectedCoordinateSystem projectedCoordinateSystem=spatialReferenceFactory3.CreateProjectedCoordinateSystem((System.Int32)spatialRefEnum); // Explict Cast controlPrecision2=projectedCoordinateSystem as ESRI.ArcGIS.Geometry.IControlPrecision2; // Dynamic Cast // Make the spatial reference high precision controlPrecision2.IsHighPrecision=true; spatialReferenceResolution=projectedCoordinateSystem as ESRI.ArcGIS.Geometry.ISpatialReferenceResolution; // Dynamic Cast spatialReferenceResolution.ConstructFromHorizon(); spatialReferenceResolution.SetDefaultXYResolution(); if (hasMs) spatialReferenceResolution.SetDefaultMResolution(); if (hasZs) spatialReferenceResolution.SetDefaultZResolution(); return projectedCoordinateSystem; } }
'''<summary>Creates a high precision spatial reference given an enumeration value and two boolean values to dictate if the spatial reference should have M and Z values.</summary> ''' '''<param name="spatialRefEnum">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="hasMs">A System.Boolean that allows initializing of the resolution for the M value. false=initialize the M value using the ISpatialReferenceResolution interface.</param> '''<param name="hasZs">A System.Boolean that that allows initializing of the resolution for the Z value. false=initialize the Z value using the ISpatialReferenceResolution interface.</param> ''' '''<remarks> '''Notes: '''Pass in a ESRI enumeration as an integer. It is possible to either type in the actual number or type out the enumeration with (int) in front of it. ''' '''You have the option of also initializing the M and Z default Resolutions by passing true values for the other two '''operands in the method call. It is possible to set the Resolution for M and Z to user defined values. To do this '''set the two boolean values to false and then use a ISpatialReferenceResolution interface to set the values. ''' '''Setting the defualt Resolutions will set all the Tolerances to twice the default resolution value. '''To set the defualt Tolerance values it will be necessary to create a ISpatialReferenceTolerance interface and set it equal to your completed '''spatial reference and call the SetDefaultXYTolerance, SetDefaultZTolerance, and SetDefaultMTolerance methods. '''</remarks> ''' '''<returns>An ISpatialReference interface will be returned with the Horizons set and XYResolution set to its default value.</returns> ''' ''' Return geographicCoordinateSystem ''' ''' Catch generatedExceptionVariable0 As System.ArgumentException ''' ''' ' Create the spatial reference ''' Dim projectedCoordinateSystem As ESRI.ArcGIS.Geometry.IProjectedCoordinateSystem=spatialReferenceFactory3.CreateProjectedCoordinateSystem(CType(spatialRefEnum, System.Int32)) ' Explicit Cast ''' ''' controlPrecision2=CType(projectedCoordinateSystem, ESRI.ArcGIS.Geometry.IControlPrecision2) ' Explict Cast ''' ''' ' Make the spatial reference high precision ''' controlPrecision2.IsHighPrecision=True ''' ''' spatialReferenceResolution=CType(projectedCoordinateSystem, ESRI.ArcGIS.Geometry.ISpatialReferenceResolution) ' Explict Cast ''' spatialReferenceResolution.ConstructFromHorizon() ''' spatialReferenceResolution.SetDefaultXYResolution() ''' ''' If hasMs Then ''' spatialReferenceResolution.SetDefaultMResolution() ''' End If ''' ''' If hasZs Then ''' spatialReferenceResolution.SetDefaultZResolution() ''' End If ''' ''' Return projectedCoordinateSystem ''' ''' End Try ''' '''End Function '''#End Region Public Function CreateHighPrecisionSpatialReference(ByVal spatialRefEnum As System.Int32, ByVal hasMs As System.Boolean, ByVal hasZs As System.Boolean) As ESRI.ArcGIS.Geometry.ISpatialReference ' Create a Projected or Geographic Coordinate System interface then set it equal to a call to the method ' CreateHighPrecisionSR cast as the respective interface you have created. ' Examples: ' Dim projSRset As ESRI.ArcGIS.Geometry.IProjectedCoordinateSystem=CType((CreateHighPrecisionSR(CType(ESRI.ArcGIS.Geometry.esriSRProjCS3Type.esriSRProjCS_Sphere_Aitoff, System.Int32), True, True)), ESRI.ArcGIS.Geometry.IProjectedCoordinateSystem) ' Dim geoSRset As ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem=CType((CreateHighPrecisionSR(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 spatialReferenceResolution As ESRI.ArcGIS.Geometry.ISpatialReferenceResolution Dim controlPrecision2 As ESRI.ArcGIS.Geometry.IControlPrecision2 Try ' Create the spatial reference Dim geographicCoordinateSystem As ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem=spatialReferenceFactory3.CreateGeographicCoordinateSystem(spatialRefEnum) controlPrecision2=CType(geographicCoordinateSystem, ESRI.ArcGIS.Geometry.IControlPrecision2) ' Explicit Cast ' Make the spatial reference high precision controlPrecision2.IsHighPrecision=True spatialReferenceResolution=CType(geographicCoordinateSystem, ESRI.ArcGIS.Geometry.ISpatialReferenceResolution) ' Explict Cast spatialReferenceResolution.ConstructFromHorizon() spatialReferenceResolution.SetDefaultXYResolution() If hasMs Then spatialReferenceResolution.SetDefaultMResolution() End If If hasZs Then spatialReferenceResolution.SetDefaultZResolution() End If Return geographicCoordinateSystem Catch generatedExceptionVariable0 As System.ArgumentException ' Create the spatial reference Dim projectedCoordinateSystem As ESRI.ArcGIS.Geometry.IProjectedCoordinateSystem=spatialReferenceFactory3.CreateProjectedCoordinateSystem(CType(spatialRefEnum, System.Int32)) ' Explicit Cast controlPrecision2=CType(projectedCoordinateSystem, ESRI.ArcGIS.Geometry.IControlPrecision2) ' Explict Cast ' Make the spatial reference high precision controlPrecision2.IsHighPrecision=True spatialReferenceResolution=CType(projectedCoordinateSystem, ESRI.ArcGIS.Geometry.ISpatialReferenceResolution) ' Explict Cast spatialReferenceResolution.ConstructFromHorizon() spatialReferenceResolution.SetDefaultXYResolution() If hasMs Then spatialReferenceResolution.SetDefaultMResolution() End If If hasZs Then spatialReferenceResolution.SetDefaultZResolution() End If Return projectedCoordinateSystem End Try End Function