1
/******************************************************************************
2
* $Id: ogrnaslayer.cpp 10645 2007-01-18 02:22:39Z warmerdam $
5
* Purpose: Implements OGRNASRelationLayer class, a special layer holding all
6
* the relations from the NAS file.
7
* Author: Frank Warmerdam, warmerdam@pobox.com
9
******************************************************************************
10
* Copyright (c) 2009, Frank Warmerdam <warmerdam@pobox.com>
12
* Permission is hereby granted, free of charge, to any person obtaining a
13
* copy of this software and associated documentation files (the "Software"),
14
* to deal in the Software without restriction, including without limitation
15
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
16
* and/or sell copies of the Software, and to permit persons to whom the
17
* Software is furnished to do so, subject to the following conditions:
19
* The above copyright notice and this permission notice shall be included
20
* in all copies or substantial portions of the Software.
22
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28
* DEALINGS IN THE SOFTWARE.
29
****************************************************************************/
34
#include "cpl_string.h"
36
CPL_CVSID("$Id: ogrnaslayer.cpp 10645 2007-01-18 02:22:39Z warmerdam $");
38
/************************************************************************/
39
/* OGRNASRelationLayer() */
40
/************************************************************************/
42
OGRNASRelationLayer::OGRNASRelationLayer( OGRNASDataSource *poDSIn )
50
/* -------------------------------------------------------------------- */
51
/* Establish the layer fields. */
52
/* -------------------------------------------------------------------- */
53
poFeatureDefn = new OGRFeatureDefn( "ALKIS_beziehungen" );
54
poFeatureDefn->Reference();
55
poFeatureDefn->SetGeomType( wkbNone );
57
OGRFieldDefn oFD( "", OFTString );
59
oFD.SetName( "beziehung_von" );
60
poFeatureDefn->AddFieldDefn( &oFD );
62
oFD.SetName( "beziehungsart" );
63
poFeatureDefn->AddFieldDefn( &oFD );
65
oFD.SetName( "beziehung_zu" );
66
poFeatureDefn->AddFieldDefn( &oFD );
69
/************************************************************************/
70
/* ~OGRNASRelationLayer() */
71
/************************************************************************/
73
OGRNASRelationLayer::~OGRNASRelationLayer()
77
poFeatureDefn->Release();
80
/************************************************************************/
82
/************************************************************************/
84
void OGRNASRelationLayer::ResetReading()
90
/************************************************************************/
91
/* GetNextFeature() */
92
/************************************************************************/
94
OGRFeature *OGRNASRelationLayer::GetNextFeature()
98
poDS->PopulateRelations();
100
/* ==================================================================== */
101
/* Loop till we find and translate a feature meeting all our */
103
/* ==================================================================== */
107
if( iNextFeature >= (int) aoRelationCollection.size() )
110
/* -------------------------------------------------------------------- */
111
/* The from/type/to values are stored in a packed string with */
112
/* \0 separators for compactness. Split out components. */
113
/* -------------------------------------------------------------------- */
114
const char *pszFromID, *pszType, *pszToID;
116
pszFromID = aoRelationCollection[iNextFeature].c_str();
117
pszType = pszFromID + strlen(pszFromID) + 1;
118
pszToID = pszType + strlen(pszType) + 1;
122
/* -------------------------------------------------------------------- */
123
/* Translate values into an OGRFeature. */
124
/* -------------------------------------------------------------------- */
125
OGRFeature *poFeature = new OGRFeature( poFeatureDefn );
127
poFeature->SetField( 0, pszFromID );
128
poFeature->SetField( 1, pszType );
129
poFeature->SetField( 2, pszToID );
131
poFeature->SetFID( iNextFeature++ );
133
/* -------------------------------------------------------------------- */
134
/* Test against the attribute query. */
135
/* -------------------------------------------------------------------- */
136
if( m_poAttrQuery != NULL
137
&& !m_poAttrQuery->Evaluate( poFeature ) )
146
/************************************************************************/
147
/* GetFeatureCount() */
148
/************************************************************************/
150
int OGRNASRelationLayer::GetFeatureCount( int bForce )
154
poDS->PopulateRelations();
156
if( m_poAttrQuery == NULL )
157
return aoRelationCollection.size();
159
return OGRLayer::GetFeatureCount( bForce );
162
/************************************************************************/
163
/* TestCapability() */
164
/************************************************************************/
166
int OGRNASRelationLayer::TestCapability( const char * pszCap )
169
if( EQUAL(pszCap,OLCFastGetExtent) )
172
else if( EQUAL(pszCap,OLCFastFeatureCount) )
173
return bPopulated && m_poAttrQuery == NULL;
175
else if( EQUAL(pszCap,OLCStringsAsUTF8) )
182
/************************************************************************/
184
/************************************************************************/
186
void OGRNASRelationLayer::AddRelation( const char *pszFromID,
188
const char *pszToID )
191
int nMergedLen = strlen(pszFromID) + strlen(pszType) + strlen(pszToID) + 3;
192
char *pszMerged = (char *) CPLMalloc(nMergedLen);
194
strcpy( pszMerged, pszFromID );
195
strcpy( pszMerged + strlen(pszFromID) + 1, pszType );
196
strcpy( pszMerged + strlen(pszFromID) + strlen(pszType) + 2, pszToID );
198
CPLString osRelation;
199
osRelation.assign( pszMerged, nMergedLen );
201
CPLFree( pszMerged );
203
aoRelationCollection.push_back( osRelation );