Showing results for 
Search instead for 
Do you mean 

How to orthorectify an RPC image with IMAGINE Developers' Toolkit

by Technical Evangelist on ‎03-18-2016 12:50 PM - edited on ‎03-22-2016 12:51 PM by Anonymous (294 Views)

Question

Can you use the IMAGINE Developers' Toolkit to create a job that will orthorectify an RPC image? 

Answer

The following example shows how to orthorectify a SPOT RPC image.

 

/************************************************************************
*************************************************************************
JOB: imageResample

PURPOSE:
This example shows how to rectify image based on SPOT5 Pushbroom sensor model
Sensor info is saved in metatdata.dim (RPC)

CALLING SYNTAX: 
imageResample -in[put] <inputfile> -dem <demfile> -out[put] <outputfilename>

imageResample -in "$IMAGINE_HOME/examples/imagery.tif"
   -dem "$IMAGINE_HOME/examples/dem.tif"
   -out "$IMAGINE_HOME/examples/output.img"

*************************************************************************
*************************************************************************/

/*
** TOOLKIT INCLUDES
*/
#include <exfr.h>
#include <emsc.h>
#include <eprj.h>
#include <eprj_MapInfo.h>
#include <eimg.h>
#include <eirf.h>
#include <eerr.h>
#include <esmg.h>
#include <eeml.h>
#include <earg.h>
#include <estr.h>
#include <efnp.h>
#include <emet.h>
#include <emod.h>
#include <ewrp.h>
#include <ewrp_private.h>

/*
** ERROR CHECKING MACROS.
*/
#define EFS1( msg, arg ) EERR_FATAL_SET_1( __LINE__, msg, arg )
#define EFS0( msg ) EERR_FATAL_SET_0( __LINE__, msg )
#define ES0( e, msg ) EERR_SHOW_0( e, EERR_DEBUG, __LINE__, msg )


/*
** GLOBAL VARIABLES
*/
char* output_filename;
char* input_filename;
char* dem_filename;
static int rc = 0;
static Eint_InitToolkitData *erdinit = NULL;


/*
** GLOBAL STRUCTURE
*/
typedef struct _WT_Struct {
 

 /* INPUT IMAGE */
 EprjMapInfo   input_mapinfo;  /* input layer mapinfo */
 EprjProParameters input_proparm;  /* input layer pro parms */
 EtxtText   input_units;  /* output units */
 EprjElevationInfo input_elevinfo;  /* input layer elevation info */
 EimgLayerStack  input_layerstack; /* input layerstack */
 
 /* DEM IMAGE */
 EtxtText   dtmunits;   /* The elevation units used by the current geometric model */
 double    dtmmean;   /* The dtm mean or the constant elevation value */
 EtxtText   dtmfilename;  /* The name of the dtm file used by the current geometric model */
 EgdaBaseData  elev_matrix;  /* The elevation matrix for map x,y */

 /* OUTPUT IMAGE */
 EprjMapInfo   output_mapinfo;  /* output layer mapinfo */
 EprjProParameters output_proparm;  /* output layer pro parms */
 EtxtText   output_units;  /* output units */
 EprjElevationInfo output_elevinfo; /* output layer elevation info */


 /* SENSOR MODEL */
 char     *modelname;   /* Model name */
 char     *modelfilename;  /* Model filename */
 Estr_StringList  *modelnamelist;  /* List of available models */
 EtxtText   geomodelname;  /* The name of the current geometric model */

 Ewrp_WarpInfo  *warpinfo;   /* the warpinfo environment */
 long    xskip;    /* X skip for recalc */
 long    yskip;    /* X skip for recalc */
 Emod_ModelInfo  *modelinfo;   /* emod model info */

} WT_Struct;
typedef struct _WT_Struct WT;

/*
** GLOBAL FUNCTIONS
*/
static void jobMain(int, char **);
static void set_input(int, char **);
static void set_dem(int, char **);
static void set_output(int, char **);
static Eprj_MapInfo *updateOutputMapinfo (WT *wt,Eprj_MapInfo *mapinfo,Eprj_ProParameters *proparm,char *units);


