📄 tabdump.cpp
字号:
/********************************************************************** * $Id: tabdump.cpp,v 1.14 2005/03/22 23:24:54 dmorissette Exp $ * * Name: tabdump.cpp * Project: MapInfo TAB format Read/Write library * Language: C++ * Purpose: Test various part of the lib., and generate binary dumps. * Author: Daniel Morissette, dmorissette@dmsolutions.ca * ********************************************************************** * Copyright (c) 1999-2001, Daniel Morissette * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. ********************************************************************** * * $Log: tabdump.cpp,v $ * Revision 1.14 2005/03/22 23:24:54 dmorissette * Added support for datum id in .MAP header (bug 910) * * Revision 1.13 2004/06/30 20:29:04 dmorissette * Fixed refs to old address danmo@videotron.ca * * Revision 1.12 2001/11/16 20:55:00 daniel * Added -d option: DumpMapFileBlockDetails() * * Revision 1.11 2001/09/19 14:33:19 warmerda * support mif files for dumping with -all * * Revision 1.10 2001/09/17 19:52:50 daniel * Added DumpViaSpatialIndex() * * Revision 1.9 2001/07/04 14:13:24 daniel * Added GetExtent() output in DumpCoordsys() * * Revision 1.8 2001/01/23 21:23:42 daniel * Added projection bounds lookup table, called from TABFile::SetProjInfo() * * Revision 1.7 2000/11/13 22:05:45 daniel * Added SearchIndex() - For string indexes only * * Revision 1.6 2000/10/18 03:57:55 daniel * Added DumpCoordsys() * * Revision 1.5 2000/02/28 17:14:31 daniel * Report indexed fields * * Revision 1.4 2000/01/15 22:30:45 daniel * Switch to MIT/X-Consortium OpenSource license * * Revision 1.3 1999/12/14 02:24:41 daniel * Use IMapInfoFile::SmartOpen() * * Revision 1.2 1999/09/20 14:27:49 warmerda * Use access of "rb" instead of "r". * * Revision 1.1 1999/07/12 04:18:26 daniel * Initial checkin * **********************************************************************/#include "mitab.h"#include "mitab_utils.h"#include <ctype.h>static int DumpMapFileBlocks(const char *pszFname);static int DumpMapFileObjects(const char *pszFname);static int DumpMapFileBlockDetails(const char *pszFname, int nOffset);static int DumpIndFileObjects(const char *pszFname);static int DumpTabFile(const char *pszFname);static int DumpCoordsys(const char *pszFname);static int DumpCoordsysStruct(const char *pszFname);static int SearchIndex(const char *pszFname, int nIndexNo, const char *pszVal);static int DumpViaSpatialIndex(const char *pszFname, double dXMin, double dYMin, double dXMax, double dYMax);#define TABTEST_USAGE \ "Usage: tabdump -a|-all <filename>\n" \ " tabdump -b|-blocks <filename>\n" \ " tabdump -d|-details <filename> <block_offset>\n" \ " tabdump -o|-objects <filename>\n" \ " tabdump -i|-index <filename> <indexno> <val>\n" \ " tabdump -e|-envelope <filename> <xmin> <ymin> <ymax> <ymax>\n"/********************************************************************** * main() * * This program is used to dump binary files (default behavior), and to * test some parts of the lib. during the development process. **********************************************************************/int main(int argc, char *argv[]){ const char *pszFname;/*--------------------------------------------------------------------- * Read program arguments. *--------------------------------------------------------------------*/ if (argc<3) { printf("%s", TABTEST_USAGE); return 1; } else { pszFname = argv[2]; } /*--------------------------------------------------------------------- * With option -blocks <filename> * Open file, and dump each block sequentially. *--------------------------------------------------------------------*/ if (EQUALN(argv[1], "-blocks", 2)) { if (strstr(pszFname, ".map") != NULL || strstr(pszFname, ".MAP") != NULL) { DumpMapFileBlocks(pszFname); } else if (strstr(pszFname, ".ind") != NULL || strstr(pszFname, ".IND") != NULL) { DumpIndFileObjects(pszFname); } else if (strstr(pszFname, ".otherextension") != NULL) { ; } }/*--------------------------------------------------------------------- * With option -blocks <filename> * Open file, and dump each block sequentially. *--------------------------------------------------------------------*/ else if (EQUALN(argv[1], "-details", 2) && argc >= 4) { if (strstr(pszFname, ".map") != NULL || strstr(pszFname, ".MAP") != NULL) { DumpMapFileBlockDetails(pszFname, atoi(argv[3])); } else if (strstr(pszFname, ".otherextension") != NULL) { ; } }/*--------------------------------------------------------------------- * With option -objects <filename> * Open file, and all geogr. objects. *--------------------------------------------------------------------*/ else if (EQUALN(argv[1], "-objects", 2)) { if (strstr(pszFname, ".map") != NULL || strstr(pszFname, ".MAP") != NULL) { DumpMapFileObjects(pszFname); } else if (strstr(pszFname, ".tab") != NULL || strstr(pszFname, ".TAB") != NULL) { DumpTabFile(pszFname); } else if (strstr(pszFname, ".ind") != NULL || strstr(pszFname, ".IND") != NULL) { DumpIndFileObjects(pszFname); } }/*--------------------------------------------------------------------- * With option -all <filename> * Dump the whole TAB dataset (all supported files) *--------------------------------------------------------------------*/ else if (EQUALN(argv[1], "-all", 2)) { if (strstr(pszFname, ".tab") != NULL || strstr(pszFname, ".TAB") != NULL || strstr(pszFname, ".mif") != NULL || strstr(pszFname, ".MIF") != NULL) { DumpTabFile(pszFname); } }/*--------------------------------------------------------------------- * With option -coordsys <filename> * Dump the dataset's projection string *--------------------------------------------------------------------*/ else if (EQUALN(argv[1], "-coordsys", 2)) { if (strstr(pszFname, ".tab") != NULL || strstr(pszFname, ".TAB") != NULL) { DumpCoordsys(pszFname); } }/*--------------------------------------------------------------------- * With option -s <filename> * Dump the dataset's coordsys and bounds info in a C struct format *--------------------------------------------------------------------*/ else if (EQUALN(argv[1], "-s", 2)) { if (strstr(pszFname, ".tab") != NULL || strstr(pszFname, ".TAB") != NULL) { DumpCoordsysStruct(pszFname); } }/*--------------------------------------------------------------------- * With option -index <filename> <indexno> <value> * Search specified index for a value. *--------------------------------------------------------------------*/ else if (EQUALN(argv[1], "-index", 2) && argc >=5) { SearchIndex(pszFname, atoi(argv[3]), argv[4]); }/*--------------------------------------------------------------------- * With option -envelope <filename> <xmin> <ymin> <ymax> <ymax> * Dump all objects that intersect the envelope. Scan via spatial index. *--------------------------------------------------------------------*/ else if (EQUALN(argv[1], "-envelope", 2) && argc >= 7) { if (strstr(pszFname, ".tab") != NULL || strstr(pszFname, ".TAB") != NULL) { DumpViaSpatialIndex(pszFname, atof(argv[3]), atof(argv[4]), atof(argv[5]), atof(argv[6])); } }/*--------------------------------------------------------------------- * With option -otheroption <filename> ... * ... do something else ... *--------------------------------------------------------------------*/ else if (EQUALN(argv[1], "-otheroption", 2)) { ; } else { printf("Cannot process file %s\n\n", pszFname); printf("%s", TABTEST_USAGE); return 1; } return 0;}/********************************************************************** * 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;}/********************************************************************** * 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); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -