Upload
ella-hunt
View
215
Download
0
Embed Size (px)
Citation preview
GIS in Water Resources Consortium
Attaching Behavior to Objects Attaching Behavior to Objects and Programming in the and Programming in the
GeodatabaseGeodatabase
Tom Wesp, AICPTom Wesp, AICP
Henry HagemeierHenry Hagemeier
ESRI San AntonioESRI San Antonio
GIS in Water Resources Consortium
Parcels and BuildingsParcels and Buildings
Two separate layers
Each with its own attributes and independent of each other.
GIS in Water Resources Consortium
Wouldn’t It Be Nice…Wouldn’t It Be Nice…
What if we could change the properties of one layer and the properties of the other would be automatically updated?
GIS in Water Resources Consortium
Our ExampleOur Example
•Parcels and Buildings
•Parcel has a field that “keeps track” of combined cost of buildings on it.
GIS in Water Resources Consortium
Programming Custom ObjectsProgramming Custom ObjectsProgramming Custom ObjectsProgramming Custom Objects
• Custom objects requires programming in Custom objects requires programming in COM-compliant language COM-compliant language – only VC++ or Delphi (don’t ask about VB)only VC++ or Delphi (don’t ask about VB)– custom object classes can use VB or VJ++custom object classes can use VB or VJ++
• CASE tools make it easierCASE tools make it easier
• Custom objects requires programming in Custom objects requires programming in COM-compliant language COM-compliant language – only VC++ or Delphi (don’t ask about VB)only VC++ or Delphi (don’t ask about VB)– custom object classes can use VB or VJ++custom object classes can use VB or VJ++
• CASE tools make it easierCASE tools make it easier
GIS in Water Resources Consortium
Custom ObjectsCustom ObjectsCustom ObjectsCustom Objects
• Developers create custom objects and Developers create custom objects and intricate data schemasintricate data schemas
• No difference between ESRI supplied No difference between ESRI supplied and developer-supplied custom objectsand developer-supplied custom objects– merely support required interfacesmerely support required interfaces– augments with new interfacesaugments with new interfaces
• Developers create custom objects and Developers create custom objects and intricate data schemasintricate data schemas
• No difference between ESRI supplied No difference between ESRI supplied and developer-supplied custom objectsand developer-supplied custom objects– merely support required interfacesmerely support required interfaces– augments with new interfacesaugments with new interfaces
GIS in Water Resources Consortium
Custom ObjectsCustom ObjectsCustom ObjectsCustom Objects
• What you will needWhat you will need– UML and MS Repository aware CASE toolUML and MS Repository aware CASE tool
• Visio Professional or EnterpriseVisio Professional or Enterprise
– Visual C++ or DelphiVisual C++ or Delphi– GeoDatabase data model diagramGeoDatabase data model diagram– ArcCatalogArcCatalog– OO programming skills and knowledge of OO programming skills and knowledge of
COMCOM
• What you will needWhat you will need– UML and MS Repository aware CASE toolUML and MS Repository aware CASE tool
• Visio Professional or EnterpriseVisio Professional or Enterprise
– Visual C++ or DelphiVisual C++ or Delphi– GeoDatabase data model diagramGeoDatabase data model diagram– ArcCatalogArcCatalog– OO programming skills and knowledge of OO programming skills and knowledge of
COMCOM
GIS in Water Resources Consortium
Creation ProcessCreation ProcessCreation ProcessCreation Process• Create the object modelCreate the object model
– 3rd party CASE tool3rd party CASE tool
• Export to the Microsoft RepositoryExport to the Microsoft Repository– 3rd party CASE tool UML export wizard3rd party CASE tool UML export wizard
• Generate stub-codeGenerate stub-code– ESRI supplied wizard (VC++ only)ESRI supplied wizard (VC++ only)
• Implement custom behaviorImplement custom behavior– you program into the stubsyou program into the stubs
• Create the GeoDatabase schemaCreate the GeoDatabase schema
• Create the object modelCreate the object model– 3rd party CASE tool3rd party CASE tool
• Export to the Microsoft RepositoryExport to the Microsoft Repository– 3rd party CASE tool UML export wizard3rd party CASE tool UML export wizard
• Generate stub-codeGenerate stub-code– ESRI supplied wizard (VC++ only)ESRI supplied wizard (VC++ only)
• Implement custom behaviorImplement custom behavior– you program into the stubsyou program into the stubs
• Create the GeoDatabase schemaCreate the GeoDatabase schema
GIS in Water Resources Consortium
Creation ProcessCreation ProcessCreation ProcessCreation Process
• Base it on a GeoDatabase objectBase it on a GeoDatabase object– give it custom behavior, propertiesgive it custom behavior, properties
• Base it on a GeoDatabase objectBase it on a GeoDatabase object– give it custom behavior, propertiesgive it custom behavior, properties
Feature
Object
«Interface»IFeature
«Interface»IFeatureBuffer
«Interface»IFeatureDraw
«Interface»IFeatureEdit
«Interface»IFeatureSetup
NetworkFeature
IFeatureEvents
Feature
Building
«Interface»IBuilding
+Owner : BSTR+Stories : int+Height : double
ESRI provides this...You do this...
GIS in Water Resources Consortium
Custom Object ExampleCustom Object Example
Feature
Object Model COM Implementation
GIS in Water Resources Consortium
Custom Object ExampleCustom Object Example
Feature
Tree
HeightKind
Object Model COM Implementation
Age()
GIS in Water Resources Consortium
Custom Object ExampleCustom Object Example
Feature
Tree
HeightKind
Feature
Object Model
Interface F1
Interface F2
COM Implementation
Age()
GIS in Water Resources Consortium
Custom Object ExampleCustom Object Example
Feature
Tree
HeightKind
Feature
Object Model
Interface F1
Interface F2
Interface F1
Interface F2
HeightKind
TreeInterface T
COM Implementation
Age()
GIS in Water Resources Consortium
Custom Object ExampleCustom Object Example
Feature
Tree
HeightKind
Feature
Object Model
Interface F1
Interface F2
Feature
Interface F1
Interface F2
HeightKind
TreeInterface T
COM Implementation
Age()
GIS in Water Resources Consortium
Visual - Almost Real - Hands on Visual - Almost Real - Hands on DemonstrationDemonstration
• Tools we will use…Tools we will use…– Visio for UML (Unified Modeling Language)Visio for UML (Unified Modeling Language)– Visual C++ for code creationVisual C++ for code creation– ArcMap to implement and view the new ArcMap to implement and view the new
behaviorbehavior
GIS in Water Resources Consortium
Our Custom ObjectOur Custom Object• ArcInfo provides tools for creating ArcInfo provides tools for creating
buildings and land parcels as polygons.buildings and land parcels as polygons.
• ArcInfo allows us to store attribute data ArcInfo allows us to store attribute data about those buildings and parcels.about those buildings and parcels.
• We want to create a custom object which We want to create a custom object which will do the following…will do the following…– Parcels store land value along with value of Parcels store land value along with value of
all building on that parcelall building on that parcel– Buildings store the floors, height, and valueBuildings store the floors, height, and value
GIS in Water Resources Consortium
But Wait! There’s more!But Wait! There’s more!
• We want the features to maintain their We want the features to maintain their relationship automatically…relationship automatically…
• For Example:For Example:– If a new building is created the parcel If a new building is created the parcel
attributes will automatically be updated with attributes will automatically be updated with the building’s valuethe building’s value
GIS Resources in Water
Adding ESRI Geodata access COM classes with Visio UML Tools
ESRI Classes::Object
ESRI Classes::Feature
Click and drag
GIS in Water Resources Consortium
Adding a Custom Class with Adding a Custom Class with Visio’s UML ToolVisio’s UML Tool
Name Object and add attributes from dialog box. Double clicking on the object opens the dialog box.
GIS in Water Resources Consortium
Drag and drop a Generalization to connect Drag and drop a Generalization to connect the new Parcel class to Featurethe new Parcel class to Feature
GIS in Water Resources Consortium
Add a COM Interface to the Parcel Add a COM Interface to the Parcel ObjectObject
Give interface a name and set its Stereotype to Interface
GIS in Water Resources Consortium
Interface for the Interface for the ParcelParcel object will allow us to object will allow us to read and write parcel value and read values of all read and write parcel value and read values of all
buildings on that parcelbuildings on that parcel
Drag and drop a Refinement to connect interface IParcel to Parcel Class
GIS in Water Resources Consortium
Add operations to the Interface IParcelAdd operations to the Interface IParcel
Adding an operation called get_CombinedBuildingValue
GIS in Water Resources Consortium
Same previous steps to create interface Same previous steps to create interface for Custom Building Behaviorfor Custom Building Behavior
GIS in Water Resources Consortium
Create a RelationshipClass to associate Create a RelationshipClass to associate parcels to buildingsparcels to buildings
The composite association tool in Visio creates the needed relationship between the buildings and parcels.
GIS in Water Resources Consortium
Finally create a ClassExtension for Finally create a ClassExtension for implementing behaviorimplementing behavior
A Class Extension is a COM class that implements behavior for a whole set of custom features in a feature class.
GIS in Water Resources Consortium
Finished UML ModelFinished UML Model
Export the UML model to the Microsoft Repository (in this case an Access database).
GIS in Water Resources Consortium
Now what? We have our object model Now what? We have our object model in a Repository. What’s next?in a Repository. What’s next?
• We need to generate code…We need to generate code…– We will use Microsoft Visual C++We will use Microsoft Visual C++
with a little help from an ESRI wizardwith a little help from an ESRI wizard
GIS in Water Resources Consortium
Start Microsoft Visual C++Start Microsoft Visual C++
Go to the “Tools” menu and choose “customize”. Click on the Add-ins tab and browse to the ArcInfo directory that contains the file “CodeGenWiz.dll” and load the dll.
GIS in Water Resources Consortium
Visual C++ with ESRI Visual C++ with ESRI CodeGenWizardCodeGenWizard
Browse to your Access database that contains your object model.
GIS in Water Resources Consortium
Select your object model…Select your object model…
GIS in Water Resources Consortium
Defining custom feature properties Defining custom feature properties with the wizardwith the wizard
GIS in Water Resources Consortium
Continue with the wizard to define Continue with the wizard to define Inherited InterfacesInherited Interfaces
Aggregation: Inner feature is called directly. (A little like OO inheritance)
Containment: Calls are “forwarded” to the inner feature.
GIS in Water Resources Consortium
Define a Developer Studio Project and Define a Developer Studio Project and compile a dll compile a dll
Feels good to finally have some code.
GIS in Water Resources Consortium
All that is left now is to add some C++ code.All that is left now is to add some C++ code.
•Define Object Behavior
•Define Object Functions
GIS in Water Resources Consortium
Well… there is a little moreWell… there is a little more
• Use ArcCatalog Case Tool Wizard to Use ArcCatalog Case Tool Wizard to create a database schema from your create a database schema from your UML model.UML model.– Connect to the RepositoryConnect to the Repository– Select the object modelSelect the object model– Define schema properties for each featureDefine schema properties for each feature– Create the schemaCreate the schema
GIS in Water Resources Consortium
Adding Case Tool in ArcCatalogAdding Case Tool in ArcCatalog
Click and drag Case tool from Customize dialog box.
GIS in Water Resources Consortium
Schema Wizard in ArcCatalogSchema Wizard in ArcCatalog
Navigate to the Repository containing your UML model.
GIS in Water Resources Consortium
Schema Wizard Schema Wizard
Shows Custom Features, Relationship Classes and Domains.
GIS in Water Resources Consortium
ArcMapArcMap
GIS in Water Resources Consortium
Thank YouThank You