/*
** COMMAND ARGUMENT PROTOTYPE.
*/
static Earg_Cmd format[] =
{
        set_input,  "-in[put] %s",        "", EARG_NO_ERR,
        set_dem,  "-dem %s",        "", EARG_NO_ERR,
  set_output,  "-out[put] %s",       "", EARG_NO_ERR,
        jobMain,  "imagerectify",      "", EARG_NO_ERR,
        EARG_END
};

 

/*
** Earg DEPENDENT FUNCTION - INPUT
*/
static void
set_input( int argc, char **argv)
{
    input_filename = estr_Duplicate(argv[1]);
    return;
}


/*
** Earg DEPENDENT FUNCTION - REFERENCE
*/
static void
set_dem(int argc, char **argv)
{
    dem_filename = estr_Duplicate(argv[1]);
    return;
}

/*
** Earg DEPENDENT FUNCTION - OUTPUT
*/
static void
set_output(int argc, char **argv)
{
    output_filename = estr_Duplicate(argv[1]);
    return;
}

 


/*
** EXECUTION ENTRY POINT
*/
int main(int argc, char **argv)
{
    /*
 ** DECLARES, INITIALIZES ALL VARIABLES TO BE USED BY THE OTHER EERR
 ** MACROS.
 */
 EERR_INIT("imageResample: main", &lclerr, lclerr);
    erdinit=eint_InitToolkit((Emsc_Opaque **)&lclerr);

    /*
    ** INITIALIZE THE ERDAS TOOLKIT
    */
    (void)eint_InitToolkit((Emsc_Opaque**)&lclerr);
    EERR_CHECK(lclerr, EFS0("Error initializing the Toolkit"));
   
    /*
    ** REGISTER WITH THE SESSION MANAGER AS A JOB.
    */
    esmg_JobInit("imageResample", &lclerr);
    EERR_CHECK(lclerr, EFS0("Error with Job Initalization!"));
   
    /*
    ** PARSE THE COMMAND LINE BASED ON THE PROTOTYPE.
    */
    earg_DoArgs(format, argc, argv, &lclerr);
    EERR_CHECK(lclerr, EFS0("Error earg_DoArgs"));
   
    /*
    ** ANNOUNCE THAT THE JOB IS DONE.
    */
    esmg_JobEnd(&lclerr);
    EERR_CHECK(lclerr, EFS0("Error esmg_JobEnd"));
   
cleanup:
    EERR_SHOW(lclerr, EERR_DEBUG);
 /*
 ** RETURN 0 WHEN JOB FINISH SUCCESSFULLY
 ** RETURN -1 WHEN FAILED.
 */
    return (rc);
}

 

static void
jobMain(int argc, char **argv)

 EERR_INIT("jobMain", &lclerr, lclerr);


 /* INPUT IMAGE */
 Estr_StringList* input_layernames = NULL;
 Eimg_LayerStack* input_layerstack = NULL;
 EprjMapInfo   input_mapinfo = NULL;
 EprjProParameters input_proparm = NULL;
 EtxtText   input_units = NULL;
 EtxtText   input_proname = NULL;
 Eprj_MapProjection* input_projection = NULL;
 Exfr_XForm *  input_xform = NULL;
 long    input_width;
 long    input_height;

 /* DEM IMAGE */
 Estr_StringList* dem_layernames = NULL;
 Eimg_LayerStack* dem_layerstack = NULL;
 EprjMapInfo   dem_mapinfo = NULL;
 EprjProParameters dem_proparm = NULL;
 EtxtText   dem_units = NULL;
 EtxtText   dem_proname = NULL;
 Eprj_MapProjection* dem_projection = NULL;
 Exfr_XForm *  dem_xform = NULL;
 Efga_Matrix *  dem_control;


  /* OUTPUT IMAGE */
 EtxtText   output_layername = NULL;
 Estr_StringList* output_layernames = NULL;
 Eimg_LayerStack* output_layerstack = NULL;

  /* MODEL SOLVE */
 Exfr_XForm *  xform = NULL;
 Exfr_XForm *  xform_inv = NULL;
 Exfr_XForm *  xform1 = NULL;
 Exfr_XForm *  f2f_xform = NULL;

 Efga_Polynomial* f2m = NULL; 
 Exfr_XForm *  pre_xform = NULL;
 Exfr_XForm *  modelxform = NULL;
 Exfr_XForm *  post_xform = NULL;

 Efga_Matrix*  mat1 = NULL;
 Efga_Matrix*  mat2 = NULL;

 Emsc_Boolean  report_error = EMSC_FALSE;
 int     status = 0;

  /* OUTPUT FOOTPRINT */
 long    i,j, count, layer = 0;
 double    minx, miny, maxx, maxy, midy;
 double    xcell, ycell;
 double    xoffset, yoffset;
 long    nrows, ncols;

  /* RESAMPLE */
 long     blockx, blocky ;
 Eprj_MapInfo*   mapinfo = (Eprj_MapInfo *)NULL;
    Eimg_PixelRectStack* pixRectStack = NULL;
 

