IProjectedCoordinateSystemEdit.define crashes

680
4
12-07-2012 07:19 AM
New Contributor
I have been working on a specialized containment comparison algorithm for a large global dataset. 

Each feature must be projected from a base class programatically and the
IProjectedCoordinateSystemEdit.define crashes even when taken from the sample code directly

Windows environment using eclipse ganymede and the ArcObjects 10.0 SDK

Has anybody else experienced this issue.  Any healp would be appreciated.
Reply
0 Kudos
4 Replies
Esri Notable Contributor
It's VB.Net, but this works for me in VS. It does not include the ControlPrecision setting nor setting the tolerance and resolution values. The other thread references a very old help topic. A more up-to-date one is here: Creating a Custom Projected Coordinate System

Another thread using C#: http://forums.esri.com/Thread.asp?c=93&f=1170&t=124093&mc=11#826802

It's older, and I haven't tested that version for a while. Here's one that worked for me.

        Dim pSR As ISpatialReference3
        pSR = Nothing

        Dim t As Type = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment")
        Dim obj As System.Object = Activator.CreateInstance(t)
        Dim pSRF As ESRI.ArcGIS.Geometry.ISpatialReferenceFactory3 = obj

         ' Create a projection, GeographicCoordinateSystem, and unit using the factory.
        Dim projection As IProjectionGEN = TryCast(pSRF.CreateProjection(CInt(esriSRProjectionType.esriSRProjection_Sinusoidal)), IProjectionGEN)
        Dim geographicCoordinateSystem As IGeographicCoordinateSystem = pSRF.CreateGeographicCoordinateSystem(CInt(esriSRGeoCSType.esriSRGeoCS_WGS1984))
        Dim unit As ILinearUnit = TryCast(pSRF.CreateUnit(CInt(esriSRUnitType.esriSRUnit_Meter)), ILinearUnit)

        ' Get the default parameters from the projection.
        Dim parameters As IParameter() = projection.GetDefaultParameters()

        ' Create a PCS using the Define method.
        Dim projectedCoordinateSystemEdit As IProjectedCoordinateSystemEdit = New ProjectedCoordinateSystemClass()
        Dim Name As Object = "Newfoundland"
        Dim [Alias] As Object = "NF_LAB"
        Dim abbreviation As Object = "NF"
        Dim remarks As Object = "Most Eastern Province in Canada"
        Dim usage As Object = "When making maps of Newfoundland"
        Dim geographicCoordinateSystemObject As Object = TryCast(geographicCoordinateSystem, Object)
        Dim unitObject As Object = TryCast(unit, Object)
        Dim projectionObject As Object = TryCast(projection, Object)
        Dim parametersObject As Object = TryCast(parameters, Object)

        ' Note: Alias is a reserved keyword in VB .NET. To use it as a variable name, encase it in brackets [ ].

        projectedCoordinateSystemEdit.Define(Name, [Alias], abbreviation, remarks, usage, geographicCoordinateSystemObject, unitObject, projectionObject, parametersObject)
        pSR = projectedCoordinateSystemEdit



Melita
Reply
0 Kudos
New Contributor
Thank you for the reply.

I was using the the Java SDK and the code from this page
http://help.arcgis.com/en/sdk/10.0/java_ao_adf/conceptualhelp/engine/index.html#//000100000299000000

I found this post as well

http://forums.arcgis.com/threads/42910-Issues-Creating-a-Custom-Projected-Coordinate-System?highligh...

Which makes me believe that the Java interface is broken.  I was hoping someone else had a similar problem and discovered a workaround but I suppose most java folks do not do this type of work with the ArcObjects Engine.

Thanks for the post.

If you hear of anything let me know.
Reply
0 Kudos
New Contributor
Just in case anyone else has to deal with this.  A great workaround for me was to define the projection from a file the change the parameters as needed. 

Good luck out there!


private static ISpatialReference getCustomSpatialRefFromFile() throws Exception {//, ISpatialReference inSpaRef
  ISpatialReferenceFactory srf = new SpatialReferenceEnvironment();
  IProjectedCoordinateSystem pcs = (IProjectedCoordinateSystem) srf.createESRISpatialReferenceFromPRJFile("test.prj");
 
                IProjectedCoordinateSystem4GEN pcsGen = (IProjectedCoordinateSystem4GEN) pcs;
  IParameter[][] parameters = new IParameter[1][7];
  pcsGen.getParameters(parameters);
   for (int i = 0; i < parameters[0].length; i++){
          IParameter currentParameter = parameters[0];
          if (currentParameter != null){
              System.out.println(currentParameter.getName() + ", " +
                  currentParameter.getIndex() + ", " + currentParameter.getValue());
          }
                        // set the value by parameter name
          if (parameters[0].getName().equals("My_Parameter") == true){IParameter p = parameters[0];p.setValue(0);}
   }
   pcs.changed();
   for (int i = 0; i < parameters[0].length; i++){
          IParameter currentParameter = parameters[0];
          if (currentParameter != null)
              System.out.println(currentParameter.getName() + ", " +
                  currentParameter.getIndex() + ", " + currentParameter.getValue());
   }
  
  return pcs;

}
Reply
0 Kudos
New Contributor
I was still getting problems with this but I think i found the problem.
You must allocate the full number of possible parameters when passing even if no value is set

private static ISpatialReference getCustomSpatialRefFromFile() throws Exception {//, ISpatialReference inSpaRef
  ISpatialReferenceFactory srf = new SpatialReferenceEnvironment();
  IProjectedCoordinateSystem pcs = (IProjectedCoordinateSystem) srf.createESRISpatialReferenceFromPRJFile("test.prj");
 
                IProjectedCoordinateSystem4GEN pcsGen = (IProjectedCoordinateSystem4GEN) pcs;
  IParameter[][] parameters = new IParameter[1][16];  // the 16 is very important.
  pcsGen.getParameters(parameters);
   for (int i = 0; i < parameters[0].length; i++){
          IParameter currentParameter = parameters[0];
          if (currentParameter != null){
              System.out.println(currentParameter.getName() + ", " +
                  currentParameter.getIndex() + ", " + currentParameter.getValue());
          }
                        // set the value by parameter name
          if (parameters[0].getName().equals("My_Parameter") == true){IParameter p = parameters[0];p.setValue(0);}
   }
   pcs.changed();
   for (int i = 0; i < parameters[0].length; i++){
          IParameter currentParameter = parameters[0];
          if (currentParameter != null)
              System.out.println(currentParameter.getName() + ", " +
                  currentParameter.getIndex() + ", " + currentParameter.getValue());
   }
  
  return pcs;

}


I hope this helps some other poor soul in the future.

It has to do "I Believe" with how ArcObjects accesses the engine using JNI which we all know can be touchy.  because it is passing marshaled data from java to a COM interface and retrieving then marshaling the return information the Arc Object Com Interface allocates a full array in memory for the object.  If it does not receive empty values to populate those registers it goes all funky.

Just a guess but it works nonetheless.

I will test with define and see if this was the problem in the first place.
Reply
0 Kudos