Cannot create Custom Projected CS from ArcObjects Java SDK?

779
2
01-07-2018 01:07 AM
KeenanGebze1
New Contributor II

Hi, 

in the ArcObjects SDK for Java, there is an example code to create a custom projected CS using IProjectedCoordinateSystemEdit define() method.

Here is the link:

How to create a custom projected coordinate system—ArcObjects 10.4 Help for Java | ArcGIS for Deskto... 

or ArcObjects Help for Java developers | ArcGIS for Desktop 

Here is the example code:

static IProjectedCoordinateSystem createProjectedCoordinateSystem() throws Exception{      
    ISpatialReferenceFactory2 spatialReferenceFactory = new SpatialReferenceEnvironment();      
    //Create a projection, GeographicCoordinateSystem, and unit using the factory.    
    IProjectionGEN projection = (IProjectionGEN) spatialReferenceFactory.createProjection(
        (int) esriSRProjectionType.esriSRProjection_Sinusoidal);
    IGeographicCoordinateSystem geographicCoordinateSystem = spatialReferenceFactory.createGeographicCoordinateSystem(
        (int) esriSRGeoCSType.esriSRGeoCS_WGS1984);
    ILinearUnit unit = (ILinearUnit)spatialReferenceFactory.createUnit(
        (int) esriSRUnitType.esriSRUnit_Meter);      
    //Get the default parameters from the projection.    
    IParameter[] parameters = projection.getDefaultParameters();      
    //Create a projected coordinate system using the Define method.    
    IProjectedCoordinateSystemEdit projectedCoordinateSystemEdit = new ProjectedCoordinateSystem();
    Object name = "Newfoundland";
    Object alias = "NF_LAB";     
    Object abbreviation = "NF";     
    Object remarks = "Most Eastern Province in Canada";     
    Object usage = "When making maps of Newfoundland";     
    Object geographicCoordinateSystemObject = geographicCoordinateSystem;     
    Object unitObject = unit;     
    Object projectionObject = projection;     
    Object parametersObject = parameters;      
    projectedCoordinateSystemEdit.define(name, alias, abbreviation, remarks, usage,
         geographicCoordinateSystemObject, unitObject, projectionObject,
         parametersObject); // <-- problem part. If I put null, then it works.     
  return (IProjectedCoordinateSystem)projectedCoordinateSystemEdit; 
}

I've run the code, but wont work and throwing native library error: Execution protection violation.

Below I've attached the error log.

I've identified the problem part. The IParameter[] parameter is making the define() method crashes. If I substitute the parameter using null values, the define() method works perfectly.

I want to create a Lambert Azimuthal Equal Area PCS in which I can custumize the central latitude and longitude.

Thankyou,

I'm using:

ArcGIS Developer Kit 10.5

ArcGIS Engine 10.5

JDK ver. 1.8.0_151 32bit 

JRE ver. 1.8.0_121 32bit (in the ArcGIS Developer Kit 10.5 folder)

0 Kudos
2 Replies
DanPatterson_Retired
MVP Emeritus

You can find the lambert projected coordinate system simply by examining what is already defined for those parameters either by looking for them in the projection information with the arc* suite or googling

North America Lambert Conformal Conic

then just pull out the pieces you need

ie

PROJCS["North_America_Lambert_Conformal_Conic",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["False_Easting",0],PARAMETER["False_Northing",0],PARAMETER["Central_Meridian",-96],PARAMETER["Standard_Parallel_1",20],PARAMETER["Standard_Parallel_2",60],PARAMETER["Latitude_Of_Origin",40],UNIT["Meter",1]]

0 Kudos
KeenanGebze1
New Contributor II

Thankyou,

I've followed your advice by saving the said projection in to a .prj file (from ArcMap) and then pass the content of the prj file into SpatialReferenceEnvironment's createESRISpatialReferenceFromPRJ(String prj) method with few modified parameters.

But an exception came out: AutomationException: 0x80040207 - The input is not a workstation prj file. in '"esri.SpatRefEnvironment"'

I didn't find much documentation about this (ArcInfo?) workstation prj file and struggled to create it. (I found one but not much of a help: How To: Make the Projections Tools for coverages work in ArcToolBox )

However, the code worked when I use the createESRISpatialReferenceFromPRJ(String prjFile) method:

SpatialReferenceEnvironment sre = new SpatialReferenceEnvironment();

return sre.createESRISpatialReferenceFromPRJFile("..\\South Pole Lambert Azimuthal Equal Area.prj");

Of course I would not prefer using this method because I've to write and read to a file every time, just to edit few parameters.

So If there is a documentation about this "ArcInfo workstation prj" file or other solution, that would be helpful.

I'll also try using ArcObjects SDK / Engine 10.4

0 Kudos