/**************************************
** INIT WT STRUCTURE
**************************************/
 WT *wt;
 wt = new WT_Struct;

 /* INPUT IMAGE */
 wt->input_mapinfo = NULL;  /* input layer mapinfo */
 wt->input_proparm = NULL;  /* input layer pro parms */
 wt->input_units = NULL;   /* output units */
 wt->input_elevinfo = NULL;  /* input layer elevation info */
 wt->input_layerstack = NULL; /* input layerstack */
 
 /* DEM IMAGE */
 wt->dtmunits = NULL;   /* The elevation units used by the current geometric model */
 wt->dtmmean = NULL;    /* The dtm mean or the constant elevation value */
 wt->dtmfilename = NULL;   /* The name of the dtm file used by the current geometric model */
 wt->elev_matrix = NULL;   /* The elevation matrix for map x,y */

 /* OUTPUT IMAGE */
 wt->output_mapinfo = NULL;  /* output layer mapinfo */
 wt->output_proparm = NULL;  /* output layer pro parms */
 wt->output_units = NULL;  /* output units */
 wt->output_elevinfo = NULL;  /* output layer elevation info */


 /* SENSOR MODEL */
 wt->modelname = NULL;   /* Model name */
 wt->modelfilename = NULL;  /* Model filename */
 wt->modelnamelist = NULL;  /* List of available models */
 wt->geomodelname = NULL;  /* The name of the current geometric model */

 wt->warpinfo = NULL;   /* the warpinfo environment */
 wt->xskip = NULL;    /* X skip for recalc */
 wt->yskip = NULL;    /* X skip for recalc */
 wt->modelinfo = NULL;   /* emod model info */

 wt->warpinfo = ewrp_WarpInfoCreate (&lclerr);
    EERR_CHECK(lclerr, EFS0("Error ewrp_WarpInfoCreate"));

 wt->warpinfo->refproparm = wt->output_proparm;
 wt->warpinfo->refunits = wt->output_units;
 wt->warpinfo->refelevinfo = wt->output_elevinfo;


 /*
 ** HARD CODED FILE NAMES
 */
 input_filename =  "D:/work/Data/output/Tk_ortho/imagery.tif";
 dem_filename = "D:/work/Data/output/Tk_ortho/ASTGTM_S34W071_dem.tif"; 
 output_filename ="D:/work/Data/output/Tk_ortho/output.img";

/**************************************
** READ FROM INPUT IMAGE
**************************************/
 input_layernames = eimg_LayerGetNames (input_filename, erdinit, &lclerr);
    EERR_CHECK(lclerr, EFS0("Error eimg_LayerGetNames"));

 input_layerstack = eimg_LayerStackOpen (input_layernames, erdinit, &lclerr, EIMG_LAYER_OPTION_END);
    EERR_CHECK(lclerr, EFS0("Error eimg_LayerStackOpen"));

 wt->warpinfo->inputlayerwidth = input_layerstack->layers[0]->width;
 wt->warpinfo->inputlayerheight = input_layerstack->layers[0]->height;
 wt->xskip = wt->warpinfo->inputlayerwidth;  
 wt->yskip = wt->warpinfo->inputlayerheight; 


 eimg_LayerMapInformationRead (input_layerstack->layers[0], input_proname, input_units, &input_xform, &lclerr);
    EERR_CHECK(lclerr, EFS0("Error eimg_LayerMapInformationRead"));

 // WRITE DESCRIPTION TO WT->GEOMODELNAME
 (void) eimg_MapInformationDescribe(input_xform, input_proname, input_units, wt->geomodelname, &lclerr);
 exfr_XFormZInfoGet(input_xform, &wt->dtmmean, wt->dtmfilename, wt->dtmunits,  &lclerr);

 input_mapinfo = eimg_LayerMapInfoGet (input_layerstack->layers[0], &lclerr);
    EERR_CHECK(lclerr, EFS0("Error eimg_LayerMapInfoGet"));

 eimg_LayerMapProjectionRead (input_layerstack->layers[0], &input_projection, &lclerr );
 eprj_ProParametersCopy (EPRJ_PROPARAMETERS_GET(input_projection), input_proparm, &lclerr);


 // ADD TO WT
 wt->warpinfo->inputfilename = input_filename;
 wt->input_layerstack = input_layerstack;
 wt->input_proparm = input_proparm.Release();
 wt->input_mapinfo = input_mapinfo.Release();
 wt->input_units = input_units;


 wt->output_proparm = eprj_ProParametersCopy (wt->input_proparm, NULL, &lclerr);
 wt->output_mapinfo = wt->input_mapinfo.Release ();
 wt->output_units = estr_Duplicate (wt->input_units);
 wt->output_elevinfo = eprj_ElevationInfoCopy (wt->input_elevinfo,NULL, &lclerr);


/**************************************
* SETUP SPOT5 PUSHBROOM SENSOR MODEL
**************************************/
 wt->modelname = "SPOT5 - Orbital Pushbroom";
 wt->modelinfo = emod_ModelCreate (wt->warpinfo, wt->modelname, &lclerr);
 EERR_CHECK(lclerr, EFS0("Error emod_ModelCreate"));
 
 
 // ADD TO WT
 wt->output_units = wt->warpinfo->refunits;
 wt->output_proparm = wt->warpinfo->refproparm;
 wt->output_elevinfo = wt->warpinfo->refelevinfo;
 wt->output_mapinfo = updateOutputMapinfo (wt, NULL, wt->output_proparm, wt->output_units);


/**************************************
** READ FROM DEM IMAGE
**************************************/

 dem_layernames = eimg_LayerGetNames (dem_filename, erdinit, &lclerr);
    EERR_CHECK(lclerr, EFS0("Error eimg_LayerGetNames"));

 dem_layerstack = eimg_LayerStackOpen (dem_layernames, erdinit, &lclerr, EIMG_LAYER_OPTION_END);
    EERR_CHECK(lclerr, EFS0("Error eimg_LayerStackOpen"));

 eimg_LayerMapInformationRead (dem_layerstack->layers[0], dem_proname, dem_units, &dem_xform, &lclerr);
    EERR_CHECK(lclerr, EFS0("Error eimg_LayerMapInformationRead"));

 dem_mapinfo = eimg_LayerMapInfoGet (dem_layerstack->layers[0], &lclerr);
    EERR_CHECK(lclerr, EFS0("Error eimg_LayerMapInfoGet"));

 eimg_LayerMapProjectionRead (dem_layerstack->layers[0], &dem_projection, &lclerr);
    EERR_CHECK(lclerr, EFS0("Error eimg_LayerMapProjectionRead"));
 
 dem_proparm = EPRJ_PROPARAMETERS_GET(dem_projection);

 // ADD TO WT
 ewrp_ElevFilenameSet (wt->modelinfo->warpinfo, dem_filename);
 ewrp_ElevConstantSet (wt->modelinfo->warpinfo, 0.0);
 ewrp_ElevUnitsSet (wt->modelinfo->warpinfo, dem_units);


/**************************************
** SOLVE SPOT5 PUSHBROOM SENSOR MODEL
**************************************/

 /*
 ** Calculate Transform (m2f, From Map coordinate to File coordinate)
 */
 xform = emod_ModelXFormGet (wt->modelinfo, &lclerr);


