PatrickG25

Retrieve image extents from various types of images

Discussion created by PatrickG25 on Oct 13, 2011
Latest reply on Oct 19, 2011 by PatrickG25
Hi,

I'm in the process of writing a program that grabs all of the images in a folder and extracts the extent information for each one and stuffs that data into an array for later use.  Here's what I have so far:

'This function takes the filepaths and filenames of a number of projected rasters and returns an array list of X min, X max, Y min, and Y max
    Public Function GetBoundingCoords(ByVal Filepaths As ArrayList, ByVal Filenames As ArrayList) As Array

        'Initialize ArcGIS (Must occur before any ArcGIS tools are accessed)
        ESRI.ArcGIS.RuntimeManager.BindLicense(ProductCode.EngineOrDesktop)

        'Create array that will be returned
        Dim RasterExtents(3, Filenames.Count - 1) As Double

        Dim i As Integer
        Dim xMin As Double
        Dim xMax As Double
        Dim yMin As Double
        Dim yMax As Double

        For i = 0 To Filenames.Count - 1

            Try
                'Get target raster file name and path
                Dim Filepath As String = Filepaths(i)
                Dim FileName As String = Filenames(i)

                'Get raster dataset
                Dim wFactory As WorkspaceFactory = New RasterWorkspaceFactoryClass
                Dim wspace As IWorkspace = wFactory.OpenFromFile(Filepath, 0)           '<------------------Problem Here
                Dim rWorkspace As IRasterWorkspace = CType(wspace, IRasterWorkspace)
                Dim rDataset As IRasterDataset = rWorkspace.OpenRasterDataset(FileName)
                Dim geoDs As IGeoDataset = DirectCast(rDataset, IGeoDataset)

                'Create coordinate system variables
                Dim strPCS As IProjectedCoordinateSystem5 = geoDs.SpatialReference
                Dim sRefEnv As ISpatialReferenceFactory3 = New SpatialReferenceEnvironment
                Dim strGCS As IGeographicCoordinateSystem2 = sRefEnv.CreateGeographicCoordinateSystem(esriSRGeoCSType.esriSRGeoCS_WGS1984)

                'Create point variables
                Dim pcsLLPoint As IPoint = geoDs.Extent.LowerLeft
                Dim pcsURPoint As IPoint = geoDs.Extent.UpperRight

                'Project points from original coordinate system to WGS 1984
                pcsLLPoint.Project(strGCS)
                pcsURPoint.Project(strGCS)

                'Assign coordinate values to variables
                xMin = pcsLLPoint.X
                xMax = pcsURPoint.X
                yMin = pcsLLPoint.Y
                yMax = pcsURPoint.Y

                RasterExtents(i, 0) = xMin
                RasterExtents(i, 1) = xMax
                RasterExtents(i, 2) = yMin
                RasterExtents(i, 3) = yMax

            Catch ex As Exception
                MsgBox(ex.Message)

            End Try

        Next

        'Return the point coordinates in the array
        Return RasterExtents

    End Function


And here is the error:

[URL=http://imageshack.us/photo/my-images/692/errormessage.jpg/][/URL]

Is this something I can do without using an ArcMap License?  Is there a programmatic way to access the coordinate information from various raster file types without using ArcMap to evaluate each image?

Thanks in advance!

- Patrick

Outcomes