Archive for the ‘ArcObjects’ Category

MXD Path update

August 8, 2009

Many times  I have faced same problem as described in this post. During application deployment phase of we may need to change all the data-source path to prod database.  Usually we dont have luxury of having ArcGIS Desktop/Catalog for updating the path or do some modifications on production environment. This is primarily because of additional license is required or production server will be entirely on other network or domain.  Due to security reasons also ESRI ArcGIS is not allowed on prod environment.  This becomes annoying when client wants to change the symbology or change the data source for some reasons.

One way to get rid of this issue is maintaining relative path on the mxd.  If you want all your new maps to be stored with relative paths, go to the File > Document Properties dialog box and click the Data Source Options button. Check the option to make relative paths the default for new map documents. This setting is stored in the registry. If this box is not checked, the default is absolute paths.  This will definitely save your effort.

You can still change the path if you have ESRI .NET assemblies installed and you need to write some scripts to achive the same.

If you are working with ArcEngine Java then you can use this tool .   Here is link for MXD Path editor for Java on linux / Solaris OS.

But issue here is whenever you change the connection properties of SDE i.e. if you want to change password alone. Then it hurts more. Reading .sde file to get connection properties using AO is a not possible. You can get connection properties straight a way.

A simple way to get the connection properties that it contains is to use it to open the SDE workspace. Once the workspace is opened, you’ll be able to access the connection properties. Note, the password will remain encrypted – you won’t be able to see it in plain text. ESRI is NOT providing option to decrypt the password since by design as it as for security reason.

Long back I have faced one issue when I saved some layers for which the datasource is SDE  feature classes. I ‘ve used  an SDE connection without save password option. But still I got SDE Connection prompt when I open a map using IMapDocument interface.  I could not supress this prompt programmetically, am not sure whether this issue is solved now.

You can click below link for read on usage of relative paths on MXD. Save a layers using relative path is optimal solution I would suggest for a developer for hassel free deployment.

How to use relative path


First Anniversary !

January 23, 2009

Happy Anniversary to

Dear All:

I am extremely happy that I have crossed one year in blogging.   I have started blogging Jan 21,2008 , its been a fantastic journey throughout.   Nearly 48000+ hits in one year and lot of appreciation and comments from many . I never thought my blog would reach these many people. I am happy that my posts were useful for the readers.

I take this opportunity to thank all readers who appreciated and encouraged me all the time. I place my sincere thanks to ESRI Folks, Jim Barry, Dave and my friends . I wish to write more useful contents on GIS programming and other topics as well.

I welcome your suggestions and comments to improve my blog further!.  Drop your comments!

Happy reading!


Jim Barry (ESRI)….

“Congrats Lakshmanan on your blog’s one year anniversary!  I only discovered it several months ago, but it quickly became one of the few “go-to” blogs for GIS developers on my short list.  Not only to hear about your experience and insights, but you do a great job keeping the pulse of other technical content out there.  I’m sure it takes a lot of work on your part, but it’s greatly appreciated.  Keep it coming!”

Increase performance to make ArcMap start and run faster

September 7, 2008

Really good news for ArcMap Users and here is technical article from ESRI on increasing the performance to make ArcMap Start and run faster.

  • ArcMap takes a long time to start and has poor performance

Below link from ESRI shows the ways to make the ArcMap to start faster.

Though this article is created on 8/24/2006 and modified on 8/26/2008. I’m wondering what are all the updates made by the ESRI recently. ArcMap is much better map viewing tool when compared with other products which I have used.

Anyway, ESRI fine tuning methods certainly helps ArcMap users in better way.

Edit: I got email from WordPress the I have copied the content from ESRI Site. Though I site the source of the article and added my comments, I donot know how it mean copying without their knowledge. I’m not sure how I have voilated terms of service of wordpress.

See the comment section for a mail from WordPress

Technology Migration ArcGIS Server 9.2 to 9.3

June 19, 2008

This post higlights some points on technology migration from ArcGIS Server 9.2 to 9.3. Some one might ask, “Hello ..dude..why do you want this so early ?”.  ArcGIS 9.3 is expected to release by this July. So this would be ideal period to discuss on this. This will be helpful for those who wants to develop new application in 9.3 or redevelop/migrate the existing 9.2 application or atleast curious to know about new features in 9.3.