/**************************************
** CALCULATE OUTPUT FOOTPRINT/BOUNDING BOX
**************************************/
 /*
 ** Calculate Transform (f2m, From File coordinate to Map coordinate)
 */
 xform_inv = exfr_XFormInvert(xform, xform_inv, &lclerr);
    EERR_CHECK(lclerr, EFS0("Error exfr_XFormInvert"));
 

 /*
 ** CALCULATE OUTPUT FOOTPRINT
 */
 mat1 = efga_MatrixCreate (2L, 4L, &lclerr);
    EERR_CHECK(lclerr, EFS0("Error efga_MatrixCreate"));

 EFGA_MATRIX(mat1, 0, 0) = 0.0;
 EFGA_MATRIX(mat1, 1, 0) = 0.0;
 EFGA_MATRIX(mat1, 0, 1) = 0.0;
 EFGA_MATRIX(mat1, 1, 1) = (double)(wt->warpinfo->inputlayerheight);
 EFGA_MATRIX(mat1, 0, 2) = (double)(wt->warpinfo->inputlayerwidth);
 EFGA_MATRIX(mat1, 1, 2) = (double)(wt->warpinfo->inputlayerheight);
 EFGA_MATRIX(mat1, 0, 3) = (double)(wt->warpinfo->inputlayerwidth);
 EFGA_MATRIX(mat1, 1, 3) = 0.0;
 
 mat2 = exfr_Transform (xform_inv, mat1, mat2, &lclerr);
    EERR_CHECK(lclerr, EFS0("Error exfr_Transform"));
 
 minx = EMSC_DBL_MAX;
 miny = EMSC_DBL_MAX;
 maxx = -EMSC_DBL_MAX;
 maxy = -EMSC_DBL_MAX;
 for (i=0; i<4; i++)
 {
  minx = EMSC_MIN (minx, EFGA_MATRIX(mat2, 0, i));
  miny = EMSC_MIN (miny, EFGA_MATRIX(mat2, 1, i));
  maxx = EMSC_MAX (maxx, EFGA_MATRIX(mat2, 0, i));
  maxy = EMSC_MAX (maxy, EFGA_MATRIX(mat2, 1, i));
 } 

 /*
 ** CALCULATE OUTPUT CELLSIZE
 */ 
 xcell = (maxx - minx) / (double)(wt->warpinfo->inputlayerwidth);
 ycell = (maxy - miny) / (double)(wt->warpinfo->inputlayerheight);

 xoffset = xcell * 0.5;
 yoffset = ycell * 0.5;
 minx += xoffset;
 maxx -= xoffset;
 miny += yoffset;
 maxy -= yoffset;

 /*
 ** CALCULATE OUTPUT # OF ROW/COLUMN
 */
 nrows = EMSC_NINT(EMSC_CHKDBL(((maxy - miny) / ycell) + 1));
 miny = maxy - (double)(nrows-1) * ycell;

 ncols = EMSC_NINT(EMSC_CHKDBL(((maxx - minx) / xcell) + 1));
 minx = maxx - (double)(ncols-1) * xcell;


