IAIS Client Sample.bas
//-----------------------------------------------------------------------------
//
// Copyright (c) 2006 Zanja Technologies, Inc
//
// TRADE SECRETS: PROPRIETARY AND CONFIDENTIAL
// Unpublished material - all rights reserved under the
// Copyright Laws of the United States.
//
// Distributed under license by ESRI, Inc.
// For additional information, contact:
// Environmental Systems Research Institute, Inc.
// 380 New York Street
// Redlands, California, USA 92373
//-----------------------------------------------------------------------------/*
This sample code in VB 6.0 creates and initializes the Client connection object, loads an image service, which is published on a server, and requests an image given the extents and the number of rows and columns.
For this sample to work, open a VB 6.0 standard EXE project. Add in references:
• | Image Server Client 1.0 Type Library [ISClient.Dll] |
• | Microsoft XML |
Attribute VB_Name = "Module1"
Public Sub Main()
'Reading the Command Line arguments
Dim args() As String
args = Split(Command$, " ")
' Insufficient number of arguements
If UBound(args) < 9 Then
MsgBox "Usage: " & vbCrLf & vbCrLf & _
"outputType <Image Service name> <XMin> <YMin> <XMax> <YMax> <Cols> <Rows> <Output File> " & vbCrLf & vbCrLf & _
"outputType can take value 'buffer' or 'file' "
End If
' Area of Interest accepted as command line argument
Dim xMin As Double
Dim yMin As Double
Dim xMax As Double
Dim yMax As Double
Dim nCols As Integer
Dim nRows As Integer
' outputType accepted as command line argument
Dim outputType As String
' image service name accepted as command line argument
Dim imageServiceName As String
' The output file where the image is to be exported
Dim outputFile As String
Dim Result As Boolean
' Saving the command line arguments
outputType = args(0)
imageServiceName = args(1)
xMin = CDbl(Val(args(2)))
yMin = CDbl(Val(args(3)))
xMax = CDbl(Val(args(4)))
yMax = CDbl(Val(args(5)))
nCols = CInt(args(6))
nRows = CInt(args(7))
outputFile = args(8)
'Creating and initializing the client connection object
Dim clientObject As IAISClientObject
Set clientObject = New AISClientObject
Dim strConfigPath As String
strConfigPath = ""
If clientObject.Init(strConfigPath) = False Then
MsgBox "Error: " & clientObject.Status
Exit Sub
End If
'Creating and initializing the Image Service object
Dim imageServiceObject As IAISImageService
Set imageServiceObject = clientObject.OpenImageService(imageServiceName, "")
If imageServiceObject Is Nothing Then Exit Sub
'Processing done based on the output type
If outputType = "file" Then
If outputFile = "" Then
MsgBox ("Please specify the output file")
Return
End If
'Creating the XML to write out images
Dim exportPropertiesXML As String
Call MakeExportPropsXML(xMin, xMax, yMin, yMax, nRows, nCols, outputFile, exportPropertiesXML)
'Creating and initializing the Image Writer object
Dim imageWriter As IAISImageWriter
Set imageWriter = New AISImageWriter
Result = imageWriter.Init(imageServiceObject)
If Not Result Then
MsgBox "Failed to initialize Image Writer Object"
Return
End If
'Saving the image to file
Result = imageWriter.Save(exportPropertiesXML)
If Not Result Then
MsgBox "Failed to save Image on file"
Return
End If
MsgBox "Image has been saved on file: " & outputFile
ElseIf outputType = "buffer" Then
Result = imageServiceObject.ExtractAoi(xMin, yMin, xMax, yMax, nCols, nRows)
'Extracting the desired Area Of Interest
If Not Result Then
MsgBox "Failed to extract the required AOI"
Exit Sub
End If
'Creating the buffer
Dim size As Long
size = imageServiceObject.GetBufferSize()
Dim buffer() As Byte
ReDim buffer(size)
'A pointer To the buffer needs to be passed to the Image Service
Dim bufferAddress As Long
bufferAddress = VarPtr(buffer(0))
'Getting the Image data into the buffer
Result = imageServiceObject.GetImageInBuffer(bufferAddress)
If Not Result Then
MsgBox "Failed to get image in the buffer"
Return
Else
MsgBox "Image is saved in buffer"
End If
Else
MsgBox "Please specify valid output type"
Exit Sub
End If
'Closing the Client connection object and the Image service object
imageServiceObject.Close
clientObject.Close
End Sub