int OGRAVCE00DataSource::Open( const char * pszNewName, int bTestOpen ) { /* -------------------------------------------------------------------- */ /* Open the source file. Supress error reporting if we are in */ /* TestOpen mode. */ /* -------------------------------------------------------------------- */ int bCompressed = FALSE; if( bTestOpen ) CPLPushErrorHandler( CPLQuietErrorHandler ); psE00 = AVCE00ReadOpenE00(pszNewName); if( CPLGetLastErrorNo() == CPLE_OpenFailed && strstr(CPLGetLastErrorMsg(),"compressed E00") != NULL ) { bCompressed = TRUE; } if( bTestOpen ) { CPLPopErrorHandler(); CPLErrorReset(); } if( psE00 == NULL ) { if( bCompressed ) { CPLError(CE_Failure, CPLE_OpenFailed, "This looks like a compressed E00 file and cannot be " "processed directly. You may need to uncompress it " "first using the E00compr library or the e00conv " "program." ); } return FALSE; } pszName = CPLStrdup( pszNewName ); /* pszCoverageName = CPLStrdup( psE00->pszCoverName ); */ pszCoverageName = CPLStrdup( pszNewName ); /* -------------------------------------------------------------------- */ /* Create layers for the "interesting" sections of the coverage. */ /* -------------------------------------------------------------------- */ int iSection; papoLayers = (OGRAVCE00Layer **) CPLCalloc( sizeof(OGRAVCE00Layer *), psE00->numSections ); nLayers = 0; for( iSection = 0; iSection < psE00->numSections; iSection++ ) { AVCE00Section *psSec = psE00->pasSections + iSection; switch( psSec->eType ) { case AVCFileARC: case AVCFilePAL: case AVCFileCNT: case AVCFileLAB: case AVCFileRPL: case AVCFileTXT: papoLayers[nLayers++] = new OGRAVCE00Layer( this, psSec ); break; case AVCFileTX6: break; case AVCFileTABLE: CheckAddTable(psSec); break; case AVCFilePRJ: { #if 0 poSRS = new OGRSpatialReference(); char **papszPRJ; AVCE00File *hFile; hFile = AVCE00ReadOpen(psE00->pszCoverPath, psSec->pszFilename, psE00->eCoverType, psSec->eType, psE00->psDBCSInfo); if( hFile && poSRS == NULL ) { papszPRJ = AVCE00ReadNextPrj( hFile ); poSRS = new OGRSpatialReference(); if( poSRS->importFromESRI( papszPRJ ) != OGRERR_NONE ) { CPLError( CE_Warning, CPLE_AppDefined, "Failed to parse PRJ section, ignoring." ); delete poSRS; poSRS = NULL; } AVCE00ReadClose( hFile ); } #endif } break; default: ; } } return nLayers > 0; }
int OGRAVCE00Layer::CheckSetupTable(AVCE00Section *psTblSectionIn) { if (psTableRead) return FALSE; const char *pszTableType = NULL; switch (eSectionType) { case AVCFileARC: pszTableType = ".AAT"; break; case AVCFilePAL: case AVCFileLAB: pszTableType = ".PAT"; break; default: break; } /* -------------------------------------------------------------------- */ /* Is the table type found anywhere in the section pszName? Do */ /* a case insensitive check. */ /* -------------------------------------------------------------------- */ if( pszTableType == NULL ) return FALSE; int iCheckOff; for( iCheckOff = 0; psTblSectionIn->pszName[iCheckOff] != '\0'; iCheckOff++ ) { if( EQUALN(psTblSectionIn->pszName + iCheckOff, pszTableType, strlen(pszTableType) ) ) break; } if( psTblSectionIn->pszName[iCheckOff] == '\0' ) return FALSE; psTableSection = psTblSectionIn; /* -------------------------------------------------------------------- */ /* Try opening the table. */ /* -------------------------------------------------------------------- */ psTableRead = AVCE00ReadOpenE00(psTblSectionIn->pszFilename); if (psTableRead == NULL) return FALSE; /* advance to the specified line number */ if (AVCE00ReadGotoSectionE00(psTableRead, psTableSection, 0) != 0) { AVCE00ReadCloseE00(psTableRead); psTableRead = NULL; return FALSE; } AVCE00ReadNextObjectE00(psTableRead); bNeedReset = 1; pszTableFilename = CPLStrdup(psTblSectionIn->pszFilename); nTableBaseField = poFeatureDefn->GetFieldCount(); if (eSectionType == AVCFileLAB) { AVCE00ReadE00Ptr psInfo = ((OGRAVCE00DataSource *) poDS)->GetInfo(); for( int iSection = 0; iSection < psInfo->numSections; iSection++ ) { if( psInfo->pasSections[iSection].eType == AVCFilePAL ) nTableAttrIndex = poFeatureDefn->GetFieldIndex( "PolyId" ); } } /* -------------------------------------------------------------------- */ /* Setup attributes. */ /* -------------------------------------------------------------------- */ AppendTableDefinition( psTableRead->hParseInfo->hdr.psTableDef ); /* -------------------------------------------------------------------- */ /* Close table so we don't have to many files open at once. */ /* -------------------------------------------------------------------- */ /* AVCE00ReadCloseE00( psTableRead ); */ return TRUE; }
int OGRAVCE00Layer::AppendTableFields( OGRFeature *poFeature ) { if (psTableRead == NULL) return FALSE; /* -------------------------------------------------------------------- */ /* Open the table if it is currently closed. */ /* -------------------------------------------------------------------- */ if (psTableRead == NULL) { psTableRead = AVCE00ReadOpenE00(pszTableFilename); if (psTableRead == NULL) return FALSE; /* advance to the specified line number */ if (AVCE00ReadGotoSectionE00(psTableRead, psTableSection, 0) != 0) { AVCE00ReadCloseE00(psTableRead); psTableRead = NULL; return FALSE; } nTablePos = 0; } /* -------------------------------------------------------------------- */ /* Read the info record. */ /* */ /* We usually assume the FID of the feature is the key but in a */ /* polygon coverage we need to use the PolyId attribute of LAB */ /* features to lookup the related attributes. In this case */ /* nTableAttrIndex will already be setup to refer to the */ /* PolyId field. */ /* -------------------------------------------------------------------- */ int nRecordId; void *hRecord; if( nTableAttrIndex == -1 ) nRecordId = (int) poFeature->GetFID(); else nRecordId = poFeature->GetFieldAsInteger( nTableAttrIndex ); if (nRecordId <= nTablePos) { if (AVCE00ReadGotoSectionE00(psTableRead, psTableSection, 0) != 0) return FALSE; nTablePos = 0; } do { hRecord = AVCE00ReadNextObjectE00(psTableRead); ++nTablePos; } while (NULL != hRecord && nTablePos < nRecordId); if( hRecord == NULL ) return FALSE; /* -------------------------------------------------------------------- */ /* Translate it. */ /* -------------------------------------------------------------------- */ return TranslateTableFields( poFeature, nTableBaseField, psTableRead->hParseInfo->hdr.psTableDef, (AVCField *) hRecord ); }
OGRFeature *OGRAVCE00Layer::GetFeature( GIntBig nFID ) { /* -------------------------------------------------------------------- */ /* If we haven't started yet, open the file now. */ /* -------------------------------------------------------------------- */ if( psRead == NULL ) { psRead = AVCE00ReadOpenE00(psSection->pszFilename); if (psRead == NULL) return NULL; /* advance to the specified line number */ if (AVCE00ReadGotoSectionE00(psRead, psSection, 0) != 0) return NULL; nNextFID = 1; } /* -------------------------------------------------------------------- */ /* Read the raw feature - the -3 fid is a special flag */ /* indicating serial access. */ /* -------------------------------------------------------------------- */ void *pFeature; if( nFID == -3 ) { while( (pFeature = AVCE00ReadNextObjectE00(psRead)) != NULL && psRead->hParseInfo->eFileType != AVCFileUnknown && !MatchesSpatialFilter( pFeature ) ) { nNextFID++; } } else { bNeedReset = TRUE; if (nNextFID > nFID) { /* advance to the specified line number */ if (AVCE00ReadGotoSectionE00(psRead, psSection, 0) != 0) return NULL; } do { pFeature = AVCE00ReadNextObjectE00(psRead); ++nNextFID; } while (NULL != pFeature && nNextFID <= nFID); } if( pFeature == NULL ) return NULL; /* -------------------------------------------------------------------- */ /* Translate the feature. */ /* -------------------------------------------------------------------- */ OGRFeature *poFeature; poFeature = TranslateFeature( pFeature ); if( poFeature == NULL ) return NULL; /* -------------------------------------------------------------------- */ /* LAB's we have to assign the FID to directly, since it */ /* doesn't seem to be stored in the file structure. */ /* -------------------------------------------------------------------- */ if( psSection->eType == AVCFileLAB ) { if( nFID == -3 ) poFeature->SetFID( nNextFID++ ); else poFeature->SetFID( nFID ); } /* -------------------------------------------------------------------- */ /* If this is a polygon layer, try to assemble the arcs to form */ /* the whole polygon geometry. */ /* -------------------------------------------------------------------- */ if( psSection->eType == AVCFilePAL || psSection->eType == AVCFileRPL ) { FormPolygonGeometry( poFeature, (AVCPal *) pFeature ); } /* -------------------------------------------------------------------- */ /* If we have an attribute table, append the attributes now. */ /* -------------------------------------------------------------------- */ AppendTableFields( poFeature ); return poFeature; }