Select to view content in your preferred language

New to .NET, need help getting bounding coordinates from a raster

1357
11
09-06-2011 11:41 AM
PatrickGross
Emerging Contributor
Hey everyone,

I'm working with a guy in my office to develop an AutoCAD solution to automatically load the appropriate topographic maps into an active AutoCAD window.

Our solution requires getting the bounding coordinates for each raster and writing them out to a table so when the main code runs, it knows which rasters lie in the given map extent.  We already have the code necessary to do coordinate translation, but I just cant figure out what ArcMap function to use to retrieve the X & Y min & max.  Any ideas?

Thanks in advance!
0 Kudos
11 Replies
AlexanderGray
Honored Contributor
Framework 4.0 is currently not supported, suggest you change your project to work against Framework 3.5. 
Also based on the error and the highlighted error you mentioned previously, the compiler may be confused between class names and variable names.  RasterWorkspace is a class name and you are using it as a variable name, that is usually considered bad form.  In that case there is no way for the compiler (vb is case insensitive) to tell if you are calling a static method on the class or an instance method on the interface.  It usually defaults to variable over class but maybe not this time.
0 Kudos
PatrickGross
Emerging Contributor
.....I got it.




Public Function GetBoundingCoords(ByVal Filepath As String, ByVal Filename As String) As IGeoDataset

        Dim coordXMax As Double
        Dim coordYMax As Double
        Dim coordXMin As Double
        Dim coordYMin As Double


        '***** Option 1: *****
        ESRI.ArcGIS.RuntimeManager.Bind(ProductCode.EngineOrDesktop)
        'Instantiate engine component.
        Dim doc As IDocument = New ESRI.ArcGIS.ArcMapUI.MxDocument()

        Dim wFactory As WorkspaceFactory = New RasterWorkspaceFactory()
        Dim rWorkspace As ESRI.ArcGIS.DataSourcesRaster.IRasterWorkspace = CType(wFactory.OpenFromFile(Filepath, 0), ESRI.ArcGIS.DataSourcesRaster.IRasterWorkspace)
        Dim rDataset As IRasterDataset = rWorkspace.OpenRasterDataset(Filename)
        Dim geoDs As IGeoDataset = DirectCast(rDataset, IGeoDataset)

        'Assign extents to variables
        coordXMax = geoDs.Extent.XMax
        coordYMax = geoDs.Extent.YMax
        coordXMin = geoDs.Extent.XMin
        coordYMin = geoDs.Extent.YMin

        'Test
        MsgBox(coordXMax)

    End Function


So, I didn't have the .NET SDK installed.  Whoops.  Once I got the ESRI.ArcGIS.Version.dll file referenced in, everything worked juuuust fine.  I still need to add some more stuff in, but this is what I was getting stuck on.

Thanks everyone for your help!
0 Kudos