0

I have written a function to get a Transverse-Mercator IProjectedCoordinateSystem. However when calling the Define function I get an RPC_E_SERVERFAULT (HRESULT: 0x80010105) and no additional information. I am looking at the examples here and here.

Does anyone know what I am doing wrong?

ISpatialReference get_tmerc(double latitude, double longitude)
{
    ISpatialReferenceFactory3 spatialReferenceFactory = new SpatialReferenceEnvironment() as ISpatialReferenceFactory3;

    var wgs84 = spatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
    var meter_unit = (ILinearUnit)spatialReferenceFactory.CreateUnit((int)esriSRUnitType.esriSRUnit_Meter);
    IProjectionGEN projection = (IProjectionGEN)spatialReferenceFactory.CreateProjection((int)esriSRProjectionType.esriSRProjection_TransverseMercator);

    IParameter[] parameters = new IParameter[5];
    IParameter parameter = spatialReferenceFactory.CreateParameter(100021); //latitude
    parameter.Value = latitude;
    parameters[0] = parameter;

    parameter = spatialReferenceFactory.CreateParameter(100010); //meridian
    parameter.Value = longitude;
    parameters[1] = parameter;

    parameter = spatialReferenceFactory.CreateParameter(100003); //scale factor
    parameter.Value = 1;
    parameters[2] = parameter;

    parameter = spatialReferenceFactory.CreateParameter(100001); //false N
    parameter.Value = 0;
    parameters[3] = parameter;

    parameter = spatialReferenceFactory.CreateParameter(100001); //false E
    parameter.Value = 0;
    parameters[4] = parameter;

    object name = "TransMerc_Name_ASDFSDF";
    object alias = "Custom_Transverse_Mercator";
    object abb_obj = "Trans_Merc";
    object rem_obj = "Transverse Mercator";
    object usage_obj = "";
    object wgs_obj = wgs84;
    object unit_obj = meter_unit;
    object proj_obj = projection;
    object para_obj = parameters;

    IProjectedCoordinateSystem proj_coord = new ProjectedCoordinateSystem() as IProjectedCoordinateSystem;
    IProjectedCoordinateSystemEdit proj_coord_edit = proj_coord as IProjectedCoordinateSystemEdit;
    //***ERROR IS HERE***
    proj_coord_edit.Define(ref name, ref alias, ref abb_obj, ref rem_obj, ref usage_obj, 
                           ref wgs_obj, ref unit_obj, ref proj_obj, ref para_obj);
    return proj_coord;
} 
  • 2
    Try using DefineEx instead and look at the sample here. – mkennedy Jun 21 at 18:02
  • @mkennedy I receive the same error, though I may have used it incorrectly. It has a ref parameter for a single IParameter object, since Transverse-Mercator has 5 IParameters that can be set I wasn't sure what to give it, so I gave it parameters[0] from my snippet above. – danielm Jun 21 at 21:32
  • 1
    Hmmm, false northing should be 100002. The only other thing I can think of is to use the internal parameter array values. fe = 0, fn = 1, cm = 2, phi0 = 6, sf = 5 – mkennedy Jun 21 at 21:46
  • Unfortunately that didn't do it. I've also tried using the projection.GetDefaultParametes() as my input parameters, and that did not work. So I'm less inclined to believe the issue is in the parameter array. – danielm Jun 24 at 14:26
  • @mkennedy I just figured it out. Thanks for the help. – danielm Jun 24 at 14:44
0

I found the issue. The main thread for the test project I had set up for this functionality was an MTA (Multi Threaded Apartment) thread. Simply calling everything from an STA (Single Threaded Apartment) thread caused the issue to go away.

    Thread t = new Thread(x => ...) //call projection code here
    t.SetApartmentState(ApartmentState.STA);
    t.Start();

I'd missed this because creating built-in projections like UTM18 worked fine and a lot ArcObjects will function when called from an MTA thread, just slower due to having to marshal calls to a background STA thread.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.