Professional Documents
Culture Documents
www.geonorth.com
Value Through Integration and Innovation
The Plan
• ArcObjects
– Concepts
– Examples
• Python
– Concepts
– Examples
• Compare/Contrast
• Discussion
www.geonorth.com
Value Through Integration and Innovation
Multiple Ways to Skin the Cat
www.geonorth.com
Value Through Integration and Innovation
ArcObjects: Serious Programming
• AML
– Throw commands into text file and you’re a
programmer
• Avenue
– Proprietary Language
www.geonorth.com
Value Through Integration and Innovation
www.geonorth.com
Value Through Integration and Innovation
ArcObjects
• Not a Language
• Building Blocks Upon
which ArcGIS was built
• COM objects
• Most commonly used
with VisualBasic or
C++
www.geonorth.com
Value Through Integration and Innovation
ArcObjects: First Rule
Whining
www.geonorth.com
Value Through Integration and Innovation
VisualBasic
www.geonorth.com
Value Through Integration and Innovation
Modeling the Real World
• Objects
www.geonorth.com
Value Through Integration and Innovation
Object Oriented
Map Car
Property MapUnits Horsepower
Method AddLayer Accelerate
Event SelectionChanged Brakes are
pressed
www.geonorth.com
Value Through Integration and Innovation
Object Orientation
• Properties
– Characteristics (nouns)
• Methods
– Actions object knows how to perform (verbs)
• Events
– Occurrences that Object can respond to
www.geonorth.com
Value Through Integration and Innovation
Objects Vs. Classes
www.geonorth.com
Value Through Integration and Innovation
Objects Vs. Classes
www.geonorth.com
Value Through Integration and Innovation
Interface vs. Objects
www.geonorth.com
Value Through Integration and Innovation
Interfaces vs. Objects
arcobjectsonline.esri.com
www.geonorth.com
Value Through Integration and Innovation
Tips
• Use Samples
– Lots of Them
– Almost Never Start from Scratch
www.geonorth.com
Value Through Integration and Innovation
Tips
www.geonorth.com
Value Through Integration and Innovation
Tips
www.geonorth.com
Value Through Integration and Innovation
ArcObjects
www.geonorth.com
Value Through Integration and Innovation
ArcObjects: Before & After
www.geonorth.com
Value Through Integration and Innovation
ArcObjects
www.geonorth.com
Value Through Integration and Innovation
Common Implementations
www.geonorth.com
Value Through Integration and Innovation
Example in ArcObjects
www.geonorth.com
Value Through Integration and Innovation
Private Sub TurnOffLayer()
Dim pDoc As IMxDocument
Dim pMap As IMap
Dim pLayer As ILayer
Set pLayer =
www.geonorth.com
Value Through Integration and Innovation
Private Function FindLayerByName(strLayerName As String, pMap As IMap) As ILayer
Dim i As Integer
For i = 0 To pMap.LayerCount - 1
If UCase(pMap.Layer(i).Name) = UCase(strLayerName) Then
Set FindLayerByName = pMap.Layer(i)
Exit Function
End If
Next i
Set FindLayerByName = Null
End Function
www.geonorth.com
Value Through Integration and Innovation
Private Sub TurnOffLayer()
Dim pDoc As IMxDocument
Dim pMap As IMap
Dim pLayer As ILayer
End Sub
www.geonorth.com
Value Through Integration and Innovation
ArcObjects 8.x to 9.0
www.geonorth.com
Value Through Integration and Innovation
Type Libraries: Diced Up
www.geonorth.com
Value Through Integration and Innovation
Type Libraries: Diced Up
Declarations
Dim pEnv as esriCore.IEnvelope Dim pEnv as esriGeometry.IEnvelope
ZoomToPoint (inPt as esricore.IPoint) ZoomToPoint(inPt As esriGeometry.IPoint)
Instantiations
Set pPt = new esriCore.Point set pPt = New esriGeometry.Point
Implementations
Implements esricore.ITool Implements esriFramework.ITool
www.geonorth.com
Value Through Integration and Innovation
ArcGIS 9.0 Type Libraries
ArcGIS Engine UI ArcGIS Engine
•esriSystemUI esriSystem
•esriDisplayUI esriGeometry
•esriOutputUI esriDisplay
•esriGeoDatabaseUI esriOutput
•esriDataSourcesRasterUI esriGeoDatabase
•esriLocationUI esriDataSourcesFile
•esriCartoUI esriDataSourcesGDB
•esriCadUI esriDataSourcesOleDB
•esriIMSUI esriDataSourcesRaster
•esriTinUI esriGeoDatabaseDistributed
•esriCatalogUI esriLocation
esriCarto
ArcGIS Application assemblies esriCad
•esriArcMapUI esriIMS
•esriArcMap esriTin
•esriArcCatalogUI esriWorker
•esriArcCatalog esriFramework
•esriEditor
•esriEditorExt
•esriGeoDatabaseDistributedUI
•esriGeoReferenceUI
www.geonorth.com
Value Through Integration and Innovation
Code Converter Utility
• VB6 Add-In
• Removes ESRI Object Library from Project
reference
• Replaces ‘esriCore.’ with appropriate name in:
• Declarations
• Instantiations
• Implementations
• ProgIDs
• Adds appropriate new references according code
that is found
www.geonorth.com
Value Through Integration and Innovation
Tips for Healthy ArcObjects Use
www.geonorth.com
Value Through Integration and Innovation
• Python/Scripting
www.geonorth.com
Value Through Integration and Innovation
Scripting in ArcGIS
• Python
• VBScript
• Perl
• Jscript
• Any scripting language that is COM
compliant
• Python is ESRI-prefered
www.geonorth.com
Value Through Integration and Innovation
Why Python?
www.geonorth.com
Value Through Integration and Innovation
Python
www.geonorth.com
Value Through Integration and Innovation
Geoprocessing with Python
www.geonorth.com
Value Through Integration and Innovation
Scripts in ArcToolBox
www.geonorth.com
Value Through Integration and Innovation
Importing Modules
www.geonorth.com
Value Through Integration and Innovation
Standard Stuff at in a Python Script
www.geonorth.com
Value Through Integration and Innovation
Indentation and Spaces
try:
www.geonorth.com
Value Through Integration and Innovation
Batch Processing
www.geonorth.com
Value Through Integration and Innovation
Batch Example
# Import COM Dispatch module
from win32com.client import Dispatch
# Create the geoprocessor object
GP = Dispatch("esriGeoprocessing.GPDispatch.1")
# Set the workspace. List all of the feature classes that start with 'G'
GP.Workspace = “c:/data/anchorage/anch.mdb”
fcs = GP.ListFeatureClasses("G*")
# or for a type: fcs = GP.ListFeatureClasses("G*","polygon")
www.geonorth.com
Value Through Integration and Innovation
Batch Example
# Reset the enumeration to make sure the first object is returned
fcs.reset()
# Get the first feature class name
fc = fcs.next()
while fc: # While the feature class name is not None
# Copy the features from the workspace to a folder
GP.Copy(fc,“c:\data\anchorage\dataout\” + fc)
# Get the next feature class name
fc = fcs.next()
www.geonorth.com
Value Through Integration and Innovation
Licensing
www.geonorth.com
Value Through Integration and Innovation
Extending Python with Wrappers
• Vector Formats
– pyshapelib (shapelib.maptools.org)
• Access to individual vertices of the shape
• Dbf file
• Indexing
– OGR (gdal.maptools.org/ogr)
• Other vector formats like MapInfo, Coverage,
PostGIS, Oracle Spatial, TIGER, SDTS, OpeNDAP,
DGN, Microstation DGN
www.geonorth.com
Value Through Integration and Innovation
Extending Python with Wrappers
• Grids
– Geodata Abstration Library GDAL
(gdal.maptools.org)
• JPEG2000, BSP, USGS DEM, Military
• Elevation Data, ECW, GRASS, TIFF/GeoTIFF,
NetCDF, Imagine, and SDTS
www.geonorth.com
Value Through Integration and Innovation
Extending Python with Wrappers
• Projections
– pyProjection
(http://hobu.biz/index_html/software/pyprojection)
• For projecting coordinates from one to another
• Uses EPSG code system and/or you can roll your own
• SDE
– PySDE (hobu.stat.aistate.edu/pysde)
• Wrapper for SDE C API and has corresponding Python
methods
www.geonorth.com
Value Through Integration and Innovation
ArcObjects or Python?
www.geonorth.com
Value Through Integration and Innovation
Thanks
www.geonorth.com
Value Through Integration and Innovation