You have to distinguish between product licenses and extension licenses. ArcGIS Desktop as a whole is licensed at three product levels: ArcView, ArcEditor, and ArcInfo.
In addition to the product itself there are various extensions that can be licensed. Spatial Analyst is one such extension.
-
If your code is running from within ArcMap there will already be a product license in use of some kind, otherwise ArcMap would not be running. That is why you are getting the first message. Typically you will only run explicit code to check out a product license in an ArcEngine application.
- The second piece of code you have is going through the geoprocessing framework to check out an SA license. Unless you're in a Python GP script, this is a poor way of doing things. In ArcObjects your first code segment is the way to handle licenses.
UPDATE
To programmatically enable an extension in a Desktop application follow the instructions in the How to use extensions help topic. VB.NET code copied directly from the help:
Dim factoryType As Type = Type.GetTypeFromProgID("esriSystem.ExtensionManager")
Dim extensionManager As IExtensionManager = CType(Activator.CreateInstance(factoryType), IExtensionManager)
Dim uid As IUID = New UIDClass()
uid.Value = "esriSpatialAnalystUI.SAExtension"
Dim extension As IExtension = extensionManager.FindExtension(uid)
Dim extensionConfig As IExtensionConfig = CType(extension, IExtensionConfig)
Dim wasEnabled As Boolean = (extensionConfig.State = esriExtensionState.esriESEnabled)
If Not wasEnabled Then
If Not(extensionConfig.State = esriExtensionState.esriESUnavailable) Then
extensionConfig.State = esriExtensionState.esriESEnabled
Else
' Handle the case when the license is not available.
' Provide an error message or exit to avoid running unavailable functionality.
End If
End If
Edited (for the sake of others in a similar situation):
There are a few things you should be checking:
1) You're passing in a string for the neartable.closest_count
variable when it requires a Long data type. Try this:
Dim lCount as Long = 10
neartable.closest_count = lCount
Also, the neartable.closest
variable is being passed a String when it expects a Boolean (ALL = True).
2) Are you sure what you are passing in is actually an IFeatureLayer?
3) Why are you getting the FeatureClass from the FeatureLayer if you're never using that variable?
4) Your input features and near features are the same - is this what you want?
5) You might consider setting all of the GeoProcessor properties, especially the EnvironmentValue:
GP.SetEnvironmentValue("workspace", "C:\workspacepathgoeshere")
6) An Events Listener (as mentioned by Kirk) can provide important information
7) Does the output table that you are trying to create already exist?
Best Answer
Are you using the (relatively) new Geoprocessor class?
If you look at the geoprocessor library of AO you will find the Spatial Analyst tools, too.