Derived Geometry Redux

A long time ago, on a blog-hosting site far far away, there was a blog called ArcDeveloper (not to be confused with ArcDeveloper.Net, which came later and did more). That was my first blog. It went in a few different directions. I wasn’t happy with it, so I killed it. There’s nothing to link to now.

Anyway, one of the posts I did on that blog had to do with creating derived geometry classes in .Net. The basic premise is simple: create a class that inherits from one of the ArcObjects geometry classes and then extend it to fit your needs. My application at the time had to do with writing an ArcGIS client for Common Alerting Protocol (CAP) feeds.

The following code shows the beginning of a derived polygon class I created for the CAP client. The constructor parses the polygon string (as defined in the CAP spec) and populates the base polygon with the points. When the object is instantiated, I have a polygon that I can pass to ArcMap for display. This is a pretty standard use of inheritance.

using ESRI.ArcGIS.Geometry; 
public class Polygon : PolygonClass 
{ 
/// <summary> 
/// Main constructor. Populates base polygon with points based upon the 
/// parsed capPointList. Set SpatialReference for base to WGS84 as per 
/// CAP standard version 1.0. 
/// </summary> 
/// <param name=”capPointList”>Delimited list of coordinates to be parsed 
/// into point objects for insertion itno base polygon. As per CAP 1.0 
/// specification, the required syntax for point list is: 
/// “y1,x1 y2,x2 y3,x3 … yn,xn y1,x1 
/// CAP specification states that first coordinate should be repeated as 
/// last coordinate in order to close the polygon.</param>

public Polygon(string capPointList) 
{ 
    IGeographicCoordinateSystem gcs; 
    ISpatialReferenceFactory spatialEnv = new SpatialReferenceEnvironmentClass(); 
    object missing = System.Reflection.Missing.Value; 
    string[] pointArray; 
    char[] splitter = {‘ ‘}; 
    ///As per CAP 1.0, spatial reference is WGS84. 
    gcs = spatialEnv.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984); 
    base.SpatialReference = (ISpatialReference)gcs; 
    pointArray = capPointList.Split(splitter); 
    for (int i = 0; i < pointArray.Length; i++) 
    { 
        /// this is a call to an external function that just makes a point object from y,x text 
        base.AddPoint(Ambient.parsePoint(pointArray[i]),ref missing, ref missing); 
    } 
}

My recent involvment with zigGIS has gotten me thinking about this approach again but, this time, with respect to passing WKB or WKT into the constructor. I think this approach would be a good way to achieve encapsulation of the parsing process as we create ESRI geometry objects from WKB and WKT.