/**************************************
** RESAMPLE
**************************************/
 
 /*
 ** CREATE OUTPUT MAPINFO BASED ON THE OUTPUT BOUNDING BOX & CELLSIZE
 */
 mapinfo = eprj_MapInfoCreate (&lclerr);
    EERR_CHECK(lclerr, EFS0("Error eprj_MapInfoCreate"));

 eprj_MapInfoProjectionNameSet (mapinfo, wt->warpinfo->refproparm->proName.data, &lclerr);
  EERR_CHECK(lclerr, EFS0("Error eprj_MapInfoProjectionNameSet"));
  eprj_MapInfoUnitsSet (mapinfo, wt->warpinfo->refunits , &lclerr);
  EERR_CHECK(lclerr, EFS0("Error eprj_MapInfoUnitsSet"));
 eprj_MapInfoUpperLeftCenterSet (mapinfo, minx, maxy, &lclerr);
  EERR_CHECK(lclerr, EFS0("Error eprj_MapInfoUpperLeftCenterSet"));
 eprj_MapInfoLowerRightCenterSet (mapinfo, maxx, miny, &lclerr);
  EERR_CHECK(lclerr, EFS0("Error eprj_MapInfoLowerRightCenterSet"));
 eprj_MapInfoPixelSizeSet (mapinfo, xcell, ycell, &lclerr);
  EERR_CHECK(lclerr, EFS0("Error eprj_MapInfoPixelSizeSet"));
 
 f2m = eprj_MapInfoToPolynomial (mapinfo, NULL, &lclerr);
  EERR_CHECK(lclerr, EFS0("Error eprj_MapInfoToPolynomial"));
 pre_xform = exfr_XFormCreateFromAffinePoly ( f2m, &lclerr);
  EERR_CHECK(lclerr, EFS0("Error exfr_XFormCreateFromAffinePoly"));
 efga_PolynomialDelete (f2m, &lclerr);
  EERR_CHECK(lclerr, EFS0("Error efga_PolynomialDelete"));

 post_xform = exfr_XFormCopy (xform, NULL, &lclerr);
  EERR_CHECK(lclerr, EFS0("Error exfr_XFormCopy"));
 
 /*
 ** CREATE THE TRANSFORM FROM OUTPUT FILE COORDINATE TO INPUT FILE COORDINATE.
 ** THIS TRANSFORM IS NEEDED FOR RESAMPLING
 */
 f2f_xform = exfr_XFormComposition (
  pre_xform,
  post_xform,
  &lclerr);
  EERR_CHECK(lclerr, EFS0("Error exfr_XFormComposition"));


 /*
 ** RESAMPLE
 */
 eimg_LayerStackClose(input_layerstack, &lclerr);
    EERR_CHECK(lclerr, EFS0("Error eimg_LayerStackClose"));

    input_layerstack=eimg_LayerStackOpen(input_layernames, erdinit,
   &lclerr,
   EIMG_LAYER_OPTION_TRANSFORMATION, f2f_xform, "Nearest Neighbor",
   EIMG_LAYER_OPTION_READONLY,
   EIMG_LAYER_OPTION_RETAIN_LAYERSTACK_RESAMPLEDATA, EMSC_TRUE,
   EIMG_LAYER_OPTION_END);
 EERR_CHECK(lclerr, EFS0("Error eimg_LayerStackOpen"));


 /*
 ** MAKE SURE THE OUTPUT IMG DOESN'T EXIST
 */
 if ( efio_FileExists(output_filename, &lclerr) ) 
 {
  efio_FileUnlink(output_filename, &lclerr); // DELETE IF EXIST
  EERR_CHECK(lclerr, EFS0("Error efio_FileUnlink"));
 }

 /*
 ** Write to Output
 */
 output_layernames = eimg_LayerNameStackCreate(input_layernames->count, &lclerr);
    EERR_CHECK(lclerr, EFS0( "Error eimg_LayerNameStackCreate" ));
   
    for(layer = 0; layer < input_layernames->count ; layer++)
 {
        /* CREATE OUTPUT LAYER NAMES */
  //emsc_Free(output_layername);
        output_layername = estr_Sprintf(NULL, "Layer_%d", &lclerr, layer+1);
        EERR_CHECK(lclerr, EFS0( "Error estr_Sprintf" ) );
        output_layernames->strings[layer] = efnp_FileNodeCreate(NULL,
   output_filename, NULL, output_layername, &lclerr);
        EERR_CHECK(lclerr, EFS0( "Error efnp_FileNodeCreate" ));
    }
   
    blockx = input_layerstack->layers[0]->blockWidth;
    blocky = input_layerstack->layers[0]->blockHeight;
 pixRectStack = eimg_PixelRectStackCreate(input_layernames->count,
   blockx, blocky,
   dem_layerstack->layers[0]->pixelType,
   &lclerr);
    EERR_CHECK(lclerr, EFS0("Error eimg_PixelRectStackCreate"));
   
 output_layerstack =eimg_LayerStackCreate(output_layernames,
   input_layerstack->layers[0]->layerType ,
   input_layerstack->layers[0]->pixelType,
   ncols,nrows,
   erdinit,
   &lclerr,
   EIMG_LAYER_OPTION_COMPUTE_STATS_ON_CLOSE,
   EIMG_LAYER_OPTION_END);
    EERR_CHECK(lclerr, EFS0("Error eimg_LayerStackCreate"));

 /*
 ** Write to Output image block by block
 */
    for (i = 0; i < nrows; i += blocky)
    {
        for (j = 0; j < ncols; j += blockx)
        {
            eimg_LayerStackRead(input_layerstack, j, i, blockx, blocky, pixRectStack, &lclerr);
            EERR_CHECK(lclerr, EFS0("Error reading block into pixRectStack!"));
           
            eimg_LayerStackWrite(output_layerstack, j, i,
                blockx, blocky, pixRectStack, &lclerr);
            EERR_CHECK(lclerr, EFS0("Error writing pixRectStack to the output layer stack!"));
        }
    }


    /*
    ** WRITE THE MAP INFO TO THE OUTPUT LAYER
    */     
 xform = exfr_XFormCreateFromMapInfo(mapinfo, EMSC_TRUE, &lclerr);
    EERR_CHECK(lclerr, EFS0("Error exfr_XFormCreateFromMapInfo!"));

 eimg_LayerStackMapInformationWrite(output_layerstack,
   mapinfo->proName.data,
   mapinfo->units.data,
   xform,
   &lclerr);
    EERR_CHECK(lclerr, EFS0("Error eimg_LayerStackMapInformationWrite!"));
    
    /*
    ** WRITE THE PROJECTION INFO TO THE OUTPUT LAYER IF IT EXISTS
    */    
    eimg_LayerStackMapProjectionWrite(output_layerstack, input_projection, &lclerr);
    EERR_CHECK(lclerr, EFS0("Error eimg_LayerStackMapProjectionWrite!"));    
   
    eimg_LayerStackClose(input_layerstack, &lclerr);
 EERR_CHECK(lclerr, EFS0("Error eimg_LayerStackClose"));
   
    eimg_LayerStackClose(output_layerstack, &lclerr);
 EERR_CHECK(lclerr, EFS0("Error eimg_LayerStackClose"));
   
    eimg_LayerStackClose(dem_layerstack, &lclerr);
 EERR_CHECK(lclerr, EFS0("Error eimg_LayerStackClose"));


