Thursday, 8 December 2011

Custom Action Handlers forArcFM GDB Manager

You can create your own custom Action Handlers for Geodatabase manager.
Geodatabase Manger works with action handlers. These action handlers are nothing but a set of executions which are set to happen at certain events. GDB Manager also comes with  ActionHandlers but our business requirement may trouble us to write one.

The following steps may help you create and implement one.

STEP 1: Code a custom action handlers Impletement PXActionHandler for your class
STEP 2: To make your desired functionality happen OVERRIDE the ENBALED and SUBEXECUTE            
              methods based on your requirement
STEP 3: Once you are done with coding part, create a STRONG NAME KEY for your assembly
STEP 4: Copy your assembly to Program Files\Miner and Miner\ArcFM Solution\bin
STEP 5: Open your VS CMD prompt and CD to Program Files\Miner and Miner\ArcFM Solution\bin and
              generate a public key token and make a note of it. Use sn.exe to create one.
STEP 6: In windows explorer find GeodatabaseManagerAdmin.exe.config file in Program Files\Miner and
               Miner\ArcFM Solution\bin folder and edit it in NOTEPAD. Find <ActionHandlerAssemblies> tag
               and add your custom action handler assembly in there as in the same format of other
               ActionHandlers with TYPE, PUBLIC KEY TOKEN, VERSION etc
STEP 7: Save and close the config file, Now open you GDB manager tool -> under Version Processing tab
               under any PROCESS right click and add NEW ACTION HANDLER and select your custom
               ActionHandler on the dropdown at your right hand side.



happy reconciling,

ArcFM Snippet #4 - Enabling & Disabling an Autoupdater


Use IMMAutoUpdater interface to disable any autoupdater

IMMAutoUpdater autoUpdater =Use "TYPE" to get your Autoupdater.

autoUpdater.AutoUpdaterMode=mmAutoUpdaterMode.mmAUMNoEvents;

To Rollback the Autoupdater or to set the autoupdater back in place, you save the autoupdater mode before setting it to NOEvents. Later that can be used to reset your AU anytime.

cheers,
Happy coding

C# 4 ! ! !

Just started with C # 4 and Visual Studio2010. Lots of updates and enhancements both in VS and C#, loooooong way to go

Saturday, 3 December 2011

Cursors in ArcObjects, Explained


In ArcObjects, a cursor refers to a set of records or subset of records obtained by any query (Attribute/ Spatial) over a FeatureClass or Table. -> Getting confused with selection set and Cursors? Cursors are always not for display, whereas selection set is bound by display or any selected features in ArcMap display is called as selection set.

Cursor ? FeatureCursor = ?
Cursor and FeatureCursor are similar objects. The work location of them brought in separation or two different terminologies among them. Yes, Cursors work location is always a table, whereas FeatureCursor’s work location is always a FeatureClass or IFeatureClass. A Cursor would return you any object that you have queried for whereas IFeatureCursor would return you an IFeature.

Types of Cursors
There are three types of cursors found in both the Cursor and FeatureCursor classes. The most commonly used type of cursor is the Search Cursor. It is used in query operations to return a subset of records based on your query. Search Cursors are read-only cursors.  Insert, update or delete is not possible with a Search Cursor.
A second type of cursor, the Insert Cursor, is specifically used to insert a new record in a table. The Update Cursor is used to update or delete records in a table. The records returned in an Update or Search Cursor can be constrained to match attribute criteria and/or spatial criteria. It is important that you create the proper type of cursor for the operation that you are performing.

Cursor Class
The Cursor class is used to create objects that work with database tables. The Cursor class in ArcObjects is an instantiable class. Which means you must use another object to obtain an instance of this class. In this case, the Table class in ArcObjects is used to create an instance of the cursor class. The Table class contains three methods that can be used to return an instance of the Cursor class. The type of cursor returned is dependent upon the method called. Figure 1 shows the Object model diagram for the Table class in ArcObjects.


 The ITable interface has three methods that can be used to return specific types of cursor objects. The Search, Insert, and Update methods on ITable are used to return cursor instances. The names of the methods correspond to the type of cursor returned.
