41
GIS in Water Resources Consortium Attaching Behavior to Attaching Behavior to Objects and Programming Objects and Programming in the Geodatabase in the Geodatabase Tom Wesp, AICP Tom Wesp, AICP Henry Hagemeier Henry Hagemeier ESRI San Antonio ESRI San Antonio

GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

Embed Size (px)

Citation preview

Page 1: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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

Page 2: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI 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.

Page 3: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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?

Page 4: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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.

Page 5: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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

Page 6: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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

Page 7: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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

Page 8: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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

Page 9: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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...

Page 10: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

GIS in Water Resources Consortium

Custom Object ExampleCustom Object Example

Feature

Object Model COM Implementation

Page 11: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

GIS in Water Resources Consortium

Custom Object ExampleCustom Object Example

Feature

Tree

HeightKind

Object Model COM Implementation

Age()

Page 12: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

GIS in Water Resources Consortium

Custom Object ExampleCustom Object Example

Feature

Tree

HeightKind

Feature

Object Model

Interface F1

Interface F2

COM Implementation

Age()

Page 13: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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()

Page 14: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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()

Page 15: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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

Page 16: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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

Page 17: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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

Page 18: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

GIS Resources in Water

Adding ESRI Geodata access COM classes with Visio UML Tools

ESRI Classes::Object

ESRI Classes::Feature

Click and drag

Page 19: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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.

Page 20: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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

Page 21: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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

Page 22: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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

Page 23: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

GIS in Water Resources Consortium

Add operations to the Interface IParcelAdd operations to the Interface IParcel

Adding an operation called get_CombinedBuildingValue

Page 24: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

GIS in Water Resources Consortium

Same previous steps to create interface Same previous steps to create interface for Custom Building Behaviorfor Custom Building Behavior

Page 25: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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.

Page 26: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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.

Page 27: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

GIS in Water Resources Consortium

Finished UML ModelFinished UML Model

Export the UML model to the Microsoft Repository (in this case an Access database).

Page 28: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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

Page 29: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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.

Page 30: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

GIS in Water Resources Consortium

Visual C++ with ESRI Visual C++ with ESRI CodeGenWizardCodeGenWizard

Browse to your Access database that contains your object model.

Page 31: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

GIS in Water Resources Consortium

Select your object model…Select your object model…

Page 32: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

GIS in Water Resources Consortium

Defining custom feature properties Defining custom feature properties with the wizardwith the wizard

Page 33: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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.

Page 34: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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.

Page 35: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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

Page 36: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

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

Page 37: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

GIS in Water Resources Consortium

Adding Case Tool in ArcCatalogAdding Case Tool in ArcCatalog

Click and drag Case tool from Customize dialog box.

Page 38: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

GIS in Water Resources Consortium

Schema Wizard in ArcCatalogSchema Wizard in ArcCatalog

Navigate to the Repository containing your UML model.

Page 39: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

GIS in Water Resources Consortium

Schema Wizard Schema Wizard

Shows Custom Features, Relationship Classes and Domains.

Page 40: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

GIS in Water Resources Consortium

ArcMapArcMap

Page 41: GIS in Water Resources Consortium Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio

GIS in Water Resources Consortium

Thank YouThank You