int OGRXPlaneReader::StartParsing( const char * pszFilename ) { fp = VSIFOpen( pszFilename, "rt" ); if (fp == NULL) return FALSE; const char* pszLine = CPLReadLine(fp); if (!pszLine || (strcmp(pszLine, "I") != 0 && strcmp(pszLine, "A") != 0)) { VSIFClose(fp); fp = NULL; return FALSE; } pszLine = CPLReadLine(fp); if (!pszLine || IsRecognizedVersion(pszLine) == FALSE) { VSIFClose(fp); fp = NULL; return FALSE; } CPLFree(this->pszFilename); this->pszFilename = CPLStrdup(pszFilename); nLineNumber = 2; CPLDebug("XPlane", "Version/Copyright : %s", pszLine); Rewind(); return TRUE; }
void OGRXPlaneReader::Rewind() { if (fp != NULL) { VSIRewind(fp); CPLReadLine(fp); CPLReadLine(fp); nLineNumber = 2; CSLDestroy(papszTokens); papszTokens = NULL; bEOF = FALSE; } }
const char *MIDDATAFile::GetLine() { const char *pszLine; if (m_eAccessMode == TABRead) { pszLine = CPLReadLine(m_fp); SetEof(VSIFEof(m_fp)); if (pszLine == NULL) { m_szLastRead[0] = '\0'; } else { // skip leading spaces while(pszLine && (*pszLine == ' ' || *pszLine == '\t') ) pszLine++; strncpy(m_szLastRead,pszLine,MIDMAXCHAR); } //if (pszLine) // printf("%s\n",pszLine); return pszLine; } else { CPLAssert(FALSE); } return NULL; }
const char *MIDDATAFile::GetLine() { const char *pszLine; if (m_eAccessMode == TABRead) { pszLine = CPLReadLine(m_fp); if (pszLine == NULL) { m_szLastRead[0] = '\0'; } else { strncpy(m_szLastRead,pszLine,MIDMAXCHAR); } //if (pszLine) // printf("%s\n",pszLine); return pszLine; } else CPLAssert(FALSE); return NULL; }
void CSVDeaccess( const char * pszFilename ) { CSVTable *psLast, *psTable; /* -------------------------------------------------------------------- */ /* A NULL means deaccess all tables. */ /* -------------------------------------------------------------------- */ if( pszFilename == NULL ) { while( psCSVTableList != NULL ) CSVDeaccess( psCSVTableList->pszFilename ); return; } /* -------------------------------------------------------------------- */ /* Find this table. */ /* -------------------------------------------------------------------- */ psLast = NULL; for( psTable = psCSVTableList; psTable != NULL && !EQUAL(psTable->pszFilename,pszFilename); psTable = psTable->psNext ) { psLast = psTable; } if( psTable == NULL ) { CPLDebug( "CPL_CSV", "CPLDeaccess( %s ) - no match.", pszFilename ); return; } /* -------------------------------------------------------------------- */ /* Remove the link from the list. */ /* -------------------------------------------------------------------- */ if( psLast != NULL ) psLast->psNext = psTable->psNext; else psCSVTableList = psTable->psNext; /* -------------------------------------------------------------------- */ /* Free the table. */ /* -------------------------------------------------------------------- */ if( psTable->fp != NULL ) VSIFClose( psTable->fp ); CSLDestroy( psTable->papszFieldNames ); CSLDestroy( psTable->papszRecFields ); CPLFree( psTable->pszFilename ); CPLFree( psTable->panLineIndex ); CPLFree( psTable->pszRawData ); CPLFree( psTable->papszLines ); CPLFree( psTable ); CPLReadLine( NULL ); }
int OGRCSVDataSource::OpenTable( const char * pszFilename ) { /* -------------------------------------------------------------------- */ /* Open the file. */ /* -------------------------------------------------------------------- */ FILE * fp; if( bUpdate ) fp = VSIFOpen( pszFilename, "rb+" ); else fp = VSIFOpen( pszFilename, "rb" ); if( fp == NULL ) { CPLError( CE_Warning, CPLE_OpenFailed, "Failed to open %s, %s.", pszFilename, VSIStrerror( errno ) ); return FALSE; } /* -------------------------------------------------------------------- */ /* Read and parse a line. Did we get multiple fields? */ /* -------------------------------------------------------------------- */ const char* pszLine = CPLReadLine( fp ); if (pszLine == NULL) { VSIFClose( fp ); return FALSE; } char chDelimiter = CSVDetectSeperator(pszLine); VSIRewind( fp ); char **papszFields = CSVReadParseLine2( fp, chDelimiter ); if( CSLCount(papszFields) < 2 ) { VSIFClose( fp ); CSLDestroy( papszFields ); return FALSE; } VSIRewind( fp ); CSLDestroy( papszFields ); /* -------------------------------------------------------------------- */ /* Create a layer. */ /* -------------------------------------------------------------------- */ nLayers++; papoLayers = (OGRCSVLayer **) CPLRealloc(papoLayers, sizeof(void*) * nLayers); papoLayers[nLayers-1] = new OGRCSVLayer( CPLGetBasename(pszFilename), fp, pszFilename, FALSE, bUpdate, chDelimiter ); return TRUE; }
OGRErr OGRSpatialReference::importFromDict( const char *pszDictFile, const char *pszCode ) { const char *pszFilename; FILE *fp; OGRErr eErr = OGRERR_UNSUPPORTED_SRS; /* -------------------------------------------------------------------- */ /* Find and open file. */ /* -------------------------------------------------------------------- */ pszFilename = CPLFindFile( "gdal", pszDictFile ); if( pszFilename == NULL ) return OGRERR_UNSUPPORTED_SRS; fp = VSIFOpen( pszFilename, "rb" ); if( fp == NULL ) return OGRERR_UNSUPPORTED_SRS; /* -------------------------------------------------------------------- */ /* Process lines. */ /* -------------------------------------------------------------------- */ const char *pszLine; while( (pszLine = CPLReadLine(fp)) != NULL ) { if( pszLine[0] == '#' ) /* do nothing */; else if( EQUALN(pszLine,"include ",8) ) { eErr = importFromDict( pszLine + 8, pszCode ); if( eErr != OGRERR_UNSUPPORTED_SRS ) break; } else if( strstr(pszLine,",") == NULL ) /* do nothing */; else if( EQUALN(pszLine,pszCode,strlen(pszCode)) && pszLine[strlen(pszCode)] == ',' ) { char *pszWKT = (char *) pszLine + strlen(pszCode)+1; eErr = importFromWkt( &pszWKT ); break; } } /* -------------------------------------------------------------------- */ /* Cleanup */ /* -------------------------------------------------------------------- */ VSIFClose( fp ); return eErr; }
int RECReadRecord( FILE *fp, char *pszRecord, int nRecordLength ) { int nDataLen = 0; while( nDataLen < nRecordLength ) { const char *pszLine = CPLReadLine( fp ); int iSegLen; nNextRecLine++; if( pszLine == NULL ) return FALSE; if( *pszLine == 0 || *pszLine == 26 /* Cntl-Z - DOS EOF */ ) return FALSE; // If the end-of-line markers is '?' the record is deleted. iSegLen = strlen(pszLine); if( pszLine[iSegLen-1] == '?' ) { pszRecord[0] = '\0'; nDataLen = 0; continue; } // Strip off end-of-line '!' marker. if( pszLine[iSegLen-1] != '!' && pszLine[iSegLen-1] != '^' ) { CPLError( CE_Failure, CPLE_AppDefined, "Apparent corrupt data line at line=%d", nNextRecLine ); return FALSE; } iSegLen--; if( nDataLen + iSegLen > nRecordLength ) { CPLError( CE_Failure, CPLE_AppDefined, "Too much data for line at line %d.", nNextRecLine-1 ); return FALSE; } strncpy( pszRecord+nDataLen, pszLine, iSegLen ); pszRecord[nDataLen+iSegLen] = '\0'; nDataLen += iSegLen; } return nDataLen; }
int RECGetFieldCount( FILE * fp ) { const char *pszLine = CPLReadLine( fp ); if( pszLine == NULL ) return -1; if( atoi(pszLine) < 1 ) return -1; nNextRecLine = 1; return atoi(pszLine); }
int RECGetFieldDefinition( FILE *fp, char *pszFieldname, int *pnType, int *pnWidth, int *pnPrecision ) { const char *pszLine = CPLReadLine( fp ); int nTypeCode; OGRFieldType eFType = OFTString; if( pszLine == NULL ) return FALSE; if( strlen(pszLine) < 44 ) return FALSE; // Extract field width. *pnWidth = atoi( RECGetField( pszLine, 37, 4 ) ); // Is this an real, integer or string field? Default to string. nTypeCode = atoi(RECGetField(pszLine,33,4)); if( nTypeCode == 0 ) eFType = OFTInteger; else if( nTypeCode > 100 && nTypeCode < 120 ) { eFType = OFTReal; } else if( nTypeCode == 6 ) { if( *pnWidth < 3 ) eFType = OFTInteger; else eFType = OFTReal; } else eFType = OFTString; *pnType = (int) eFType; strcpy( pszFieldname, RECGetField( pszLine, 2, 10 ) ); *pnPrecision = 0; if( nTypeCode > 100 && nTypeCode < 120 ) *pnPrecision = nTypeCode - 100; else if( eFType == OFTReal ) { *pnPrecision = *pnWidth - 1; } nNextRecLine++; return TRUE; }
const char *S57ClassRegistrar::ReadLine( FILE * fp ) { if( fp != NULL ) return CPLReadLine( fp ); if( papszNextLine == NULL ) return NULL; if( *papszNextLine == NULL ) { papszNextLine = NULL; return NULL; } else return *(papszNextLine++); }
int MIDDATAFile::Close() { if (m_fp == NULL) return 0; // Close file VSIFClose(m_fp); m_fp = NULL; // clear readline buffer. CPLReadLine( NULL ); CPLFree(m_pszFname); m_pszFname = NULL; return 0; }
void GXFClose( GXFHandle hGXF ) { GXFInfo_t *psGXF = (GXFInfo_t *) hGXF; CPLFree( psGXF->panRawLineOffset ); CPLFree( psGXF->pszUnitName ); CSLDestroy( psGXF->papszMapDatumTransform ); CSLDestroy( psGXF->papszMapProjection ); CPLFree( psGXF->pszTitle ); CPLFree( psGXF->pszTransformName ); VSIFClose( psGXF->fp ); CPLReadLine( NULL ); CPLFree( psGXF ); }
/********************************************************************** * ConvertCover() * * Create a binary coverage from an E00 file. * * It would be possible to have an option for the precision... coming soon! **********************************************************************/ static void ConvertCovere00toavc(FILE *fpIn, const char *pszCoverName) { AVCE00WritePtr hWriteInfo; const char *pszLine; hWriteInfo = AVCE00WriteOpen(pszCoverName, AVC_DEFAULT_PREC); if (hWriteInfo) { while (CPLGetLastErrorNo() == 0 && (pszLine = CPLReadLine(fpIn) ) != NULL ) { AVCE00WriteNextLine(hWriteInfo, pszLine); } AVCE00WriteClose(hWriteInfo); } }
int OGRRECDataSource::Open( const char * pszFilename ) { pszName = CPLStrdup( pszFilename ); /* -------------------------------------------------------------------- */ /* Verify that the extension is REC. */ /* -------------------------------------------------------------------- */ if( !(strlen(pszFilename) > 4 && EQUAL(pszFilename+strlen(pszFilename)-4,".rec") ) ) return FALSE; /* -------------------------------------------------------------------- */ /* Open the file. */ /* -------------------------------------------------------------------- */ const char * pszLine; FILE * fp; fp = VSIFOpen( pszFilename, "rb" ); if( fp == NULL ) return FALSE; /* -------------------------------------------------------------------- */ /* Read a line, and verify that it consists of at least one */ /* field that is a number greater than zero. */ /* -------------------------------------------------------------------- */ int nFieldCount; pszLine = CPLReadLine( fp ); nFieldCount = atoi(pszLine); if( nFieldCount < 1 || nFieldCount > 1000 ) { VSIFClose( fp ); return FALSE; } /* -------------------------------------------------------------------- */ /* Create a layer. */ /* -------------------------------------------------------------------- */ poLayer = new OGRRECLayer( CPLGetBasename(pszFilename), fp, nFieldCount ); return poLayer->IsValid(); }
void OGRXPlaneFixReader::Read() { const char* pszLine; while((pszLine = CPLReadLine(fp)) != NULL) { papszTokens = CSLTokenizeString(pszLine); nTokens = CSLCount(papszTokens); nLineNumber ++; if (nTokens == 1 && strcmp(papszTokens[0], "99") == 0) { CSLDestroy(papszTokens); papszTokens = NULL; bEOF = TRUE; return; } else if (nTokens == 0 || assertMinCol(3) == FALSE) { CSLDestroy(papszTokens); papszTokens = NULL; continue; } ParseRecord(); CSLDestroy(papszTokens); papszTokens = NULL; if (poInterestLayer && poInterestLayer->IsEmpty() == FALSE) return; } papszTokens = NULL; bEOF = TRUE; }
OGRFeature * OGRRECLayer::GetNextUnfilteredFeature() { /* -------------------------------------------------------------------- */ /* Read and assemble the source data record. */ /* -------------------------------------------------------------------- */ int nDataLen = 0; char *pszRecord = (char *) CPLMalloc(nRecordLength + 2 ); while( nDataLen < nRecordLength ) { const char *pszLine = CPLReadLine( fpREC ); int iSegLen; if( pszLine == NULL ) { CPLFree( pszRecord ); return NULL; } if( *pszLine == 0 || *pszLine == 26 /* Cntl-Z - DOS EOF */ ) { CPLFree( pszRecord ); return NULL; } // If the end-of-line markers is '?' the record is deleted. iSegLen = strlen(pszLine); if( pszLine[iSegLen-1] == '?' ) { pszRecord[0] = '\0'; nDataLen = 0; continue; } // Strip off end-of-line '!' marker. if( pszLine[iSegLen-1] != '!' && pszLine[iSegLen-1] != '^' ) { CPLError( CE_Failure, CPLE_AppDefined, "Apparent corrupt data line .. record FID=%d", nNextFID ); CPLFree( pszRecord ); return NULL; } iSegLen--; if( nDataLen + iSegLen > nRecordLength ) { CPLError( CE_Failure, CPLE_AppDefined, "Too much data for record %d.", nNextFID ); CPLFree( pszRecord ); return NULL; } strncpy( pszRecord+nDataLen, pszLine, iSegLen ); pszRecord[nDataLen+iSegLen] = '\0'; nDataLen += iSegLen; } /* -------------------------------------------------------------------- */ /* Create the OGR feature. */ /* -------------------------------------------------------------------- */ OGRFeature *poFeature; poFeature = new OGRFeature( poFeatureDefn ); /* -------------------------------------------------------------------- */ /* Set attributes for any indicated attribute records. */ /* -------------------------------------------------------------------- */ int iAttr; for( iAttr = 0; iAttr < nFieldCount; iAttr++) { const char *pszFieldText = RECGetField( pszRecord, panFieldOffset[iAttr] + 1, panFieldWidth[iAttr] ); if( strlen(pszFieldText) != 0 ) poFeature->SetField( iAttr, pszFieldText ); } /* -------------------------------------------------------------------- */ /* Translate the record id. */ /* -------------------------------------------------------------------- */ poFeature->SetFID( nNextFID++ ); m_nFeaturesRead++; CPLFree( pszRecord ); return poFeature; }
int ILI1Reader::ReadFeatures() { char **tokens = NULL; const char *firsttok = NULL; const char *pszLine; char *topic = NULL; int ret = TRUE; while (ret && (tokens = ReadParseLine())) { firsttok = tokens[0]; if (EQUAL(firsttok, "SCNT")) { //read description do { pszLine = CPLReadLine( fpItf ); } while (pszLine && !EQUALN(pszLine, "////", 4)); ret = (pszLine != NULL); } else if (EQUAL(firsttok, "MOTR")) { //read model do { pszLine = CPLReadLine( fpItf ); } while (pszLine && !EQUALN(pszLine, "////", 4)); ret = (pszLine != NULL); } else if (EQUAL(firsttok, "MTID")) { } else if (EQUAL(firsttok, "MODL")) { } else if (EQUAL(firsttok, "TOPI")) { CPLFree(topic); topic = CPLStrdup(CSLGetField(tokens, 1)); } else if (EQUAL(firsttok, "TABL")) { CPLDebug( "OGR_ILI", "Reading table '%s'", GetLayerNameString(topic, CSLGetField(tokens, 1)) ); const char *layername = GetLayerNameString(topic, CSLGetField(tokens, 1)); curLayer = GetLayerByName(layername); int multiple = HasMultiplePointGeom(layername); // create only a new layer if there is no curLayer AND // if there are more than one point geometry columns if (curLayer == NULL && multiple < 1) { //create one CPLDebug( "OGR_ILI", "No model found, using default field names." ); OGRSpatialReference *poSRSIn = NULL; int bWriterIn = 0; OGRwkbGeometryType eReqType = wkbUnknown; OGRILI1DataSource *poDSIn = NULL; curLayer = new OGRILI1Layer(GetLayerNameString(topic, CSLGetField(tokens, 1)), poSRSIn, bWriterIn, eReqType, poDSIn); AddLayer(curLayer); } if(curLayer != NULL) { for (int i=0; i < curLayer->GetLayerDefn()->GetFieldCount(); i++) { CPLDebug( "OGR_ILI", "Field %d: %s", i, curLayer->GetLayerDefn()->GetFieldDefn(i)->GetNameRef()); } } ret = ReadTable(layername); } else if (EQUAL(firsttok, "ETOP")) { } else if (EQUAL(firsttok, "EMOD")) { } else if (EQUAL(firsttok, "ENDE")) { CSLDestroy(tokens); CPLFree(topic); return TRUE; } else { CPLDebug( "OGR_ILI", "Unexpected token: %s", firsttok ); } CSLDestroy(tokens); tokens = NULL; } CSLDestroy(tokens); CPLFree(topic); return ret; }
int OGRGeneralCmdLineProcessor( int nArgc, char ***ppapszArgv, int nOptions ) { char **papszReturn = NULL; int iArg; char **papszArgv = *ppapszArgv; (void) nOptions; /* -------------------------------------------------------------------- */ /* Preserve the program name. */ /* -------------------------------------------------------------------- */ papszReturn = CSLAddString( papszReturn, papszArgv[0] ); /* ==================================================================== */ /* Loop over all arguments. */ /* ==================================================================== */ for( iArg = 1; iArg < nArgc; iArg++ ) { /* -------------------------------------------------------------------- */ /* --version */ /* -------------------------------------------------------------------- */ if( EQUAL(papszArgv[iArg],"--version") ) { printf( "%s\n", GDALVersionInfo( "--version" ) ); CSLDestroy( papszReturn ); return 0; } /* -------------------------------------------------------------------- */ /* --license */ /* -------------------------------------------------------------------- */ else if( EQUAL(papszArgv[iArg],"--license") ) { printf( "%s\n", GDALVersionInfo( "LICENSE" ) ); CSLDestroy( papszReturn ); return 0; } /* -------------------------------------------------------------------- */ /* --config */ /* -------------------------------------------------------------------- */ else if( EQUAL(papszArgv[iArg],"--config") ) { if( iArg + 2 >= nArgc ) { CPLError( CE_Failure, CPLE_AppDefined, "--config option given without a key and value argument." ); CSLDestroy( papszReturn ); return -1; } CPLSetConfigOption( papszArgv[iArg+1], papszArgv[iArg+2] ); iArg += 2; } /* -------------------------------------------------------------------- */ /* --mempreload */ /* -------------------------------------------------------------------- */ else if( EQUAL(papszArgv[iArg],"--mempreload") ) { int i; if( iArg + 1 >= nArgc ) { CPLError( CE_Failure, CPLE_AppDefined, "--mempreload option given without directory path."); CSLDestroy( papszReturn ); return -1; } char **papszFiles = CPLReadDir( papszArgv[iArg+1] ); if( CSLCount(papszFiles) == 0 ) { CPLError( CE_Failure, CPLE_AppDefined, "--mempreload given invalid or empty directory."); CSLDestroy( papszReturn ); return -1; } for( i = 0; papszFiles[i] != NULL; i++ ) { CPLString osOldPath, osNewPath; if( EQUAL(papszFiles[i],".") || EQUAL(papszFiles[i],"..") ) continue; osOldPath = CPLFormFilename( papszArgv[iArg+1], papszFiles[i], NULL ); osNewPath.Printf( "/vsimem/%s", papszFiles[i] ); CPLDebug( "VSI", "Preloading %s to %s.", osOldPath.c_str(), osNewPath.c_str() ); if( CPLCopyFile( osNewPath, osOldPath ) != 0 ) return -1; } CSLDestroy( papszFiles ); iArg += 1; } /* -------------------------------------------------------------------- */ /* --debug */ /* -------------------------------------------------------------------- */ else if( EQUAL(papszArgv[iArg],"--debug") ) { if( iArg + 1 >= nArgc ) { CPLError( CE_Failure, CPLE_AppDefined, "--debug option given without debug level." ); CSLDestroy( papszReturn ); return -1; } CPLSetConfigOption( "CPL_DEBUG", papszArgv[iArg+1] ); iArg += 1; } /* -------------------------------------------------------------------- */ /* --optfile */ /* */ /* Annoyingly the options inserted by --optfile will *not* be */ /* processed properly if they are general options. */ /* -------------------------------------------------------------------- */ else if( EQUAL(papszArgv[iArg],"--optfile") ) { const char *pszLine; FILE *fpOptFile; if( iArg + 1 >= nArgc ) { CPLError( CE_Failure, CPLE_AppDefined, "--optfile option given without filename." ); CSLDestroy( papszReturn ); return -1; } fpOptFile = VSIFOpen( papszArgv[iArg+1], "rb" ); if( fpOptFile == NULL ) { CPLError( CE_Failure, CPLE_AppDefined, "Unable to open optfile '%s'.\n%s", papszArgv[iArg+1], VSIStrerror( errno ) ); CSLDestroy( papszReturn ); return -1; } while( (pszLine = CPLReadLine( fpOptFile )) != NULL ) { char **papszTokens; int i; if( pszLine[0] == '#' || strlen(pszLine) == 0 ) continue; papszTokens = CSLTokenizeString( pszLine ); for( i = 0; papszTokens != NULL && papszTokens[i] != NULL; i++) papszReturn = CSLAddString( papszReturn, papszTokens[i] ); CSLDestroy( papszTokens ); } VSIFClose( fpOptFile ); iArg += 1; } /* -------------------------------------------------------------------- */ /* --formats */ /* -------------------------------------------------------------------- */ #ifdef OGR_ENABLED else if( EQUAL(papszArgv[iArg], "--formats") ) { int iDr; printf( "Supported Formats:\n" ); OGRSFDriverRegistrar *poR = OGRSFDriverRegistrar::GetRegistrar(); for( iDr = 0; iDr < poR->GetDriverCount(); iDr++ ) { OGRSFDriver *poDriver = poR->GetDriver(iDr); if( poDriver->TestCapability( ODrCCreateDataSource ) ) printf( " -> \"%s\" (read/write)\n", poDriver->GetName() ); else printf( " -> \"%s\" (readonly)\n", poDriver->GetName() ); } CSLDestroy( papszReturn ); return 0; } #endif /* OGR_ENABLED */ /* -------------------------------------------------------------------- */ /* --locale */ /* -------------------------------------------------------------------- */ else if( EQUAL(papszArgv[iArg],"--locale") && iArg < nArgc-1 ) { setlocale( LC_ALL, papszArgv[++iArg] ); } /* -------------------------------------------------------------------- */ /* --pause - "hit enter" pause useful to connect a debugger. */ /* -------------------------------------------------------------------- */ else if( EQUAL(papszArgv[iArg],"--pause") ) { char szLine[81]; printf( "Hit <ENTER> to continue.\n" ); fgets( szLine, sizeof(szLine), stdin ); } /* -------------------------------------------------------------------- */ /* --help-general */ /* -------------------------------------------------------------------- */ else if( EQUAL(papszArgv[iArg],"--help-general") ) { printf( "Generic GDAL/OGR utility command options:\n" ); printf( " --version: report version of GDAL/OGR in use.\n" ); printf( " --license: report GDAL/OGR license info.\n" ); #ifdef OGR_ENABLED printf( " --formats: report all configured format drivers.\n" ); #endif /* OGR_ENABLED */ printf( " --optfile filename: expand an option file into the argument list.\n" ); printf( " --config key value: set system configuration option.\n" ); printf( " --debug [on/off/value]: set debug level.\n" ); printf( " --help-general: report detailed help on general options.\n" ); CSLDestroy( papszReturn ); return 0; } /* -------------------------------------------------------------------- */ /* carry through unrecognised options. */ /* -------------------------------------------------------------------- */ else { papszReturn = CSLAddString( papszReturn, papszArgv[iArg] ); } } *ppapszArgv = papszReturn; return CSLCount( *ppapszArgv ); }
int ILI1Reader::ReadFeatures() { char **tokens = NULL; const char *pszLine = NULL; char *topic = CPLStrdup("(null)"); int ret = TRUE; while (ret && (tokens = ReadParseLine()) != NULL) { const char *firsttok = tokens[0]; if (EQUAL(firsttok, "SCNT")) { //read description do { pszLine = CPLReadLine( fpItf ); } while (pszLine && !STARTS_WITH_CI(pszLine, "////")); ret = (pszLine != NULL); } else if (EQUAL(firsttok, "MOTR")) { //read model do { pszLine = CPLReadLine( fpItf ); } while (pszLine && !STARTS_WITH_CI(pszLine, "////")); ret = (pszLine != NULL); } else if (EQUAL(firsttok, "MTID")) { } else if (EQUAL(firsttok, "MODL")) { } else if (EQUAL(firsttok, "TOPI") && CSLCount(tokens) >= 2) { CPLFree(topic); topic = CPLStrdup(CSLGetField(tokens, 1)); } else if (EQUAL(firsttok, "TABL") && CSLCount(tokens) >= 2) { const char *layername = GetLayerNameString(topic, CSLGetField(tokens, 1)); CPLDebug( "OGR_ILI", "Reading table '%s'", layername ); curLayer = GetLayerByName(layername); if (curLayer == NULL) { //create one CPLError( CE_Warning, CPLE_AppDefined, "No model definition for table '%s' found, " "using default field names.", layername ); OGRFeatureDefn* poFeatureDefn = new OGRFeatureDefn( GetLayerNameString(topic, CSLGetField(tokens, 1))); poFeatureDefn->SetGeomType( wkbUnknown ); GeomFieldInfos oGeomFieldInfos; curLayer = new OGRILI1Layer(poFeatureDefn, oGeomFieldInfos, NULL); AddLayer(curLayer); } if(curLayer != NULL) { for (int i=0; i < curLayer->GetLayerDefn()->GetFieldCount(); i++) { CPLDebug( "OGR_ILI", "Field %d: %s", i, curLayer->GetLayerDefn()->GetFieldDefn(i)->GetNameRef()); } } ret = ReadTable(layername); } else if (EQUAL(firsttok, "ETOP")) { } else if (EQUAL(firsttok, "EMOD")) { } else if (EQUAL(firsttok, "ENDE")) { CSLDestroy(tokens); CPLFree(topic); return TRUE; } else { CPLError( CE_Warning, CPLE_AppDefined, "Unexpected token: %s", firsttok ); } CSLDestroy(tokens); tokens = NULL; } CSLDestroy(tokens); CPLFree(topic); return ret; }
static int GXFReadRawScanlineFrom( GXFInfo_t * psGXF, long iOffset, long * pnNewOffset, double * padfLineBuf ) { const char *pszLine; int nValuesRead = 0, nValuesSought = psGXF->nRawXSize; VSIFSeek( psGXF->fp, iOffset, SEEK_SET ); while( nValuesRead < nValuesSought ) { pszLine = CPLReadLine( psGXF->fp ); if( pszLine == NULL ) break; /* -------------------------------------------------------------------- */ /* Uncompressed case. */ /* -------------------------------------------------------------------- */ if( psGXF->nGType == 0 ) { /* we could just tokenize the line, but that's pretty expensive. Instead I will parse on white space ``by hand''. */ while( *pszLine != '\0' && nValuesRead < nValuesSought ) { int i; /* skip leading white space */ for( ; isspace((unsigned char)*pszLine); pszLine++ ) {} /* Skip the data value (non white space) */ for( i = 0; pszLine[i] != '\0' && !isspace((unsigned char)pszLine[i]); i++) {} if( strncmp(pszLine,psGXF->szDummy,i) == 0 ) { padfLineBuf[nValuesRead++] = psGXF->dfSetDummyTo; } else { padfLineBuf[nValuesRead++] = CPLAtof(pszLine); } /* skip further whitespace */ for( pszLine += i; isspace((unsigned char)*pszLine); pszLine++ ) {} } } /* -------------------------------------------------------------------- */ /* Compressed case. */ /* -------------------------------------------------------------------- */ else { int nLineLen = (int)strlen(pszLine); while( *pszLine != '\0' && nValuesRead < nValuesSought ) { if( nLineLen < psGXF->nGType ) return CE_Failure; if( pszLine[0] == '!' ) { padfLineBuf[nValuesRead++] = psGXF->dfSetDummyTo; } else if( pszLine[0] == '"' ) { int nCount, i; double dfValue; pszLine += psGXF->nGType; nLineLen -= psGXF->nGType; if( nLineLen < psGXF->nGType ) { pszLine = CPLReadLine( psGXF->fp ); if( pszLine == NULL ) return CE_Failure; nLineLen = (int)strlen(pszLine); if( nLineLen < psGXF->nGType ) return CE_Failure; } nCount = (int) GXFParseBase90( psGXF, pszLine, FALSE); pszLine += psGXF->nGType; nLineLen -= psGXF->nGType; if( nLineLen < psGXF->nGType ) { pszLine = CPLReadLine( psGXF->fp ); if( pszLine == NULL ) return CE_Failure; nLineLen = (int)strlen(pszLine); if( nLineLen < psGXF->nGType ) return CE_Failure; } if( *pszLine == '!' ) dfValue = psGXF->dfSetDummyTo; else dfValue = GXFParseBase90( psGXF, pszLine, TRUE ); if( nValuesRead + nCount > nValuesSought ) { CPLError(CE_Failure, CPLE_AppDefined, "Wrong count value"); return CE_Failure; } for( i=0; i < nCount && nValuesRead < nValuesSought; i++ ) padfLineBuf[nValuesRead++] = dfValue; } else { padfLineBuf[nValuesRead++] = GXFParseBase90( psGXF, pszLine, TRUE ); } pszLine += psGXF->nGType; nLineLen -= psGXF->nGType; } } } /* -------------------------------------------------------------------- */ /* Return the new offset, if requested. */ /* -------------------------------------------------------------------- */ if( pnNewOffset != NULL ) { *pnNewOffset = VSIFTell( psGXF->fp ); } return CE_None; }
void IDADataset::ReadColorTable() { /* -------------------------------------------------------------------- */ /* Decide what .clr file to look for and try to open. */ /* -------------------------------------------------------------------- */ CPLString osCLRFilename; osCLRFilename = CPLGetConfigOption( "IDA_COLOR_FILE", "" ); if( strlen(osCLRFilename) == 0 ) osCLRFilename = CPLResetExtension(GetDescription(), "clr" ); FILE *fp = VSIFOpen( osCLRFilename, "r" ); if( fp == NULL ) { osCLRFilename = CPLResetExtension(osCLRFilename, "CLR" ); fp = VSIFOpen( osCLRFilename, "r" ); } if( fp == NULL ) return; /* -------------------------------------------------------------------- */ /* Skip first line, with the column titles. */ /* -------------------------------------------------------------------- */ CPLReadLine( fp ); /* -------------------------------------------------------------------- */ /* Create a RAT to populate. */ /* -------------------------------------------------------------------- */ GDALRasterAttributeTable *poRAT = new GDALDefaultRasterAttributeTable(); poRAT->CreateColumn( "FROM", GFT_Integer, GFU_Min ); poRAT->CreateColumn( "TO", GFT_Integer, GFU_Max ); poRAT->CreateColumn( "RED", GFT_Integer, GFU_Red ); poRAT->CreateColumn( "GREEN", GFT_Integer, GFU_Green ); poRAT->CreateColumn( "BLUE", GFT_Integer, GFU_Blue ); poRAT->CreateColumn( "LEGEND", GFT_String, GFU_Name ); /* -------------------------------------------------------------------- */ /* Apply lines. */ /* -------------------------------------------------------------------- */ const char *pszLine = CPLReadLine( fp ); int iRow = 0; while( pszLine != NULL ) { char **papszTokens = CSLTokenizeStringComplex( pszLine, " \t", FALSE, FALSE ); if( CSLCount( papszTokens ) >= 5 ) { poRAT->SetValue( iRow, 0, atoi(papszTokens[0]) ); poRAT->SetValue( iRow, 1, atoi(papszTokens[1]) ); poRAT->SetValue( iRow, 2, atoi(papszTokens[2]) ); poRAT->SetValue( iRow, 3, atoi(papszTokens[3]) ); poRAT->SetValue( iRow, 4, atoi(papszTokens[4]) ); // find name, first nonspace after 5th token. const char *pszName = pszLine; // skip from while( *pszName == ' ' || *pszName == '\t' ) pszName++; while( *pszName != ' ' && *pszName != '\t' && *pszName != '\0' ) pszName++; // skip to while( *pszName == ' ' || *pszName == '\t' ) pszName++; while( *pszName != ' ' && *pszName != '\t' && *pszName != '\0' ) pszName++; // skip red while( *pszName == ' ' || *pszName == '\t' ) pszName++; while( *pszName != ' ' && *pszName != '\t' && *pszName != '\0' ) pszName++; // skip green while( *pszName == ' ' || *pszName == '\t' ) pszName++; while( *pszName != ' ' && *pszName != '\t' && *pszName != '\0' ) pszName++; // skip blue while( *pszName == ' ' || *pszName == '\t' ) pszName++; while( *pszName != ' ' && *pszName != '\t' && *pszName != '\0' ) pszName++; // skip pre-name white space while( *pszName == ' ' || *pszName == '\t' ) pszName++; poRAT->SetValue( iRow, 5, pszName ); iRow++; } CSLDestroy( papszTokens ); pszLine = CPLReadLine( fp ); } VSIFClose( fp ); /* -------------------------------------------------------------------- */ /* Attach RAT to band. */ /* -------------------------------------------------------------------- */ ((IDARasterBand *) GetRasterBand( 1 ))->poRAT = poRAT; /* -------------------------------------------------------------------- */ /* Build a conventional color table from this. */ /* -------------------------------------------------------------------- */ ((IDARasterBand *) GetRasterBand( 1 ))->poColorTable = poRAT->TranslateToColorTable(); }
GDALDataset *DOQ2Dataset::Open( GDALOpenInfo * poOpenInfo ) { int nWidth=0, nHeight=0, nBandStorage=0, nBandTypes=0; /* -------------------------------------------------------------------- */ /* We assume the user is pointing to the binary (ie. .bil) file. */ /* -------------------------------------------------------------------- */ if( poOpenInfo->nHeaderBytes < 212 || poOpenInfo->fp == NULL ) return NULL; int nLineCount = 0; const char *pszLine; int nBytesPerPixel=0; const char *pszDatumLong=NULL, *pszDatumShort=NULL; const char *pszUnits=NULL; char *pszQuadname = NULL; char *pszQuadquad = NULL; char *pszState = NULL; int nZone=0, nProjType=0; int nSkipBytes=0, nBytesPerLine, i, nBandCount = 0; double dfULXMap=0.0, dfULYMap = 0.0; double dfXDim=0.0, dfYDim=0.0; char **papszMetadata = NULL; if(! EQUALN((const char *) poOpenInfo->pabyHeader, "BEGIN_USGS_DOQ_HEADER", 21) ) return NULL; /* read and discard the first line */ pszLine = CPLReadLine( poOpenInfo->fp ); while( (pszLine = CPLReadLine( poOpenInfo->fp )) != NULL ) { char **papszTokens; nLineCount++; if( EQUAL(pszLine,"END_USGS_DOQ_HEADER") ) break; papszTokens = CSLTokenizeString( pszLine ); if( CSLCount( papszTokens ) < 2 ) { CSLDestroy( papszTokens ); break; } if( EQUAL(papszTokens[0],"SAMPLES_AND_LINES") && CSLCount(papszTokens) >= 3 ) { nWidth = atoi(papszTokens[1]); nHeight = atoi(papszTokens[2]); } else if( EQUAL(papszTokens[0],"BYTE_COUNT") ) { nSkipBytes = atoi(papszTokens[1]); } else if( EQUAL(papszTokens[0],"XY_ORIGIN") && CSLCount(papszTokens) >= 3 ) { dfULXMap = atof(papszTokens[1]); dfULYMap = atof(papszTokens[2]); } else if( EQUAL(papszTokens[0],"HORIZONTAL_RESOLUTION") ) { dfXDim = dfYDim = atof(papszTokens[1]); } else if( EQUAL(papszTokens[0],"BAND_ORGANIZATION") ) { if( EQUAL(papszTokens[1],"SINGLE FILE") ) nBandStorage = 1; if( EQUAL(papszTokens[1],"BSQ") ) nBandStorage = 1; if( EQUAL(papszTokens[1],"BIL") ) nBandStorage = 1; if( EQUAL(papszTokens[1],"BIP") ) nBandStorage = 4; } else if( EQUAL(papszTokens[0],"BAND_CONTENT") ) { if( EQUAL(papszTokens[1],"BLACK&WHITE") ) nBandTypes = 1; else if( EQUAL(papszTokens[1],"COLOR") ) nBandTypes = 5; else if( EQUAL(papszTokens[1],"RGB") ) nBandTypes = 5; else if( EQUAL(papszTokens[1],"RED") ) nBandTypes = 5; else if( EQUAL(papszTokens[1],"GREEN") ) nBandTypes = 5; else if( EQUAL(papszTokens[1],"BLUE") ) nBandTypes = 5; nBandCount++; } else if( EQUAL(papszTokens[0],"BITS_PER_PIXEL") ) { nBytesPerPixel = (atoi(papszTokens[1]) / 8); } else if( EQUAL(papszTokens[0],"HORIZONTAL_COORDINATE_SYSTEM") ) { if( EQUAL(papszTokens[1],"UTM") ) nProjType = 1; else if( EQUAL(papszTokens[1],"SPCS") ) nProjType = 2; else if( EQUAL(papszTokens[1],"GEOGRAPHIC") ) nProjType = 0; } else if( EQUAL(papszTokens[0],"COORDINATE_ZONE") ) { nZone = atoi(papszTokens[1]); } else if( EQUAL(papszTokens[0],"HORIZONTAL_UNITS") ) { if( EQUAL(papszTokens[1],"METERS") ) pszUnits = "UNIT[\"metre\",1]"; else if( EQUAL(papszTokens[1],"FEET") ) pszUnits = "UNIT[\"US survey foot\",0.304800609601219]"; } else if( EQUAL(papszTokens[0],"HORIZONTAL_DATUM") ) { if( EQUAL(papszTokens[1],"NAD27") ) { pszDatumLong = NAD27_DATUM; pszDatumShort = "NAD 27"; } else if( EQUAL(papszTokens[1],"WGS72") ) { pszDatumLong = WGS72_DATUM; pszDatumShort = "WGS 72"; } else if( EQUAL(papszTokens[1],"WGS84") ) { pszDatumLong = WGS84_DATUM; pszDatumShort = "WGS 84"; } else if( EQUAL(papszTokens[1],"NAD83") ) { pszDatumLong = NAD83_DATUM; pszDatumShort = "NAD 83"; } else { pszDatumLong = "DATUM[\"unknown\"]"; pszDatumShort = "unknown"; } } else { /* we want to generically capture all the other metadata */ CPLString osMetaDataValue; int iToken; for( iToken = 1; papszTokens[iToken] != NULL; iToken++ ) { if( EQUAL(papszTokens[iToken],"*") ) continue; if( iToken > 1 ) osMetaDataValue += " " ; osMetaDataValue += papszTokens[iToken]; } papszMetadata = CSLAddNameValue( papszMetadata, papszTokens[0], osMetaDataValue ); } CSLDestroy( papszTokens ); } CPLReadLine( NULL ); /* -------------------------------------------------------------------- */ /* Do these values look coherent for a DOQ file? It would be */ /* nice to do a more comprehensive test than this! */ /* -------------------------------------------------------------------- */ if( nWidth < 500 || nWidth > 25000 || nHeight < 500 || nHeight > 25000 || nBandStorage < 0 || nBandStorage > 4 || nBandTypes < 1 || nBandTypes > 9 ) { CSLDestroy( papszMetadata ); return NULL; } /* -------------------------------------------------------------------- */ /* Check the configuration. We don't currently handle all */ /* variations, only the common ones. */ /* -------------------------------------------------------------------- */ if( nBandTypes > 5 ) { CPLError( CE_Failure, CPLE_OpenFailed, "DOQ Data Type (%d) is not a supported configuration.\n", nBandTypes ); CSLDestroy( papszMetadata ); return NULL; } /* -------------------------------------------------------------------- */ /* Confirm the requested access is supported. */ /* -------------------------------------------------------------------- */ if( poOpenInfo->eAccess == GA_Update ) { CSLDestroy( papszMetadata ); CPLError( CE_Failure, CPLE_NotSupported, "The DOQ2 driver does not support update access to existing" " datasets.\n" ); return NULL; } /* -------------------------------------------------------------------- */ /* Create a corresponding GDALDataset. */ /* -------------------------------------------------------------------- */ DOQ2Dataset *poDS; poDS = new DOQ2Dataset(); poDS->nRasterXSize = nWidth; poDS->nRasterYSize = nHeight; poDS->SetMetadata( papszMetadata ); CSLDestroy( papszMetadata ); /* -------------------------------------------------------------------- */ /* Assume ownership of the file handled from the GDALOpenInfo. */ /* -------------------------------------------------------------------- */ poDS->fpImage = poOpenInfo->fp; poOpenInfo->fp = NULL; /* -------------------------------------------------------------------- */ /* Compute layout of data. */ /* -------------------------------------------------------------------- */ if( nBandCount < 2 ) nBandCount = nBytesPerPixel; else nBytesPerPixel *= nBandCount; nBytesPerLine = nBytesPerPixel * nWidth; /* -------------------------------------------------------------------- */ /* Create band information objects. */ /* -------------------------------------------------------------------- */ for( i = 0; i < nBandCount; i++ ) { poDS->SetBand( i+1, new RawRasterBand( poDS, i+1, poDS->fpImage, nSkipBytes + i, nBytesPerPixel, nBytesPerLine, GDT_Byte, TRUE ) ); } if (nProjType == 1) { poDS->pszProjection = CPLStrdup(CPLSPrintf( UTM_FORMAT, pszDatumShort, nZone, pszDatumLong, nZone * 6 - 183, pszUnits )); } else { poDS->pszProjection = CPLStrdup(""); } poDS->dfULX = dfULXMap; poDS->dfULY = dfULYMap; poDS->dfXPixelSize = dfXDim; poDS->dfYPixelSize = dfYDim; if ( pszQuadname ) CPLFree( pszQuadname ); if ( pszQuadquad) CPLFree( pszQuadquad ); if ( pszState) CPLFree( pszState ); /* -------------------------------------------------------------------- */ /* Initialize any PAM information. */ /* -------------------------------------------------------------------- */ poDS->SetDescription( poOpenInfo->pszFilename ); poDS->TryLoadXML(); /* -------------------------------------------------------------------- */ /* Check for overviews. */ /* -------------------------------------------------------------------- */ poDS->oOvManager.Initialize( poDS, poOpenInfo->pszFilename ); return( poDS ); }
/********************************************************************** * IMapInfoFile::SmartOpen() * * Use this static method to automatically open any flavour of MapInfo * dataset. This method will detect the file type, create an object * of the right type, and open the file. * * Call GetFileClass() on the returned object if you need to find out * its exact type. (To access format-specific methods for instance) * * Returns the new object ptr. , or NULL if the open failed. **********************************************************************/ IMapInfoFile *IMapInfoFile::SmartOpen(const char *pszFname, GBool bTestOpenNoError /*=FALSE*/) { IMapInfoFile *poFile = NULL; int nLen = 0; if (pszFname) nLen = strlen(pszFname); if (nLen > 4 && (EQUAL(pszFname + nLen-4, ".MIF") || EQUAL(pszFname + nLen-4, ".MID") ) ) { /*------------------------------------------------------------- * MIF/MID file *------------------------------------------------------------*/ poFile = new MIFFile; } else if (nLen > 4 && EQUAL(pszFname + nLen-4, ".TAB")) { /*------------------------------------------------------------- * .TAB file ... is it a TABFileView or a TABFile? * We have to read the .tab header to find out. *------------------------------------------------------------*/ FILE *fp; const char *pszLine; char *pszAdjFname = CPLStrdup(pszFname); GBool bFoundFields = FALSE, bFoundView=FALSE, bFoundSeamless=FALSE; TABAdjustFilenameExtension(pszAdjFname); fp = VSIFOpen(pszAdjFname, "r"); while(fp && (pszLine = CPLReadLine(fp)) != NULL) { while (isspace((unsigned char)*pszLine)) pszLine++; if (EQUALN(pszLine, "Fields", 6)) bFoundFields = TRUE; else if (EQUALN(pszLine, "create view", 11)) bFoundView = TRUE; else if (EQUALN(pszLine, "\"\\IsSeamless\" = \"TRUE\"", 21)) bFoundSeamless = TRUE; } if (bFoundView) poFile = new TABView; else if (bFoundFields && bFoundSeamless) poFile = new TABSeamless; else if (bFoundFields) poFile = new TABFile; if (fp) VSIFClose(fp); CPLFree(pszAdjFname); } /*----------------------------------------------------------------- * Perform the open() call *----------------------------------------------------------------*/ if (poFile && poFile->Open(pszFname, "r", bTestOpenNoError) != 0) { delete poFile; poFile = NULL; } if (!bTestOpenNoError && poFile == NULL) { CPLError(CE_Failure, CPLE_FileIO, "%s could not be opened as a MapInfo dataset.", pszFname); } return poFile; }
OGRRECLayer::OGRRECLayer( const char *pszLayerNameIn, FILE * fp, int nFieldCountIn ) { fpREC = fp; bIsValid = FALSE; nStartOfData = 0; nNextFID = 1; poFeatureDefn = new OGRFeatureDefn( pszLayerNameIn ); SetDescription( poFeatureDefn->GetName() ); poFeatureDefn->Reference(); nFieldCount = 0; panFieldOffset = (int *) CPLCalloc(sizeof(int),nFieldCountIn); panFieldWidth = (int *) CPLCalloc(sizeof(int),nFieldCountIn); /* -------------------------------------------------------------------- */ /* Read field definition lines. */ /* -------------------------------------------------------------------- */ int iField; for( nFieldCount=0, iField = 0; iField < nFieldCountIn; iField++ ) { const char *pszLine = CPLReadLine( fp ); int nTypeCode; OGRFieldType eFType = OFTString; if( pszLine == NULL ) return; if( strlen(pszLine) < 44 ) return; // Extract field width. panFieldWidth[nFieldCount] = atoi( RECGetField( pszLine, 37, 4 ) ); if( panFieldWidth[nFieldCount] < 0 ) return; // Is this an real, integer or string field? Default to string. nTypeCode = atoi(RECGetField(pszLine,33,4)); if( nTypeCode == 12 ) eFType = OFTInteger; else if( nTypeCode > 100 && nTypeCode < 120 ) { eFType = OFTReal; } else if( nTypeCode == 0 || nTypeCode == 6 || nTypeCode == 102 ) { if( panFieldWidth[nFieldCount] < 3 ) eFType = OFTInteger; else eFType = OFTReal; } else eFType = OFTString; OGRFieldDefn oField( RECGetField( pszLine, 2, 10 ), eFType ); // Establish field offset. if( nFieldCount > 0 ) panFieldOffset[nFieldCount] = panFieldOffset[nFieldCount-1] + panFieldWidth[nFieldCount-1]; if( nTypeCode > 100 && nTypeCode < 120 ) { oField.SetWidth( panFieldWidth[nFieldCount] ); oField.SetPrecision( nTypeCode - 100 ); } else if( eFType == OFTReal ) { oField.SetWidth( panFieldWidth[nFieldCount]*2 ); oField.SetPrecision( panFieldWidth[nFieldCount]-1 ); } else oField.SetWidth( panFieldWidth[nFieldCount] ); // Skip fields that are only screen labels. if( panFieldWidth[nFieldCount] == 0 ) continue; poFeatureDefn->AddFieldDefn( &oField ); nFieldCount++; } if( nFieldCount == 0 ) return; nRecordLength = panFieldOffset[nFieldCount-1]+panFieldWidth[nFieldCount-1]; bIsValid = TRUE; nStartOfData = VSIFTell( fp ); }
int main() { FILE *fpIn, *fpOut; const char *pszLine = NULL; int iFile = 0; if ((fpIn = fopen("mapinfow.prj", "r")) == NULL) { printf("mapinfow.prj not found.\n"); exit(1); } while((pszLine = CPLReadLine(fpIn)) != NULL) { char **papszParams = CSLTokenizeStringComplex(pszLine, " ,", TRUE,FALSE); if (CSLCount(papszParams) >= 3 && !EQUALN(papszParams[0], "---", 3)) { int nProj = 0; int nDatum= 0; int nUnitsParamIndex = 0; if ((fpOut = fopen(CPLSPrintf("tttproj%04.4d.mif", iFile), "w")) == NULL) { printf("Failed creating MIF output file!\n"); exit(2); } nProj = atoi(papszParams[1]); nDatum = atoi(papszParams[2]); if (nProj >= 1000) { printf("File tttproj%04.4d.mif uses projection %d ... \n" "this case is not handled properly by this version\n", iFile, nProj); } if (nProj == 1) nUnitsParamIndex = -1; // No units for geographic proj. else if (nProj == 0) { nUnitsParamIndex = 2; // NonEarth... units only. printf("File tttproj%04.4d.mif is NonEarth\n", iFile); } else if (nDatum == 999 || nDatum == 9999) { nUnitsParamIndex = -1; // Custom datum defn= 9999,x,x,x,x,... // Units are in numeric fmt // No conversion required. printf("File tttproj%04.4d.mif has custom datum\n", iFile); } else nUnitsParamIndex = 3; fprintf(fpOut, "Version 300\n"); fprintf(fpOut, "Charset \"WindowsLatin1\"\n"); fprintf(fpOut, "Delimiter \",\"\n"); if (nProj == 0) fprintf(fpOut, "CoordSys Nonearth "); else fprintf(fpOut, "CoordSys Earth Projection %d", nProj); for(int i=2; papszParams[i]!=NULL; i++) { if (i == nUnitsParamIndex) { // Units string (except for proj=1: geographic) const char *pszUnits = "???"; switch(atoi(papszParams[i])) { case 6: pszUnits = "cm"; break; case 31: pszUnits = "ch"; break; case 3: pszUnits = "ft"; break; case 2: pszUnits = "in"; break; case 1: pszUnits = "km"; break; case 30: pszUnits = "li"; break; case 7: pszUnits = "m"; break; case 0: pszUnits = "mi"; break; case 5: pszUnits = "mm"; break; case 9: pszUnits = "nmi"; break; case 32: pszUnits = "rd"; break; case 8: pszUnits = "survey ft"; break; case 4: pszUnits = "yd"; break; default: printf("WARNING: Unsupported units type: %s in\n%s\n", papszParams[i], pszLine); pszUnits = "m"; break; } if (nProj == 0) fprintf(fpOut, "Units \"%s\" Bounds (-1,-1)(1,1)", pszUnits); else fprintf(fpOut, ", \"%s\"", pszUnits); } else fprintf(fpOut, ", %s", papszParams[i]); } fprintf(fpOut, "\n"); fprintf(fpOut, "Columns 1\n"); fprintf(fpOut, " ttt Char(10)\n"); fprintf(fpOut, "Data\n"); fprintf(fpOut, "POINT 0 0\n"); fclose(fpOut); if ((fpOut = fopen(CPLSPrintf("tttproj%04.4d.mid", iFile++), "w"))) { fprintf(fpOut, "ttt\n"); fclose(fpOut); } } CSLDestroy(papszParams); } }