410 likes | 557 Views
Attaching Behavior to Objects and Programming in the Geodatabase. Tom Wesp, AICP Henry Hagemeier ESRI San Antonio. Parcels and Buildings. Two separate layers Each with its own attributes and independent of each other. Wouldn’t It Be Nice….
E N D
Attaching Behavior to Objects and Programming in the Geodatabase Tom Wesp, AICP Henry Hagemeier ESRI San Antonio
Parcels and Buildings Two separate layers Each with its own attributes and independent of each other.
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?
Our Example • Parcels and Buildings • Parcel has a field that “keeps track” of combined cost of buildings on it.
Programming Custom Objects • Custom objects requires programming in COM-compliant language • only VC++ or Delphi (don’t ask about VB) • custom object classes can use VB or VJ++ • CASE tools make it easier
Custom Objects • Developers create custom objects and intricate data schemas • No difference between ESRI supplied and developer-supplied custom objects • merely support required interfaces • augments with new interfaces
Custom Objects • What you will need • UML and MS Repository aware CASE tool • Visio Professional or Enterprise • Visual C++ or Delphi • GeoDatabase data model diagram • ArcCatalog • OO programming skills and knowledge of COM
Creation Process • Create the object model • 3rd party CASE tool • Export to the Microsoft Repository • 3rd party CASE tool UML export wizard • Generate stub-code • ESRI supplied wizard (VC++ only) • Implement custom behavior • you program into the stubs • Create the GeoDatabase schema
Creation Process • Base it on a GeoDatabase object • give it custom behavior, properties You do this... ESRI provides this...
Custom Object Example Feature COM Implementation Object Model
Custom Object Example Feature Tree Height Kind Age() COM Implementation Object Model
Custom Object Example Interface F1 Feature Feature Interface F2 Tree Height Kind Age() COM Implementation Object Model
Custom Object Example Interface F1 Feature Feature Interface F2 Tree Interface T Tree Height Kind Height Kind Interface F1 Interface F2 Age() COM Implementation Object Model
Custom Object Example Interface F1 Feature Feature Interface F2 Tree Interface T Tree Height Kind Height Kind Interface F1 Feature Interface F2 Age() COM Implementation Object Model
Visual - Almost Real - Hands on Demonstration • Tools we will use… • Visio for UML (Unified Modeling Language) • Visual C++ for code creation • ArcMap to implement and view the new behavior
Our Custom Object • ArcInfo provides tools for creating buildings and land parcels as polygons. • ArcInfo allows us to store attribute data about those buildings and parcels. • We want to create a custom object which will do the following… • Parcels store land value along with value of all building on that parcel • Buildings store the floors, height, and value
But Wait! There’s more! • We want the features to maintain their relationship automatically… • For Example: • If a new building is created the parcel attributes will automatically be updated with the building’s value
Adding ESRI Geodata access COM classes with Visio UML Tools ESRI Classes::Object Click and drag ESRI Classes::Feature
Adding a Custom Class with Visio’s UML Tool Name Object and add attributes from dialog box. Double clicking on the object opens the dialog box.
Drag and drop a Generalization to connect the new Parcel class to Feature
Add a COM Interface to the Parcel Object Give interface a name and set its Stereotype to Interface
Interface for the Parcel object will allow us to read and write parcel value and read values of all buildings on that parcel Drag and drop a Refinement to connect interface IParcel to Parcel Class
Add operations to the Interface IParcel Adding an operation called get_CombinedBuildingValue
Same previous steps to create interface for Custom Building Behavior
Create a RelationshipClass to associate parcels to buildings The composite association tool in Visio creates the needed relationship between the buildings and parcels.
Finally create a ClassExtension for implementing behavior A Class Extension is a COM class that implements behavior for a whole set of custom features in a feature class.
Finished UML Model Export the UML model to the Microsoft Repository (in this case an Access database).
Now what? We have our object model in a Repository. What’s next? • We need to generate code… • We will use Microsoft Visual C++ with a little help from an ESRI wizard
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.
Visual C++ with ESRI CodeGenWizard Browse to your Access database that contains your object model.
Continue with the wizard to define Inherited Interfaces Aggregation: Inner feature is called directly. (A little like OO inheritance) Containment: Calls are “forwarded” to the inner feature. IParcel Parcel IRow Feature IRowEvents IRelated ObjectEvents
Define a Developer Studio Project and compile a dll Feels good to finally have some code.
All that is left now is to add some C++ code. • Define Object Behavior • Define Object Functions
Well… there is a little more • Use ArcCatalog Case Tool Wizard to create a database schema from your UML model. • Connect to the Repository • Select the object model • Define schema properties for each feature • Create the schema
Adding Case Tool in ArcCatalog Click and drag Case tool from Customize dialog box.
Schema Wizard in ArcCatalog Navigate to the Repository containing your UML model.
Schema Wizard Shows Custom Features, Relationship Classes and Domains.