English

How To: Make a ProjCoordSys or GeoCoordSys when a Type constant is not available.

Summary

Most developers find that the geographic and projected coordinate system constants provide enough choice to cover the needs of all of their datasets. However, you may occasionally find that there is no constant which perfectly matches what you need. This document provides a step-by-step flowchart for using MapObjects' projection object classes for constructing a ProjCoordSys or GeoCoordSys object to perfectly match the way your data is stored on disk, or perfectly match the way you want your data displayed on the map.

Procedure

To build your own ProjCoordSys object, start at Step 1. To build your own GeoCoordSys object, start at Step 2.

  1. Make a new ProjCoordSys object. For example, in Visual Basic type:
    Code:
    Dim thePcs as New MapObjects2.ProjCoordSys

    If there is a ProjCoordSys Type constant which matches your desired coordinate system, then write that constant into the new ProjCoordSys object's Type property, for example:
    Code:
    thePCS.Type = moProjCS_NAD1983UTM_20N

    ... and then proceed directly to Step 18 below. If there is no ProjCoordSys Type constant that meets your needs, please continue with Step 2.

    Note:
    All the available Projection constants for MapObjects are listed in the MapObjects Help. Look up "projections, predefined" on the Index tab. Alternatively, look under MapObjects Reference -> Constants on the Contents tab.

  2. Make a new GeoCoordSys object. Determine the Datum of your desired projection. If MapObjects has a GeoCoordSys Type constant which matches that Datum, then set the Type property of the new GeoCoordSys object to the appropriate GeoCoordSys Type constant. For example:
    Code:
    Dim theGCS as New MapObjects2.GeoCoordSys
    theGCS.Type = moGeoCS_WGS1984

    Note that the GeoCoordSys Type constants contain preset PrimeMeridians. Go to that GeoCoordSys's PrimeMeridian property, read out the PrimeMeridian object, and read its Longitude property. In VB, this can be done with the following code snippet:
    Code:
    Dim theGCS As New MapObjects2.GeoCoordSys
    Dim thePM as MapObjects2.PrimeMeridian
    theGCS.Type = moGeoCS_NAD1983 ' See the MapObjects Help for a complete listing of GCS "Type" constants.
    Set thePM = theGCS.PrimeMeridian
    MsgBox "Longitude = " & thePM.Longitude

    If an existing GeoCoordSys Type constant matches both the datum and the prime meridian you want, then jump directly to Step 8 below; otherwise, please continue with Step 3.

  3. If MapObjects does not have a GeoCoordSys Type constant which matches your Datum, then create a new Datum object, for example:
    Code:
    Dim theDatum as New MapObjects2.Datum

    In the MapObjects Help, check the list of Datum Type constants to see if any fit the projection you are trying to create. If one does, set that new Datum object's "Type" property to that chosen Type constant, for example:
    Code:
    theDatum.Type = moDatum_NorthAmerican1983HARN

    ... and then proceed directly to Step 7 below. If none of the existing Datum Type constants meet your needs, then continue with Step 4.

  4. Make a new Spheroid object:
    Code:
    Dim theSpheroid as New MapObjects2.Spheroid

    Review the Spheroid Type constants in the MapObjects Help to see if any fit the projection you are trying to create. If so, then set the Type property of that new Spheroid object to that Type constant and proceed directly to Step 6 below. If none of the existing Spheroid Type constants meet your needs, then continue with Step 5.

  5. Set the Axis and Flattening properties of the new Spheroid object. See the MapObjects Help for more information on these properties. For example:
    Code:
    theSpheroid.Axis = 6378137
    theSpheroid.Flattening = 0.003353

  6. Write the Spheroid object into the Spheroid property of the new Datum object created in Step 3 above. For example:
    Code:
    theDatum.Spheroid = theSpheroid

  7. Write the Datum object into the Datum property of the new GeoCoordSys object created in Step 2 above. For example:
    Code:
    theGCS.Datum = theDatum

  8. You now have a fully built and configured GeoCoordSys object which you can use in the CoordinateSystem property of a MapLayer or of a Map control. If this is all you need, then stop here. Otherwise, if you are in the middle of creating a ProjCoordSys object, then continue with Step 9.

  9. Write the GeoCoordSys object into the GeoCoordSys property of the new ProjCoordSys object created in Step 1 above. For example:
    Code:
    thePCS.GeoCoordSys = theGCS

  10. Create a new Unit object. For example:
    Code:
    Dim theUnit as New MapObjects2.Unit

    Determine the measurement unit of the desired projected coordinate system. If MapObjects has a Unit Type constant that matches what you want, then set the Type property of the new Unit object to the correct Unit Type constant and proceed directly to Step 12 below. If there is no Unit Type constant that meets your needs, please continue with Step 11.

  11. If your desired measurement unit is linear, then set the Factor property of the new Unit object to a value which matches the number of meters per your particular unit. If your desired measurement unit is spherical or angular, then the Factor is the number of radians per your particular unit. For example, if you were using a linear measure, and the desired measurement unit is equivalent to 237.5 meters in length:
    Code:
    theUnit.Factor = 237.5

  12. Write the Unit object into the Unit property of the new ProjCoordSys object created in Step 1 above. For example:
    Code:
    thePCS.Unit = theUnit

  13. Create a new Projection object:
    Code:
    Dim theProj As New MapObjects2.Projection

    Determine what the projection is of the desired projected coordinate system you want to create. If MapObjects has a Projection Type constant that matches the desired projection, then set the Type property of the new Projection object to the appropriate Projection Type constant, for example:
    Code:
    theProj.Type = moProjection_Mercator

    ... and then proceed directly to Step 16 below. If, on the other hand, there is no Projection Type constant that meets your needs, please continue with Step 14.

  14. If, by following the steps in this article, you have arrived at this step (14), then MapObjects does not have a Projection Type constant appropriate for the projected coordinate system you are trying to create. You must follow the instructions in the MapObjects Help for creating a custom projection COM server DLL. To find the instructions, look up "projections, custom" on the Index tab of the MapObjects Help.

    Note:
    The object you create must contain two stubbed out functions called GeogToProj() and ProjToGeog(). It is completely up to you to write the formulas to be implemented in either or both of these functions. Implementing ICustomProjection provides access to the parameters you will be setting in Step 17 below so that your formulas can use them when converting the input x/y points into transformed x/y points.


    Note:
    See the MapObject Help topic titled "Creating custom projections" for all of the instructions and information you should need. To find this topic, look up "projections, custom" on the Index tab of the MapObjects Help.

  15. In your MapObjects application's calling procedure, create an instance of the COM object you created in Step 14. Write that object into the "Custom" property of the new Projection object created in Step 13 above. For example:
    Code:
    Dim myProj As New CUSTOMPROJLib.MyProjection
    Set theProj.Custom = MyProj

  16. Write the Projection object into the Projection property of the new ProjCoordSys object created in Step 1 above. For example:
    Code:
    thePCS.Projection = theProj

  17. Use the ProjCoordSys's SetParameter method as many times as necessary in order to set all of the parameters needed for the proper operation of the projected coordinate system. For example:
    Code:
    thePCS.SetParameter moParm_StandardParallel1, 46
    thePCS.SetParameter moParm_StandardParallel2, 60
    thePCS.SetParameter moParm_CentralMeridian, 68.5
    thePCS.SetParameter moParm_FalseEasting, 0
    thePCS.SetParameter moParm_FalseNorthing, 0
    thePCS.SetParameter moParm_OriginLatitude, 44

  18. You should now have a fully built and configured ProjCoordSys object which you can use in the CoordinateSystem property of the Map control, enabling the Map to draw MapLayer features using your desired coordinate system.

Related Information