⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ogrdgnlayer.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************** * $Id: ogrdgnlayer.cpp,v 1.33 2005/02/22 12:54:50 fwarmerdam Exp $ * * Project:  OpenGIS Simple Features Reference Implementation * Purpose:  Implements OGRDGNLayer class. * Author:   Frank Warmerdam, warmerdam@pobox.com * ****************************************************************************** * Copyright (c) 2000, 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: ogrdgnlayer.cpp,v $ * Revision 1.33  2005/02/22 12:54:50  fwarmerdam * use OGRLayer base spatial filter support * * Revision 1.32  2005/02/02 21:09:44  fwarmerdam * track m_nFeaturesRead * * Revision 1.31  2004/02/24 14:24:08  warmerda * Fixed a bug where 0/0 linkages terminated all other linkages on an element. * * Revision 1.30  2004/02/23 21:45:03  warmerda * added support for various link formats * * Revision 1.29  2003/11/27 14:15:20  warmerda * added surface type in createcomplexheaderfromgroup call * * Revision 1.28  2003/09/29 14:25:30  warmerda * Fixed memory leak as reported by Steve Brooks. * * Revision 1.27  2003/05/21 03:42:01  warmerda * Expanded tabs * * Revision 1.26  2003/05/15 14:47:24  warmerda * implement quaternion support on write * * Revision 1.25  2003/05/12 18:48:57  warmerda * added preliminary 3D write support * * Revision 1.24  2003/01/02 21:45:23  warmerda * move OGRBuildPolygonsFromEdges into C API * * Revision 1.23  2002/11/11 20:34:22  warmerda * added create support * * Revision 1.22  2002/10/29 19:45:29  warmerda * OGR driver now always builds an index if any features are to be read.  This * is primarily done to ensure that color tables appearing late in the file * will still affect feature elements occuring before them ... such as with * the m_epoche.dgn file.  Also implement fast feature counting and spatial * extents support based on the index. * * Revision 1.21  2002/05/31 19:03:46  warmerda * removed old CollectLines code * * Revision 1.20  2002/05/31 16:57:21  warmerda * made Text, MSLink and EntityNum attributes available * * Revision 1.19  2002/03/27 21:36:50  warmerda * added implementation of GetFeature() * * Revision 1.18  2002/02/22 22:18:44  warmerda * added support for commplex shapes * * Revision 1.17  2002/02/20 22:27:35  warmerda * fixed problem with units on text height for very small values * * Revision 1.16  2002/01/21 21:36:16  warmerda * removed DGNid * * Revision 1.15  2002/01/21 20:55:10  warmerda * use dgnlib spatial filtering support * * Revision 1.14  2002/01/18 18:52:21  warmerda * set rotation angle for labels * * Revision 1.13  2002/01/15 06:39:56  warmerda * remove _gv_color, flesh out pen and brush style settings * * Revision 1.12  2002/01/09 14:12:12  warmerda * Treat SHAPE elements as polygon geometries, not linestrings. * * Revision 1.11  2001/11/09 18:14:36  warmerda * added size info for LABELs * * Revision 1.10  2001/11/09 15:59:23  warmerda * set style information for text, drop _gv_ogrfs * * Revision 1.9  2001/11/06 14:44:41  warmerda * Removed printf() statement. * * Revision 1.8  2001/07/18 04:55:16  warmerda * added CPL_CSVID * * Revision 1.7  2001/06/19 15:50:23  warmerda * added feature attribute query support * * Revision 1.6  2001/03/07 19:29:46  warmerda * added support for stroking curves * * Revision 1.5  2001/03/07 15:20:13  warmerda * Only apply the _gv_color property if the color lookup is successful. * * Revision 1.4  2001/01/16 21:19:29  warmerda * Added preliminary text support * * Revision 1.3  2001/01/16 18:11:12  warmerda * majorly extended, added arc support * * Revision 1.2  2000/12/28 21:29:17  warmerda * use stype field * * Revision 1.1  2000/11/28 19:03:47  warmerda * New * */#include "ogr_dgn.h"#include "cpl_conv.h"#include "ogr_featurestyle.h"#include "ogr_api.h"CPL_CVSID("$Id: ogrdgnlayer.cpp,v 1.33 2005/02/22 12:54:50 fwarmerdam Exp $");/************************************************************************//*                           OGRDGNLayer()                              *//************************************************************************/OGRDGNLayer::OGRDGNLayer( const char * pszName, DGNHandle hDGN,                          int bUpdate )    {    this->hDGN = hDGN;    this->bUpdate = bUpdate;/* -------------------------------------------------------------------- *//*      Work out what link format we are using.                         *//* -------------------------------------------------------------------- */    OGRFieldType eLinkFieldType;    pszLinkFormat = (char *) CPLGetConfigOption( "DGN_LINK_FORMAT", "FIRST" );    if( EQUAL(pszLinkFormat,"FIRST") )        eLinkFieldType = OFTInteger;    else if( EQUAL(pszLinkFormat,"LIST") )        eLinkFieldType = OFTIntegerList;    else if( EQUAL(pszLinkFormat,"STRING") )        eLinkFieldType = OFTString;    else    {        CPLError( CE_Warning, CPLE_AppDefined,                   "DGN_LINK_FORMAT=%s, but only FIRST, LIST or STRING supported.",                  pszLinkFormat );        pszLinkFormat = "FIRST";        eLinkFieldType = OFTInteger;    }    pszLinkFormat = CPLStrdup(pszLinkFormat);/* -------------------------------------------------------------------- *//*      Create the feature definition.                                  *//* -------------------------------------------------------------------- */    poFeatureDefn = new OGRFeatureDefn( pszName );        OGRFieldDefn        oField( "", OFTInteger );/* -------------------------------------------------------------------- *//*      Element type                                                    *//* -------------------------------------------------------------------- */    oField.SetName( "Type" );    oField.SetType( OFTInteger );    oField.SetWidth( 2 );    oField.SetPrecision( 0 );    poFeatureDefn->AddFieldDefn( &oField );/* -------------------------------------------------------------------- *//*      Level number.                                                   *//* -------------------------------------------------------------------- */    oField.SetName( "Level" );    oField.SetType( OFTInteger );    oField.SetWidth( 2 );    oField.SetPrecision( 0 );    poFeatureDefn->AddFieldDefn( &oField );/* -------------------------------------------------------------------- *//*      graphic group                                                   *//* -------------------------------------------------------------------- */    oField.SetName( "GraphicGroup" );    oField.SetType( OFTInteger );    oField.SetWidth( 4 );    oField.SetPrecision( 0 );    poFeatureDefn->AddFieldDefn( &oField );/* -------------------------------------------------------------------- *//*      ColorIndex                                                      *//* -------------------------------------------------------------------- */    oField.SetName( "ColorIndex" );    oField.SetType( OFTInteger );    oField.SetWidth( 3 );    oField.SetPrecision( 0 );    poFeatureDefn->AddFieldDefn( &oField );/* -------------------------------------------------------------------- *//*      Weight                                                          *//* -------------------------------------------------------------------- */    oField.SetName( "Weight" );    oField.SetType( OFTInteger );    oField.SetWidth( 2 );    oField.SetPrecision( 0 );    poFeatureDefn->AddFieldDefn( &oField );/* -------------------------------------------------------------------- *//*      Style                                                           *//* -------------------------------------------------------------------- */    oField.SetName( "Style" );    oField.SetType( OFTInteger );    oField.SetWidth( 1 );    oField.SetPrecision( 0 );    poFeatureDefn->AddFieldDefn( &oField );/* -------------------------------------------------------------------- *//*      EntityNum                                                       *//* -------------------------------------------------------------------- */    oField.SetName( "EntityNum" );    oField.SetType( eLinkFieldType );    oField.SetWidth( 0 );    oField.SetPrecision( 0 );    poFeatureDefn->AddFieldDefn( &oField );/* -------------------------------------------------------------------- *//*      MSLink                                                          *//* -------------------------------------------------------------------- */    oField.SetName( "MSLink" );    oField.SetType( eLinkFieldType );    oField.SetWidth( 0 );    oField.SetPrecision( 0 );    poFeatureDefn->AddFieldDefn( &oField );/* -------------------------------------------------------------------- *//*      Text                                                            *//* -------------------------------------------------------------------- */    oField.SetName( "Text" );    oField.SetType( OFTString );    oField.SetWidth( 0 );    oField.SetPrecision( 0 );    poFeatureDefn->AddFieldDefn( &oField );/* -------------------------------------------------------------------- *//*      Create template feature for evaluating simple expressions.      *//* -------------------------------------------------------------------- */    bHaveSimpleQuery = FALSE;    poEvalFeature = new OGRFeature( poFeatureDefn );    /* TODO: I am intending to keep track of simple attribute queries (ones       using only FID, Type and Level and short circuiting their operation       based on the index.  However, there are some complexities with       complex elements, and spatial queries that have caused me to put it       off for now.    */}/************************************************************************//*                           ~OGRDGNLayer()                             *//************************************************************************/OGRDGNLayer::~OGRDGNLayer(){    if( m_nFeaturesRead > 0 && poFeatureDefn != NULL )    {        CPLDebug( "Mem", "%d features read on layer '%s'.",                  (int) m_nFeaturesRead,                   poFeatureDefn->GetName() );    }    delete poEvalFeature;    delete poFeatureDefn;    CPLFree( pszLinkFormat );}/************************************************************************//*                          SetSpatialFilter()                          *//************************************************************************/void OGRDGNLayer::SetSpatialFilter( OGRGeometry * poGeomIn ){    if( !InstallFilter(poGeomIn) )        return;    if( m_poFilterGeom != NULL )    {        DGNSetSpatialFilter( hDGN,                              m_sFilterEnvelope.MinX,                              m_sFilterEnvelope.MinY,                              m_sFilterEnvelope.MaxX,                              m_sFilterEnvelope.MaxY );    }    else    {        DGNSetSpatialFilter( hDGN, 0.0, 0.0, 0.0, 0.0 );    }    ResetReading();}/************************************************************************//*                            ResetReading()                            *//************************************************************************/void OGRDGNLayer::ResetReading(){    iNextShapeId = 0;    DGNRewind( hDGN );}/************************************************************************//*                             GetFeature()                             *//************************************************************************/OGRFeature *OGRDGNLayer::GetFeature( long nFeatureId ){    OGRFeature *poFeature;    DGNElemCore *psElement;    if( !DGNGotoElement( hDGN, nFeatureId ) )        return NULL;    // We should likely clear the spatial search region as it affects     // DGNReadElement() but I will defer that for now.     psElement = DGNReadElement( hDGN );    poFeature = ElementToFeature( psElement );    DGNFreeElement( hDGN, psElement );    if( poFeature == NULL )        return NULL;    if( poFeature->GetFID() != nFeatureId )    {        delete poFeature;        return NULL;    }    return poFeature;}/************************************************************************//*                           ConsiderBrush()                            *//*                                                                      *//*      Method to set the style for a polygon, including a brush if     *//*      appropriate.                                                    *//************************************************************************/void OGRDGNLayer::ConsiderBrush( DGNElemCore *psElement, const char *pszPen,                                 OGRFeature *poFeature ){    int         gv_red, gv_green, gv_blue;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -