📄 mitab_feature.cpp
字号:
/********************************************************************** * $Id: mitab_feature.cpp,v 1.66 2006/10/17 14:34:31 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.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.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.62 2005/11/08 22:02:36 fwarmerdam * cast strstr() results as per email from Charles Savage for VC8. * * Revision 1.61 2005/10/12 19:13:30 jlacroix * bug1012 Make sure Style Units are set when seting a feature from StyleString * * Revision 1.60 2005/10/07 21:22:33 dmorissette * Clone region/pline/mpoint components in TABCollection::CloneTABFeature() * * Revision 1.59 2005/10/06 23:05:08 dmorissette * TABCollection: Added automated sync'ing of OGRFeature's geometry in * SetRegion/Pline/MpointDirectly() methods (bug 1126) * * Revision 1.58 2005/10/06 19:15:30 dmorissette * Collections: added support for reading/writing pen/brush/symbol ids and * for writing collection objects to .TAB/.MAP (bug 1126) * * Revision 1.57 2005/10/04 15:44:31 dmorissette * First round of support for Collection objects. Currently supports reading * from .TAB/.MAP and writing to .MIF. Still lacks symbol support and write * support. (Based in part on patch and docs from Jim Hope, bug 1126) * * Revision 1.56 2005/07/14 16:15:05 jlacroix * \n and \ are now unescaped internally. * * Revision 1.55 2005/05/19 15:26:59 jlacroix * Implement a method to set the StyleString of a TABFeature. * This is done via the ITABFeaturePen, Brush and Symbol classes. * * 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::GetIntMBR() * * Return the integer coordinates values of the MBR of this feature. **********************************************************************/void TABFeature::GetIntMBR(GInt32 &nXMin, GInt32 &nYMin, GInt32 &nXMax, GInt32 &nYMax){ nXMin = m_nXMin; nYMin = m_nYMin; nXMax = m_nXMax; nYMax = m_nYMax;}/********************************************************************** * 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();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -