Changeset 13345

Show
Ignore:
Timestamp:
12/15/07 00:34:08 (7 months ago)
Author:
warmerdam
Message:

Add improved support for initializing BASEDATA objects. Add support for
writing rotated/sheared affine geotransforms as XForms. (#2087).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/warmerdam/1.4-esri/gdal/frmts/hfa/hfa.h

    r11783 r13345  
    145145const Eprj_MapInfo CPL_DLL *HFAGetMapInfo( HFAHandle ); 
    146146int CPL_DLL HFAGetGeoTransform( HFAHandle, double* ); 
     147CPLErr CPL_DLL HFASetGeoTransform( HFAHandle, const char*, const char*,double*); 
    147148CPLErr CPL_DLL HFASetMapInfo( HFAHandle, const Eprj_MapInfo * ); 
    148149const Eprj_Datum CPL_DLL *HFAGetDatum( HFAHandle ); 
     
    204205                   Efga_Polynomial **ppasPolyListForward, 
    205206                   Efga_Polynomial **ppasPolyListReverse ); 
     207CPLErr CPL_DLL 
     208HFAWriteXFormStack( HFAHandle psInfo, int nBand, int nXFormCount, 
     209                    Efga_Polynomial **ppasPolyListForward, 
     210                    Efga_Polynomial **ppasPolyListReverse ); 
    206211int CPL_DLL  
    207212HFAEvaluateXFormStack( int nStepCount, int bForward, 
  • sandbox/warmerdam/1.4-esri/gdal/frmts/hfa/hfadataset.cpp

    r12621 r13345  
    18211821/*      Write out definitions.                                          */ 
    18221822/* -------------------------------------------------------------------- */ 
    1823     HFASetMapInfo( hHFA, &sMapInfo ); 
     1823    if( adfGeoTransform[2] == 0.0 && adfGeoTransform[4] == 0.0 ) 
     1824    { 
     1825        HFASetMapInfo( hHFA, &sMapInfo ); 
     1826    } 
     1827    else 
     1828    { 
     1829        HFASetGeoTransform( hHFA,  
     1830                            sMapInfo.proName, sMapInfo.units, 
     1831                            adfGeoTransform ); 
     1832    } 
    18241833 
    18251834    if( bHaveSRS && sPro.proName != NULL ) 
  • sandbox/warmerdam/1.4-esri/gdal/frmts/hfa/hfadictionary.cpp

    r10646 r13345  
    6363    "Eimg_NonInitializedValue",  
    6464    "{1:*bvalueBD,}Eimg_NonInitializedValue", 
    65      
     65 
    6666    NULL, 
    6767    NULL }; 
  • sandbox/warmerdam/1.4-esri/gdal/frmts/hfa/hfafield.cpp

    r11783 r13345  
    376376        GUInt32         nOffset; 
    377377 
    378         /* set the count for fixed sized arrays */ 
     378        /* set the count for fixed sized arrays */ 
    379379        if( nBytes > -1 ) 
    380380            nCount = nItemCount; 
     
    478478    { 
    479479        CPLError( CE_Failure, CPLE_NotSupported,  
    480             "HFAField::SetInstValue() not supported yet for pointer values." ); 
     480                  "HFAField::SetInstValue() not supported yet for pointer values." ); 
    481481         
    482482        return CE_Failure; 
     
    501501                      "not currently supported.", 
    502502                      pszField ); 
    503               return CE_Failure; 
     503            return CE_Failure; 
    504504        } 
    505505 
     
    660660            { 
    661661                return( poItemObjectType-> 
    662                             SetInstValue( pszField, pabyData + nExtraOffset, 
    663                                           nDataOffset + nExtraOffset, 
    664                                           nDataSize - nExtraOffset, 
    665                                           chReqType, pValue ) ); 
     662                        SetInstValue( pszField, pabyData + nExtraOffset, 
     663                                      nDataOffset + nExtraOffset, 
     664                                      nDataSize - nExtraOffset, 
     665                                      chReqType, pValue ) ); 
    666666            } 
    667667        } 
    668668        break; 
     669 
     670      case 'b':  
     671      {  
     672          GInt32 nRows = 1;  
     673          GInt32 nColumns = 1;  
     674          GInt16 nBaseItemType; 
     675 
     676          // Extract existing rows, columns, and datatype. 
     677          memcpy( &nRows, pabyData, 4 ); 
     678          HFAStandard( 4, &nRows ); 
     679          memcpy( &nColumns, pabyData+4, 4 ); 
     680          HFAStandard( 4, &nColumns ); 
     681          memcpy( &nBaseItemType, pabyData+8, 2 ); 
     682          HFAStandard( 2, &nBaseItemType ); 
     683 
     684          // Are we using special index values to update the rows, columnrs 
     685          // or type? 
     686         
     687          if( nIndexValue == -3 ) 
     688              nBaseItemType = nIntValue; 
     689          else if( nIndexValue == -2 ) 
     690              nColumns = nIntValue; 
     691          else if( nIndexValue == -1 ) 
     692              nRows = nIntValue; 
     693 
     694          if( nIndexValue < -3 || nIndexValue >= nRows * nColumns )  
     695              return CE_Failure;  
     696 
     697          // Write back the rows, columns and basedatatype. 
     698          HFAStandard( 4, &nRows );  
     699          memcpy( pabyData, &nRows, 4 );  
     700          HFAStandard( 4, &nColumns );  
     701          memcpy( pabyData+4, &nColumns, 4 );  
     702          HFAStandard( 2, &nBaseItemType );  
     703          memcpy ( pabyData + 8, &nBaseItemType, 2 );  
     704          HFAStandard( 2, &nBaseItemType ); // swap back for our use. 
     705 
     706          // We ignore the 2 byte objecttype value.   
     707 
     708          nDataSize -= 12;  
     709 
     710          if( nIndexValue >= 0 ) 
     711          {  
     712              if( (nIndexValue+1) * (HFAGetDataTypeBits(nBaseItemType)/8) 
     713                  > nDataSize )  
     714              {  
     715                  CPLError( CE_Failure, CPLE_AppDefined,  
     716                            "Attempt to extend field %s in node past end of data,\n"  
     717                            "not currently supported.",  
     718                            pszField );  
     719                  return CE_Failure;  
     720              }  
     721 
     722              if( nBaseItemType == EPT_f64 ) 
     723              { 
     724                  double dfNumber = dfDoubleValue;  
     725 
     726                  HFAStandard( 8, &dfNumber );  
     727                  memcpy( pabyData + 12 + nIndexValue * 8, &dfNumber, 8 );  
     728              } 
     729              else 
     730              { 
     731                  CPLError( CE_Failure, CPLE_AppDefined,  
     732                            "Setting basedata field %s with type %s not currently supported.",  
     733                            pszField, HFAGetDataTypeName( nBaseItemType ) );  
     734                  return CE_Failure;  
     735              } 
     736          }  
     737      }  
     738      break;                
    669739 
    670740      default: 
     
    704774/* -------------------------------------------------------------------- */ 
    705775    if( nIndexValue < 0 || nIndexValue >= nInstItemCount ) 
    706         return FALSE; 
     776    { 
     777        if( chItemType == 'b' && nIndexValue >= -3 && nIndexValue < 0 ) 
     778            /* ok - special index values */; 
     779        else 
     780            return FALSE; 
     781    } 
    707782 
    708783/* -------------------------------------------------------------------- */ 
     
    841916          // We ignore the 2 byte objecttype value.  
    842917 
    843           if( nIndexValue < 0 || nIndexValue >= nRows * nColumns ) 
     918          if( nIndexValue < -3 || nIndexValue >= nRows * nColumns ) 
    844919              return FALSE; 
    845920 
    846921          pabyData += 12; 
    847922 
    848           CPLAssert( nRows >= 1 && nColumns >= 1 ); 
    849  
    850           if( nBaseItemType == EPT_u8 ) 
     923          if( nIndexValue == -3 )  
     924          { 
     925              dfDoubleRet = nIntRet = nBaseItemType; 
     926          } 
     927          else if( nIndexValue == -2 ) 
     928          { 
     929              dfDoubleRet = nIntRet = nColumns; 
     930          } 
     931          else if( nIndexValue == -1 ) 
     932          { 
     933              dfDoubleRet = nIntRet = nRows; 
     934          } 
     935          else if( nBaseItemType == EPT_u8 ) 
    851936          { 
    852937              dfDoubleRet = pabyData[nIndexValue]; 
     
    11171202             
    11181203/* -------------------------------------------------------------------- */ 
     1204/*      For BASEDATA objects, we want to first dump their dimension     */ 
     1205/*      and type.                                                       */ 
     1206/* -------------------------------------------------------------------- */ 
     1207    if( chItemType == 'b' ) 
     1208    { 
     1209        int nDataType, nRows, nColumns; 
     1210        ExtractInstValue( NULL, -3, pabyData, nDataOffset,  
     1211                          nDataSize, 'i', &nDataType ); 
     1212        ExtractInstValue( NULL, -2, pabyData, nDataOffset,  
     1213                          nDataSize, 'i', &nColumns ); 
     1214        ExtractInstValue( NULL, -1, pabyData, nDataOffset,  
     1215                          nDataSize, 'i', &nRows ); 
     1216        VSIFPrintf( fpOut, "%sBASEDATA(%s): %dx%d of %s\n",  
     1217                    pszPrefix, pszFieldName, 
     1218                    nColumns, nRows, HFAGetDataTypeName( nDataType ) ); 
     1219    } 
     1220         
     1221/* -------------------------------------------------------------------- */ 
    11191222/*      Dump each entry in the field array.                             */ 
    11201223/* -------------------------------------------------------------------- */ 
     
    11451248          { 
    11461249              double dfValue; 
    1147          
     1250 
    11481251              if( ExtractInstValue( NULL, iEntry,  
    11491252                                    pabyData, nDataOffset, nDataSize,  
  • sandbox/warmerdam/1.4-esri/gdal/frmts/hfa/hfaopen.cpp

    r11783 r13345  
    16521652"{1:x{0:pcstring,}Emif_String,type,1:x{0:pcstring,}Emif_String,MIFDictionary,0:pCMIFObject,}Emif_MIFObject,", 
    16531653"{1:x{1:x{0:pcstring,}Emif_String,type,1:x{0:pcstring,}Emif_String,MIFDictionary,0:pCMIFObject,}Emif_MIFObject,projection,1:x{0:pcstring,}Emif_String,title,}Eprj_MapProjection842,", 
     1654"{0:poEmif_String,titleList,}Exfr_GenericXFormHeader,{1:lorder,1:lnumdimtransform,1:lnumdimpolynomial,1:ltermcount,0:plexponentlist,1:*bpolycoefmtx,1:*bpolycoefvector,}Efga_Polynomial,", 
    16541655".", 
    16551656NULL 
     
    28972898 
    28982899 
    2899 int HFAReadXFormStack( HFAHandle hHFA,  
     2900int HFAReadXFormStack( HFAHandle hHFA, 
    29002901                       Efga_Polynomial **ppasPolyListForward, 
    29012902                       Efga_Polynomial **ppasPolyListReverse ) 
     
    30443045    return TRUE; 
    30453046} 
     3047 
     3048/************************************************************************/ 
     3049/*                         HFAWriteXFormStack()                         */ 
     3050/************************************************************************/ 
     3051 
     3052CPLErr HFAWriteXFormStack( HFAHandle hHFA, int nBand, int nXFormCount,  
     3053                           Efga_Polynomial **ppasPolyListForward, 
     3054                           Efga_Polynomial **ppasPolyListReverse ) 
     3055 
     3056{ 
     3057    CPLErr eErr; 
     3058 
     3059    if( nXFormCount == 0 ) 
     3060        return CE_None; 
     3061 
     3062    if( ppasPolyListForward[0]->order != 1 ) 
     3063    { 
     3064        CPLError( CE_Failure, CPLE_AppDefined,  
     3065                  "For now HFAWriteXFormStack() only supports order 1 polynomials" ); 
     3066        return CE_Failure; 
     3067    } 
     3068 
     3069    if( nBand < 0 || nBand > hHFA->nBands ) 
     3070        return CE_Failure; 
     3071 
     3072/* -------------------------------------------------------------------- */ 
     3073/*      If no band number is provided, operate on all bands.            */ 
     3074/* -------------------------------------------------------------------- */ 
     3075    if( nBand == 0 ) 
     3076    { 
     3077        for( nBand = 1; nBand <= hHFA->nBands; nBand++ ) 
     3078        { 
     3079            eErr = HFAWriteXFormStack( hHFA, nBand, nXFormCount,  
     3080                                       ppasPolyListForward,  
     3081                                       ppasPolyListReverse ); 
     3082            if( eErr != CE_None ) 
     3083                return eErr; 
     3084        } 
     3085        return eErr; 
     3086    } 
     3087 
     3088/* -------------------------------------------------------------------- */ 
     3089/*      Fetch our band node.                                            */ 
     3090/* -------------------------------------------------------------------- */ 
     3091    HFAEntry *poBandNode = hHFA->papoBand[nBand-1]->poNode; 
     3092    HFAEntry *poXFormHeader; 
     3093     
     3094    poXFormHeader = poBandNode->GetNamedChild( "MapToPixelXForm" ); 
     3095    if( poXFormHeader == NULL ) 
     3096    { 
     3097        poXFormHeader = new HFAEntry( hHFA, "MapToPixelXForm",  
     3098                                      "Exfr_GenericXFormHeader", poBandNode ); 
     3099        poXFormHeader->MakeData( 23 ); 
     3100        poXFormHeader->SetPosition(); 
     3101        poXFormHeader->SetStringField( "titleList.string", "Affine" ); 
     3102    } 
     3103 
     3104/* -------------------------------------------------------------------- */ 
     3105/*      Loop over XForms.                                               */ 
     3106/* -------------------------------------------------------------------- */ 
     3107    for( int iXForm = 0; iXForm < nXFormCount; iXForm++ ) 
     3108    { 
     3109        Efga_Polynomial *psForward = *ppasPolyListForward + iXForm; 
     3110        CPLString     osXFormName; 
     3111        osXFormName.Printf( "XForm%d", iXForm ); 
     3112 
     3113        HFAEntry *poXForm = poXFormHeader->GetNamedChild( osXFormName ); 
     3114         
     3115        if( poXForm == NULL ) 
     3116        { 
     3117            poXForm = new HFAEntry( hHFA, osXFormName, "Efga_Polynomial", 
     3118                                    poXFormHeader ); 
     3119            poXForm->MakeData( 136 ); 
     3120            poXForm->SetPosition(); 
     3121        } 
     3122 
     3123        poXForm->SetIntField( "order", 1 ); 
     3124        poXForm->SetIntField( "numdimtransform", 2 ); 
     3125        poXForm->SetIntField( "numdimpolynomial", 2 ); 
     3126        poXForm->SetIntField( "termcount", 3 ); 
     3127        poXForm->SetIntField( "exponentlist[0]", 0 ); 
     3128        poXForm->SetIntField( "exponentlist[1]", 0 ); 
     3129        poXForm->SetIntField( "exponentlist[2]", 1 ); 
     3130        poXForm->SetIntField( "exponentlist[3]", 0 ); 
     3131        poXForm->SetIntField( "exponentlist[4]", 0 ); 
     3132        poXForm->SetIntField( "exponentlist[5]", 1 ); 
     3133 
     3134        poXForm->SetIntField( "polycoefmtx[-3]", EPT_f64 ); 
     3135        poXForm->SetIntField( "polycoefmtx[-2]", 2 ); 
     3136        poXForm->SetIntField( "polycoefmtx[-1]", 2 ); 
     3137        poXForm->SetDoubleField( "polycoefmtx[0]",  
     3138                                 psForward->polycoefmtx[0] ); 
     3139        poXForm->SetDoubleField( "polycoefmtx[1]",  
     3140                                 psForward->polycoefmtx[1] ); 
     3141        poXForm->SetDoubleField( "polycoefmtx[2]",  
     3142                                 psForward->polycoefmtx[2] ); 
     3143        poXForm->SetDoubleField( "polycoefmtx[3]",  
     3144                                 psForward->polycoefmtx[3] ); 
     3145 
     3146        poXForm->SetIntField( "polycoefvector[-3]", EPT_f64 ); 
     3147        poXForm->SetIntField( "polycoefvector[-2]", 1 ); 
     3148        poXForm->SetIntField( "polycoefvector[-1]", 2 ); 
     3149        poXForm->SetDoubleField( "polycoefvector[0]",  
     3150                                 psForward->polycoefvector[0] ); 
     3151        poXForm->SetDoubleField( "polycoefvector[1]",  
     3152                                 psForward->polycoefvector[1] ); 
     3153    } 
     3154 
     3155    return CE_None; 
     3156} 
     3157 
     3158/************************************************************************/ 
     3159/*                         HFASetGeoTransform()                         */ 
     3160/*                                                                      */ 
     3161/*      Set a MapInformation and XForm block.  Allows for rotated       */ 
     3162/*      and shared geotransforms.                                       */ 
     3163/************************************************************************/ 
     3164 
     3165CPLErr HFASetGeoTransform( HFAHandle hHFA,  
     3166                           const char *pszProName, 
     3167                           const char *pszUnits, 
     3168                           double *padfGeoTransform ) 
     3169 
     3170{ 
     3171/* -------------------------------------------------------------------- */ 
     3172/*      Write MapInformation.                                           */ 
     3173/* -------------------------------------------------------------------- */ 
     3174    int nBand; 
     3175 
     3176    for( nBand = 1; nBand <= hHFA->nBands; nBand++ ) 
     3177    { 
     3178        HFAEntry *poBandNode = hHFA->papoBand[nBand-1]->poNode; 
     3179         
     3180        HFAEntry *poMI = poBandNode->GetNamedChild( "MapInformation" ); 
     3181        if( poMI == NULL ) 
     3182        { 
     3183            poMI = new HFAEntry( hHFA, "MapInformation",  
     3184                                 "Eimg_MapInformation", poBandNode ); 
     3185            poMI->MakeData( 18 + strlen(pszProName) + strlen(pszUnits) ); 
     3186            poMI->SetPosition(); 
     3187        } 
     3188 
     3189        poMI->SetStringField( "projection.string", pszProName ); 
     3190        poMI->SetStringField( "units.string", pszUnits ); 
     3191    } 
     3192 
     3193/* -------------------------------------------------------------------- */ 
     3194/*      Write XForm.                                                    */ 
     3195/* -------------------------------------------------------------------- */ 
     3196    Efga_Polynomial sForward, sReverse; 
     3197    double          adfAdjTransform[6], adfRevTransform[6]; 
     3198 
     3199    // Offset by half pixel. 
     3200 
     3201    memcpy( adfAdjTransform, padfGeoTransform, sizeof(double) * 6 ); 
     3202    adfAdjTransform[0] += adfAdjTransform[1] * 0.5; 
     3203    adfAdjTransform[0] += adfAdjTransform[2] * 0.5; 
     3204    adfAdjTransform[3] += adfAdjTransform[4] * 0.5; 
     3205    adfAdjTransform[3] += adfAdjTransform[5] * 0.5; 
     3206 
     3207    // Invert 
     3208    HFAInvGeoTransform( adfAdjTransform, adfRevTransform ); 
     3209 
     3210    // Assign to polynomial object. 
     3211 
     3212    sForward.order = 1; 
     3213    sForward.polycoefvector[0] = adfRevTransform[0]; 
     3214    sForward.polycoefmtx[0]    = adfRevTransform[1]; 
     3215    sForward.polycoefmtx[1]    = adfRevTransform[4]; 
     3216    sForward.polycoefvector[1] = adfRevTransform[3]; 
     3217    sForward.polycoefmtx[2]    = adfRevTransform[2]; 
     3218    sForward.polycoefmtx[3]    = adfRevTransform[5]; 
     3219 
     3220    sReverse = sForward; 
     3221    Efga_Polynomial *psForward=&sForward, *psReverse=&sReverse; 
     3222 
     3223    return HFAWriteXFormStack( hHFA, 0, 1, &psForward, &psReverse ); 
     3224}