?? mitab_feature.cpp
字號(hào):
/**********************************************************************
* $Id: mitab_feature.cpp,v 1.82 2008/02/22 20:20:44 dmorissette Exp $
*
* Name: mitab_feature.cpp
* Project: MapInfo TAB Read/Write library
* Language: C++
* Purpose: Implementation of the feature classes specific to MapInfo files.
* Author: Daniel Morissette, dmorissette@dmsolutions.ca
*
**********************************************************************
* Copyright (c) 1999-2002, 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: mitab_feature.cpp,v $
* Revision 1.82 2008/02/22 20:20:44 dmorissette
* Fixed the internal compressed coordinate range detection test to prevent
* possible overflow of the compressed integer coordinate values leading
* to some coord. errors in very rare cases while writing to TAB (bug 1854)
*
* Revision 1.81 2008/02/20 21:35:30 dmorissette
* Added support for V800 COLLECTION of large objects (bug 1496)
*
* Revision 1.80 2008/02/05 22:22:48 dmorissette
* Added support for TAB_GEOM_V800_MULTIPOINT (bug 1496)
*
* Revision 1.79 2008/02/01 19:36:31 dmorissette
* Initial support for V800 REGION and MULTIPLINE (bug 1496)
*
* Revision 1.78 2008/01/29 20:46:32 dmorissette
* Added support for v9 Time and DateTime fields (byg 1754)
*
* Revision 1.77 2007/12/11 04:21:54 dmorissette
* Fixed leaks in ITABFeature???::Set???FromStyleString() (GDAL ticket 1696)
*
* Revision 1.76 2007/09/18 17:43:56 dmorissette
* Fixed another index splitting issue: compr coordinates origin was not
* stored in the TABFeature in ReadGeometry... (bug 1732)
*
* Revision 1.75 2007/09/14 19:29:24 dmorissette
* Completed handling of bCoordBlockDataOnly arg to Read/WriteGeometry()
* functions to avoid screwing up pen/brush ref counters (bug 1732)
*
* Revision 1.74 2007/09/14 18:30:19 dmorissette
* Fixed the splitting of object blocks with the optimized spatial
* index mode that was producing files with misaligned bytes that
* confused MapInfo (bug 1732)
*
* Revision 1.73 2007/09/12 20:22:31 dmorissette
* Added TABFeature::CreateFromMapInfoType()
*
* Revision 1.72 2007/06/12 14:17:16 dmorissette
* Added TABFile::TwoPointLineAsPolyline() to allow writing two point lines
* as polylines (bug 1735)
*
* Revision 1.71 2007/06/11 17:57:06 dmorissette
* Removed stray calls to poMapFile->GetCurObjBlock()
*
* Revision 1.70 2007/06/11 14:52:30 dmorissette
* Return a valid m_nCoordDatasize value for Collection objects to prevent
* trashing of collection data during object splitting (bug 1728)
*
* Revision 1.69 2007/02/28 20:41:40 dmorissette
* Added missing NULL pointer checks in SetPenFromStyleString(),
* SetBrushFromStyleString() and SetSymbolFromStyleString() (bug 1670)
*
* Revision 1.68 2007/02/22 18:35:53 dmorissette
* Fixed problem writing collections where MITAB was sometimes trying to
* read past EOF in write mode (bug 1657).
*
* Revision 1.67 2006/11/28 18:49:07 dmorissette
* Completed changes to split TABMAPObjectBlocks properly and produce an
* optimal spatial index (bug 1585)
*
* Revision 1.66 2006/10/17 14:34:31 dmorissette
* Fixed problem with null brush bg color (bug 1603)
*
* Revision 1.65 2006/07/25 13:22:58 dmorissette
* Fixed initialization of MBR of TABCollection members (bug 1520)
*
* Revision 1.64 2006/06/29 19:49:35 dmorissette
* Fixed problem writing PLINE MULTIPLE to TAB format introduced in
* MITAB 1.5.0 (bug 1466).
*
* Revision 1.63 2006/02/08 05:02:57 dmorissette
* Fixed crash when attempting to write TABPolyline object with an invalid
* geometry (GDAL bug 1059)
*
* ...
*
* Revision 1.1 1999/07/12 04:18:24 daniel
* Initial checkin
*
**********************************************************************/
#include "mitab.h"
#include "mitab_utils.h"
#include "mitab_geometry.h"
/*=====================================================================
* class TABFeature
*====================================================================*/
/**********************************************************************
* TABFeature::TABFeature()
*
* Constructor.
**********************************************************************/
TABFeature::TABFeature(OGRFeatureDefn *poDefnIn):
OGRFeature(poDefnIn)
{
m_nMapInfoType = TAB_GEOM_NONE;
m_bDeletedFlag = FALSE;
SetMBR(0.0, 0.0, 0.0, 0.0);
}
/**********************************************************************
* TABFeature::~TABFeature()
*
* Destructor.
**********************************************************************/
TABFeature::~TABFeature()
{
}
/**********************************************************************
* TABFeature::CreateFromMapInfoType()
*
* Factory that creates a TABFeature of the right class for the specified
* MapInfo Type
*
**********************************************************************/
TABFeature *TABFeature::CreateFromMapInfoType(int nMapInfoType,
OGRFeatureDefn *poDefn)
{
TABFeature *poFeature = NULL;
/*-----------------------------------------------------------------
* Create new feature object of the right type
*----------------------------------------------------------------*/
switch(nMapInfoType)
{
case TAB_GEOM_NONE:
poFeature = new TABFeature(poDefn);
break;
case TAB_GEOM_SYMBOL_C:
case TAB_GEOM_SYMBOL:
poFeature = new TABPoint(poDefn);
break;
case TAB_GEOM_FONTSYMBOL_C:
case TAB_GEOM_FONTSYMBOL:
poFeature = new TABFontPoint(poDefn);
break;
case TAB_GEOM_CUSTOMSYMBOL_C:
case TAB_GEOM_CUSTOMSYMBOL:
poFeature = new TABCustomPoint(poDefn);
break;
case TAB_GEOM_LINE_C:
case TAB_GEOM_LINE:
case TAB_GEOM_PLINE_C:
case TAB_GEOM_PLINE:
case TAB_GEOM_MULTIPLINE_C:
case TAB_GEOM_MULTIPLINE:
case TAB_GEOM_V450_MULTIPLINE_C:
case TAB_GEOM_V450_MULTIPLINE:
case TAB_GEOM_V800_MULTIPLINE_C:
case TAB_GEOM_V800_MULTIPLINE:
poFeature = new TABPolyline(poDefn);
break;
case TAB_GEOM_ARC_C:
case TAB_GEOM_ARC:
poFeature = new TABArc(poDefn);
break;
case TAB_GEOM_REGION_C:
case TAB_GEOM_REGION:
case TAB_GEOM_V450_REGION_C:
case TAB_GEOM_V450_REGION:
case TAB_GEOM_V800_REGION_C:
case TAB_GEOM_V800_REGION:
poFeature = new TABRegion(poDefn);
break;
case TAB_GEOM_RECT_C:
case TAB_GEOM_RECT:
case TAB_GEOM_ROUNDRECT_C:
case TAB_GEOM_ROUNDRECT:
poFeature = new TABRectangle(poDefn);
break;
case TAB_GEOM_ELLIPSE_C:
case TAB_GEOM_ELLIPSE:
poFeature = new TABEllipse(poDefn);
break;
case TAB_GEOM_TEXT_C:
case TAB_GEOM_TEXT:
poFeature = new TABText(poDefn);
break;
case TAB_GEOM_MULTIPOINT_C:
case TAB_GEOM_MULTIPOINT:
case TAB_GEOM_V800_MULTIPOINT_C:
case TAB_GEOM_V800_MULTIPOINT:
poFeature = new TABMultiPoint(poDefn);
break;
case TAB_GEOM_COLLECTION_C:
case TAB_GEOM_COLLECTION:
case TAB_GEOM_V800_COLLECTION_C:
case TAB_GEOM_V800_COLLECTION:
poFeature = new TABCollection(poDefn);
break;
default:
/*-------------------------------------------------------------
* Unsupported feature type... we still return a valid feature
* with NONE geometry after producing a Warning.
* Callers can trap that case by checking CPLGetLastErrorNo()
* against TAB_WarningFeatureTypeNotSupported
*------------------------------------------------------------*/
// poFeature = new TABDebugFeature(poDefn);
poFeature = new TABFeature(poDefn);
CPLError(CE_Warning, TAB_WarningFeatureTypeNotSupported,
"Unsupported object type %d (0x%2.2x). Feature will be "
"returned with NONE geometry.",
nMapInfoType, nMapInfoType);
}
return poFeature;
}
/**********************************************************************
* TABFeature::CopyTABFeatureBase()
*
* Used by CloneTABFeature() to copy the basic (fields, geometry, etc.)
* TABFeature members.
*
* The newly created feature is owned by the caller, and will have it's own
* reference to the OGRFeatureDefn.
*
* It is possible to create the clone with a different OGRFeatureDefn,
* in this case, the fields won't be copied of course.
*
**********************************************************************/
void TABFeature::CopyTABFeatureBase(TABFeature *poDestFeature)
{
/*-----------------------------------------------------------------
* Copy fields only if OGRFeatureDefn is the same
*----------------------------------------------------------------*/
OGRFeatureDefn *poThisDefnRef = GetDefnRef();
if (poThisDefnRef == poDestFeature->GetDefnRef())
{
for( int i = 0; i < poThisDefnRef->GetFieldCount(); i++ )
{
poDestFeature->SetField( i, GetRawFieldRef( i ) );
}
}
/*-----------------------------------------------------------------
* Copy the geometry
*----------------------------------------------------------------*/
poDestFeature->SetGeometry( GetGeometryRef() );
double dXMin, dYMin, dXMax, dYMax;
GetMBR(dXMin, dYMin, dXMax, dYMax);
poDestFeature->SetMBR(dXMin, dYMin, dXMax, dYMax);
GInt32 nXMin, nYMin, nXMax, nYMax;
GetIntMBR(nXMin, nYMin, nXMax, nYMax);
poDestFeature->SetIntMBR(nXMin, nYMin, nXMax, nYMax);
// m_nMapInfoType is not carried but it is not required anyways.
// it will default to TAB_GEOM_NONE
}
/**********************************************************************
* TABFeature::CloneTABFeature()
*
* Duplicate feature, including stuff specific to each TABFeature type.
*
* The newly created feature is owned by the caller, and will have it's own
* reference to the OGRFeatureDefn.
*
* It is possible to create the clone with a different OGRFeatureDefn,
* in this case, the fields won't be copied of course.
*
* This method calls the generic TABFeature::CopyTABFeatureBase() and
* then copies any members specific to its own type.
**********************************************************************/
TABFeature *TABFeature::CloneTABFeature(OGRFeatureDefn *poNewDefn/*=NULL*/)
{
/*-----------------------------------------------------------------
* Alloc new feature and copy the base stuff
*----------------------------------------------------------------*/
TABFeature *poNew = new TABFeature(poNewDefn ? poNewDefn : GetDefnRef());
CopyTABFeatureBase(poNew);
/*-----------------------------------------------------------------
* And members specific to this class
*----------------------------------------------------------------*/
// Nothing to do for this class
return poNew;
}
/**********************************************************************
* TABFeature::SetMBR()
*
* Set the values for the MBR corners for this feature.
**********************************************************************/
void TABFeature::SetMBR(double dXMin, double dYMin,
double dXMax, double dYMax)
{
m_dXMin = MIN(dXMin, dXMax);
m_dYMin = MIN(dYMin, dYMax);
m_dXMax = MAX(dXMin, dXMax);
m_dYMax = MAX(dYMin, dYMax);
}
/**********************************************************************
* TABFeature::GetMBR()
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -