📄 ogravclayer.cpp
字号:
/****************************************************************************** * $Id: ogravclayer.cpp,v 1.8 2005/02/22 12:55:03 fwarmerdam Exp $ * * Project: OGR * Purpose: Implements OGRAVCLayer class. This is the base class for E00 * and binary coverage layer implementations. It provides some base * layer operations, and methods for transforming between OGR * features, and the in memory structures of the AVC library. * Author: Frank Warmerdam, warmerdam@pobox.com * ****************************************************************************** * Copyright (c) 2002, Frank Warmerdam <warmerdam@pobox.com> * * 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: ogravclayer.cpp,v $ * Revision 1.8 2005/02/22 12:55:03 fwarmerdam * use OGRLayer base spatial filter support * * Revision 1.7 2005/02/02 21:09:44 fwarmerdam * track m_nFeaturesRead * * Revision 1.6 2004/10/19 22:05:03 dmorissette * Remove trailing spaces in string attribute fields (MapServer bug 184) * * Revision 1.5 2002/12/21 19:48:05 warmerda * rearrange code a bit to workaround VStudio.NET bug * * Revision 1.4 2002/02/18 20:36:50 warmerda * added attribute query * * Revision 1.3 2002/02/15 02:35:16 warmerda * added preliminary text support * * Revision 1.2 2002/02/14 23:01:04 warmerda * added region and attribute support * * Revision 1.1 2002/02/13 20:48:18 warmerda * New * */#include "ogr_avc.h"#include "cpl_conv.h"#include "cpl_string.h"CPL_CVSID("$Id: ogravclayer.cpp,v 1.8 2005/02/22 12:55:03 fwarmerdam Exp $");/************************************************************************//* OGRAVCLayer() *//************************************************************************/OGRAVCLayer::OGRAVCLayer( AVCFileType eSectionTypeIn, OGRAVCDataSource *poDSIn ){ eSectionType = eSectionTypeIn; poDS = poDSIn;}/************************************************************************//* ~OGRAVCLayer() *//************************************************************************/OGRAVCLayer::~OGRAVCLayer(){ if( m_nFeaturesRead > 0 && poFeatureDefn != NULL ) { CPLDebug( "AVC", "%d features read on layer '%s'.", (int) m_nFeaturesRead, poFeatureDefn->GetName() ); } if( poFeatureDefn != NULL ) { delete poFeatureDefn; poFeatureDefn = NULL; }}/************************************************************************//* TestCapability() *//************************************************************************/int OGRAVCLayer::TestCapability( const char * pszCap ){ return FALSE;}/************************************************************************//* GetSpatialRef() *//************************************************************************/OGRSpatialReference *OGRAVCLayer::GetSpatialRef(){ return poDS->GetSpatialRef();}/************************************************************************//* SetupFeatureDefinition() *//************************************************************************/int OGRAVCLayer::SetupFeatureDefinition( const char *pszName ){ switch( eSectionType ) { case AVCFileARC: { poFeatureDefn = new OGRFeatureDefn( pszName ); poFeatureDefn->SetGeomType( wkbLineString ); OGRFieldDefn oUserId( "UserId", OFTInteger ); OGRFieldDefn oFNode( "FNODE#", OFTInteger ); OGRFieldDefn oTNode( "TNODE#", OFTInteger ); OGRFieldDefn oLPoly( "LPOLY#", OFTInteger ); OGRFieldDefn oRPoly( "RPOLY#", OFTInteger ); poFeatureDefn->AddFieldDefn( &oUserId ); poFeatureDefn->AddFieldDefn( &oFNode ); poFeatureDefn->AddFieldDefn( &oTNode ); poFeatureDefn->AddFieldDefn( &oLPoly ); poFeatureDefn->AddFieldDefn( &oRPoly ); } return TRUE; case AVCFilePAL: case AVCFileRPL: { poFeatureDefn = new OGRFeatureDefn( pszName ); poFeatureDefn->SetGeomType( wkbPolygon ); OGRFieldDefn oArcIds( "ArcIds", OFTIntegerList ); poFeatureDefn->AddFieldDefn( &oArcIds ); } return TRUE; case AVCFileCNT: { poFeatureDefn = new OGRFeatureDefn( pszName ); poFeatureDefn->SetGeomType( wkbPoint ); OGRFieldDefn oLabelIds( "LabelIds", OFTIntegerList ); poFeatureDefn->AddFieldDefn( &oLabelIds ); } return TRUE; case AVCFileLAB: { poFeatureDefn = new OGRFeatureDefn( pszName ); poFeatureDefn->SetGeomType( wkbPoint ); OGRFieldDefn oValueId( "ValueId", OFTInteger ); poFeatureDefn->AddFieldDefn( &oValueId ); OGRFieldDefn oPolyId( "PolyId", OFTInteger ); poFeatureDefn->AddFieldDefn( &oPolyId ); } return TRUE; case AVCFileTXT: case AVCFileTX6: { poFeatureDefn = new OGRFeatureDefn( pszName ); poFeatureDefn->SetGeomType( wkbPoint ); OGRFieldDefn oUserId( "UserId", OFTInteger ); poFeatureDefn->AddFieldDefn( &oUserId ); OGRFieldDefn oText( "Text", OFTString ); poFeatureDefn->AddFieldDefn( &oText ); OGRFieldDefn oHeight( "Height", OFTReal ); poFeatureDefn->AddFieldDefn( &oHeight ); OGRFieldDefn oLevel( "Level", OFTInteger ); poFeatureDefn->AddFieldDefn( &oLevel ); } return TRUE; default: poFeatureDefn = NULL; return FALSE; }}/************************************************************************//* TranslateFeature() *//* *//* Translate the AVC structure for a feature to the the *//* corresponding OGR definition. It is assumed that the passed *//* in feature is of a type matching the section type *//* established by SetupFeatureDefinition(). *//************************************************************************/OGRFeature *OGRAVCLayer::TranslateFeature( void *pAVCFeature ){ m_nFeaturesRead++; switch( eSectionType ) {/* ==================================================================== *//* ARC *//* ==================================================================== */ case AVCFileARC: { AVCArc *psArc = (AVCArc *) pAVCFeature;/* -------------------------------------------------------------------- *//* Create feature. *//* -------------------------------------------------------------------- */ OGRFeature *poOGRFeature = new OGRFeature( GetLayerDefn() ); poOGRFeature->SetFID( psArc->nArcId );/* -------------------------------------------------------------------- *//* Apply the line geometry. *//* -------------------------------------------------------------------- */ OGRLineString *poLine = new OGRLineString(); poLine->setNumPoints( psArc->numVertices ); for( int iVert = 0; iVert < psArc->numVertices; iVert++ ) poLine->setPoint( iVert, psArc->pasVertices[iVert].x, psArc->pasVertices[iVert].y ); poOGRFeature->SetGeometryDirectly( poLine );/* -------------------------------------------------------------------- *//* Apply attributes. *//* -------------------------------------------------------------------- */ poOGRFeature->SetField( 0, psArc->nUserId ); poOGRFeature->SetField( 1, psArc->nFNode ); poOGRFeature->SetField( 2, psArc->nTNode ); poOGRFeature->SetField( 3, psArc->nLPoly ); poOGRFeature->SetField( 4, psArc->nRPoly ); return poOGRFeature; }/* ==================================================================== *//* PAL (Polygon) *//* RPL (Region) *//* ==================================================================== */ case AVCFilePAL: case AVCFileRPL: { AVCPal *psPAL = (AVCPal *) pAVCFeature;/* -------------------------------------------------------------------- *//* Create feature. *//* -------------------------------------------------------------------- */ OGRFeature *poOGRFeature = new OGRFeature( GetLayerDefn() ); poOGRFeature->SetFID( psPAL->nPolyId );/* -------------------------------------------------------------------- *//* Apply attributes. *//* -------------------------------------------------------------------- */ // Setup ArcId list. int *panArcs, i; panArcs = (int *) CPLMalloc(sizeof(int) * psPAL->numArcs ); for( i = 0; i < psPAL->numArcs; i++ ) panArcs[i] = psPAL->pasArcs[i].nArcId; poOGRFeature->SetField( 0, psPAL->numArcs, panArcs ); CPLFree( panArcs ); return poOGRFeature; }/* ==================================================================== *//* CNT (Centroid) *//* ==================================================================== */ case AVCFileCNT: { AVCCnt *psCNT = (AVCCnt *) pAVCFeature;/* -------------------------------------------------------------------- *//* Create feature. *//* -------------------------------------------------------------------- */ OGRFeature *poOGRFeature = new OGRFeature( GetLayerDefn() ); poOGRFeature->SetFID( psCNT->nPolyId );/* -------------------------------------------------------------------- *//* Apply Geometry *//* -------------------------------------------------------------------- */ poOGRFeature->SetGeometryDirectly( new OGRPoint( psCNT->sCoord.x, psCNT->sCoord.y ) );/* -------------------------------------------------------------------- *//* Apply attributes. *//* -------------------------------------------------------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -