⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tabdump.cpp

📁 mitab,读取MapInfo的地图文件
💻 CPP
📖 第 1 页 / 共 3 页
字号:
 *                          DumpMapFileBlocks()
 *
 * Read and dump a .MAP file... simply dump all blocks sequentially.
 **********************************************************************/
static int DumpMapFileBlocks(const char *pszFname)
{
    FILE        *fp;
    TABRawBinBlock *poBlock;
    int         nOffset = 0;
    VSIStatBuf  sStatBuf;

    /*---------------------------------------------------------------------
     * Try to open source file
     * Note: we use stat() to fetch the file size.
     *--------------------------------------------------------------------*/
    if ( VSIStat(pszFname, &sStatBuf) == -1 )
    {
        printf("stat() failed for %s\n", pszFname);
        return -1;
    }

    fp = fopen(pszFname, "rb");
    if (fp == NULL)
    {
        printf("Failed to open %s\n", pszFname);
        return -1;
    }


    /*---------------------------------------------------------------------
     * Read/Dump blocks until EOF is reached
     *--------------------------------------------------------------------*/
    while (nOffset < sStatBuf.st_size )
    {
        poBlock = TABCreateMAPBlockFromFile(fp, nOffset, 512);

        if (poBlock)
        {
            poBlock->Dump();
            printf("\n");
            delete poBlock;
        }
        else
        {
            // An error happened (could be EOF)... abort now.
            break;
        }

        nOffset += 512;
    }

    /*---------------------------------------------------------------------
     * Cleanup and exit.
     *--------------------------------------------------------------------*/
    fclose(fp);

    return 0;
}


/**********************************************************************
 *                          DumpMapFileObjects()
 *
 * Open a .MAP file and print all the geogr. objects found.
 **********************************************************************/
static int DumpMapFileObjects(const char *pszFname)
{
    TABMAPFile  oMAPFile;

    /*---------------------------------------------------------------------
     * Try to open source file
     *--------------------------------------------------------------------*/
    if (oMAPFile.Open(pszFname, "rb") != 0)
    {
        printf("Failed to open %s\n", pszFname);
        return -1;
    }

    oMAPFile.Dump();

    /*---------------------------------------------------------------------
     * Read/Dump objects until EOF is reached
     *--------------------------------------------------------------------*/
    while ( 0 )
    {

    }

    /*---------------------------------------------------------------------
     * Cleanup and exit.
     *--------------------------------------------------------------------*/
    oMAPFile.Close();

    return 0;
}


/**********************************************************************
 *                          DumpMapFileIndexTree2MIF()
 *
 * Open a .MAP file and dump the index tree to a .MIF file
 **********************************************************************/
static int DumpMapFileIndexTree2MIF(const char *pszFname, int nMaxDepth)
{
    TABMAPFile  oMAPFile;
    FILE *fpMIF, *fpMID;

    /*---------------------------------------------------------------------
     * Try to open source file
     *--------------------------------------------------------------------*/
    if (oMAPFile.Open(pszFname, "rb") != 0)
    {
        printf("Failed to open %s\n", pszFname);
        return -1;
    }

    /*---------------------------------------------------------------------
     * Create MIF/MID dataset
     *--------------------------------------------------------------------*/
    if ((fpMIF=VSIFOpen(CPLSPrintf("%s.spindex.mif",pszFname),"wt"))==NULL)
    {
        printf("Unable to create %s\n", CPLSPrintf("%s.spindex.mif",pszFname));
        return -1;
    }

    if ((fpMID=VSIFOpen(CPLSPrintf("%s.spindex.mid",pszFname),"wt"))==NULL)
    {
        printf("Unable to create %s\n", CPLSPrintf("%s.spindex.mid",pszFname));
        return -1;
    }

    printf("Dumping spatial index from %s to %s.spindex.mif/.mid\n", 
           pszFname, pszFname);

    VSIFPrintf(fpMIF, 
               "VERSION 300\n"
               "CHARSET \"Neutral\"\n"
               "DELIMITER \",\"\n"
               "COLUMNS 9\n"
               "  ID        integer\n"
               "  PARENT_ID integer\n"
               "  ID_IN_NODE integer\n"
               "  DEPTH     integer\n"
               "  AREA      integer\n"
               "  XMIN      integer\n"
               "  YMIN      integer\n"
               "  XMAX      integer\n"
               "  YMAX      integer\n"
               "DATA\n");

    /*---------------------------------------------------------------------
     * Dump spatial Index Tree
     *--------------------------------------------------------------------*/
    oMAPFile.DumpSpatialIndexToMIF(NULL, fpMIF, fpMID, -1, -1, 0, nMaxDepth);

    /*---------------------------------------------------------------------
     * Cleanup and exit.
     *--------------------------------------------------------------------*/
    oMAPFile.Close();

    VSIFClose(fpMIF);
    VSIFClose(fpMID);

    return 0;
}

/**********************************************************************
 *                          DumpMapFileBlockDetails()
 *
 * Read and dump specified map file block.
 **********************************************************************/
static int DumpMapFileBlockDetails(const char *pszFname, int nOffset)
{
    FILE        *fp;
    TABRawBinBlock *poBlock;

    /*---------------------------------------------------------------------
     * Try to open source file
     * Note: we use stat() to fetch the file size.
     *--------------------------------------------------------------------*/
    fp = fopen(pszFname, "rb");
    if (fp == NULL)
    {
        printf("Failed to open %s\n", pszFname);
        return -1;
    }

    /*---------------------------------------------------------------------
     * Read/Dump blocks until EOF is reached
     *--------------------------------------------------------------------*/
    poBlock = TABCreateMAPBlockFromFile(fp, nOffset, 512);

    if (poBlock)
    {
        switch(poBlock->GetBlockClass())
        {
          case TABMAP_OBJECT_BLOCK:
            ((TABMAPObjectBlock*)poBlock)->Dump(NULL, TRUE);
            break;
          default:
            poBlock->Dump(NULL);
        }

        printf("\n");
        delete poBlock;
    }

    /*---------------------------------------------------------------------
     * Cleanup and exit.
     *--------------------------------------------------------------------*/
    fclose(fp);

    return 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;
}


/**********************************************************************
 *                          DumpIndFileObjects()
 *
 * Read and dump a .IND file
 **********************************************************************/
static int DumpIndFileObjects(const char *pszFname)
{
    TABINDFile  oINDFile;

    /*---------------------------------------------------------------------
     * Try to open source file
     *--------------------------------------------------------------------*/
    if (oINDFile.Open(pszFname, "rb") != 0)
    {
        printf("Failed to open %s\n", pszFname);
        return -1;
    }

    // oINDFile.SetIndexFieldType(1,TABFChar);
    oINDFile.Dump();

    /*---------------------------------------------------------------------
     * Read/Dump objects until EOF is reached
     *--------------------------------------------------------------------*/
    while ( 0 )
    {

    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -