int SDTSRawPolygon::Read( DDFRecord * poRecord ) { /* ==================================================================== */ /* Loop over fields in this record, looking for those we */ /* recognise, and need. */ /* ==================================================================== */ for( int iField = 0; iField < poRecord->GetFieldCount(); iField++ ) { DDFField *poField = poRecord->GetField( iField ); const char *pszFieldName; CPLAssert( poField != NULL ); pszFieldName = poField->GetFieldDefn()->GetName(); if( EQUAL(pszFieldName,"POLY") ) { oModId.Set( poField ); } else if( EQUAL(pszFieldName,"ATID") ) { ApplyATID( poField ); } } return TRUE; }
int SDTSRawPoint::Read( SDTS_IREF * poIREF, DDFRecord * poRecord ) { /* ==================================================================== */ /* Loop over fields in this record, looking for those we */ /* recognise, and need. */ /* ==================================================================== */ for( int iField = 0; iField < poRecord->GetFieldCount(); iField++ ) { DDFField *poField = poRecord->GetField( iField ); CPLAssert( poField != NULL ); const char *pszFieldName = poField->GetFieldDefn()->GetName(); if( EQUAL(pszFieldName,"PNTS") ) oModId.Set( poField ); else if( EQUAL(pszFieldName,"ATID") ) ApplyATID( poField ); else if( EQUAL(pszFieldName,"ARID") ) { oAreaId.Set( poField ); } else if( EQUAL(pszFieldName,"SADR") ) { poIREF->GetSADR( poField, 1, &dfX, &dfY, &dfZ ); } } return TRUE; }
int SDTSRawLine::Read( SDTS_IREF * poIREF, DDFRecord * poRecord ) { // E.Rouault: Not sure if this test is really useful if( poRecord->GetStringSubfield( "LINE", 0, "MODN", 0 ) == NULL ) return FALSE; /* ==================================================================== */ /* Loop over fields in this record, looking for those we */ /* recognise, and need. I don't use the getSubfield() */ /* interface on the record in order to retain some slight bit */ /* of efficiency. */ /* ==================================================================== */ for( int iField = 0; iField < poRecord->GetFieldCount(); iField++ ) { DDFField *poField = poRecord->GetField( iField ); const char *pszFieldName; CPLAssert( poField != NULL ); pszFieldName = poField->GetFieldDefn()->GetName(); if( EQUAL(pszFieldName,"LINE") ) oModId.Set( poField ); else if( EQUAL(pszFieldName,"ATID") ) ApplyATID( poField ); else if( EQUAL(pszFieldName,"PIDL") ) oLeftPoly.Set( poField ); else if( EQUAL(pszFieldName,"PIDR") ) oRightPoly.Set( poField ); else if( EQUAL(pszFieldName,"SNID") ) oStartNode.Set( poField ); else if( EQUAL(pszFieldName,"ENID") ) oEndNode.Set( poField ); else if( EQUAL(pszFieldName,"SADR") ) { nVertices = poIREF->GetSADRCount( poField ); padfX = reinterpret_cast<double *>( CPLRealloc( padfX, sizeof(double) * nVertices*3 ) ); padfY = padfX + nVertices; padfZ = padfX + 2*nVertices; poIREF->GetSADR( poField, nVertices, padfX, padfY, padfZ ); } } return TRUE; }
int main( int nArgc, char ** papszArgv ) { DDFModule oModule; const char *pszFilename = NULL; int bFSPTHack = FALSE; int bXML = FALSE; /* -------------------------------------------------------------------- */ /* Check arguments. */ /* -------------------------------------------------------------------- */ for( int iArg = 1; iArg < nArgc; iArg++ ) { if( EQUAL(papszArgv[iArg],"-fspt_repeating") ) bFSPTHack = TRUE; else if( EQUAL(papszArgv[iArg],"-xml") ) bXML = TRUE; else pszFilename = papszArgv[iArg]; } if( pszFilename == NULL ) { printf( "Usage: 8211dump [-xml] [-fspt_repeating] filename\n" ); exit( 1 ); } /* -------------------------------------------------------------------- */ /* Open file. */ /* -------------------------------------------------------------------- */ if( !oModule.Open( pszFilename ) ) exit( 1 ); /* -------------------------------------------------------------------- */ /* Apply FSPT hack if required. */ /* -------------------------------------------------------------------- */ if( bFSPTHack ) { DDFFieldDefn *poFSPT = oModule.FindFieldDefn( "FSPT" ); if( poFSPT == NULL ) fprintf( stderr, "unable to find FSPT field to set repeating flag.\n" ); else poFSPT->SetRepeatingFlag( TRUE ); } /* -------------------------------------------------------------------- */ /* Dump header, and all records. */ /* -------------------------------------------------------------------- */ DDFRecord *poRecord; if( bXML ) { printf("<DDFModule>\n"); int nFieldDefnCount = oModule.GetFieldCount(); for( int i = 0; i < nFieldDefnCount; i++ ) { DDFFieldDefn* poFieldDefn = oModule.GetField(i); const char* pszDataStructCode; switch( poFieldDefn->GetDataStructCode() ) { case dsc_elementary: pszDataStructCode = "elementary"; break; case dsc_vector: pszDataStructCode = "vector"; break; case dsc_array: pszDataStructCode = "array"; break; case dsc_concatenated: pszDataStructCode = "concatenated"; break; default: pszDataStructCode = "(unknown)"; break; } const char* pszDataTypeCode; switch( poFieldDefn->GetDataTypeCode() ) { case dtc_char_string: pszDataTypeCode = "char_string"; break; case dtc_implicit_point: pszDataTypeCode = "implicit_point"; break; case dtc_explicit_point: pszDataTypeCode = "explicit_point"; break; case dtc_explicit_point_scaled: pszDataTypeCode = "explicit_point_scaled"; break; case dtc_char_bit_string: pszDataTypeCode = "char_bit_string"; break; case dtc_bit_string: pszDataTypeCode = "bit_string"; break; case dtc_mixed_data_type: pszDataTypeCode = "mixed_data_type"; break; default: pszDataTypeCode = "(unknown)"; break; } printf("<DDFFieldDefn tag=\"%s\" fieldName=\"%s\" arrayDescr=\"%s\" " "formatControls=\"%s\" dataStructCode=\"%s\" dataTypeCode=\"%s\">\n", poFieldDefn->GetName(), poFieldDefn->GetDescription(), poFieldDefn->GetArrayDescr(), poFieldDefn->GetFormatControls(), pszDataStructCode, pszDataTypeCode); int nSubfieldCount = poFieldDefn->GetSubfieldCount(); for( int iSubField = 0; iSubField < nSubfieldCount; iSubField++ ) { DDFSubfieldDefn* poSubFieldDefn = poFieldDefn->GetSubfield(iSubField); printf(" <DDFSubfieldDefn name=\"%s\" format=\"%s\"/>\n", poSubFieldDefn->GetName(), poSubFieldDefn->GetFormat()); } printf("</DDFFieldDefn>\n"); } for( poRecord = oModule.ReadRecord(); poRecord != NULL; poRecord = oModule.ReadRecord() ) { printf("<DDFRecord>\n"); int nFieldCount = poRecord->GetFieldCount(); for( int iField = 0; iField < nFieldCount; iField++ ) { DDFField* poField = poRecord->GetField(iField); DDFFieldDefn* poDefn = poField->GetFieldDefn(); const char* pszFieldName = poDefn->GetName(); printf(" <DDFField name=\"%s\"", pszFieldName); if( poField->GetRepeatCount() > 1 ) printf(" repeatCount=\"%d\"", poField->GetRepeatCount()); int iOffset = 0, nLoopCount; int nRepeatCount = poField->GetRepeatCount(); const char* pachData = poField->GetData(); int nDataSize = poField->GetDataSize(); if( nRepeatCount == 1 && poDefn->GetSubfieldCount() == 0 ) { printf(" value=\"0x"); for( int i = 0; i < nDataSize - 1; i++ ) printf( "%02X", pachData[i] ); printf("\">\n"); } else printf(">\n"); for( nLoopCount = 0; nLoopCount < nRepeatCount; nLoopCount++ ) { for( int iSubField = 0; iSubField < poDefn->GetSubfieldCount(); iSubField++ ) { int nBytesConsumed; DDFSubfieldDefn* poSubFieldDefn = poDefn->GetSubfield(iSubField); const char* pszSubFieldName = poSubFieldDefn->GetName(); printf(" <DDFSubfield name=\"%s\" ", pszSubFieldName); DDFDataType eType = poSubFieldDefn->GetType(); const char* pachSubdata = pachData + iOffset; int nMaxBytes = nDataSize - iOffset; if( eType == DDFFloat ) printf("type=\"float\">%f", poSubFieldDefn->ExtractFloatData( pachSubdata, nMaxBytes, NULL ) ); else if( eType == DDFInt ) printf("type=\"integer\">%d", poSubFieldDefn->ExtractIntData( pachSubdata, nMaxBytes, NULL ) ); else if( eType == DDFBinaryString ) { int nBytes, i; GByte *pabyBString = (GByte *) poSubFieldDefn->ExtractStringData( pachSubdata, nMaxBytes, &nBytes ); printf( "type=\"binary\">0x" ); for( i = 0; i < nBytes; i++ ) printf( "%02X", pabyBString[i] ); } else { GByte* pabyString = (GByte *)poSubFieldDefn->ExtractStringData( pachSubdata, nMaxBytes, NULL ); int bBinary = FALSE; int i; for( i = 0; pabyString[i] != '\0'; i ++ ) { if( pabyString[i] < 32 || pabyString[i] > 127 ) { bBinary = TRUE; break; } } if( bBinary ) { printf( "type=\"binary\">0x" ); for( i = 0; pabyString[i] != '\0'; i ++ ) printf( "%02X", pabyString[i] ); } else { char* pszEscaped = CPLEscapeString((const char*)pabyString, -1, CPLES_XML); printf("type=\"string\">%s", pszEscaped); CPLFree(pszEscaped); } } printf("</DDFSubfield>\n"); poSubFieldDefn->GetDataLength( pachSubdata, nMaxBytes, &nBytesConsumed ); iOffset += nBytesConsumed; } } printf(" </DDFField>\n"); } printf("</DDFRecord>\n"); } printf("</DDFModule>\n"); } else { oModule.Dump( stdout ); long nStartLoc; nStartLoc = VSIFTellL( oModule.GetFP() ); for( poRecord = oModule.ReadRecord(); poRecord != NULL; poRecord = oModule.ReadRecord() ) { printf( "File Offset: %ld\n", nStartLoc ); poRecord->Dump( stdout ); nStartLoc = VSIFTellL( oModule.GetFP() ); } } oModule.Close(); #ifdef DBMALLOC malloc_dump(1); #endif }
static void AddPrimaryAttrToDBFSchema( DBFHandle hDBF, SDTSTransfer *poTransfer, char ** papszModuleList ) { for( int iModule = 0; papszModuleList != NULL && papszModuleList[iModule] != NULL; iModule++ ) { SDTSAttrReader *poAttrReader; /* -------------------------------------------------------------------- */ /* Get a reader on the desired module. */ /* -------------------------------------------------------------------- */ poAttrReader = (SDTSAttrReader *) poTransfer->GetLayerIndexedReader( poTransfer->FindLayer( papszModuleList[iModule] ) ); if( poAttrReader == NULL ) { printf( "Unable to open attribute module %s, skipping.\n" , papszModuleList[iModule] ); continue; } poAttrReader->Rewind(); /* -------------------------------------------------------------------- */ /* Read the first record so we can clone schema information off */ /* of it. */ /* -------------------------------------------------------------------- */ SDTSAttrRecord *poAttrFeature; poAttrFeature = (SDTSAttrRecord *) poAttrReader->GetNextFeature(); if( poAttrFeature == NULL ) { fprintf( stderr, "Didn't find any meaningful attribute records in %s.\n", papszModuleList[iModule] ); continue; } /* -------------------------------------------------------------------- */ /* Clone schema off the first record. Eventually we need to */ /* get the information out of the DDR record, but it isn't */ /* clear to me how to accomplish that with the SDTS++ API. */ /* */ /* The following approach may fail (dramatically) if some */ /* records do not include all subfields. Furthermore, no */ /* effort is made to make DBF field names unique. The SDTS */ /* attributes often have names much beyond the 14 character dbf */ /* limit which may result in non-unique attributes. */ /* -------------------------------------------------------------------- */ DDFFieldDefn *poFDefn = poAttrFeature->poATTR->GetFieldDefn(); int iSF; DDFField *poSR = poAttrFeature->poATTR; for( iSF=0; iSF < poFDefn->GetSubfieldCount(); iSF++ ) { DDFSubfieldDefn *poSFDefn = poFDefn->GetSubfield( iSF ); int nWidth = poSFDefn->GetWidth(); switch( poSFDefn->GetType() ) { case DDFString: if( nWidth == 0 ) { int nMaxBytes; const char * pachData = poSR->GetSubfieldData(poSFDefn, &nMaxBytes); nWidth = strlen(poSFDefn->ExtractStringData(pachData, nMaxBytes, NULL )); } DBFAddField( hDBF, poSFDefn->GetName(), FTString, nWidth, 0 ); break; case DDFInt: if( nWidth == 0 ) nWidth = 9; DBFAddField( hDBF, poSFDefn->GetName(), FTInteger, nWidth, 0 ); break; case DDFFloat: DBFAddField( hDBF, poSFDefn->GetName(), FTDouble, 18, 6 ); break; default: fprintf( stderr, "Dropping attribute `%s' of module `%s'. " "Type unsupported\n", poSFDefn->GetName(), papszModuleList[iModule] ); break; } } if( !poAttrReader->IsIndexed() ) delete poAttrFeature; } /* next module */ }
int SDTSRasterReader::GetBlock( int nXOffset, int nYOffset, void * pData ) { DDFRecord *poRecord = NULL; int nBytesPerValue; int iTry; CPLAssert( nXOffset == 0 ); /* -------------------------------------------------------------------- */ /* Analyse the datatype. */ /* -------------------------------------------------------------------- */ CPLAssert( EQUAL(szFMT,"BI16") || EQUAL(szFMT,"BFP32") ); if( EQUAL(szFMT,"BI16") ) nBytesPerValue = 2; else nBytesPerValue = 4; for(iTry=0;iTry<2;iTry++) { /* -------------------------------------------------------------------- */ /* Read through till we find the desired record. */ /* -------------------------------------------------------------------- */ CPLErrorReset(); while( (poRecord = oDDFModule.ReadRecord()) != NULL ) { if( poRecord->GetIntSubfield( "CELL", 0, "ROWI", 0 ) == nYOffset + nYStart ) { break; } } if( CPLGetLastErrorType() == CE_Failure ) return FALSE; /* -------------------------------------------------------------------- */ /* If we didn't get what we needed just start over. */ /* -------------------------------------------------------------------- */ if( poRecord == NULL ) { if (iTry == 0) oDDFModule.Rewind(); else { CPLError( CE_Failure, CPLE_AppDefined, "Cannot read scanline %d. Raster access failed.\n", nYOffset ); return FALSE; } } else { break; } } /* -------------------------------------------------------------------- */ /* Validate the records size. Does it represent exactly one */ /* scanline? */ /* -------------------------------------------------------------------- */ DDFField *poCVLS; poCVLS = poRecord->FindField( "CVLS" ); if( poCVLS == NULL ) return FALSE; if( poCVLS->GetRepeatCount() != nXSize ) { CPLError( CE_Failure, CPLE_AppDefined, "Cell record is %d long, but we expected %d, the number\n" "of pixels in a scanline. Raster access failed.\n", poCVLS->GetRepeatCount(), nXSize ); return FALSE; } /* -------------------------------------------------------------------- */ /* Does the CVLS field consist of exactly 1 B(16) field? */ /* -------------------------------------------------------------------- */ if( poCVLS->GetDataSize() < nBytesPerValue * nXSize || poCVLS->GetDataSize() > nBytesPerValue * nXSize + 1 ) { CPLError( CE_Failure, CPLE_AppDefined, "Cell record is not of expected format. Raster access " "failed.\n" ); return FALSE; } /* -------------------------------------------------------------------- */ /* Copy the data to the application buffer, and byte swap if */ /* required. */ /* -------------------------------------------------------------------- */ memcpy( pData, poCVLS->GetData(), nXSize * nBytesPerValue ); #ifdef CPL_LSB if( nBytesPerValue == 2 ) { for( int i = 0; i < nXSize; i++ ) { ((GInt16 *) pData)[i] = CPL_MSBWORD16(((GInt16 *) pData)[i]); } } else { for( int i = 0; i < nXSize; i++ ) { CPL_MSBPTR32( ((GByte *)pData) + i*4 ); } } #endif return TRUE; }