285
285
* datatypes in debug statements, errors and other user output.
287
287
* @param eDataType type to get name of.
288
* @return string corresponding to type.
288
* @return string corresponding to existing data type
289
* or NULL pointer if invalid type given.
291
292
const char * CPL_STDCALL GDALGetDataTypeName( GDALDataType eDataType )
371
372
/************************************************************************/
373
/* GDALGetAsyncStatusTypeByName() */
374
/************************************************************************/
376
* Get AsyncStatusType by symbolic name.
378
* Returns a data type corresponding to the given symbolic name. This
379
* function is opposite to the GDALGetAsyncStatusTypeName().
381
* @param pszName string containing the symbolic name of the type.
383
* @return GDAL AsyncStatus type.
385
GDALAsyncStatusType CPL_DLL CPL_STDCALL GDALGetAsyncStatusTypeByName( const char *pszName )
387
VALIDATE_POINTER1( pszName, "GDALGetAsyncStatusTypeByName", GARIO_ERROR);
391
for( iType = 1; iType < GARIO_TypeCount; iType++ )
393
if( GDALGetAsyncStatusTypeName((GDALAsyncStatusType)iType) != NULL
394
&& EQUAL(GDALGetAsyncStatusTypeName((GDALAsyncStatusType)iType), pszName) )
396
return (GDALAsyncStatusType)iType;
404
/************************************************************************/
405
/* GDALGetAsyncStatusTypeName() */
406
/************************************************************************/
409
* Get name of AsyncStatus data type.
411
* Returns a symbolic name for the AsyncStatus data type. This is essentially the
412
* the enumerated item name with the GARIO_ prefix removed. So GARIO_COMPLETE returns
413
* "COMPLETE". The returned strings are static strings and should not be modified
414
* or freed by the application. These strings are useful for reporting
415
* datatypes in debug statements, errors and other user output.
417
* @param eAsyncStatusType type to get name of.
418
* @return string corresponding to type.
421
const char * CPL_STDCALL GDALGetAsyncStatusTypeName( GDALAsyncStatusType eAsyncStatusType )
424
switch( eAsyncStatusType )
442
/************************************************************************/
372
443
/* GDALGetPaletteInterpretationName() */
373
444
/************************************************************************/
958
1030
return pasReturn;
1033
/************************************************************************/
1034
/* GDALFindAssociatedFile() */
1035
/************************************************************************/
1038
* Find file with alternate extension.
1040
* Finds the file with the indicated extension, substituting it in place
1041
* of the extension of the base filename. Generally used to search for
1042
* associated files like world files .RPB files, etc. If necessary, the
1043
* extension will be tried in both upper and lower case. If a sibling file
1044
* list is available it will be used instead of doing VSIStatExL() calls to
1045
* probe the file system.
1047
* Note that the result is a dynamic CPLString so this method should not
1048
* be used in a situation where there could be cross heap issues. It is
1049
* generally imprudent for application built on GDAL to use this function
1050
* unless they are sure they will always use the same runtime heap as GDAL.
1052
* @param pszBaseFilename the filename relative to which to search.
1053
* @param pszExt the target extension in either upper or lower case.
1054
* @param papszSiblingFiles the list of files in the same directory as
1055
* pszBaseFilename or NULL if they are not known.
1056
* @param nFlags special options controlling search. None defined yet, just
1059
* @return an empty string if the target is not found, otherwise the target
1060
* file with similar path style as the pszBaseFilename.
1063
CPLString GDALFindAssociatedFile( const char *pszBaseFilename,
1065
char **papszSiblingFiles,
1071
CPLString osTarget = CPLResetExtension( pszBaseFilename, pszExt );
1073
if( papszSiblingFiles == NULL )
1075
VSIStatBufL sStatBuf;
1077
if( VSIStatExL( osTarget, &sStatBuf, VSI_STAT_EXISTS_FLAG ) != 0 )
1079
CPLString osAltExt = pszExt;
1081
if( islower( pszExt[0] ) )
1086
osTarget = CPLResetExtension( pszBaseFilename, osAltExt );
1088
if( VSIStatExL( osTarget, &sStatBuf, VSI_STAT_EXISTS_FLAG ) != 0 )
1094
int iSibling = CSLFindString( papszSiblingFiles,
1095
CPLGetFilename(osTarget) );
1099
osTarget.resize(osTarget.size() - strlen(papszSiblingFiles[iSibling]));
1100
osTarget += papszSiblingFiles[iSibling];
961
1106
/************************************************************************/
962
1107
/* GDALLoadOziMapFile() */
1002
1147
const char *pszProj = NULL, *pszProjParms = NULL;
1003
1148
OGRErr eErr = OGRERR_NONE;
1150
/* The Map Scale Factor has been introduced recently on the 6th line */
1151
/* and is a trick that is used to just change that line without changing */
1152
/* the rest of the MAP file but providing an imagery that is smaller or larger */
1153
/* so we have to correct the pixel/line values read in the .MAP file so they */
1154
/* match the actual imagery dimension. Well, this is a bad summary of what */
1155
/* is explained at http://tech.groups.yahoo.com/group/OziUsers-L/message/12484 */
1005
1158
for ( iLine = 5; iLine < nLines; iLine++ )
1007
if ( EQUALN(papszLines[iLine], "Map Projection", 14) )
1160
if ( EQUALN(papszLines[iLine], "MSF,", 4) )
1162
dfMSF = atof(papszLines[iLine] + 4);
1163
if (dfMSF <= 0.01) /* Suspicious values */
1165
CPLDebug("OZI", "Suspicious MSF value : %s", papszLines[iLine]);
1169
else if ( EQUALN(papszLines[iLine], "Map Projection", 14) )
1009
1171
pszProj = papszLines[iLine];
1013
if ( EQUALN(papszLines[iLine], "Projection Setup", 16) )
1173
else if ( EQUALN(papszLines[iLine], "Projection Setup", 16) )
1015
1175
pszProjParms = papszLines[iLine];
1099
1261
GDALInitGCPs( 1, asGCPs + nCoordinateCount );
1101
1263
// Set pixel/line part
1102
asGCPs[nCoordinateCount].dfGCPPixel = CPLAtofM(papszTok[2]);
1103
asGCPs[nCoordinateCount].dfGCPLine = CPLAtofM(papszTok[3]);
1264
asGCPs[nCoordinateCount].dfGCPPixel = CPLAtofM(papszTok[2]) / dfMSF;
1265
asGCPs[nCoordinateCount].dfGCPLine = CPLAtofM(papszTok[3]) / dfMSF;
1105
1267
asGCPs[nCoordinateCount].dfGCPX = dfLon;
1106
1268
asGCPs[nCoordinateCount].dfGCPY = dfLat;
1126
1288
/* possible. Otherwise we will need to use them as GCPs. */
1127
1289
/* -------------------------------------------------------------------- */
1128
1290
if( !GDALGCPsToGeoTransform( nCoordinateCount, asGCPs, padfGeoTransform,
1291
CSLTestBoolean(CPLGetConfigOption("OZI_APPROX_GEOTRANSFORM", "NO")) ) )
1131
1293
if ( pnGCPCount && ppasGCPs )
1517
return GDALReadTabFile2(pszBaseFilename, padfGeoTransform,
1518
ppszWKT, pnGCPCount, ppasGCPs,
1523
int GDALReadTabFile2( const char * pszBaseFilename,
1524
double *padfGeoTransform, char **ppszWKT,
1525
int *pnGCPCount, GDAL_GCP **ppasGCPs,
1526
char** papszSiblingFiles, char** ppszTabFileNameOut )
1357
1528
const char *pszTAB;
1360
/* -------------------------------------------------------------------- */
1361
/* Try lower case, then upper case. */
1362
/* -------------------------------------------------------------------- */
1531
if (ppszTabFileNameOut)
1532
*ppszTabFileNameOut = NULL;
1363
1534
pszTAB = CPLResetExtension( pszBaseFilename, "tab" );
1365
fpTAB = VSIFOpen( pszTAB, "rt" );
1536
if (papszSiblingFiles)
1538
int iSibling = CSLFindString(papszSiblingFiles, CPLGetFilename(pszTAB));
1541
CPLString osTabFilename = pszBaseFilename;
1542
osTabFilename.resize(strlen(pszBaseFilename) -
1543
strlen(CPLGetFilename(pszBaseFilename)));
1544
osTabFilename += papszSiblingFiles[iSibling];
1545
if ( GDALLoadTabFile(osTabFilename, padfGeoTransform, ppszWKT,
1546
pnGCPCount, ppasGCPs ) )
1548
if (ppszTabFileNameOut)
1549
*ppszTabFileNameOut = CPLStrdup(osTabFilename);
1556
/* -------------------------------------------------------------------- */
1557
/* Try lower case, then upper case. */
1558
/* -------------------------------------------------------------------- */
1560
fpTAB = VSIFOpenL( pszTAB, "rt" );
1562
if( fpTAB == NULL && VSIIsCaseSensitiveFS(pszTAB) )
1370
1564
pszTAB = CPLResetExtension( pszBaseFilename, "TAB" );
1371
fpTAB = VSIFOpen( pszTAB, "rt" );
1565
fpTAB = VSIFOpenL( pszTAB, "rt" );
1375
1568
if( fpTAB == NULL )
1571
VSIFCloseL( fpTAB );
1380
1573
/* -------------------------------------------------------------------- */
1381
1574
/* We found the file, now load and parse it. */
1382
1575
/* -------------------------------------------------------------------- */
1383
return GDALLoadTabFile( pszTAB, padfGeoTransform, ppszWKT,
1384
pnGCPCount, ppasGCPs );
1576
if (GDALLoadTabFile( pszTAB, padfGeoTransform, ppszWKT,
1577
pnGCPCount, ppasGCPs ) )
1579
if (ppszTabFileNameOut)
1580
*ppszTabFileNameOut = CPLStrdup(pszTAB);
1387
1586
/************************************************************************/
1512
1711
double *padfGeoTransform )
1714
return GDALReadWorldFile2(pszBaseFilename, pszExtension,
1715
padfGeoTransform, NULL, NULL);
1718
int GDALReadWorldFile2( const char *pszBaseFilename, const char *pszExtension,
1719
double *padfGeoTransform, char** papszSiblingFiles,
1720
char** ppszWorldFileNameOut )
1515
1722
const char *pszTFW;
1516
1723
char szExtUpper[32], szExtLower[32];
1519
1726
VALIDATE_POINTER1( pszBaseFilename, "GDALReadWorldFile", FALSE );
1520
1727
VALIDATE_POINTER1( padfGeoTransform, "GDALReadWorldFile", FALSE );
1729
if (ppszWorldFileNameOut)
1730
*ppszWorldFileNameOut = NULL;
1522
1732
/* -------------------------------------------------------------------- */
1523
1733
/* If we aren't given an extension, try both the unix and */
1524
1734
/* windows style extensions. */
1537
1747
szDerivedExtension[2] = 'w';
1538
1748
szDerivedExtension[3] = '\0';
1540
if( GDALReadWorldFile( pszBaseFilename, szDerivedExtension,
1541
padfGeoTransform ) )
1750
if( GDALReadWorldFile2( pszBaseFilename, szDerivedExtension,
1751
padfGeoTransform, papszSiblingFiles,
1752
ppszWorldFileNameOut ) )
1544
1755
// unix version - extension + 'w'
1548
1759
strcpy( szDerivedExtension, oBaseExt.c_str() );
1549
1760
strcat( szDerivedExtension, "w" );
1550
return GDALReadWorldFile( pszBaseFilename, szDerivedExtension,
1761
return GDALReadWorldFile2( pszBaseFilename, szDerivedExtension,
1762
padfGeoTransform, papszSiblingFiles,
1763
ppszWorldFileNameOut );
1554
1766
/* -------------------------------------------------------------------- */
1569
1781
szExtLower[i] = (char) tolower(szExtLower[i]);
1572
/* -------------------------------------------------------------------- */
1573
/* Try lower case, then upper case. */
1574
/* -------------------------------------------------------------------- */
1575
1784
VSIStatBufL sStatBuf;
1578
1787
pszTFW = CPLResetExtension( pszBaseFilename, szExtLower );
1580
bGotTFW = VSIStatL( pszTFW, &sStatBuf ) == 0;
1789
if (papszSiblingFiles)
1791
int iSibling = CSLFindString(papszSiblingFiles, CPLGetFilename(pszTFW));
1794
CPLString osTFWFilename = pszBaseFilename;
1795
osTFWFilename.resize(strlen(pszBaseFilename) -
1796
strlen(CPLGetFilename(pszBaseFilename)));
1797
osTFWFilename += papszSiblingFiles[iSibling];
1798
if (GDALLoadWorldFile( osTFWFilename, padfGeoTransform ))
1800
if (ppszWorldFileNameOut)
1801
*ppszWorldFileNameOut = CPLStrdup(osTFWFilename);
1808
/* -------------------------------------------------------------------- */
1809
/* Try lower case, then upper case. */
1810
/* -------------------------------------------------------------------- */
1812
bGotTFW = VSIStatExL( pszTFW, &sStatBuf, VSI_STAT_EXISTS_FLAG ) == 0;
1814
if( !bGotTFW && VSIIsCaseSensitiveFS(pszTFW) )
1585
1816
pszTFW = CPLResetExtension( pszBaseFilename, szExtUpper );
1586
bGotTFW = VSIStatL( pszTFW, &sStatBuf ) == 0;
1817
bGotTFW = VSIStatExL( pszTFW, &sStatBuf, VSI_STAT_EXISTS_FLAG ) == 0;
1593
1823
/* -------------------------------------------------------------------- */
1594
1824
/* We found the file, now load and parse it. */
1595
1825
/* -------------------------------------------------------------------- */
1596
return GDALLoadWorldFile( pszTFW, padfGeoTransform );
1826
if (GDALLoadWorldFile( pszTFW, padfGeoTransform ))
1828
if (ppszWorldFileNameOut)
1829
*ppszWorldFileNameOut = CPLStrdup(pszTFW);
1599
1835
/************************************************************************/
2072
2308
* --config key value: set system configuration option.
2073
2309
* --debug [on/off/value]: set debug level.
2074
2310
* --mempreload dir: preload directory contents into /vsimem
2311
* --pause: Pause for user input (allows time to attach debugger)
2312
* --locale [locale]: Install a locale using setlocale() (debugging)
2075
2313
* --help-general: report detailed help on general options.
2077
2315
* The argument array is replaced "in place" and should be freed with
2088
2326
* exit( -argc );
2090
2328
* @param nArgc number of values in the argument list.
2091
* @param Pointer to the argument list array (will be updated in place).
2329
* @param ppapszArgv pointer to the argument list array (will be updated in place).
2330
* @param nOptions unused for now.
2093
2332
* @return updated nArgc argument count. Return of 0 requests terminate
2094
2333
* without error, return of -1 requests exit with error code.
2187
2427
papszFiles[i], NULL );
2188
2428
osNewPath.Printf( "/vsimem/%s", papszFiles[i] );
2430
if( VSIStatL( osOldPath, &sStatBuf ) != 0
2431
|| VSI_ISDIR( sStatBuf.st_mode ) )
2433
CPLDebug( "VSI", "Skipping preload of %s.",
2434
osOldPath.c_str() );
2190
2438
CPLDebug( "VSI", "Preloading %s to %s.",
2191
2439
osOldPath.c_str(), osNewPath.c_str() );
2193
2441
if( CPLCopyFile( osNewPath, osOldPath ) != 0 )
2443
CPLError( CE_Failure, CPLE_AppDefined,
2444
"Failed to copy %s to /vsimem",
2445
osOldPath.c_str() );
2197
2450
CSLDestroy( papszFiles );
2383
2636
printf( " --optfile filename: expand an option file into the argument list.\n" );
2384
2637
printf( " --config key value: set system configuration option.\n" );
2385
2638
printf( " --debug [on/off/value]: set debug level.\n" );
2639
printf( " --pause: wait for user input, time to attach debugger\n" );
2640
printf( " --locale [locale]: install locale for debugging (ie. en_US.UTF-8)\n" );
2386
2641
printf( " --help-general: report detailed help on general options.\n" );
2387
2642
CSLDestroy( papszReturn );
2399
2654
/* -------------------------------------------------------------------- */
2656
/* -------------------------------------------------------------------- */
2657
else if( EQUAL(papszArgv[iArg],"--pause") )
2659
printf( "Hit <ENTER> to Continue.\n" );
2660
CPLReadLine( stdin );
2663
/* -------------------------------------------------------------------- */
2400
2664
/* carry through unrecognised options. */
2401
2665
/* -------------------------------------------------------------------- */
2542
2804
CPLString osAuxFilename = CPLResetExtension(pszBasename, pszAuxSuffixLC);
2543
2805
GDALDataset *poODS = NULL;
2544
2806
GByte abyHeader[32];
2547
2809
fp = VSIFOpenL( osAuxFilename, "rb" );
2812
if ( fp == NULL && VSIIsCaseSensitiveFS(osAuxFilename))
2552
2814
// Can't found file with lower case suffix. Try the upper case one.
2553
// no point in doing this on Win32 with case insensitive filenames.
2555
2815
osAuxFilename = CPLResetExtension(pszBasename, pszAuxSuffixUC);
2556
2816
fp = VSIFOpenL( osAuxFilename, "rb" );
2560
2819
if( fp != NULL )
2562
VSIFReadL( abyHeader, 1, 32, fp );
2563
if( EQUALN((char *) abyHeader,"EHFA_HEADER_TAG",15) )
2564
poODS = (GDALDataset *) GDALOpenShared( osAuxFilename, eAccess );
2821
if( VSIFReadL( abyHeader, 1, 32, fp ) == 32 &&
2822
EQUALN((char *) abyHeader,"EHFA_HEADER_TAG",15) )
2824
/* Avoid causing failure in opening of main file from SWIG bindings */
2825
/* when auxiliary file cannot be opened (#3269) */
2826
CPLTurnFailureIntoWarning(TRUE);
2827
poODS = (GDALDataset *) GDALOpenShared( osAuxFilename, eAccess );
2828
CPLTurnFailureIntoWarning(FALSE);
2565
2830
VSIFCloseL( fp );
2645
2909
osAuxFilename += pszAuxSuffixUC;
2646
2910
fp = VSIFOpenL( osAuxFilename, "rb" );
2650
2913
if( fp != NULL )
2652
VSIFReadL( abyHeader, 1, 32, fp );
2653
if( EQUALN((char *) abyHeader,"EHFA_HEADER_TAG",15) )
2915
if( VSIFReadL( abyHeader, 1, 32, fp ) == 32 &&
2916
EQUALN((char *) abyHeader,"EHFA_HEADER_TAG",15) )
2918
/* Avoid causing failure in opening of main file from SWIG bindings */
2919
/* when auxiliary file cannot be opened (#3269) */
2920
CPLTurnFailureIntoWarning(TRUE);
2654
2921
poODS = (GDALDataset *) GDALOpenShared( osAuxFilename, eAccess );
2922
CPLTurnFailureIntoWarning(FALSE);
2655
2924
VSIFCloseL( fp );