~ubuntu-branches/debian/sid/gdal/sid

« back to all changes in this revision

Viewing changes to ogr/ogrsf_frmts/nas/ogrnasrelationlayer.cpp

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2012-05-07 15:04:42 UTC
  • mfrom: (5.5.16 experimental)
  • Revision ID: package-import@ubuntu.com-20120507150442-2eks97loeh6rq005
Tags: 1.9.0-1
* Ready for sid, starting transition.
* All symfiles updated to latest builds.
* Added dh_numpy call in debian/rules to depend on numpy ABI.
* Policy bumped to 3.9.3, no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
 * $Id: ogrnaslayer.cpp 10645 2007-01-18 02:22:39Z warmerdam $
 
3
 *
 
4
 * Project:  OGR
 
5
 * Purpose:  Implements OGRNASRelationLayer class, a special layer holding all
 
6
 *           the relations from the NAS file.
 
7
 * Author:   Frank Warmerdam, warmerdam@pobox.com
 
8
 *
 
9
 ******************************************************************************
 
10
 * Copyright (c) 2009, Frank Warmerdam <warmerdam@pobox.com>
 
11
 *
 
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:
 
18
 *
 
19
 * The above copyright notice and this permission notice shall be included
 
20
 * in all copies or substantial portions of the Software.
 
21
 *
 
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
 ****************************************************************************/
 
30
 
 
31
#include "ogr_nas.h"
 
32
#include "cpl_conv.h"
 
33
#include "cpl_port.h"
 
34
#include "cpl_string.h"
 
35
 
 
36
CPL_CVSID("$Id: ogrnaslayer.cpp 10645 2007-01-18 02:22:39Z warmerdam $");
 
37
 
 
38
/************************************************************************/
 
39
/*                        OGRNASRelationLayer()                         */
 
40
/************************************************************************/
 
41
 
 
42
OGRNASRelationLayer::OGRNASRelationLayer( OGRNASDataSource *poDSIn )
 
43
 
 
44
{
 
45
    poDS = poDSIn;
 
46
 
 
47
    iNextFeature = 0;
 
48
    bPopulated = FALSE;
 
49
 
 
50
/* -------------------------------------------------------------------- */
 
51
/*      Establish the layer fields.                                     */
 
52
/* -------------------------------------------------------------------- */
 
53
    poFeatureDefn = new OGRFeatureDefn( "ALKIS_beziehungen" );
 
54
    poFeatureDefn->Reference();
 
55
    poFeatureDefn->SetGeomType( wkbNone );
 
56
 
 
57
    OGRFieldDefn  oFD( "", OFTString );
 
58
 
 
59
    oFD.SetName( "beziehung_von" );
 
60
    poFeatureDefn->AddFieldDefn( &oFD );
 
61
 
 
62
    oFD.SetName( "beziehungsart" );
 
63
    poFeatureDefn->AddFieldDefn( &oFD );
 
64
 
 
65
    oFD.SetName( "beziehung_zu" );
 
66
    poFeatureDefn->AddFieldDefn( &oFD );
 
67
}
 
68
 
 
69
/************************************************************************/
 
70
/*                        ~OGRNASRelationLayer()                        */
 
71
/************************************************************************/
 
72
 
 
73
OGRNASRelationLayer::~OGRNASRelationLayer()
 
74
 
 
75
{
 
76
    if( poFeatureDefn )
 
77
        poFeatureDefn->Release();
 
78
}
 
79
 
 
80
/************************************************************************/
 
81
/*                            ResetReading()                            */
 
82
/************************************************************************/
 
83
 
 
84
void OGRNASRelationLayer::ResetReading()
 
85
 
 
86
{
 
87
    iNextFeature = 0;
 
88
}
 
89
 
 
90
/************************************************************************/
 
91
/*                           GetNextFeature()                           */
 
92
/************************************************************************/
 
93
 
 
94
OGRFeature *OGRNASRelationLayer::GetNextFeature()
 
