GEOG 490/590

GIS Programming

Exercise 8: Raster Analysis

This exercise lets you practice the use of raster data in spatial analysis. The exercise covers the raster analysis lecture we had this week. The topics include:

1. Con Operation - Con

2. Math Operation - SquareRoot

3. Local Operation - Combine

4. Neighborhood Operation - FocalStatistics

You can use the sample code (Ex8_CodeSample.txt) for this exercise. You will need to use serveral rasters for this exercise. You can download sample data here.

Create an ArcMap add-in and copy and paste the sampe code into an event can could trigger the individual procedures (e.g., a button on a dockable window). Or, you can copy the code to a new class and call the individual procedures from the event control. The procedures intended to be associated with these events have a suffix of Demo on their names (e.g., MathOpDemo(), ConOpConDemo(), NBROpDemo(), LocalOpDemo()). Make sure you enable the ArcGIS Spatial Analyst Extension before running the addin application you created. See the additional code below if you want to enable the extension programmatically.

1. Before you can debug the program, you need to add the required references and import the namespaces to your project first. Please use online help to figure out which references and namespaces need to be added.

2. The sample code reads the data directly from the C:\temp\data folder. You don't have to add any layer to ArcMap beforehand. All data names are hard-coded in the program. Please read the sample code for these file names.

3. Try the following tasks on individual procedures.

* MathOpDemo(): Use MathOpSQRT function as a template to create your own math tools.

* ConOpConDemo(): Try using a RasterDescriptor as an input to other raster operations and see how it affects the results. Also, try to specify different raster datasets as the True raster of the Con method.

* NBROpDemo(): Experiment with different FocalStatistic filter types and RasterNeighborhood definitions.

* LocalOpDemo(): Experiment with different IRasterAnalysisEnvironment settings. Try to add another raster dataset in the combine process.

Sample code for enabling Spatial Analyst Extension programmatically

Dim pExt As ESRI.ArcGIS.esriSystem.IExtension = My.ArcMap.Application.FindExtensionByName("Spatial Analyst")

Dim pExtConfig As ESRI.ArcGIS.esriSystem.IExtensionConfig = pExt

pExtConfig.State = ESRI.ArcGIS.esriSystem.esriExtensionState.esriESEnabled