Yet 9.2 Web ADF have not been explored fully, atleast by myself. Now 9.3 is almost ready. I guess 9.2 released in November 2006. With in 2 years ESRI came up with brand new 9.3.  Web ADF in 9.2 has been under lot of critiscm from several folks though used widely. The ADF learning path is bit hard, thats the naked truth thats the reason everyone hate using 9.2 atleast in .NET. On Other hand Java ADF in 9.2 seems good but lacks documentation. I have not heared much annoyance/comments with respect to java.  Server is not so easy as conventional IMS.  ArcGIS Server provides extensive functionalities than IMS product. It all depends on your requirement and bussiness needs.  Lets get into topic without further noise.

In General, 9.3 ADF built on the same framework in 9.2 with a number of technology and performance enhancements have been incorporated in 9.3 to provide comprehensive platform. The core object model has undergone minor (believe so) changes.  ADF (.NET) is hybrid platform- mix of server side and client side development enviroment. Basic web controls like Map, TOC and Overview has been re-engineered and scriptable now.

Your migration options depend on whether you built a Web ADF application using the Web Mapping Application template (includes applications generated by Manager) or you build a custom Web ADF application without the template.  Below matrix explains the possiblities to upgrade.

9.2 to 9.2 Migration

 Key points for developers:

  • Using ASP.NET partial postback pattern instead of client callback. If you might written lot of code for TOC, rendering by now controls will take care of all your needs. Even if required, it will be on client side
  • Customised Web ADF Javascript libraries. Night mare on Javascript is gone. Developer can get full details of script along with neat documentation.
  • Custom tasks uses partial post back
  • Shallow stateful pattern is no longer supported in 9.3.  Developers should be aware of this. Because adding/removing layers done thru pooled server objects using shallow stateful concepts. Here 9.3 HTTP hanlder (ESRI.ArcGIS.ADF.Web.UI.WebControls.MapHandler) responsible for Map draw operations.
  • Understanding of REST or Javascript API is must.

Sailent features in 9.3 :

  1. Ready made utilities for migrating from 9.2
  2. ArcGIS JavaScript Extension for the Google Maps API
  3. ArcGIS JavaScript Extension for Virtual Earth
  4. Javascript is made public, documented, JSON based, and object oriented. Makes life easy for developer.  9.3 ADF will use JSON instead of XML for it’s communications between the client and server – this alone speeds things up ~30%
  5. Integration with other Javascript frameworks – like Dojo or ExtJS. This allows much more control over how the application looks and behaves.
  6. Improved Map Control, TOC and Overview control. Number of callbacks is reduced.
  7. The resource manager can be managed in Javascript, and has lots of configuration – i.e. layer aliases, fields to show, map tips etc.
  8. Results Viewer: bi-directional highlight. The task can have different results behavior (fields, map tips etc). Kudos!
  9. Additional web controls, additional AjaxExtenders – DockExtender, HoverExpandExtender (pin window type of thing)
  10. Use of HTTP Handlers used instead of pages so the page lifecycle is avoided, so it’s faster
  11. Blending at 9.2 used a single tiling scheme. At 9.3 each resource has it’s own tiling scheme, and the “blending has been massively improved”
  12. Javascript intellisense for Visual Studio 2008.
  13. Better templates and utility to convert previous version templates.
  14. Eliminated lots of callbacks, http handlers improve performance because the control tree is not re-created and destroyed
  15. Visual studio 2008 and .NET 3.5 framework supported
  16. Out-of-box printing tool and export using Adobe Acrobat Reader (PDF)
  17. ArcGIS Image Server is now an optional extension to ArcGIS Server
  18. Integration with Arc Web services
  19. ArcSDE is fully integrated with ArcGIS Server. SDE license bundled with Server.
  20. Windows Vista Support
  21. PostgreSQL support
  22. OGC specifications
  23. Much more…..

Hear the  Latest Podcasts on ArcGIS Server 9.3 from ESRI. CLICK HERE 

To summarise ArcGIS Server 9.3 seems improved much quality and performance wise.

  • Those who are new to Server and about to start development in 9.3 then donot look back web ADF at all.
  • If you are graduating from 9.2 and coming out of Web ADF then 9.3 REST/javascript API will be solace.
  • Are you about to migrate to 9.3 then look at both pros and cons. Don’t jump.

I thank fellow bloggers Dave, James Fee, Tom and others who helped me with valuable inputs. I dare to write this post because am NOT in beta evaluation. Hence people like me who look for similar information, this post may help. If there were any mistakes/omissions/additions or want of further details, please do comment or email me.

VS2008 and ArcGIS 9.3

June 17, 2008

