GPPointFileInfo\SpatialReferenceClass.vb
Creating a non-trival custom GP tool - inputs, outputs, and responding to environment settings
GPPointFileInfo\SpatialReferenceClass.vb
' Copyright 2008 ESRI
' 
' All rights reserved under the copyright laws of the United States
' and applicable international laws, treaties, and conventions.
' 
' You may freely redistribute and use this sample code, with or
' without modification, provided you include the original copyright
' notice and use restrictions.
' 
' See use restrictions at <your ArcGIS install location>/developerkit/userestrictions.txt.
' 

Imports Microsoft.VisualBasic
Imports System
Imports System.Runtime.InteropServices
Imports ESRI.ArcGIS.Geometry

Namespace GPPointFileInfo
  Public Class SpatialReferenceClass
        Implements GPPointFileInfo.ISpatialReference
    Private _spatialReference As ESRI.ArcGIS.Geometry.ISpatialReference
    Private _isUnknown As Boolean

    Public Sub New(ByVal coordinateSystem As ICoordinateSystem)
      _spatialReference = GetSpatialReference(coordinateSystem)

      _isUnknown = GetIsUnknown(_spatialReference)
    End Sub

        Public ReadOnly Property SpatialReference() As ESRI.ArcGIS.Geometry.ISpatialReference Implements ISpatialReference.SpatialReference
            Get
                Return _spatialReference
            End Get
        End Property

    Private Function GetSpatialReference(ByVal coordinateSystem As ICoordinateSystem) As ESRI.ArcGIS.Geometry.ISpatialReference
      Dim spatialReference As ESRI.ArcGIS.Geometry.ISpatialReference

      If (TypeOf coordinateSystem Is IESOutputCoordinateSystem) AndAlso (coordinateSystem.SpatialReference Is Nothing) Then
        spatialReference = GetUnknownSpatialReference()
      Else
        spatialReference = coordinateSystem.SpatialReference
      End If

      Dim spatialReferenceResolution As ISpatialReferenceResolution = TryCast(spatialReference, ISpatialReferenceResolution)

      spatialReferenceResolution.ConstructFromHorizon()
      spatialReferenceResolution.SetDefaultXYResolution()
      spatialReferenceResolution.SetDefaultZResolution()

      Dim spatialReferenceTolerance As ISpatialReferenceTolerance = TryCast(spatialReference, ISpatialReferenceTolerance)

      spatialReferenceTolerance.SetDefaultXYTolerance()
      spatialReferenceTolerance.SetDefaultZTolerance()

      Return spatialReference
    End Function

    Private Function GetUnknownSpatialReference() As ESRI.ArcGIS.Geometry.ISpatialReference
      Return New UnknownCoordinateSystemClass()
    End Function

        Public ReadOnly Property IsUnknown() As Boolean Implements ISpatialReference.IsUnknown
            Get
                Return _isUnknown
            End Get
        End Property

    Private Function GetIsUnknown(ByVal spatialReference As ESRI.ArcGIS.Geometry.ISpatialReference) As Boolean
      Return (spatialReference.Name = "Unknown")
    End Function
  End Class
End Namespace