cleanup:

 if (input_layernames)
 {
  eimg_LayerNameStackDelete(input_layernames, &lclerr);
  EERR_DELETE(lclerr);
 }
 if (dem_layernames)
 {
  eimg_LayerNameStackDelete(dem_layernames, &lclerr);
  EERR_DELETE(lclerr);
 } 
 if (output_layernames)
 {
  eimg_LayerNameStackDelete(output_layernames, &lclerr);
  EERR_DELETE(lclerr);
 }

 if (input_mapinfo)    eprj_MapInfoFree(input_mapinfo); 
 if (dem_mapinfo)    eprj_MapInfoFree(dem_mapinfo); 

    if (input_projection)    eprj_ProjectionFree(&input_projection);
    if (dem_projection)    eprj_ProjectionFree(&dem_projection);


 return;
}

 

static Eprj_MapInfo *
updateOutputMapinfo (
WT *wt,
Eprj_MapInfo *mapinfo,
Eprj_ProParameters *proparm,
char *units)
{
 Eerr_ErrorReport *errtn = NULL;
 Eprj_MapInfo *mapinfo_ret;

 if (mapinfo) mapinfo_ret = mapinfo;
 else mapinfo_ret = eprj_MapInfoCreate (&errtn);

 eprj_MapInfoProjectionNameSet (mapinfo_ret,
  "Unknown", &errtn);
 eprj_MapInfoUnitsSet (mapinfo_ret,
  "other", &errtn);

 if (proparm) {
  eprj_MapInfoProjectionNameSet (mapinfo_ret,
   proparm->proName.data, &errtn);
 }

 if (units) {
  eprj_MapInfoUnitsSet (mapinfo_ret, units, &errtn);
 }

 return mapinfo_ret;
}

Contributors