Ejemplo n.º 1
0
/**********************************************************************
 *                          ConvertCover()
 *
 * Convert a complete coverage to E00.
 **********************************************************************/
static void ConvertCoveravctoe00(const char *pszFname, FILE *fpOut)
{
    AVCE00ReadPtr hReadInfo;
    const char *pszLine;

    hReadInfo = AVCE00ReadOpen(pszFname);

    if (hReadInfo)
    {
        while ((pszLine = AVCE00ReadNextLine(hReadInfo)) != NULL)
        {
            fprintf(fpOut, "%s\n", pszLine);
        }

        AVCE00ReadClose(hReadInfo);
    }
}
Ejemplo n.º 2
0
int OGRAVCBinDataSource::Open( const char * pszNewName, int bTestOpen )

{
/* -------------------------------------------------------------------- */
/*      Open the source file.  Supress error reporting if we are in     */
/*      TestOpen mode.                                                  */
/* -------------------------------------------------------------------- */
    if( bTestOpen )
        CPLPushErrorHandler( CPLQuietErrorHandler );

    psAVC = AVCE00ReadOpen( pszNewName );

    if( bTestOpen )
    {
        CPLPopErrorHandler();
        CPLErrorReset();
    }

    if( psAVC == NULL )
        return FALSE;

    pszName = CPLStrdup( pszNewName );
    pszCoverageName = CPLStrdup( psAVC->pszCoverName );

/* -------------------------------------------------------------------- */
/*      Create layers for the "interesting" sections of the coverage.   */
/* -------------------------------------------------------------------- */
    int		iSection;

    papoLayers = (OGRLayer **)
        CPLCalloc( sizeof(OGRLayer *), psAVC->numSections );
    nLayers = 0;

    for( iSection = 0; iSection < psAVC->numSections; iSection++ )
    {
        AVCE00Section *psSec = psAVC->pasSections + iSection;

        switch( psSec->eType )
        {
          case AVCFileARC:
          case AVCFilePAL:
          case AVCFileCNT:
          case AVCFileLAB:
          case AVCFileRPL:
          case AVCFileTXT:
          case AVCFileTX6:
            papoLayers[nLayers++] = new OGRAVCBinLayer( this, psSec );
            break;

          case AVCFilePRJ:
          {
              char 	**papszPRJ;
              AVCBinFile *hFile;
              
              hFile = AVCBinReadOpen(psAVC->pszCoverPath, 
                                     psSec->pszFilename, 
                                     psAVC->eCoverType, 
                                     psSec->eType,
                                     psAVC->psDBCSInfo);
              if( hFile && poSRS == NULL )
              {
                  papszPRJ = AVCBinReadNextPrj( 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;
                  }
                  AVCBinReadClose( hFile );
              }
          }
          break;

          default:
            ;
        }
    }
    
    return nLayers > 0;
}
Ejemplo n.º 3
0
/**********************************************************************
 *                          AVCE00DeleteCoverage()
 *
 * Delete a coverage directory, its contents, and the associated info
 * tables.
 *
 * Note:
 * When deleting tables, only the ../info/arc????.nit and arc????.dat
 * need to be deleted; the arc.dir does not need to be updated.  This
 * is exactly what Arc/Info's KILL command does.
 *
 * Returns 0 on success or -1 on error.
 **********************************************************************/
int     AVCE00DeleteCoverage(const char *pszCoverToDelete)
{
    int i, j, nStatus = 0;
    char *pszInfoPath, *pszCoverPath, *pszCoverName;
    const char *pszFname;
    char **papszTables=NULL, **papszFiles=NULL;
    AVCE00ReadPtr   psInfo;
    VSIStatBuf      sStatBuf;

    CPLErrorReset();

    /*-----------------------------------------------------------------
     * Since we don't want to duplicate all the logic to figure coverage
     * and info dir name, etc... we'll simply open the coverage and
     * grab the info we need from the coverage handle.
     * By the same way, this will verify that the coverage exists and is
     * valid.
     *----------------------------------------------------------------*/
    psInfo = AVCE00ReadOpen(pszCoverToDelete);

    if (psInfo == NULL)
    {
        CPLError(CE_Failure, CPLE_FileIO,
                 "Cannot delete coverage %s: it does not appear to be valid\n",
                 pszCoverToDelete);
        return -1;
    }

    pszCoverPath = CPLStrdup(psInfo->pszCoverPath);
    pszInfoPath = CPLStrdup(psInfo->pszInfoPath);
    pszCoverName = CPLStrdup(psInfo->pszCoverName);

    AVCE00ReadClose(psInfo);

    /*-----------------------------------------------------------------
     * Delete files in cover directory.
     *----------------------------------------------------------------*/
    papszFiles = CPLReadDir(pszCoverPath);
    for(i=0; nStatus==0 && papszFiles && papszFiles[i]; i++)
    {
        if (!EQUAL(".", papszFiles[i]) &&
            !EQUAL("..", papszFiles[i]))
        {
            pszFname = CPLSPrintf("%s%s", pszCoverPath, papszFiles[i]);
            if (unlink(pszFname) != 0)
            {
                CPLError(CE_Failure, CPLE_FileIO, 
                         "Failed deleting %s%s: %s", 
                         pszCoverPath, papszFiles[i], strerror);
                nStatus = -1;
                break;
            }
        }
    }

    CSLDestroy(papszFiles);
    papszFiles = NULL;

    /*-----------------------------------------------------------------
     * Get the list of info files (ARC????) to delete and delete them
     *----------------------------------------------------------------*/
    if (nStatus == 0)
    {
        papszTables = AVCBinReadListTables(pszInfoPath, 
                                           pszCoverName,
                                           &papszFiles);

        for(i=0; nStatus==0 && papszFiles && papszFiles[i]; i++)
        {
            /* Convert table filename to lowercases */
            for(j=0; papszFiles[i] && papszFiles[i][j]!='\0'; j++)
                papszFiles[i][j] = tolower(papszFiles[i][j]);

            /* Delete the .DAT file */
            pszFname = CPLSPrintf("%s%s.dat", pszInfoPath, papszFiles[i]);
            if ( VSIStat(pszFname, &sStatBuf) != -1 &&
                 unlink(pszFname) != 0)
            {
                CPLError(CE_Failure, CPLE_FileIO, 
                         "Failed deleting %s%s: %s", 
                         pszInfoPath, papszFiles[i], strerror);
                nStatus = -1;
                break;
            }

            /* Delete the .DAT file */
            pszFname = CPLSPrintf("%s%s.nit", pszInfoPath, papszFiles[i]);
            if ( VSIStat(pszFname, &sStatBuf) != -1 &&
                 unlink(pszFname) != 0)
            {
                CPLError(CE_Failure, CPLE_FileIO, 
                         "Failed deleting %s%s: %s", 
                         pszInfoPath, papszFiles[i], strerror);
                nStatus = -1;
                break;
            }
        }

        CSLDestroy(papszTables);
        CSLDestroy(papszFiles);
    }


    /*-----------------------------------------------------------------
     * Delete the coverage directory itself
     *----------------------------------------------------------------*/
     if (rmdir(pszCoverPath) != 0)
    {
        CPLError(CE_Failure, CPLE_FileIO, 
                 "Failed deleting directory %s: %s", pszCoverPath, strerror);
        nStatus = -1;
    }


    CPLFree(pszCoverPath);
    CPLFree(pszInfoPath);
    CPLFree(pszCoverName);

    return nStatus;
}
Ejemplo n.º 4
0
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;
}