Exemplo n.º 1
0
/**********************************************************************
 *                          DumpTabFile()
 *
 * Open a .TAB file and print all the geogr. objects found.
 **********************************************************************/
static int DumpTabFile(const char *pszFname)
{
    IMapInfoFile  *poFile;
    int      nFeatureId;
    TABFeature *poFeature;

    /*---------------------------------------------------------------------
     * Try to open source file
     *--------------------------------------------------------------------*/
    if ((poFile = IMapInfoFile::SmartOpen(pszFname)) == NULL)
    {
        printf("Failed to open %s\n", pszFname);
        return -1;
    }

    poFile->Dump();

    /*---------------------------------------------------------------------
     * Check for indexed fields
     *--------------------------------------------------------------------*/
    for(int iField=0; iField<poFile->GetLayerDefn()->GetFieldCount(); iField++)
    {
        if (poFile->IsFieldIndexed(iField))
            printf("  Field %d is indexed\n", iField);
    }

    /*---------------------------------------------------------------------
     * Read/Dump objects until EOF is reached
     *--------------------------------------------------------------------*/
    nFeatureId = -1;
    while ( (nFeatureId = poFile->GetNextFeatureId(nFeatureId)) != -1 )
    {
        poFeature = poFile->GetFeatureRef(nFeatureId);
        if (poFeature)
        {
//            poFeature->DumpReadable(stdout);
            printf("\nFeature %d:\n", nFeatureId);
            poFeature->DumpMID();
            poFeature->DumpMIF();
        }
        else
            break;      // GetFeatureRef() failed: Abort the loop
    }

    /*---------------------------------------------------------------------
     * Cleanup and exit.
     *--------------------------------------------------------------------*/
    poFile->Close();

    delete poFile;

    return 0;
}
Exemplo n.º 2
0
/**********************************************************************
 *                          DumpViaSpatialIndex()
 *
 * Open a .TAB file and print all the geogr. objects that match the 
 * specified filter.  Scanes the file via the spatial index.
 **********************************************************************/
static int DumpViaSpatialIndex(const char *pszFname, 
                               double dXMin, double dYMin, 
                               double dXMax, double dYMax)
{
    IMapInfoFile  *poFile;
    TABFeature *poFeature;

    /*---------------------------------------------------------------------
     * Try to open source file
     *--------------------------------------------------------------------*/
    if ((poFile = IMapInfoFile::SmartOpen(pszFname)) == NULL)
    {
        printf("Failed to open %s\n", pszFname);
        return -1;
    }

    poFile->Dump();

    /*---------------------------------------------------------------------
     * Check for indexed fields
     *--------------------------------------------------------------------*/
    for(int iField=0; iField<poFile->GetLayerDefn()->GetFieldCount(); iField++)
    {
        if (poFile->IsFieldIndexed(iField))
            printf("  Field %d is indexed\n", iField);
    }


    /*---------------------------------------------------------------------
     * Set spatial filter
     *--------------------------------------------------------------------*/
    OGRLinearRing oSpatialFilter;

    oSpatialFilter.setNumPoints(5);
    oSpatialFilter.setPoint(0, dXMin, dYMin);
    oSpatialFilter.setPoint(1, dXMax, dYMin);
    oSpatialFilter.setPoint(2, dXMax, dYMax);
    oSpatialFilter.setPoint(3, dXMin, dYMax);
    oSpatialFilter.setPoint(4, dXMin, dYMin);

    poFile->SetSpatialFilter( &oSpatialFilter );

    /*---------------------------------------------------------------------
     * Read/Dump objects until EOF is reached
     *--------------------------------------------------------------------*/
    while ( (poFeature = (TABFeature*)poFile->GetNextFeature()) != NULL )
    {
//        poFeature->DumpReadable(stdout);
        printf("\nFeature %ld:\n", poFeature->GetFID());
        poFeature->DumpMID();
        poFeature->DumpMIF();
    }

    /*---------------------------------------------------------------------
     * Cleanup and exit.
     *--------------------------------------------------------------------*/
    poFile->Close();

    delete poFile;

    return 0;
}