After one of these methods has been called, ArcObjects returns an instance of ICursor. Figure 2 shows the object model diagram for the Cursor class. Search, Insert, and Update all return an instance of ICursor. ICursor has one property (Fields) and a number of methods that can be used to manipulate the subset of records. Some of the methods available on ICursor may not be applicable depending on the type of cursor that you are working with. For instance, if you created a Search Cursor, the InsertRow and UpdateRow methods will return an error if called since you are not working with Insert or Update Cursors.


FeatureCursor Class
The FeatureCursor class is very similar to the Cursor class with the exception that FeatureCursor are used when you’re working with geographic datasets rather than traditional database tables. Geographic datasets are typically shapefiles and geodatabase FeatureClass. Similar to the Cursor class, the FeatureCursor class is an instantiable class created through the use of a method on a FeatureClass object. We also have Search, Insert and Update methods alike ITable interface which returns an instance of IFeatureCursor. The properties and methods available on IFeatureCursor are functionally similar to those on ICursor.


Applying Attribute and Spatial Constraints
While you browse along the OMD of a FeatureClass and Table, Search, Insert and Update methods are used to return a cursor that contains a parameter of IQueryFilter instance.
IQueryFilter object is the query to subset a table or it helps you to subset a record from a table or a FeatureClass, in memory. Similarly for any query of Spatial sort SpatialFilter should be used, but SpatialFilter can only be applied on a FeatureClass. If further attempt over the Table gives you an ERROR as because we lack spatial information over any normal table.
  
QueryFilter
To subset any record from a table or a FeatureClass, you need to define a QueryFilter which specifies the records to be returned. Create a new instance of IQueryFilter and define an attribute constraint for your search by using WhereClause property.

IQueryFilter qFilter = new QueryFilterClass;
qFilter.WhereClasue=”Name=’ArcObjects’”;

This would be used as like
 IFeatureCursor fCursor= featureClass.Search (qFilter, true);


SpatialFilter
As discussed earlier a SpatialFilter can only be applied to produce a subset of records based on spatial criteria.
Just like QueryFilter, SpatialFilter is also a creatable class so the New keyword can be used to create an instance of this class. SpatialFilter uses a Geometry property and a SpatialRel property to define the search criteria. The Geometry property is used to specify a particular geographic feature. SpatialRel can be set to one of a predefined set of constants such as intersects, overlaps, or touches. Because SpatialFilter is a type of QueryFilter, it also has access to all the methods and properties on that class. Therefore, you can use the WhereClause property on IQueryFilter to combine spatial and attribute constraints. The below snippet helps you understand how a SpatialFilter and QueryFilter can be combined together.

ISpatialFilter spatialFilter = new SpatialFilterClass;
spatialFilter.Geometry = pMyPloygon;
spatialFilter.SpatialRel = esriSpatialRelContains;
spatialFilter.WhereClause =”Name=’ArcObjects’”;
IFeatureCursor fCursor = featureClass.Search (spatialFilter, true);

Accessing Records in a Cursor
I believe we have a good understanding on creating cursors, now let’s look at how we can access the cursor (records) returned from a table or FeatureClass.
When a cursor is created you also get a Pointer created, this pointer points to the first record in the cursor while the cursor is initialized. To keep moving to the next record you need to make a call to the NextRow (Table) or NextFeature (IFeatureClass) method. These two methods help you to move the pointer ahead from its current position in the cursor and thereby fetching that particular record information. Subsequent call to the NextRow or NextFeature methods will keep the pointer heading towards the end of the record set or the Cursor which will return null at once point.

IFeatureCursor featureCursor= featureClass.Search (queryFilter, true);
IFeature pFeature=featureCursor.NextFeature ();
While (pFeature! =null)
{
                // To-do any of your logic

                // this keeps the pointer moving head of the current position
                PFeaure= featureCursor.NextFeature ();
}

Reference
Understanding Cursors in ArcObjects by Eric Pimpler, President, GeoSpatial Training & Consulting, LLC

Friday, 2 December 2011

Why do my BaseTool not hitting OnCreate? ? ?

I could find my BaseTool not hitting OnCreate Method many times. While I get into customize window I realize my constructor is been hit but then its not getting into OnCreate :(.
Also while I navigate to my category, again I find my Constructor is been hit but not OnCreate. All my intializations are within my OnCreate method by tradition. Whlie not gettin into OnCreate everytime am gettin my objects null hence,my tool says OBJECT NOT SET TO THE REFERENCE OF AN OBJECT, worried :'(.... any idea anyone? ?

Rajesh K