Programming ArcObjects with VBA A Task-Oriented Approach Copyright 2005 by CRC Press LLC 2781title 6/10/04 9:38 AM Page 1 Programming ArcObjects with VBA A Task-Oriented Approach Kang-Tsung Chang g CRC PR ESS Boca Raton London New York Washington, D.C. Copyright 2005 by CRC Press LLC 2781_C00.fm Page iv Thursday, June 10, 2004 10:45 AM Library of Congress Cataloging-in-Publication Data Chang, Kang-Tsung. Programming ArcObjects with VBA : a task-oriented approach / Kang-Tsung Chang. p. cm. Includes bibliographical references and index. ISBN 0-8493-2781-4 (alk. paper) 1. Microsoft Visual Basic for applications. 2. Graphical user interfaces (Computer systems) 3. Geographic information systems. 4. ArcGIS. I. Title. T58.62.C27 2004 005.1′17—dc22 2004045487 This book contains information obtained from authentic and highly regarded sources. Reprinted material is quoted with permission, and sources are indicated. A wide variety of references are listed. Reasonable efforts have been made to publish reliable data and information, but the author and the publisher cannot assume responsibility for the validity of all materials or for the consequences of their use. Neither this book nor any part may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, microfilming, and recording, or by any information storage or retrieval system, without prior permission in writing from the publisher. The consent of CRC Press LLC does not extend to copying for general distribution, for promotion, for creating new works, or for resale. Specific permission must be obtained in writing from CRC Press LLC for such copying. Direct all inquiries to CRC Press LLC, 2000 N.W. Corporate Blvd., Boca Raton, Florida 33431. Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for identification and explanation, without intent to infringe. Visit the CRC Press Web site at www.crcpress.com © 2005 by CRC Press LLC No claim to original U.S. Government works International Standard Book Number 0-8493-2781-4 Library of Congress Card Number 2004045487 Printed in the United States of America 1 2 3 4 5 6 7 8 9 0 Printed on acid-free paper Copyright 2005 by CRC Press LLC 2781_C00.fm Page v Thursday, June 10, 2004 10:45 AM About the Author Kang-tsung (Karl) Chang is a professor of geography at the University of Idaho. He received his B.S. in geography from National Taiwan University and his M.A. and Ph.D. from Clark University. He has taught geographic information sys- tems (GIS) and macro programming in GIS since 1988. He has previously published three other books on GIS. Copyright 2005 by CRC Press LLC 2781_C00.fm Page vii Thursday, June 10, 2004 10:45 AM Contents Introduction The Task-Oriented Approach About This Book Typographical Conventions Chapter 1 ArcObjects 1.1 Geodatabase 1.1.1 Vector Data 1.1.2 Raster Data 1.1.3 Triangulated Irregular Networks (TINs) 1.1.4 Location Data 1.1.5 Nongeographic Data 1.2 ArcObjects 1.2.1 Objects and Classes 1.2.2 Relationships between Classes 1.2.3 Interfaces 1.2.4 Properties and Methods 1.3 Organization of ArcObjects 1.4 Help Sources on ArcObjects 1.4.1 ArcObjects Developer Help 1.4.2 Object Model Diagrams 1.4.3 ESRI Object Browser References Chapter 2 Programming Basics 2.1 Basic Elements 2.1.1 Projects, Modules, Procedures, and Macros 2.1.2 Variables 2.1.3 Use of Properties and Methods 2.1.4 QueryInterface 2.1.5 Comment Lines and Line Continuation 2.1.6 Arrays 2.1.7 Collections 2.2 Writing Code 2.2.1 If…Then…Else Statement 2.2.2 Select Case Statement 2.2.3 Do…Loop Statement 2.2.4 For…Next Statement 2.2.5 For Each…Next Statement 2.2.6 With Statement Copyright 2005 by CRC Press LLC 2781_C00.fm Page viii Thursday, June 10, 2004 10:45 AM 2.2.7 Dialog Boxes 2.3 Calling Subs and Functions 2.4 Visual Basic Editor 2.5 Debugging Code 2.5.1 Type of Error 2.5.2 On Error Statement 2.5.3 Use of Breakpoint and Immediate Window Chapter 3 Customization of the User Interface 3.1 Creating a Toolbar with Existing ArcMap Commands 3.2 Adding a New Button 3.3 Adding a New Tool 3.4 Storing a New Toolbar in a Template 3.5 Adding a Form 3.5.1 Designing a Form 3.5.2 Associating Controls with Procedures 3.5.3 Running a Form 3.5.4 Linking a Button to a Form 3.6 Storing a Form in a Template Chapter 4 Dataset and Layer Management 4.1 Using Datasets in ArcGIS 4.2 ArcObjects for Datasets and Layers 4.3 Adding Datasets as Layers 4.3.1 AddFeatureClass 4.3.2 AddFeatureClasses 4.3.3 AddRaster 4.3.4 AddLayerFile 4.3.5 AddTable 4.4 Managing Layers 4.4.1 FindLayer 4.5 Managing Datasets 4.5.1 CopyDataset 4.5.2 DeleteDataset 4.6 Reporting Geographic Dataset Information 4.6.1 SpatialRef Chapter 5 Attribute Data Management 5.1 Managing Attribute Data in ArcGIS 5.2 ArcObjects for Attribute Data Management 5.2.1 Tables 5.2.2 Fields and Field 5.2.3 Relationship Classes Copyright 2005 by CRC Press LLC 2781_C00.fm Page ix Thursday, June 10, 2004 10:45 AM 5.3 Listing Fields and Field Properties 5.3.1 ListOfFields 5.3.2 ListFieldProps 5.3.3 UseFindLayer 5.4 Adding or Deleting Fields 5.4.1 AddDeleteField 5.5 Calculating Field Values 5.5.1 CalculateField 5.5.2 UpdateValue 5.6 Joining and Relating Tables 5.6.1 JoinTableToLayer 5.6.2 JoinMultipleTables 5.6.3 RelateTableToLaye 5.6.4 RelationalDatabase Chapter 6 Data Conversion 6.1 Converting Data in ArcGIS 6.2 ArcObjects for Data Conversion 6.2.1 Objects for Feature Data Conversion 6.2.2 Objects for Rasterization and Vectorization 6.2.3 Objects for XY Event 6.3 Converting Shapefile to GeoDatabase 6.3.1 ShapefileToAccess 6.3.2 MultipleShapefilesToAccess 6.3.3 ShapefilesToFeatureDataset 6.4 Converting Coverage to GeoDatabase and Shapefile 6.4.1 CoverageToAccess 6.4.2 CoverageToShapefile 6.5 Performing Rasterization and Vectorization 6.5.1 FeatureToRaster 6.5.2 FCDescriptorToRaster 6.5.3 RasterToShapefile 6.5.4 RasterDescriptorToShapefile 6.6 Adding XY Events 6.6.1 XYEvents Chapter 7 Coordinate Systems 7.1 Managing Coordinate Systems in ArcGIS 7.1.1 Defining Coordinate Systems 7.1.2 Performing Geographic Transformations 7.1.3 Projecting Datasets 7.2 ArcObjects for Coordinate Systems 7.3 Manipulating On-the-Fly Projection 7.3.1 UTM_OnTheFly Copyright 2005 by CRC Press LLC 2781_C00.fm Page x Thursday, June 10, 2004 10:45 AM 7.3.2 IDTM_OnTheFly 7.4 Defining Coordinate Systems 7.4.1 DefineGCS 7.4.2 CopySpatialReference 7.5 Performing Geographic Transformations 7.5.1 NAD27to83_Map 7.5.2 NAD27to83_Shapefile 7.6 Projecting Datasets 7.6.1 ProjectShapefile 7.6.2 Use of a Different Datum 7.6.3 ReprojectShapefile Chapter 8 Data Display 8.1 Displaying Data in ArcGIS 8.1.1 Displaying Vector 8.1.2 Displaying Raster Data 8.1.3 Use of Color Ramp and Classification Tools 8.1.4 Designing a Layout 8.2 ArcObjects for Data Display 8.2.1 Renderer Objects 8.2.2 Classification Objects 8.2.3 Color Ramp and Color Objects 8.2.4 Layout Objects 8.3 Displaying Vector Data 8.3.1 GraduatedColors 8.3.2 GraduatedSymbols 8.3.3 UniqueSymbols 8.4 Displaying Raster Data 8.4.1 RasterUniqueSymbols 8.4.2 RasterClassifyColorRamp 8.4.3 RasterUserDefinedColorRamp 8.5 Making a Page Layout 8.5.1 Layout Chapter 9 Data Exploration 9.1 Exploring Data in ArcGIS 9.2 ArcObjects for Data Exploration 9.2.1 Use of a Query Filter 9.2.2 Cursor 9.2.3 Data Statistics 9.3 Performing Attribute Query 9.3.1 SelectFeatures 9.3.2 SelectRecords Copyright 2005 by CRC Press LLC 2781_C00.fm Page xi Thursday, June 10, 2004 10:45 AM 9.4 Performing Spatial Query 9.4.1 SpatialQuery 9.4.2 SpatialQuery 9.4.3 MultipleSpatialQueries 9.4.4 SelectByShape 9.5 Combining Spatial and Attribute Queries 9.5.1 BufferSelect 9.5.2 IntersectSelect 9.6 Deriving Descriptive Statistic 9.6.1 DataStatistics 9.6.2 DataSubsetStatistics Chapter 10 Vector Data Operations 10.1 Analyzing Vector Data in ArcGIS 10.2 ArcObjects for Vector Data Analysis 10.3 Buffering 10.3.1 Buffer 10.3.2 Buffer Options 10.4 Performing Overlay 10.4.1 Intersect 10.4.2 Updating Area and Perimeter of a Shapefile 10.5 Joining Data By Location 10.5.1 JoinByLocation 10.6 Manipulating Features 10.6.1 Dissolve 10.6.2 Merge 10.6.3 Centroid Chapter 11 Raster Data Operations 11.1 Analyzing Raster Data in ArcGIS 11.2 ArcObjects for Raster Data Analysis 11.2.1 Raster Objects 11.2.2 Operator Objects 11.3 Managing Raster Data 11.3.1 MakePermanent 11.3.2 ExtractByMask 11.3.3 RasterQuery 11.3.4 Query2Rasters 11.4 Performing Local Operations 11.4.1 ReclassNumberField 11.4.2 Combine2Rasters 11.4.3 Other Local Operations 11.5 Performing Neighborhood Operations 11.5.1 FocalMean Copyright 2005 by CRC Press LLC 2781_C00.fm Page xii Thursday, June 10, 2004 10:45 AM 11.6 Performing Zonal Operations 11.6.1 ZonalMean 11.7 Performing Distance Measure Operations 11.7.1 EucDist 11.7.2 Use of a Feature Layer as the Source in EucDist 11.7.3 Slice 11.7.4 CostDist 11.7.5 CostDistFull Chapter 12 Terrain Mapping and Analysis 12.1 Performing Terrain Mapping and Analysis in ArcGIS 12.2 ArcObjects for Terrain Mapping and Analysis 12.3 Deriving Contour, Slope, Aspect, and Hillshade 12.3.1 Contour 12.3.2 Slope 12.3.3 Choice of Slope Measure 12.3.4 ReclassifySlope 12.3.5 Aspect 12.3.6 Aspect_Symbol 12.3.7 Hillshade 12.4 Performing Viewshed Analysis 12.4.1 Visibility 12.5 Performing Watershed Analysis 12.5.1 Watershed 12.6 Creating and Editing TIN 12.6.1 RasterToTin 12.6.2 EditTin 12.6.3 TinNodes Chapter 13 Spatial Interpolation 13.1 Running Spatial Interpolation in ArcGIS 13.2 ArcObjects for Spatial Interpolation 13.3 Performing Spatial Interpolations 13.3.1 Idw 13.3.2 Spline 13.3.3 Trend Surface 13.3.4 Kriging 13.4 Comparing Interpolation Methods 13.4.1 Compare Copyright 2005 by CRC Press LLC
Description: