arcobject training
DESCRIPTION
ArcObjectsTRANSCRIPT
ArcObjects Training
Topics
Introduction to ArcGIS Introduction to ArcObjects Object Model diagrams (OMD) Navigating OMD Common ArcMAP Objects Programming with VBA Programming with .net Brief Introduction on SDE
Introduction to ArcGIS
Introduction to ArcGIS
Introduction to ArcGIS– ArcGIS is a suite consisting of a group of geographic
information system (GIS) software products produced by ESRI– software products that consists of Desktop GIS,Server GIS and
Mobile GIS
Introduction to ArcGIS
Desktop GIS consists of ArcGIS Desktop, ArcGIS Engine Server GIS products include ArcGIS Server Mobile GIS products include ArcGIS Mobile and ArcPad
Introduction to ArcGIS
ArcGIS clients
Application/Data servers
ArcGIS DesktopEXTENSIONS
ArcGIS Engine
Components ArcObjects
ArcReader ArcView
ArcInfo
ArcEditor
Customapplication
RDBMS
ArcSDE
ArcGIS Server ArcIMS
EXTENSIONS
ArcPad
Network
Webbrowser
Introduction to ArcGIS
Desktop GIS– ArcGIS Desktop : provides data and tools to help you create,
edit, import, map, query, analyze, and publish geographic information.
– ArcGIS Engine : provides a standard framework for developers to create custom GIS and mapping applications. ArcGIS Engine is a core set of cross-platform components compatible with multiple programming languages that enables developers to rapidly build GIS solutions on ESRI’s ArcGIS platform.
Introduction to ArcGIS
ArcGIS Desktop– ArcGIS Desktop includes a suite of applications including
ArcCatalog, ArcMAP, ArcGlobe, ArcToolbox.– Based on the functionality desktop application available in
three levels of licenses.– ArcView focuses on comprehensive data use ,mapping , and
analysis.– ArcEditor adds advanced geographic editing and data creation.– ArcInfo is a complete, professional GIS desktop containing
comprehensive GIS functionality, including rich geo-processing tools.
Introduction to ArcGIS
ArcMap Main menu Standard toolbar Editor toolbar TOC Tools Graphic Area Status bar Draw Toolbar Data View Layout View Supports Shape files,
PGDB, File GDB, SDE, and data servers.
Introduction to ArcGIS
Practical workouts– How to add files in ArcMAP and Start editing, Modify /Add
features, and Stop editing operations.– Use of MXD files.– Describe Properties of Feature classes.– Toolbars in ArcGIS.– Symbology, Labeling features, and Snap settings.– Querying of data.– Use of ArcCatalog.– Use of ArctoolBox.
Introduction to ArcObjects
Introduction to ArcObjects
What Are “ArcObjects” ?– A set of components/objects of the ArcGIS platform which can
be accessed through programming environment ( VBA, VB, C++,.NET, VB Script)
ArcObjects have– Characteristics which can be queried or set– The ability to perform operations– The ability to respond to changes in application
Object Model Diagrams (OMD)
Object Model Diagrams
OMDs help you write code– Show interfaces, methods, and properties for each class– Show relationships between classes
Over 2,700 classes on several diagrams Over 3,000 interfaces
Object Model Diagrams
Synoptic view of ArcObjects Included with ArcObjects Developer Kit ArcGIS installation option Diagrams (OMD’s) in PDF format Located at ArcGIS\DeveloperKit\Diagrams
Object Model Diagrams
Reading ArcObjects OMD’s Classes
In ArcObjects you will encounter three distinct types of classes– Abstract Classes– Class (Instantiable Classes)– Co-Classes (Creatable Classes)
Object Model Diagrams
Abstract Class – In ArcObjects OMDs these classes
are represented by a 2D shaded rectangle with the class name in italics
– These classes are not creatable or Instantiable.
Object Model Diagrams
Class (Instantiable Classes) – In ArcObjects OMDs these
symbols are represented as 3D rectangles with no shading
– These classes are non-creatable classes in the sense that you can’t use the “New” keyword to create a new object instance of these types of classes
– We must use other objects to derive an instance of this type of class
Object Model Diagrams
CoClass (Creatable Class)– In ArcObjects OMDs these symbols
are represented as a shaded 3D rectangle.
– These classes can be created with “New” keyword to create a new object instance of these types of classes.
– In addition, object instances from these classes can be created from other objects just as they can with Instantiable objects
Object Model Diagrams
Interfaces– In ArcObjects OMDs
Interfaces are represented with a “Lollipop” symbol
– Interfaces are like sub-classes within a larger class
– Interfaces expose various characteristics and behaviors of a class through properties and methods
Object Model Diagrams
Relationship Notation– Is a type of– Is composed of– Creates a– Multiplicity– Association
*_____
Egg
Bird
Wing
Feather
2
Abstract
Class
Class
Class
ChickenCoClass
NestCoClass
*
Object Model Diagrams
Methods and Properties
– Properties are represented by the “Barbell symbol”
– Read/Write property
– Read Only property
– Write Only property
– Property Put by Reference
– Methods are represented by an arrow
Navigating OMD
Navigating OMD
Example: Return name of first layer in ArcMap TOC– Start with IMxDocument,
interface of document object, MxDocument
– Use FocusMap property to reference the Map object through IMap interface
Navigating OMD
Example: Return name of first layer in ArcMAP TOC– Start with IMxDocument, interface
of document object, MxDocument– Use FocusMap property to
reference the Map object through IMap interface
– Use Layer property of the map to reference layer object
Common ArcMAP Objects
Common ArcMap Objects
Common ArcMap Objects
Common ArcMap Objects
MxDocument
Map
Layer
*
*
FeatureLayer
Application
Programming With VBA
Programming With VBA
Scope– Using VBA, you author macros that are stored within the
document/template structure of the application– You can also create custom commands and tools, called UI
Controls.– UI Controls are macros that also contain hooks into the application
framework so that you can respond to actions that happen on the buttons or commands you create.
Programming With VBA
How to access the VBA environment in ArcGIS – VBA programming is accessible through the Tools->Macros->Visual
Basic Editor
Programming With VBA
Document Events– Code executes when user interacts with document– Open document– Close document– New document– others
Programming With VBA
Defining Variables– Must define object variables before setting
– Use the Dim, Private, or Public statements
– Variables pointing to ArcObjects must reference one of the object’s interfaces
Programming With VBA
Defining procedure scope– Public: May call procedure from any module
– Private: Procedure may be called only from other procedures in the same module
Programming With VBA
Most generally used ArcObjects libraries
FeatureLayer
Map
MxDocument
Carto*
*Layer
FeatureDataset*
Geodatabase
FeatureClass
Table
DataSet
0 .. 1Carto Layer
Programming With VBA
Access maps from MxDocument– Get the active map
– Get all maps (IMaps)
Dim pMxDoc As IMxDocumentSet pMxDoc = ThisDocumentDim pMap As IMapSet pMap = pMxDoc.FocusMap
Dim pAllMaps As IMapsSet pAllMaps = pMxDoc.Maps
Programming With VBA
Looping through a collection of maps
' Map collection example … Dim intIndex As Integer Dim pMaps As IMaps Set pMaps = pMxDoc.Maps
For intIndex = 0 To pMaps.Count - 1 MsgBox pMaps.Item(intIndex).Name Next intIndex
0
1
2
Programming With VBA
Access layers from Map or MxDocument– Get the selected layer (IMxDocument)
– Get a specific layer (IMap)
– Get all layers (An enumeration of layers)
Dim pLayer As ILayerSet pLayer = pMxDoc.SelectedLayer
Dim pLayer As ILayerSet pMap = pMxDoc.FocusMapSet pLayer = pMap.Layer(3)
Dim pAllLayers As IEnumLayerSet pAllLayers = pMap.Layers
Programming With VBA
IMap’s Layers property returns IEnumLayers– Like a collection with fewer methods and properties– Next returns ILayer– Reset moves to top of Enum
Set pLayer = pLayers.Next
Nothing
pLayers.Reset
IEnumLayerTop
Set pLayer = pLayers.Next
Set pLayer = pLayers.Next
Set pLayer = pLayers.Next
Dim pLayer As ILayerDim pLayers As IEnumLayerSet pLayers = pMap.Layers
Programming With VBA
Looping through layers– Loop based on a Condition
' Layer enum example Dim pLayer As ILayer Dim pMapLayers As IEnumLayer Set pMapLayers = pMap.Layers
Set pLayer = pMapLayers.Next Do Until pLayer Is Nothing MsgBox pLayer.Name Set pLayer = pMapLayers.Next Loop
Nothing!
Programming With VBA
Data creation objects
Table
FieldsField 1 ..
DatasetWorkspaceWorkspaceFactory
AccessWorkspaceFactory
Row
FeatureClassArcInfoWorkspaceFactory
ShapefileWorkspaceFactory
Others
*
WorkspaceFactory
Programming With VBA
Opening an existing Workspace– Use IWorkspaceFactory to return a Workspace object– Generic interface for all sub-types of WorkspaceFactory– OpenFromFile: Access an existing folder on disk– Open: Connect to an existing database (e.g., ArcSDE)
Programming With VBA
Connecting to an ArcSDE database– Use SDEWorkspaceFactory
– Set connection properties with IPropertySet
Use IWorkspaceFactory toretrieve a workspace
Use SetProperties methodto set Database Connection properties (Server, Instance, etc)
Programming With VBA
Getting a FeatureDataset– IFeatureWorkspace interface on Workspace– OpenFeatureDataset method
Dim pFWorkspace As IFeatureWorkspaceSet pFWorkspace = pWorkspace 'QI for IFeatureWorkspace
Dim pCover As IFeatureDatasetSet pCover = pFWorkspace.OpenFeatureDataset("streets")
FeatureClasses
Workspace FeatureDataset
Programming With VBA
Getting FeatureClasses– Use IFeatureClassContainer to get existing FeatureClasses from a FeatureDataset
Programming With VBA
Adding a shapefile to mapPublic Sub Addshapefile()
Dim pWorkspaceFactory As IWorkspaceFactoryDim pFeatureWorkspace As IFeatureWorkspaceDim pFeatureLayer As IFeatureLayerDim pMxDocument As IMxDocumentDim pMap As IMap 'Create a new ShapefileWorkspaceFactory object and open a shapefile folder
Set pWorkspaceFactory = New ShapefileWorkspaceFactorySet pFeatureWorkspace = pWorkspaceFactory.OpenFromFile("D:\Program Files\ArcGIS\DeveloperKit\SamplesNET\data\World",
0) 'Create a new FeatureLayer and assign a shapefile to it
Set pFeatureLayer = New FeatureLayerSet pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass("Country") pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName 'Add the FeatureLayer to the focus mapSet pMxDocument = Application.DocumentSet pMap = pMxDocument.FocusMap pMap.AddLayer pFeatureLayer
End Sub
Programming With VBA
GxDialog• ArcCatalog type dialog box for browsing directories
– User-friendly identification of input/output files– Can open modally for saving or opening a file
• Properties that define appearance and behavior– StartingLocation– Title– ObjectFilter– AllowMultiSelect– FinalLocation
Programming With VBA
Example: GxDialogDim pGxDialog As IGxDialogDim pGxObjEnum As IEnumGxObjectSet pGxDialog = New GxDialog
pGxDialog.AllowMultiSelect = TruepGxDialog.StartingLocation = "D:\Program Files\ArcGIS\DeveloperKit\SamplesNET\
data\World"pGxDialog.Title = "Select Files for Input"pGxDialog.ButtonCaption = "GO!"pGxDialog.DoModalOpen 0, pGxObjEnum
Programming With VBA
Looping through layers
Geometry objects
Point MultiPoint
Ring
PathSegment
Geometry
EnvelopeCurve
Polyline
Line BezierCurveCircularArc
Polycurve
**
*
Polygon
*
Geometrycollection
*
Segments have start and endwith curve in between
Aggregate to paths/rings Aggregate to lines/polygons Edit at any level
Feature geometry
Points
Segments
Bezier curve
Line Circular arc
3 Rings (closed paths)
2 Paths
1 Poly1 Line
Multipoints PolygonsPolylines
Points and multipoints
Points are zero dimensional– Defined with x- and y-coordinates– May have Z and M properties
Multipoints are collections of points
Point
Multipoint with six points
Dim pPoint As IPoint
Set pPoint = New Point
pPoint.X = 300
pPoint.Y = 450
Dim pMultiPts As IPointCollection
Set pMultiPts = New MultiPoint
pMultiPts.AddPoint pPoint
Consist of two points (From and To) and a function defining the curve between them
Subclasses: Line, BezierCurve, CircularArc Segments used to create other geometry
– Paths, polylines, rings, and polygonsDim pLine As ILineSet pLine = New LinepSegment.FromPoint = pPointApSegment.ToPoint = pPointB
Segments
From
To
FromTo
Polylines and polygons
Polylines– Collections of connected or unconnected paths
Polygons– Composed of one or several rings
1 Polyline with four segments
1 Polygon with seven rings
Envelopes
Define a feature’s spatial extent– Minimum bounding rectangle
All geometry has an envelope– Get or set with IGeometry :: Envelope
Dim pEnvelope As IEnvelopeSet pEnvelope = pLine.Envelope
Zooming in to a Feature
Get the extent using a shape’s Envelope property– On the IGeometry interface– Set the ActiveView Extent property with an Envelope
Feature Geometry
Envelope1 Polygon Feature
pMxDoc.ActiveView.Extent = pFeature.Shape.EnvelopepMxDoc.ActiveView.Refresh
Geometry spatial operator interfaces
Interfaces supported by subtypes of Geometry– ITopologicalOperator– IProximityOperator– IRelationalOperator
Use to …– Perform familiar spatial operations such as buffer, cut, and clip– Measure distances between shapes– Examine spatial relationships
ITopologicalOperator
Provides methods for working with geometry Supported by Point, Multipoint, Polyline, and Polygon
BufferIntersect Union
Cut Clip
Dim pTopoOp As ITopologicalOperator
Dim pBuffPoly As IPolygon
Set pTopoOp = pFeature.Shape
Set pBuffPoly = pTopoOp.Buffer (intBufferDistance)
IRelationalOperator
Methods for examining spatial relationships (return Boolean)– Equals: Are input geometries structurally equivalent?– Touches: Do input geometry boundaries intersect?– Contains: Is one geometry contained by the other?– Disjoint: Are input geometries spatially distinct?– Several others
Dim pRelationOp As IRelationalOperator
Dim booTouches As Boolean
Set pRelationOp = pPoly
booTouches = pRelationOp.Touches (pAnotherPoly)
IProximityOperator
Methods for examining proximity relationships between features– ReturnDistance: Returns the minimum distance between
features (double)– ReturnNearestPoint: Finds and returns the nearest point on the
specified feature (point)
Dim pProxOp As IProximityOperator
Dim dblDistance As Double
Set pProxOp = pLine
dblDistance = pProxOp.ReturnDistance (pSomeOtherLine)
?
Basic steps: Building a COM component
1.Create a new COM project2.Create a COM Class3.Reference the ArcObjects libraries4.Implement the required interface(s)5.Compile the component as a DLL6.Register your component with ArcGIS
The steps are the same regardless of the language
Programming With . Net
Programming with .net
Introduction– In the past, ArcGIS programming was largely written in VBA
(Visual Basic for Applications) Script. This language, while useful for writing macros for applications, lacks the depth and breadth for large scale major initiatives which programming in the .Net framework can provide. To this end, ESRI has made it possible to program in the .Net Framework.
Programming with .net
Software Requirements– ArcMap 9.2 (With service pack 6)– ArcGIS .Net SDK (Option available While Installation)– Microsoft Visual Studio dot net 2005
Programming with .net
Programming Wizard– Available with ArcGIS
installation– Guide you to create the
classes and toolbars– Generic code (default
Events) will be available with new classes.
Programming with .net
Steps to write program– Navigate to File > New > Project…
– In the Project Types bar, expand the Visual C# (or the Visual Basic if you want to use VB) and expand the ArcGIS subfolder. In this Subfolder will be the Desktop folder (Or MapInfo, or Engine if you have that installed). Once this is selected you will see a number of options in the Templates box, Select Class Library (ArcMAP).
– Click OK!
Programming with .net
Steps to write program– Right click on Class1.cs in the Solution Explorer and select
Delete.
– In the Solution Explorer, right click on the HelloArcGIS that is in bold typeface.
– Select Add > New Item.
– At the Add New Item Dialog Select Base Command. Leave the Name textbox as the default/Give specific name and click Add.
– Select Desktop ArcMAP Command, Click OK.
Programming with .net
Steps to write program– Edit each of the public properties of your command so that they
reflect the command you are creating.
– Expand the Overridden Class Methods code region
– Click on Project > Add Reference
– Scroll down and select the System.Windows.Forms DLL.
– Click OK
Programming with .net
Steps to write program– Modify the using statements as per requirement.
– Modify the OnClick method so that the code to display a message box is included
– Double click on Command1.bmp in the Solution Explorer to open up the bmp editor in MSVS, edit the bmp in any way you would like using the tools included in MSVS
– Click on Build > Build Solution
Programming with .net
Steps to write program– Click on Debug > Start Debugging
– Right click on a menu bar in ArcMap and select the Customize… button
– Select the Commands tab, and then locate ArcGuides in the Categories list. Select
– “Hello World For ArcGIS” and click and drag it onto an ArcMap toolbar
Programming with .net
Practical workouts– Hello world ICommand
– Read layers and Feature classes
– ITool with draw features on map
– Toolbar example
– Different types of feature selection methods
– Query filter and Spatial filter
– Use of Topological operators
– Read/Write feature attributes
– Apply symbols
Help Documents
Sample source code & Help Documents– http://arcgisdeveloperonline.esri.com
Questions
Thank You