Archive for the ‘Java’ Category

ArcGIS Server Java Samples

July 14, 2008

I’m surprised to see lot of ArcGIS Server Java Samples posted in ArcScripts Section of ESRI.  This is really great news for Java Developers.

  1.  Custom Query :
  2. Hide Layers:
  3. Simple Routing Task:
  4. Search Attribute Task (with Source Code):       (Using ArcGIS Server 9.3)
  5. Bookmark Map Extent:
  6. Add Layers to mapservice :
  7. Upload and Download Points, Lines and Polygons (CSV and WebGraphics)

.. and more java samples for reference. I guess ESRI started shifting their interest to Java too.


ESRI Javascript API is FREE

June 20, 2008

The JavaScript API’s are not part of the ArcGIS Server installation, but are being made available (for FREE!) to any JavaScript developers out on the Web. You can start using them right now with your 9.3 RC1 ArcGIS Server.

They are available at:

The new resource centers have all of the downloads for the JavaScript API’s, Samples, SDK, and documentation.


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.

ArcGIS Server 9.3 on Dojo

June 4, 2008

Dave has started blogging on Dojo toolkit and gave nice refrences for kick start.  For those who werent part of ArcGIS Server Beta program (me too),it’s worth noting that the Javascript API that will be shipping with 9.3 is based on Dojo.

Here is from Wiki on Dojo Tool kit for first sip

“The Dojo Toolkit is a modular open source JavaScript toolkit (or library), designed to ease the rapid development of JavaScript- or Ajax-based applications and web sites. It was started by Alex Russell in 2004 and is dual-licensed under the BSD License and the Academic Free License. The Dojo Foundation is a non-profit organization designed to promote the adoption of the toolkit”

Its right time to learn Dojo Tool kit for working ArcGIS Server 9.3.  Get ready folks.


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.


How to convert IFields to Fields

April 15, 2008


I am trying connect to external database (simple standalone DBF) to one of layer dynamically using ADF. I wrote a method to connect to database and return the fields. I can able to join with database but retrieving fields seems bit tough!. The RelQueryTable class has method  getFields() which returns  IFields objects . How to convert to IFields to Fields object in com.esri.arcgisws which has getFieldArray() to obtain fields list.


Can anyone ping me or give me any clues? 


private Fields JoinTable(IServerContext pSC, IFeatureClass pFeatclass){


ShapefileWorkspaceFactory filefactory = (ShapefileWorkspaceFactory)pSC.createObject(ShapefileWorkspaceFactory.getClsid());

Workspace ws = (Workspace) filefactory.openFromFile(“C:/test/”, 0);

IRelationshipClass pRelationshipClass ;              

ITable table = ws.openTable(“1Z.dbf”);

factory = (MemoryRelationshipClassFactory)pSC.createObject(MemoryRelationshipClassFactory.getClsid());

MemoryRelationshipClass rclass = (MemoryRelationshipClass)“test”, pFeatclass, “ZONENO”, new ObjectClass(table),”ZONENO”, “forward”, “backward”, esriRelCardinality.esriRelCardinalityOneToOne);                     

RelQueryTableFactory relQueryTableFact = (RelQueryTableFactory)pSC.createObject(RelQueryTableFactory.getClsid());

RelQueryTable relQueryTab = (RelQueryTable) (rclass, true, null, null, “”, true, true);

System.out.println(“After Joining total Field count::::::”+ relQueryTab.getFields().getFieldCount())                        

return  relQueryTab.getFields();        


catch(Exception ex){

System.out.println(“ERROR in JOINTable Method”+ ex.toString());

return null;



SP5 offers IBM Portal Server ArcGIS Portlet development

April 15, 2008

ArcGIS Server 9.2 Service Pack 5 includes an enhancement to the ArcGIS Server Java ADF which provides support for IBM Portal Server ArcGIS Portlet development. This gives you the ability to create and publish GIS Mapping Portlets inside IBM Portal Server. In conjunction, SP5 includes a plug-in for the IBM Rational Application Developer (RAD) environment so that you can create and deploy those ArcGIS Portlets more efficiently. The following documents have been added related to this SP5 enhancement.

Install ArcGIS RAD plug-in

Developing ArcGIS portlet Applications in RAD

Will ESRI upload these plug-in s as zip file who don’t have internet connection. ESRI please awake!

Chart Renderering using Web ADF

April 8, 2008


These are days am working with ArcGIS Server [9.2+SP3]- Java edition. I’ve started with ESRI samples and grown up to creating tasks for my application. Task framework is handy to create our own custom business logic with rich UI. I’m trying to recreate or mimic ‘Charts’ functionality similar to Arc Map.  User can select a layer (yet to code), field(s) and chart type to draw charts.   User has option to prevent overlap, change map base symbol color, field(s) color also. It works fine. No harm, charts draws fine. 


While I try to remove the rendering, I couldn’t do so. Later, When I investigated, chart rendering has been applied to the map service (i.e. on server objects) since it is pooled one. I have searched in forum/developers help, I learnt that package has ONLY five classes WebClassBreakInfo, WebClassBreaksRenderer, WebSimpleRenderer, WebUniqueValueInfo, and WebUniqueValueRenderer.  The Chart Rendering option is NOT available with the web ADF.  My senior colleague who attended Dev Summit has explained me that only ArcIMS has this functionality through ArcXML using Chart Symbol Object and not in 9.2. ESRI will incorporate in 9.3 ;adding charts in graphics layer or from other source. This helps me that am working in right direction.


As a developer, you should not expect that everything can only done thru available methods/properties, sometimes we may need to use reverse logic to obtain desired result. One of my fellow colleague suggested that before applying chart rendering to layer object, feature renderer of the layer is stored temporarily once chart renderer is applied , web context is refreshed. Then now apply the feature renderer stored in temporary object to server object so that user can see the charts whereas a server object doesn’t get changed. This is simple and better idea for time being. 


There are several other interesting learning’s/findings in creating this task. I’ve used custom xsl from Daniel Garcia Roman Class break rendering. 


I’m facing some problems like how to update overview map dynamically when rendering type is changed, while changing radio events are not firing properly (I’ve to click twice). Yet to implement normalization, exclusions, orientation, size etc. For a developer who is fairly having good understanding of ArcObjects doing task is not so tough. Here, we are working with ArcObjects remotely. I always use VBA help to understand methods/properties of classes. Then try to migrate to java. Proper casting, creating objects in server context, error handling, using appropriate packages are very vital in server app development. I strongly feel that lack of samples in Developer help for Java as in .NET is a big handicap. We have depend on forums/experts  to understand certain basic issues.



Eclipse plug-in for debugging ArcObjects code

March 27, 2008


Finally ESRI has made Eclipse plug-in for debugging ArcObjects Code. This is great news for java devlopers who uses print line statements.  One of the most important aspect of any tool is debugging.I strongly feel that Mircosoft products brings great developer productivity.  This is also one of  reasons why many huge fans for MS products than java.  Its better late than never, ESRI shown some concern to java developers!. Kudos ESRI 🙂

About the plug-in

One of the most valuable tools that developers have at their disposal is a debugger through which they can step through code one statement at a time and inspect objects in the application. As many of you may already know, Java classes in the ArcObjects API are really only proxies to underlying COM ArcObjects. As a result, examining these proxies in the debugger only reveals their internal details and not the state of the ArcObjects. This makes it difficult to find out information such as the coordinates of a geometry, or the layers in a map service. Consequently, developers have to sprinkle their code with System.out.printlns and analyze traces on the console to get this information. This approach can be inconvenient and time consuming.

With this new Eclipse plug-in, Java developers can examine the state of the underlying ArcObjects right in Eclipse IDE’s Debug Perspective by enabling the “Show Logical Structure” option on the Expression and Variables window. Here’s an example of a Point object without the “Show Logical Structure” option enabled.


This information provides little insight into the underlying ArcObject and is not helpful in reasoning through a workflow while debugging. Now here’s the logical representation of the same object with the “Show Logical Structure” option enabled.


The logical representation presents more comprehensible information about the underlying ArcObject’s state. This state is defined by the no-argument getter methods on it. You might sometimes see exception messages like “Exception Occurred: com.sun.jdi.InvocationException occurred invoking method” in the logical representation. This is normal and happens when some property of the ArcObject is not valid in the current context of the application.

The underlying ArcObjects could be running remotely in a separate process as in the case of ArcGIS Server web applications, or in the same process like in ArcGIS Engine applications. Thus, both Engine and Server developers can take advantage of this plug-in to debug their applications.

How to get the plug-in

Follow these steps to download and install the plug-in from the EDN Website:

  1. In the Eclipse workbench, go to Help > Software Updates > Find and Install
  2. Select Search for new features to install, and click Next
  3. Create a New Remote Site for the URL “”
  4. Enable this remote site and click Finish.
  5. Expand the EDN tree in Search Results, and select the ArcGIS Debug feature.
  6. Proceed to install the plug-in, and restart the workbench when prompted.

ESRI Code Challenge Results!

March 25, 2008

Dear ESRI Devleopers,

Its time to congratulate  the winners of the 2008 ArcGIS Server Code Challenge contest

First Place: $15,000

Display Geospatial Analysis results in Google Maps and Microsoft Virtual Earth with ArcGIS Server

John Waterman, Vice President of Geospatial Solutions, East Burke, Vermont, USA

Second Place: $7,500

ArcGIS Server Virtual Earth Tile Server

Dave Bouwman, Senior Software Architect, Data Transfer Solutions (DTS), Fort Collins, Colorado, USA

Third Place: $2,500

SDE Web Catalog

Loganathan Vijay Sambandhan, GIS Developer, Buffalo, New York, USA

Honorable Mention

Google Maps Adapter to ArcGIS Server Map Cache

Nianwei Liu, Senior System Analyst Programmer, Charlotte, North Carolina, USA