Changeset 11783
- Timestamp:
- 07/25/07 18:29:10 (1 year ago)
- Files:
-
- sandbox/warmerdam/1.4-esri/gdal/frmts/hfa/hfa.h (modified) (2 diffs)
- sandbox/warmerdam/1.4-esri/gdal/frmts/hfa/hfadataset.cpp (modified) (4 diffs)
- sandbox/warmerdam/1.4-esri/gdal/frmts/hfa/hfafield.cpp (modified) (1 diff)
- sandbox/warmerdam/1.4-esri/gdal/frmts/hfa/hfaopen.cpp (modified) (2 diffs)
- sandbox/warmerdam/1.4-esri/gdal/frmts/hfa/hfatype.cpp (modified) (2 diffs)
- sandbox/warmerdam/1.4-esri/gdal/gcore/gdalpamdataset.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/warmerdam/1.4-esri/gdal/frmts/hfa/hfa.h
r11315 r11783 120 120 Eprj_Spheroid proSpheroid; /* projection spheroid */ 121 121 } Eprj_ProParameters; 122 123 typedef struct { 124 int order; 125 double polycoefmtx[12]; 126 double polycoefvector[2]; 127 } Efga_Polynomial; 122 128 123 129 /* -------------------------------------------------------------------- */ … … 193 199 GIntBig nStackDataOffset, 194 200 int nStackCount, int nStackIndex ); 201 202 int CPL_DLL 203 HFAReadXFormStack( HFAHandle psInfo, 204 Efga_Polynomial **ppasPolyListForward, 205 Efga_Polynomial **ppasPolyListReverse ); 206 int CPL_DLL 207 HFAEvaluateXFormStack( int nStepCount, int bForward, 208 Efga_Polynomial *pasPolyList, 209 double *pdfX, double *pdfY ); 195 210 196 211 /* -------------------------------------------------------------------- */ sandbox/warmerdam/1.4-esri/gdal/frmts/hfa/hfadataset.cpp
r11758 r11783 279 279 CPLErr WriteProjection(); 280 280 281 void UseXFormStack( int nStepCount, 282 Efga_Polynomial *pasPolyListForward, 283 Efga_Polynomial *pasPolyListReverse ); 284 281 285 protected: 282 286 virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int, … … 1258 1262 bGeoDirty = FALSE; 1259 1263 pszProjection = CPLStrdup(""); 1260 this->bMetadataDirty = FALSE;1264 bMetadataDirty = FALSE; 1261 1265 bIgnoreUTM = FALSE; 1262 1266 } … … 2458 2462 2459 2463 /* -------------------------------------------------------------------- */ 2460 /* Get geotransform. */ 2461 /* -------------------------------------------------------------------- */ 2462 HFAGetGeoTransform( hHFA, poDS->adfGeoTransform ); 2464 /* Get geotransform, or if that fails, try to find XForms to */ 2465 /* build gcps, and metadata. */ 2466 /* -------------------------------------------------------------------- */ 2467 if( !HFAGetGeoTransform( hHFA, poDS->adfGeoTransform ) ) 2468 { 2469 Efga_Polynomial *pasPolyListForward = NULL; 2470 Efga_Polynomial *pasPolyListReverse = NULL; 2471 int nStepCount = 2472 HFAReadXFormStack( hHFA, &pasPolyListForward, 2473 &pasPolyListReverse ); 2474 2475 if( nStepCount > 0 ) 2476 { 2477 poDS->UseXFormStack( nStepCount, 2478 pasPolyListForward, 2479 pasPolyListReverse ); 2480 CPLFree( pasPolyListForward ); 2481 CPLFree( pasPolyListReverse ); 2482 } 2483 } 2463 2484 2464 2485 /* -------------------------------------------------------------------- */ … … 2649 2670 nBandCount, panBandMap, 2650 2671 nPixelSpace, nLineSpace, nBandSpace ); 2672 } 2673 2674 /************************************************************************/ 2675 /* UseXFormStack() */ 2676 /************************************************************************/ 2677 2678 void HFADataset::UseXFormStack( int nStepCount, 2679 Efga_Polynomial *pasPLForward, 2680 Efga_Polynomial *pasPLReverse ) 2681 2682 { 2683 /* -------------------------------------------------------------------- */ 2684 /* Store the transform as metadata. */ 2685 /* -------------------------------------------------------------------- */ 2686 int iStep, i; 2687 2688 GDALMajorObject::SetMetadataItem( 2689 "XFORM_STEPS", 2690 CPLString().Printf("%d",nStepCount), 2691 "XFORMS" ); 2692 2693 for( iStep = 0; iStep < nStepCount; iStep++ ) 2694 { 2695 GDALMajorObject::SetMetadataItem( 2696 CPLString().Printf("XFORM%d_ORDER", iStep), 2697 CPLString().Printf("%d",pasPLForward[iStep].order), 2698 "XFORMS" ); 2699 2700 if( pasPLForward[iStep].order == 1 ) 2701 { 2702 for( i = 0; i < 4; i++ ) 2703 GDALMajorObject::SetMetadataItem( 2704 CPLString().Printf("XFORM%d_POLYCOEFMTX[%d]", iStep, i), 2705 CPLString().Printf("%.15g", 2706 pasPLForward[iStep].polycoefmtx[i]), 2707 "XFORMS" ); 2708 2709 for( i = 0; i < 2; i++ ) 2710 GDALMajorObject::SetMetadataItem( 2711 CPLString().Printf("XFORM%d_POLYCOEFVECTOR[%d]", iStep, i), 2712 CPLString().Printf("%.15g", 2713 pasPLForward[iStep].polycoefvector[i]), 2714 "XFORMS" ); 2715 2716 continue; 2717 } 2718 2719 CPLAssert( pasPLForward[iStep].order == 2 ); 2720 2721 for( i = 0; i < 10; i++ ) 2722 GDALMajorObject::SetMetadataItem( 2723 CPLString().Printf("XFORM%d_FWD_POLYCOEFMTX[%d]", iStep, i), 2724 CPLString().Printf("%.15g", 2725 pasPLForward[iStep].polycoefmtx[i]), 2726 "XFORMS" ); 2727 2728 for( i = 0; i < 2; i++ ) 2729 GDALMajorObject::SetMetadataItem( 2730 CPLString().Printf("XFORM%d_FWD_POLYCOEFVECTOR[%d]", iStep, i), 2731 CPLString().Printf("%.15g", 2732 pasPLForward[iStep].polycoefvector[i]), 2733 "XFORMS" ); 2734 2735 for( i = 0; i < 10; i++ ) 2736 GDALMajorObject::SetMetadataItem( 2737 CPLString().Printf("XFORM%d_REV_POLYCOEFMTX[%d]", iStep, i), 2738 CPLString().Printf("%.15g", 2739 pasPLReverse[iStep].polycoefmtx[i]), 2740 "XFORMS" ); 2741 2742 for( i = 0; i < 2; i++ ) 2743 GDALMajorObject::SetMetadataItem( 2744 CPLString().Printf("XFORM%d_REV_POLYCOEFVECTOR[%d]", iStep, i), 2745 CPLString().Printf("%.15g", 2746 pasPLReverse[iStep].polycoefvector[i]), 2747 "XFORMS" ); 2748 } 2651 2749 } 2652 2750 sandbox/warmerdam/1.4-esri/gdal/frmts/hfa/hfafield.cpp
r11719 r11783 1144 1144 case 'b': 1145 1145 { 1146 GInt32 nRows, nColumns; 1147 1148 GInt16 nBaseItemType; 1149 1150 memcpy( &nRows, pabyData+8, 4 ); 1151 HFAStandard( 4, &nRows ); 1152 memcpy( &nColumns, pabyData+12, 4 ); 1153 HFAStandard( 4, &nColumns ); 1154 memcpy( &nBaseItemType, pabyData+16, 2 ); 1155 HFAStandard( 2, &nBaseItemType ); 1156 1157 VSIFPrintf( fpOut, "%dx%d basedata of type %s\n", 1158 nRows, nColumns, HFAGetDataTypeName(nBaseItemType) ); 1146 double dfValue; 1147 1148 if( ExtractInstValue( NULL, iEntry, 1149 pabyData, nDataOffset, nDataSize, 1150 'd', &dfValue ) ) 1151 VSIFPrintf( fpOut, "%.15g\n", 1152 pszPrefix, dfValue ); 1153 else 1154 VSIFPrintf( fpOut, "(access failed)\n", 1155 pszPrefix ); 1159 1156 } 1160 1157 break; sandbox/warmerdam/1.4-esri/gdal/frmts/hfa/hfaopen.cpp
r11544 r11783 969 969 return FALSE; 970 970 971 // Verify that there aren't any further xform steps. 972 if( hHFA->papoBand[0]->poNode->GetNamedChild( "MapToPixelXForm.XForm1" ) 973 != NULL ) 974 return FALSE; 975 971 976 // we should check that the exponent list is 0 0 1 0 0 1 but 972 977 // we don't because we are lazy … … 2824 2829 } 2825 2830 2831 /************************************************************************/ 2832 /* HFAReadAndValidatePoly() */ 2833 /************************************************************************/ 2834 2835 static int HFAReadAndValidatePoly( HFAEntry *poTarget, 2836 const char *pszName, 2837 Efga_Polynomial *psRetPoly ) 2838 2839 { 2840 CPLString osFldName; 2841 2842 memset( psRetPoly, 0, sizeof(Efga_Polynomial) ); 2843 2844 osFldName.Printf( "%sorder", pszName ); 2845 psRetPoly->order = poTarget->GetIntField(osFldName); 2846 2847 if( psRetPoly->order < 1 || psRetPoly->order > 2 ) 2848 return FALSE; 2849 2850 /* -------------------------------------------------------------------- */ 2851 /* Validate that things are in a "well known" form. */ 2852 /* -------------------------------------------------------------------- */ 2853 int numdimtransform, numdimpolynomial, termcount; 2854 2855 osFldName.Printf( "%snumdimtransform", pszName ); 2856 numdimtransform = poTarget->GetIntField(osFldName); 2857 2858 osFldName.Printf( "%snumdimpolynomial", pszName ); 2859 numdimpolynomial = poTarget->GetIntField(osFldName); 2860 2861 osFldName.Printf( "%stermcount", pszName ); 2862 termcount = poTarget->GetIntField(osFldName); 2863 2864 if( numdimtransform != 2 || numdimpolynomial != 2 ) 2865 return FALSE; 2866 2867 if( (psRetPoly->order == 1 && termcount != 3) 2868 || (psRetPoly->order == 2 && termcount != 6) ) 2869 return FALSE; 2870 2871 // we don't check the exponent organization for now. Hopefully 2872 // it is always standard. 2873 2874 /* -------------------------------------------------------------------- */ 2875 /* Get coefficients. */ 2876 /* -------------------------------------------------------------------- */ 2877 int i; 2878 2879 for( i = 0; i < termcount*2 - 2; i++ ) 2880 { 2881 osFldName.Printf( "%spolycoefmtx[%d]", pszName, i ); 2882 psRetPoly->polycoefmtx[i] = poTarget->GetDoubleField(osFldName); 2883 } 2884 2885 for( i = 0; i < 2; i++ ) 2886 { 2887 osFldName.Printf( "%spolycoefvector[%d]", pszName, i ); 2888 psRetPoly->polycoefvector[i] = poTarget->GetDoubleField(osFldName); 2889 } 2890 2891 return TRUE; 2892 } 2893 2894 /************************************************************************/ 2895 /* HFAReadXFormStack() */ 2896 /************************************************************************/ 2897 2898 2899 int HFAReadXFormStack( HFAHandle hHFA, 2900 Efga_Polynomial **ppasPolyListForward, 2901 Efga_Polynomial **ppasPolyListReverse ) 2902 2903 { 2904 if( hHFA->nBands == 0 ) 2905 return 0; 2906 2907 /* -------------------------------------------------------------------- */ 2908 /* Get the HFA node. */ 2909 /* -------------------------------------------------------------------- */ 2910 HFAEntry *poXFormHeader; 2911 2912 poXFormHeader = hHFA->papoBand[0]->poNode->GetNamedChild( "MapToPixelXForm" ); 2913 if( poXFormHeader == NULL ) 2914 return 0; 2915 2916 /* -------------------------------------------------------------------- */ 2917 /* Loop over children, collecting XForms. */ 2918 /* -------------------------------------------------------------------- */ 2919 HFAEntry *poXForm; 2920 int nStepCount = 0; 2921 *ppasPolyListForward = NULL; 2922 *ppasPolyListReverse = NULL; 2923 2924 for( poXForm = poXFormHeader->GetChild(); 2925 poXForm != NULL; 2926 poXForm = poXForm->GetNext() ) 2927 { 2928 int bSuccess = FALSE; 2929 Efga_Polynomial sForward, sReverse; 2930 2931 if( EQUAL(poXForm->GetType(),"Efga_Polynomial") ) 2932 { 2933 bSuccess = 2934 HFAReadAndValidatePoly( poXForm, "", &sForward ); 2935 2936 if( bSuccess ) 2937 { 2938 double adfGT[6], adfInvGT[6]; 2939 2940 adfGT[0] = sForward.polycoefvector[0]; 2941 adfGT[1] = sForward.polycoefmtx[0]; 2942 adfGT[2] = sForward.polycoefmtx[2]; 2943 adfGT[3] = sForward.polycoefvector[1]; 2944 adfGT[4] = sForward.polycoefmtx[1]; 2945 adfGT[5] = sForward.polycoefmtx[3]; 2946 2947 bSuccess = HFAInvGeoTransform( adfGT, adfInvGT ); 2948 2949 memset( &sReverse, 0, sizeof(sReverse) ); 2950 2951 sReverse.order = sForward.order; 2952 sReverse.polycoefvector[0] = adfInvGT[0]; 2953 sReverse.polycoefmtx[0] = adfInvGT[1]; 2954 sReverse.polycoefmtx[2] = adfInvGT[2]; 2955 sReverse.polycoefvector[1] = adfInvGT[3]; 2956 sReverse.polycoefmtx[1] = adfInvGT[4]; 2957 sReverse.polycoefmtx[3] = adfInvGT[5]; 2958 } 2959 } 2960 else if( EQUAL(poXForm->GetType(),"GM_PolyPair") ) 2961 { 2962 bSuccess = 2963 HFAReadAndValidatePoly( poXForm, "forward.", &sForward ); 2964 bSuccess = bSuccess && 2965 HFAReadAndValidatePoly( poXForm, "reverse.", &sReverse ); 2966 } 2967 2968 if( bSuccess ) 2969 { 2970 nStepCount++; 2971 *ppasPolyListForward = (Efga_Polynomial *) 2972 CPLRealloc( *ppasPolyListForward, 2973 sizeof(Efga_Polynomial) * nStepCount); 2974 memcpy( *ppasPolyListForward + nStepCount - 1, 2975 &sForward, sizeof(sForward) ); 2976 2977 *ppasPolyListReverse = (Efga_Polynomial *) 2978 CPLRealloc( *ppasPolyListReverse, 2979 sizeof(Efga_Polynomial) * nStepCount); 2980 memcpy( *ppasPolyListReverse + nStepCount - 1, 2981 &sReverse, sizeof(sReverse) ); 2982 } 2983 } 2984 2985 return nStepCount; 2986 } 2987 2988 /************************************************************************/ 2989 /* HFAEvaluateXFormStack() */ 2990 /************************************************************************/ 2991 2992 int HFAEvaluateXFormStack( int nStepCount, int bForward, 2993 Efga_Polynomial *pasPolyList, 2994 double *pdfX, double *pdfY ) 2995 2996 { 2997 int iStep; 2998 2999 for( iStep = 0; iStep < nStepCount; iStep++ ) 3000 { 3001 double dfXOut, dfYOut; 3002 Efga_Polynomial *psStep; 3003 3004 if( bForward ) 3005 psStep = pasPolyList + iStep; 3006 else 3007 psStep = pasPolyList + nStepCount - iStep - 1; 3008 3009 if( psStep->order == 1 ) 3010 { 3011 dfXOut = psStep->polycoefvector[0] 3012 + psStep->polycoefmtx[0] * *pdfX 3013 + psStep->polycoefmtx[2] * *pdfY; 3014 3015 dfYOut = psStep->polycoefvector[1] 3016 + psStep->polycoefmtx[1] * *pdfX 3017 + psStep->polycoefmtx[3] * *pdfY; 3018 3019 *pdfX = dfXOut; 3020 *pdfY = dfYOut; 3021 } 3022 else if( psStep->order == 2 ) 3023 { 3024 dfXOut = psStep->polycoefvector[0] 3025 + psStep->polycoefmtx[0] * *pdfX 3026 + psStep->polycoefmtx[2] * *pdfY 3027 + psStep->polycoefmtx[4] * *pdfX * *pdfX 3028 + psStep->polycoefmtx[6] * *pdfX * *pdfY 3029 + psStep->polycoefmtx[8] * *pdfY * *pdfY; 3030 dfYOut = psStep->polycoefvector[1] 3031 + psStep->polycoefmtx[1] * *pdfX 3032 + psStep->polycoefmtx[3] * *pdfY 3033 + psStep->polycoefmtx[5] * *pdfX * *pdfX 3034 + psStep->polycoefmtx[7] * *pdfX * *pdfY 3035 + psStep->polycoefmtx[9] * *pdfY * *pdfY; 3036 3037 *pdfX = dfXOut; 3038 *pdfY = dfYOut; 3039 } 3040 else 3041 return FALSE; 3042 } 3043 3044 return TRUE; 3045 } sandbox/warmerdam/1.4-esri/gdal/frmts/hfa/hfatype.cpp
r11719 r11783 358 358 /* establish where the remaining fields (if any) would start. */ 359 359 /* -------------------------------------------------------------------- */ 360 if( strchr(pszFieldPath,'[') != NULL ) 361 { 362 const char *pszEnd = strchr(pszFieldPath,'['); 360 const char *pszFirstArray = strchr(pszFieldPath,'['); 361 const char *pszFirstDot = strchr(pszFieldPath,'.'); 362 363 if( pszFirstArray != NULL 364 && (pszFirstDot == NULL 365 || pszFirstDot > pszFirstArray) ) 366 { 367 const char *pszEnd = pszFirstArray; 363 368 364 369 nArrayIndex = atoi(pszEnd+1); … … 370 375 } 371 376 372 else if( strchr(pszFieldPath,'.')!= NULL )373 { 374 const char *pszEnd = strchr(pszFieldPath,'.');377 else if( pszFirstDot != NULL ) 378 { 379 const char *pszEnd = pszFirstDot; 375 380 376 381 nNameLen = pszEnd - pszFieldPath; sandbox/warmerdam/1.4-esri/gdal/gcore/gdalpamdataset.cpp
r10646 r11783 876 876 } 877 877 878 papszMD = poAuxDS->GetMetadata("XFORMS"); 879 if( CSLCount(papszMD) > 0 ) 880 { 881 char **papszMerged = 882 CSLMerge( CSLDuplicate(GetMetadata("XFORMS")), papszMD ); 883 GDALPamDataset::SetMetadata( papszMerged, "XFORMS" ); 884 CSLDestroy( papszMerged ); 885 } 886 878 887 /* ==================================================================== */ 879 888 /* Process bands. */