95
 
 
96
{
 
97
    if( !bPopulated )
 
98
        poDS->PopulateRelations();
 
99
 
 
100
/* ==================================================================== */
 
101
/*      Loop till we find and translate a feature meeting all our       */
 
102
/*      requirements.                                                   */
 
103
/* ==================================================================== */
 
104
    while( TRUE )
 
105
    {
 
106
        // out of features?
 
107
        if( iNextFeature >= (int) aoRelationCollection.size() )
 
108
            return NULL;
 
109
 
 
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;
 
115
 
 
116
        pszFromID = aoRelationCollection[iNextFeature].c_str();
 
117
        pszType = pszFromID + strlen(pszFromID) + 1;
 
118
        pszToID = pszType + strlen(pszType) + 1;
 
119
 
 
120
        m_nFeaturesRead++;
 
121
 
 
122
/* -------------------------------------------------------------------- */
 
123
/*      Translate values into an OGRFeature.                            */
 
124
/* -------------------------------------------------------------------- */
 
125
        OGRFeature *poFeature = new OGRFeature( poFeatureDefn );
 
126
 
 
127
        poFeature->SetField( 0, pszFromID );
 
128
        poFeature->SetField( 1, pszType );
 
129
        poFeature->SetField( 2, pszToID );
 
130
 
 
131
        poFeature->SetFID( iNextFeature++ );
 
132
 
 
133
/* -------------------------------------------------------------------- */
 
134
/*      Test against the attribute query.                               */
 
135
/* -------------------------------------------------------------------- */
 
136
        if( m_poAttrQuery != NULL
 
137
            && !m_poAttrQuery->Evaluate( poFeature ) )
 
138
            delete poFeature;
 
139
        else
 
140
            return poFeature;
 
141
    }
 
142
 
 
143
    return NULL;
 
144
}
 
145
 
 
146
/************************************************************************/
 
147
/*                          GetFeatureCount()                           */
 
148
/************************************************************************/
 
149
 
 
150
int OGRNASRelationLayer::GetFeatureCount( int bForce )
 
151
 
 
152
{
 
153
    if( !bPopulated )
 
154
        poDS->PopulateRelations();
 
155
 
 
156
    if( m_poAttrQuery == NULL )
 
157
        return aoRelationCollection.size();
 
158
    else
 
159
        return OGRLayer::GetFeatureCount( bForce );
 
160
}
 
161
 
 
162
/************************************************************************/
 
163
/*                           TestCapability()                           */
 
164
/************************************************************************/
 
165
 
 
166
int OGRNASRelationLayer::TestCapability( const char * pszCap )
 
167
 
 
168
{
 
169
    if( EQUAL(pszCap,OLCFastGetExtent) )
 
170
        return TRUE;
 
171
 
 
172
    else if( EQUAL(pszCap,OLCFastFeatureCount) )
 
173
        return bPopulated && m_poAttrQuery == NULL;
 
174
 
 
175
    else if( EQUAL(pszCap,OLCStringsAsUTF8) )
 
176
        return TRUE;
 
177
 
 
178
    else 
 
179
        return FALSE;
 
180
}
 
181
 
 
182
/************************************************************************/
 
183
/*                            AddRelation()                             */
 
184
/************************************************************************/
 
185
 
 
186
void OGRNASRelationLayer::AddRelation( const char *pszFromID,
 
187
                                       const char *pszType,
 
188
                                       const char *pszToID )
 
189
 
 
190
{
 
191
    int nMergedLen = strlen(pszFromID) + strlen(pszType) + strlen(pszToID) + 3;
 
192
    char *pszMerged = (char *) CPLMalloc(nMergedLen);
 
193
    
 
194
    strcpy( pszMerged, pszFromID );
 
195
    strcpy( pszMerged + strlen(pszFromID) + 1, pszType );
 
196
    strcpy( pszMerged + strlen(pszFromID) + strlen(pszType) + 2, pszToID );
 
197
 
 
198
    CPLString osRelation;
 
199
    osRelation.assign( pszMerged, nMergedLen );
 
200
 
 
201
    CPLFree( pszMerged );
 
202
 
 
203
    aoRelationCollection.push_back( osRelation );
 
204
}
 
205