📄 ntffilereader.cpp
字号:
/****************************************************************************** * $Id: ntffilereader.cpp,v 1.32 2004/11/17 19:30:15 fwarmerdam Exp $ * * Project: NTF Translator * Purpose: NTFFileReader class implementation. * Author: Frank Warmerdam, warmerdam@pobox.com * ****************************************************************************** * Copyright (c) 1999, Frank Warmerdam * * 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: ntffilereader.cpp,v $ * Revision 1.32 2004/11/17 19:30:15 fwarmerdam * further fixes to stroking 3pt arcs * * Revision 1.31 2003/02/19 07:00:50 warmerda * expand tabs * * Revision 1.30 2003/01/07 16:46:28 warmerda * Added support for forming polygons by caching line geometries * * Revision 1.29 2002/11/17 05:16:49 warmerda * added meridian 2 support * * Revision 1.28 2002/10/02 20:48:39 warmerda * Added support for GENERIC_CPOLY layer * * Revision 1.27 2002/07/08 14:49:44 warmerda * added TILE_REF uniquification support * * Revision 1.26 2002/06/18 02:29:41 warmerda * fixed possible one-off error in att records ended with variable value * * Revision 1.25 2002/02/11 16:53:32 warmerda * ensure file opened in binary mode * * Revision 1.24 2002/02/08 20:43:06 warmerda * improved error checking and propagation * * Revision 1.23 2001/12/12 02:47:10 warmerda * avoid leaking records, check odd conditions * * Revision 1.22 2001/12/11 20:37:49 warmerda * add option to avoid caching indexed records on multiple readers * * Revision 1.21 2001/08/28 20:50:03 warmerda * expand tabs * * Revision 1.20 2001/08/28 20:41:14 warmerda * added support for type 5 GTYPE values on GEOMETRY record * * Revision 1.19 2001/08/23 13:36:38 warmerda * fixed circle to line to close properly * * Revision 1.18 2001/07/18 04:55:16 warmerda * added CPL_CSVID * * Revision 1.17 2001/04/30 15:14:19 warmerda * Allow GEOMETRY3D in place of GEOMETRY in GetIndexedRecord(). This fixes * problem reported by Jakob for OS of Ireland files. Also removed broken * handling of GEOM_ID for NRT_TEXTREC GetNextIndexedRecordGroup(). Fixes * problem with placement of TEXT records in any indexed (generic) translations. * * Revision 1.16 2001/01/19 20:31:12 warmerda * expand tabs * * Revision 1.15 2001/01/17 19:08:37 warmerda * added CODELIST support * * Revision 1.14 2000/12/23 05:12:17 warmerda * improve error reporting if MAX_REC_GROUP exceeded * * Revision 1.13 2000/12/06 19:31:16 warmerda * added BL2000 support * * Revision 1.12 2000/09/28 16:30:31 warmerda * avoid warnings * * Revision 1.11 1999/10/04 03:08:52 warmerda * added raster support * * Revision 1.10 1999/10/03 03:43:43 warmerda * Handle GType 7 "circle" geometries by producing a reasonable linear * approximation. * * Revision 1.9 1999/10/03 01:02:56 warmerda * added NAMEREC and COLLECT handling * * Revision 1.8 1999/10/01 14:47:51 warmerda * major upgrade: generic, string feature codes, etc * * Revision 1.7 1999/09/29 16:44:08 warmerda * added spatial ref handling * * Revision 1.6 1999/09/14 01:34:36 warmerda * added scale support, and generation of TEXT_HT_GROUND * * Revision 1.5 1999/09/13 14:07:59 warmerda * added nrt_comment, geometry3d, and landline99 support * * Revision 1.4 1999/08/31 17:49:56 warmerda * Drop duplicate vertices in ProcessGeometry() * * Revision 1.3 1999/08/30 16:49:59 warmerda * added new products, fixed to use ProcessAttValue() * * Revision 1.2 1999/08/28 18:24:42 warmerda * added TestForLayer() optimization * * Revision 1.1 1999/08/28 03:13:35 warmerda * New * */#include <stdarg.h>#include "ntf.h"#include "cpl_conv.h"#include "cpl_string.h"#include "ogr_api.h"CPL_CVSID("$Id: ntffilereader.cpp,v 1.32 2004/11/17 19:30:15 fwarmerdam Exp $");static int DefaultNTFRecordGrouper( NTFFileReader *, NTFRecord **, NTFRecord * );#ifndef PI# define PI 3.14159265358979323846#endif/************************************************************************//* NTFFileReader *//************************************************************************/NTFFileReader::NTFFileReader( OGRNTFDataSource * poDataSource ){ fp = NULL; nFCCount = 0; papszFCNum = NULL; papszFCName = NULL; nPreSavedPos = nPostSavedPos = 0; nSavedFeatureId = nBaseFeatureId = 1; nFeatureCount = -1; poSavedRecord = NULL; nAttCount = 0; pasAttDesc = NULL; pszTileName = NULL; pszProduct = NULL; pszPVName = NULL; pszFilename = NULL; apoCGroup[0] = NULL; poDS = poDataSource; memset( apoTypeTranslation, 0, sizeof(apoTypeTranslation) ); nProduct = NPC_UNKNOWN; pfnRecordGrouper = DefaultNTFRecordGrouper; dfXYMult = 1.0; dfZMult = 1.0; dfXOrigin = 0; dfYOrigin = 0; nNTFLevel = 0; dfTileXSize = 0; dfTileYSize = 0; dfScale = 0.0; dfPaperToGround = 0.0; nCoordWidth = 6; nZWidth = 6; for( int i = 0; i < 100; i++ ) { anIndexSize[i] = 0; apapoRecordIndex[i] = NULL; } panColumnOffset = NULL; poRasterLayer = NULL; nRasterXSize = nRasterYSize = nRasterDataType = 1; bIndexBuilt = FALSE; bIndexNeeded = FALSE; if( poDS->GetOption("CACHE_LINES") != NULL && EQUAL(poDS->GetOption("CACHE_LINES"),"OFF") ) bCacheLines = FALSE; else bCacheLines = TRUE; nLineCacheSize = 0; papoLineCache = NULL;}/************************************************************************//* ~NTFFileReader() *//************************************************************************/NTFFileReader::~NTFFileReader(){ CacheClean(); DestroyIndex(); ClearDefs(); CPLFree( pszFilename ); CPLFree( panColumnOffset );}/************************************************************************//* SetBaseFID() *//************************************************************************/void NTFFileReader::SetBaseFID( long nNewBase ){ CPLAssert( nSavedFeatureId == 1 ); nBaseFeatureId = nNewBase; nSavedFeatureId = nBaseFeatureId;}/************************************************************************//* ClearDefs() *//* *//* Clear attribute definitions and feature classes. All the *//* stuff that would have to be cleaned up by Open(), and the *//* destructor. *//************************************************************************/void NTFFileReader::ClearDefs(){ int i; Close(); ClearCGroup(); CSLDestroy( papszFCNum ); papszFCNum = NULL; CSLDestroy( papszFCName ); papszFCName = NULL; nFCCount = 0; for( i = 0; i < nAttCount; i++ ) { if( pasAttDesc[i].poCodeList != NULL ) delete pasAttDesc[i].poCodeList; } CPLFree( pasAttDesc ); nAttCount = 0; pasAttDesc = NULL; CPLFree( pszProduct ); pszProduct = NULL; CPLFree( pszPVName ); pszPVName = NULL; CPLFree( pszTileName ); pszTileName = NULL;}/************************************************************************//* Close() *//* *//* Close the file, but don't wipe out our knowledge about this *//* file. *//************************************************************************/void NTFFileReader::Close(){ if( poSavedRecord != NULL ) delete poSavedRecord; poSavedRecord = NULL; nPreSavedPos = nPostSavedPos = 0; nSavedFeatureId = nBaseFeatureId; if( fp != NULL ) { VSIFClose( fp ); fp = NULL; } CacheClean();}/************************************************************************//* Open() *//************************************************************************/int NTFFileReader::Open( const char * pszFilenameIn ){ if( pszFilenameIn != NULL ) { ClearDefs(); CPLFree( pszFilename ); pszFilename = CPLStrdup( pszFilenameIn ); } else Close(); /* -------------------------------------------------------------------- *//* Open the file. *//* -------------------------------------------------------------------- */ fp = VSIFOpen( pszFilename, "rb" ); // notdef: we should likely issue a proper CPL error message based // based on errno here. if( fp == NULL ) { CPLError( CE_Failure, CPLE_OpenFailed, "Unable to open file `%s' for read access.\n", pszFilename ); return FALSE; }/* -------------------------------------------------------------------- *//* If we are just reopening an existing file we will just scan *//* past the section header ... no need to reform all the definitions.*//* -------------------------------------------------------------------- */ if( pszFilenameIn == NULL ) { NTFRecord *poRecord; for( poRecord = new NTFRecord( fp ); poRecord->GetType() != NRT_VTR && poRecord->GetType() != NRT_SHR; poRecord = new NTFRecord( fp ) ) { delete poRecord; } delete poRecord; return TRUE; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -