Lesson 3: General Programming Practices

Overview

This lesson covers some general topics of interest to developers working with the GeoCalc tool kit.  These topics include:

 

Identifiers

All ISerializable objects that are stored in the GeoCalc DataSource must have at least one identifier, and many objects have multiple identifiers.  An identifier, combined with an object type, is enough information to uniquely identify any object in the DataSource.  An identifier consists of a pair of strings referred to as the issuer and the code.  For example, there is a ProjectedCoordSys defined in geocalc.xml that has an identifier where issuer = "BMG" and code = "UTM-19N".  This object is uniquely identified in the DataSource by this information:

Object Type:

ProjectedCoordSys

Issuer:

BMG

Code:

UTM-19N

The issuer of an identifier is the source that provided the definition for the object.  Many objects in the supplied data source files have an identifier where the issuer is equal to "BMG", which indicates that Blue Marble Geographics has provided the definition.  Some other objects have an identifier where the issuer is equal to "EPSG", which indicates that the definition came from the EPSG database.  All objects in the GeoCalc DataSource must have an identifier where the issuer is equal to "GC".

The code of an identifier is a value that distinguishes an object from other objects of the same type defined by the same issuer.

The identifiers for an ISerializable object are stored in the IdentifierCollection that can be accessed through the ISerializable::Identifiers property.  The IdentifierCollection accessed by this property provides the functionality to get the identifiers and also to add, remove, and change the identifiers.

 

Error Handling

When an unexpected and problematic condition occurs in GeoCalc during runtime, GeoCalc may raise an error.  It is possible to define error handlers that will catch errors raised by GeoCalc and deal with them appropriately.  If an error is not handled, then it will cause the application to crash.  

For example, the DataSource.GetProjectedCoordSys method will raise an error if the specified identifier does not exist in the DataSource.  Here is an example of how this error can be handled:

[VB6]

Dim gcDataSource As New DataSource

gcDataSource.LoadFile ("c:\bmg\GeoCalcCOM\data\geocalc.xml")

    

On Error GoTo GetCoordSysError

Dim cs As ICoordSys

Set cs = gcDataSource.GetProjectedCoordSys("NOT_A_VALID_ISSUER", "NOT_A_VALID_CODE")

    

Exit Sub

GetCoordSysError:

MsgBox ("Error: " + Err.Description)

 

[Delphi 7]

var

  gcDataSource : DataSource;

  cs : ICoordSys;

begin

  gcDataSource := CoDataSource.Create;

  gcDataSource.LoadFile('c:\bmg\GeoCalcCOM\data\geocalc.xml');

  try

    cs := gcDataSource.GetProjectedCoordSys('NOT_A_VALID_ISSUER', 'NOT_A_VALID_CODE');

  except

    on e : EOleException do ShowMessage(e.Message);

  end;