ESRI : “Visual Studio 2008 will be a fully supported development platform for working with the .NET, VC++, and C++ APIs at ArcGIS 9.3. However, at this time, we do not recommend installing VS2008 and working with the ArcGIS Engine Controls. Our tests have revealed a significant issue (NIM013454) that would prevent developers from successfully using Visual Studio 2008 to build ArcGIS controls-based applications with the Tech Preview version of ArcGIS 9.3. Additionally the installation of Visual Studio 2008 also affects the application exe’s compiled with Visual Studio 2005 so these exe’s will crash when displaying a control. Uninstalling Visual Studio 2008 does not resolve the issue. We are working on a solution to this issue; if testing proves successful, the fix will be included in the forthcoming Beta of the ArcGIS 9.3 release.”

Does any one know/tested whether this issue has been fixed in 9.3 Beta? . Please comment if you have an answer.

Search Differences Featureclass vs Featurelayer

June 4, 2008

What is the difference between searching a featurelcass versus a featurelayer?


       Returns an object cursor that can be used to fetch feature objects selected by the specified query.


     Use this method to return a read-only cursor of the layer’s features.

There is ‘Search; method in both IFeatureLayer and IFeatureClass Interface. Both returns cursor based on search criteria. What is difference between these?. This question is obivious for a novice. If you have gone through Help documentation you can figure out easily. Else here is a straight answer

They are the same unless you have a definition query assigned to the layer. In that case the FeatureLayer.Search will only return features that also meet the definition query criteria, while FeatureClass.Search will return all features regardless of definition query. 

This FeatureLayer Search method will not work on joined fields. If the FeaureLayer has any joins, you should use the IGeoFeatureLayer::SeachDisplayFeatures method instead.

You cannot use the cursor returned by IFeatureLayer::Search to update features, instead use IFeatureClass::Update.

I hope this post helps you to understand difference in search method between two interfaces. If you are beginner this tip will be very useful to you. If you have any doubts/clarifications, please feel free to comment. Thanks!



ArcGIS 9.1, 9.2 Difference

June 3, 2008

Those who wants to know difference between ArcGIS 9.1 & 9.2

Summary (based on COM type libraries):







ArcGIS 9.1 933 36 3918 3043 7930
ArcGIS 9.2 1100 40 4798 3832 9770

Note: Hidden or restricted types in COM type library are not included.

Coding Practices and list of Frequent Errors

June 3, 2008

 Coding Practices and list of Frequent Errors

We have recently concluded a project and project closure meeting is conducted in order to ascertains the views/experience of stake holders especially developers. The project was about customizing ArcMap with set of new commands and tools using Microsoft .NET Technology. The project was developed by the team of junior programmers (first time coders) lead by a senior developer.

I would like to come out with the list of frequent errors committed by programmers, missing validations and performance improvement ways. I have briefly discussed here. You can take this as a check list before start coding. There is no particular order followed in this list.

1. System.NullReferenceException – “Object reference not set to an instance of an object.”

This is the most frequently committed error by every developer. I would rate this error as an top rated one. You see people asking about this everywhere; about why are they getting this error. This error primarily occurred when coders are not seriously looking at the Objects created for the class. Below are a few common causes for this

Cause: You are trying to use a reference variable whose value is Nothing/Null.

• When the value is Nothing/null for the reference variable that means it is not actually holding a reference to an instance of any object.
• You either never assigned something to the variable, never created an instance of the value assigned to the variable
• You set the variable equal to Nothing/null manually, or you called a function that set the variable to Nothing/null for you.

I wish to highlight that there is a difference between C#. NET and VB.NET. In certain instances VB.NET code will compile whereas the C# even not allow do this. This is for generic cases for example accessing string.

C#.NET won’t compile

string a;
if (a.Length == 0)


Console.WriteLine (“Yes”);


VB.NET will compile
Dim a As String

If a.Length = 0 Then


End if

But, there will be case in ArcObjects like this.

pMxDoc = m_MxDoc
pMap = pMxDoc.FocusMap
pFeatureLayer = pMap.Layer(0)
Dim Test As String = pFeatureLayer.Name
pFeatureClass = pFeatureLayer.FeatureClass
pFeatureCursor = pFeatureClass.Search(Nothing, False)

pFeature = pFeatureCursor.NextFeature //Culprit is here

We have written code and tested several times works well. But, when Layer (0) doesn’t have any features its throws an ugly error. We may test the code several times with the contents while there were no features and trying the get the Feature object it explodes. This is one such sample.

There are ‘n’ numbers of ways to cause this error in ArcObjects. I always suggest to check whether object is not ‘Nothing’ or object reference is properly set. Give higher importance when dealing with objects particularly while using COM objects.

2. ‘Maximum open cursors exceeded’ or ‘Layer in Use- Maximum number of streams exceeded’

This is also another frequent error which developer does. The maximum cursors will be opened while loop through recordset.

Where: Looping through a recordset using IFeatureCursor may cause the above error:

Garbage collection takes care of releasing resources in managed code. This process is non-deterministic and will release resources at some undetermined time. In most cases this approach works fine, however in this situation it is necessary to mark the COM object as eligible for garbage collection so the resources will be released in a timely manner. i.e. Explicit release of COM Objects when once usage is completed.

You can get sample code and detail on clicking this.

3. Opening and Closing Database Connection using predefined Methods.

It is best practice to open and close database connection using separate common methods by passing its parameters. We have to use this method whenever we need to open/close DB connection. It is also advisable that we need to close the DB connection on ‘Finally’ block; this prevents keeping the connection open when error has occurred in method.

// Open Connection
// Do Something…..

Catch (Exception ex)
//Show Error Messages
//Release unwanted Objects
//Close DB connection

//Close DB Connection here as well…

4. Checking ArcObjects License using AoInitialize object

It is very important to check license availability of the application developed. Especially while using ESRI products understanding License Concepts is bit tough if you are novice. It is worth to give a reading on EDN about license on ESRI products.

Whenever we develop a project first and foremost requirement gathered is product/license used at client side. We have to ascertain the Product used along with Service Packs. As developer we may develop with product used at our organization. This brings greater conflict if you mismatched. Its strongly recommend you to use same product license and service similar to client environment. This will reduce major pain during deployment.

Here are other frequent errors which should be taken care of

5. Use of Feature Class names for all validation; avoid using layer name which may change at any course of time

6. Whenever updating (inserting) data in database in bulk use IFeatureBuffer/IRowBuffer interface for better performance.

7. Always use Try/Catch Block in each and every subroutine/method. This is MUST for any disciplined programmer. Otherwise it would be of hell later when you encounter errors at final stage.

8. IndexOutofRange/ ArrayBound Exception/Over Flow erros/InvalidCast Exception are few common errors can be avoided easily by taking little care while coding. Read OMD for better usage. Especially while using C#.NET casting objects is very vital. There is a performance difference between two ways of casting.

a. pFeatLayer = (IFeatureLayer)pLayer;
a. pFeatLayer = pLayer as IFeatureLayer ;

9. Use of proper collections plays huge role in performance e.g. ArrayList in place of HashTable . The hashtable is used to retrieve value using Key/Value pair whereas Arraylist to use to store the content that cannot be accessed at random. Usage of collection should be judicious. Note, key has to be unique while storing in hash tables otherwise throws an error. Determining which variable to store as key and which as value is paramount importance while retrieving. We often mismatch and take a long detour.

10. Providing proper Error Messages.

User doesn’t want detailed error message or stack trace, providing meaning full error message is very important. I suggest using resource files for doing this job. The usage of constants and providing simple, meaningful message makes application user friendly.

11. Use of proper Enumeration while using Collections- Enumeration, Dictionary etc

12. File Not Found/Read-Write Error.

Sometimes we need to write data in text/excel file,  we must check whether file exists or not at the specified path and then proceed further. At times file which we are about to write will be opened by others or shared, we have to handle such situations. Use of System.IO.Exception solves the issue. Here is an sample code in VB.NET

       pStreamWr= New StreamWriter(strFoldPath + “\” + abc + “.csv”)
        blnOpen = False
Catch ex As IOException
        MessageBox.Show(abc + “.csv file is already in use. Please close the file and click Ok.”)
        blnOpen = True
Catch ex As UnauthorizedAccessException
        MessageBox.Show(abc + “.csv file property is Read-only. Please change the file property and click Ok.”)
        blnOpen = True
End Try

13. Usage of Constants throughout the project helps managing application easier. For example Message Box title /Form Title have to constant through out the application, hence usage of application level constant will solve the issue. Using resource file will be handy and easier.

14. Editing Concepts:

When to use pooled vs. non-pooled objects in case of Web Application is another question which we come across often. General practice is if your edits are quick, and you do not need to have un-do / re-do type capabilities, you apply them against a pooled object.For example – if you just need to insert a point into a layer – collect the x, y and attribute information via your web front end, and then create the feature in one transaction. This will work with a pooled object just fine.
If you want to have a longer running edit session, where the save is not automatically committed back to the database, use a non-pooled object.

15. Avoid simple errors like – allowing users to type in Dropdown list, this is prevented setting appropriate property in the control; Form will be opened multiple times on clicking command has been avoided by setting as Modal.

These are some of the points which has brought out at this instance. Many of developers may use better coding practice to avoid these sorts of error, but these points will be useful for many who just begin coding. As I said in top of this post these are used as check list to avoid frequent errors. If this post helps please drop your comments/Suggestion, you may suggest few more points to this one.


ArcObjects Tutorial II: Add Command to Toolbar

May 23, 2008

Welcome to second walkthrough on adding custom ArcGIS component (command) to standard tool bar in ArcMap. We have successfully created custom command using C#; adding this command to ArcMap standard toolbar through ESRI IExtension.

 Tools & Language: Visual Studio 2005, C#.NET, ArcGIS 9.2

Manually we can add the command using ArcMap Tools–>Customize–>Click Command Tab, Choose the category and drag the command to toolbar. If we want to save this command permanently in ArcMap; use ‘Save In’ option to ‘Normal.mxt’ . The command will be saved on template.  

The purpose of this walkthrough is to add the custom command to ESRI toolbar programmatically.  ESRI has provided option to develop Application Extension inheriting ESRI IExtension. By inheriting IExtension class we can create our own extension and add the extension in categories manager. Applications loads extension AUTOMATICALLY on Startup. Life cycle of loading extension is a) Application starts b) Extension are loaded c) Document is loaded  d)  Document is closed e) Extensions are unloaded .

There are two types of extension they are Visible and Invisible (present walkthrough). Visible extension inherits IExtensionConfig and it will be added in Extension Manager Window. Looks like other ESRI extension along with its description.

Once you added this class, new class ‘ApplicationExtension1.cs’ will create by inheriting base class IExtension. This class contains functions to Register COM components (Register and UnRegister) and IExtension members like Extension name (Property-String) , Startup, Shutdown methods.

Our objective is to add the developed custom command to existing standard toolbar, i.e. whenever we open Map Document is opened, and command should be added in the toolbar. For achieving this, we have add delegate (IDocumentEvent_NewDocumentEventHandler) and pass a method to be fired on startup.

public void Startup(ref object initializationData)


           //m_application is ArcMap Application

            m_application = initializationData as IApplication;

            if (m_application == null)


                 IMxDocument pMxDoc;       

            // pMxDoc is ArcMap Map Document 

            pMxDoc = (IMxDocument)m_application.Document;          

 // Creating Event Handler with a Method ’onNewOpenDoc’          

((IDocumentEvents_Event)pMxDoc).NewDocument += new IDocumentEvents_NewDocumentEventHandler(OnNewOpenDoc);



private void OnNewOpenDoc()


ICommandBar pCmdBar; 

//Create two new UID objects from UID class

UID pUID = new UID();

UID pCommandUID=new UID(); 

//pUID value is ArcMap Standard ToolBar UID Value  taken from here


pUID.Value = “{5DEB1DB8-C2A9-11D1-B9A2-080009EE4E51}”; 

pCmdBar= ICommandBar)m_application.Document.CommandBars.Find(pUID, false, false); 


// pCommandUID value is custom command UID value found in the class //created


pCommandUID.Value = “{a657d37d-5cdd-4315-8866-87e389f2ffb8}”;

object index=0; 

// Note object called index is set to ‘0′; command will be added as first //command in toolbar 

pCmdBar.Add(pCommandUID,ref index); 


In ‘OnNewOpenDoc’ method we have to write code for adding the custom command to toolbar.  This method gets fired on opening every new ArcMap Instance.


Build and run the project. Now you can notice your custom command appeared as first item in a standard toolbar (make visible, if not) of ArcMap.   


I hope that this tutorial will be of much help to beginner who starts programming in ArcObjects. I will add some useful external links to this post. 



Attachment: extending-arcgisnet  PDF  

Password to personal geodatabase

May 23, 2008


Can I use or set passwords on a personal geodatabase?


No, while the underlying .mdb file supports the use of passwords, the geodatabase and ArcGIS do not. Microsoft Access .mdb files that are password protected cannot be opened in ArcGIS, nor can password protected personal geodatabases be created in ArcGIS.

If the intention is to restrict users from accessing the personal geodatabase, setting the appropriate user level permissions on the folder is recommended. For more information on setting different permissions for different users accessing a personal geodatabase, see the following ESRI Knowledge Base article in the Related Information below.


Related Information


Source: ESRI Technical Article