?? tabdump.cpp
字號:
/**********************************************************************
* $Id: tabdump.cpp,v 1.16 2006/11/20 20:05:58 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.16 2006/11/20 20:05:58 dmorissette
* First pass at improving generation of spatial index in .map file (bug 1585)
* New methods for insertion and splittung in the spatial index are done.
* Also implemented a method to dump the spatial index to .mif/.mid
* Still need to implement splitting of TABMapObjectBlock to get optimal
* results.
*
* Revision 1.15 2006/09/05 23:05:51 dmorissette
* Added -spatialindex option to call TABMAPFile::DumpSpatialIndex() (bug 1585)
*
* 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 DumpMapFileIndexTree2MIF(const char *pszFname, int nMaxDepth);
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 -s|-spatialindex <filename> [maxdepth]\n" \
" tabdump -e|-envelope <filename> <xmin> <ymin> <ymax> <ymax>\n" \
" tabdump -c|-coordsys <filename>\n" \
" tabdump -Cc|-Ccoordsys <filename>\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 -spatialindex <filename> [maxdepth]
* Dump Spatial Index Tree of .MAP file
*--------------------------------------------------------------------*/
else if (EQUALN(argv[1], "-spatialindex", 2))
{
if (strstr(pszFname, ".map") != NULL ||
strstr(pszFname, ".MAP") != NULL)
{
if (argc >= 4)
DumpMapFileIndexTree2MIF(pszFname, atoi(argv[3]));
else
DumpMapFileIndexTree2MIF(pszFname, -1);
}
}
/*---------------------------------------------------------------------
* 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 -Ccoordsys <filename>
* Dump the dataset's coordsys and bounds info in a C struct format
*--------------------------------------------------------------------*/
else if (EQUALN(argv[1], "-Ccoordsys", 3))
{
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;
}
/**********************************************************************
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -