📄 mitab_feature.cpp
字号:
/********************************************************************** * $Id: mitab_feature.cpp,v 1.54 2004/12/01 18:25:03 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.54 2004/12/01 18:25:03 dmorissette * Fixed potential memory leaks in error conditions (bug 881) * * Revision 1.53 2004/10/19 14:21:11 jlacroix * Support pen width bigger than 7 with GetStyleString. (Bug 683) * * Revision 1.52 2004/10/11 20:18:27 dmorissette * Do not output a BG color in style string for transparent brushes (bug 693) * * Revision 1.51 2004/06/30 20:29:03 dmorissette * Fixed refs to old address danmo@videotron.ca * * Revision 1.50 2003/12/19 08:30:10 fwarmerdam * write 3d geometries to tab in 2D * * Revision 1.49 2003/03/28 14:01:14 warmerda * use TRUE/FALSE in place of true/false * * Revision 1.48 2002/08/27 17:17:33 warmerda * handle errors better, auto-add FID column if there aren't any columns * * Revision 1.47 2002/06/17 15:00:30 julien * Add IsInteriorRing() function in TABRegion to validate if a ring is internal * * Revision 1.46 2002/03/26 03:17:13 daniel * Added Get/SetCenter() to MultiPoint * * Revision 1.45 2002/03/26 01:48:40 daniel * Added Multipoint object type (V650) * * Revision 1.44 2002/01/23 20:29:56 daniel * Fixed warning produced by CPLAssert() in non-DEBUG mode. * * Revision 1.43 2001/12/05 22:38:59 daniel * Fixed problems writing TAB_GEOM_LINE (bug 610, 633). * * Revision 1.42 2001/11/23 22:50:17 daniel * Fixed geometry type assertion in TABPolyline::WriteGeomToMAPFile (bug605) * * Revision 1.41 2001/11/17 21:54:06 daniel * Made several changes in order to support writing objects in 16 bits * coordinate format. New TABMAPObjHdr-derived classes are used to hold * object info in mem until block is full. * * Revision 1.40 2001/09/17 21:33:44 daniel * TABText: do not produce an error when reading 0-length text strings. * * Revision 1.39 2001/09/05 13:33:33 daniel * TABPolyline::ValidateMapInfoType(): return TAB_GEOM_NONE if numpoints < 2 * * Revision 1.38 2001/07/03 03:14:52 daniel * GetLabelStyleString(): take line spacing and num. of lines into account * when calculating text height. * * Revision 1.37 2001/06/25 01:04:21 daniel * StyleString fixes: include font name in text style string, and placed * brush before pen in region style strings. * * Revision 1.36 2001/05/01 18:34:12 daniel * TABRegion: use outside/inside ring relationship to build geometry if * the information is available in the source file. * * Revision 1.35 2001/02/28 07:15:08 daniel * Added support for text label line end point * * Revision 1.34 2001/01/22 16:03:58 warmerda * expanded tabs * * Revision 1.33 2000/11/23 21:11:07 daniel * OOpps... VC++ didn't like the way TABPenDef, etc. were initialized * * Revision 1.32 2000/11/23 20:47:45 daniel * Use MI defaults for Pen, Brush, Font, Symbol instead of all zeros * * Revision 1.31 2000/10/18 03:23:37 warmerda * ensure TABText::m_dWidth is initialized in constructor * * Revision 1.30 2000/10/03 19:29:51 daniel * Include OGR StyleString stuff (implemented by Stephane) * * Revision 1.29 2000/09/19 17:23:52 daniel * Maintain and/or compute valid region and polyline center/label point * * Revision 1.28 2000/09/07 23:32:13 daniel * Added RecordDeletedFlag to TABFeature with get/set methods * * Revision 1.27 2000/07/10 14:56:25 daniel * Handle m_nOriginQuadrant==0 as quadrant 3 (reverse x and y axis) * * Revision 1.26 2000/04/21 12:39:05 daniel * Added TABPolyline::GetNumParts()/GetPartRef() * * Revision 1.25 2000/02/28 16:44:10 daniel * Added support for indexed, unique, and for new V450 object types * * ... * * 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::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); // 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() * * Return the values for the MBR corners for this feature. **********************************************************************/void TABFeature::GetMBR(double &dXMin, double &dYMin, double &dXMax, double &dYMax){ dXMin = m_dXMin; dYMin = m_dYMin; dXMax = m_dXMax; dYMax = m_dYMax;}/********************************************************************** * TABFeature::ReadRecordFromDATFile() * * Fill the fields part of the feature from the contents of the * table record pointed to by poDATFile. * * It is assumed that poDATFile currently points to the beginning of * the table record and that this feature's OGRFeatureDefn has been * properly initialized for this table. **********************************************************************/int TABFeature::ReadRecordFromDATFile(TABDATFile *poDATFile){ int iField, numFields, nValue; double dValue; const char *pszValue; CPLAssert(poDATFile); numFields = poDATFile->GetNumFields(); for(iField=0; iField<numFields; iField++) { switch(poDATFile->GetFieldType(iField)) { case TABFChar: pszValue = poDATFile->ReadCharField(poDATFile-> GetFieldWidth(iField)); SetField(iField, pszValue); break; case TABFDecimal: dValue = poDATFile->ReadDecimalField(poDATFile-> GetFieldWidth(iField)); SetField(iField, dValue); break; case TABFInteger: nValue = poDATFile->ReadIntegerField(poDATFile-> GetFieldWidth(iField)); SetField(iField, nValue); break; case TABFSmallInt: nValue = poDATFile->ReadSmallIntField(poDATFile-> GetFieldWidth(iField)); SetField(iField, nValue); break; case TABFFloat: dValue = poDATFile->ReadFloatField(poDATFile-> GetFieldWidth(iField)); SetField(iField, dValue); break; case TABFLogical: pszValue = poDATFile->ReadLogicalField(poDATFile-> GetFieldWidth(iField)); SetField(iField, pszValue); break; case TABFDate: pszValue = poDATFile->ReadDateField(poDATFile-> GetFieldWidth(iField)); SetField(iField, pszValue); break; default: // Other type??? Impossible! CPLError(CE_Failure, CPLE_AssertionFailed, "Unsupported field type!"); } } return 0;}/********************************************************************** * TABFeature::WriteRecordToDATFile() * * Write the attribute part of the feature to the .DAT file. * * It is assumed that poDATFile currently points to the beginning of * the table record and that this feature's OGRFeatureDefn has been * properly initialized for this table. * * Returns 0 on success, -1 on error. **********************************************************************/int TABFeature::WriteRecordToDATFile(TABDATFile *poDATFile, TABINDFile *poINDFile, int *panIndexNo){ int iField, numFields, nStatus=0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -