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

« back to all changes in this revision

Viewing changes to ogr/ogrsf_frmts/gml/gmlfeature.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
1
/**********************************************************************
2
 
 * $Id: gmlfeature.cpp 17165 2009-06-01 22:44:30Z warmerdam $
 
2
 * $Id: gmlfeature.cpp 22954 2011-08-19 21:47:19Z rouault $
3
3
 *
4
4
 * Project:  GML Reader
5
5
 * Purpose:  Implementation of GMLFeature.
40
40
{
41
41
    m_poClass = poClass;
42
42
    m_pszFID = NULL;
43
 
    m_pszGeometry = NULL;
44
43
    
45
44
    m_nPropertyCount = 0;
46
 
    m_papszProperty = NULL;
 
45
    m_pasProperties = NULL;
 
46
 
 
47
    m_nGeometryCount = 0;
 
48
    m_papsGeometry = m_apsGeometry;
 
49
    m_apsGeometry[0] = NULL;
 
50
    m_apsGeometry[1] = NULL;
47
51
    
48
52
    m_papszOBProperties = NULL;
49
53
}
56
60
 
57
61
{
58
62
    CPLFree( m_pszFID );
59
 
    
60
 
    for( int i = 0; i < m_nPropertyCount; i++ )
61
 
    {
62
 
        if( m_papszProperty[i] )
63
 
            CPLFree( m_papszProperty[i] );
64
 
    }
65
 
 
66
 
    CPLFree( m_papszProperty );
67
 
    CPLFree( m_pszGeometry );
 
63
 
 
64
    int i;
 
65
    for( i = 0; i < m_nPropertyCount; i++ )
 
66
    {
 
67
        int nSubProperties = m_pasProperties[i].nSubProperties;
 
68
        if (nSubProperties == 1)
 
69
            CPLFree( m_pasProperties[i].aszSubProperties[0] );
 
70
        else if (nSubProperties > 1)
 
71
        {
 
72
            for( int j = 0; j < nSubProperties; j++)
 
73
                CPLFree( m_pasProperties[i].papszSubProperties[j] );
 
74
            CPLFree( m_pasProperties[i].papszSubProperties );
 
75
        }
 
76
    }
 
77
 
 
78
    if (m_nGeometryCount == 1)
 
79
    {
 
80
        CPLDestroyXMLNode(m_apsGeometry[0]);
 
81
    }
 
82
    else if (m_nGeometryCount > 1)
 
83
    {
 
84
        for(i=0;i<m_nGeometryCount;i++)
 
85
            CPLDestroyXMLNode(m_papsGeometry[i]);
 
86
        CPLFree(m_papsGeometry);
 
87
    }
 
88
 
 
89
    CPLFree( m_pasProperties );
68
90
    CSLDestroy( m_papszOBProperties );
69
91
}
70
92
 
83
105
}
84
106
 
85
107
/************************************************************************/
86
 
/*                            GetProperty()                             */
87
 
/************************************************************************/
88
 
 
89
 
const char *GMLFeature::GetProperty( int iIndex ) const
90
 
 
91
 
{
92
 
    if( iIndex < 0 || iIndex >= m_nPropertyCount )
93
 
        return NULL;
94
 
    else
95
 
        return m_papszProperty[iIndex];
96
 
}
97
 
 
98
 
/************************************************************************/
99
 
/*                            SetProperty()                             */
100
 
/************************************************************************/
101
 
 
102
 
void GMLFeature::SetProperty( int iIndex, const char *pszValue )
103
 
 
104
 
{
105
 
    if( iIndex < 0 || iIndex >= m_poClass->GetPropertyCount() )
106
 
    {
107
 
        CPLAssert( FALSE );
108
 
        return;
109
 
    }
110
 
 
 
108
/*                        SetPropertyDirectly()                         */
 
109
/************************************************************************/
 
110
 
 
111
void GMLFeature::SetPropertyDirectly( int iIndex, char *pszValue )
 
112
 
 
113
{
111
114
    if( iIndex >= m_nPropertyCount )
112
115
    {
113
 
        m_papszProperty = (char **) 
114
 
            CPLRealloc( m_papszProperty, 
115
 
                        sizeof(char *) * m_poClass->GetPropertyCount() );
116
 
        for( int i = m_nPropertyCount; i < m_poClass->GetPropertyCount(); i++ )
117
 
            m_papszProperty[i] = NULL;
118
 
        m_nPropertyCount = m_poClass->GetPropertyCount();
 
116
        int nClassPropertyCount = m_poClass->GetPropertyCount();
 
117
        m_pasProperties = (GMLProperty*)
 
118
            CPLRealloc( m_pasProperties,
 
119
                        sizeof(GMLProperty) * nClassPropertyCount );
 
120
        int i;
 
121
        for( i = 0; i < m_nPropertyCount; i ++ )
 
122
        {
 
123
            /* Make sure papszSubProperties point to the right address in case */
 
124
            /* m_pasProperties has been relocated */
 
125
            if (m_pasProperties[i].nSubProperties <= 1)
 
126
                m_pasProperties[i].papszSubProperties = m_pasProperties[i].aszSubProperties;
 
127
        }
 
128
        for( i = m_nPropertyCount; i < nClassPropertyCount; i++ )
 
129
        {
 
130
            m_pasProperties[i].nSubProperties = 0;
 
131
            m_pasProperties[i].papszSubProperties = m_pasProperties[i].aszSubProperties;
 
132
            m_pasProperties[i].aszSubProperties[0] = NULL;
 
133
            m_pasProperties[i].aszSubProperties[1] = NULL;
 
134
        }
 
135
        m_nPropertyCount = nClassPropertyCount;
119
136
    }
120
137
 
121
 
    CPLFree( m_papszProperty[iIndex] );
122
 
    m_papszProperty[iIndex] = CPLStrdup( pszValue );
 
138
    GMLProperty* psProperty = &m_pasProperties[iIndex];
 
139
    int nSubProperties = psProperty->nSubProperties;
 
140
    if (nSubProperties == 0)
 
141
        psProperty->aszSubProperties[0] = pszValue;
 
142
    else if (nSubProperties == 1)
 
143
    {
 
144
        psProperty->papszSubProperties = (char**) CPLMalloc(
 
145
                            sizeof(char*) * (nSubProperties + 2) );
 
146
        psProperty->papszSubProperties[0] = psProperty->aszSubProperties[0];
 
147
        psProperty->aszSubProperties[0] = NULL;
 
148
        psProperty->papszSubProperties[nSubProperties] = pszValue;
 
149
        psProperty->papszSubProperties[nSubProperties + 1] = NULL;
 
150
    }
 
151
    else
 
152
    {
 
153
        psProperty->papszSubProperties = (char**) CPLRealloc(
 
154
                            psProperty->papszSubProperties,
 
155
                            sizeof(char*) * (nSubProperties + 2) );
 
156
        psProperty->papszSubProperties[nSubProperties] = pszValue;
 
157
        psProperty->papszSubProperties[nSubProperties + 1] = NULL;
 
158
    }
 
159
    psProperty->nSubProperties ++;
123
160
}
124
161
 
125
162
/************************************************************************/
133
170
    
134
171
    if( m_pszFID != NULL )
135
172
        printf( "  FID = %s\n", m_pszFID );
136
 
    
137
 
    for( int i = 0; i < m_nPropertyCount; i++ )
138
 
        printf( "  %s = %s\n", 
139
 
                m_poClass->GetProperty( i )->GetName(),
140
 
                GetProperty( i ) );
141
 
 
142
 
    if( m_pszGeometry )
143
 
        printf( "  %s\n", m_pszGeometry );
 
173
 
 
174
    int i;
 
175
    for( i = 0; i < m_nPropertyCount; i++ )
 
176
    {
 
177
        const GMLProperty * psGMLProperty = GetProperty( i );
 
178
        printf( "  %s = ", m_poClass->GetProperty( i )->GetName());
 
179
        for ( int j = 0; j < psGMLProperty->nSubProperties; j ++)
 
180
        {
 
181
            if (j > 0) printf(", ");
 
182
            printf("%s", psGMLProperty->papszSubProperties[j]);
 
183
        }
 
184
        printf("\n");
 
185
    }
 
186
 
 
187
    for(i=0;i<m_nGeometryCount;i++)
 
188
    {
 
189
        char* pszXML = CPLSerializeXMLTree(m_papsGeometry[i]);
 
190
        printf( "  %s\n", pszXML );
 
191
        CPLFree(pszXML);
 
192
    }
144
193
}
145
194
 
146
195
/************************************************************************/
147
196
/*                        SetGeometryDirectly()                         */
148
197
/************************************************************************/
149
198
 
150
 
void GMLFeature::SetGeometryDirectly( char *pszGeometry )
151
 
 
152
 
{
153
 
    if( m_pszGeometry )
154
 
        CPLFree( m_pszGeometry );
155
 
 
156
 
    m_pszGeometry = pszGeometry;
 
199
void GMLFeature::SetGeometryDirectly( CPLXMLNode* psGeom )
 
200
 
 
201
{
 
202
    if (m_apsGeometry[0] != NULL)
 
203
        CPLDestroyXMLNode(m_apsGeometry[0]);
 
204
    m_nGeometryCount = 1;
 
205
    m_apsGeometry[0] = psGeom;
 
206
}
 
207
 
 
208
/************************************************************************/
 
209
/*                             AddGeometry()                            */
 
210
/************************************************************************/
 
211
 
 
212
void GMLFeature::AddGeometry( CPLXMLNode* psGeom )
 
213
 
 
214
{
 
215
    if (m_nGeometryCount == 0)
 
216
    {
 
217
        m_apsGeometry[0] = psGeom;
 
218
    }
 
219
    else if (m_nGeometryCount == 1)
 
220
    {
 
221
        m_papsGeometry = (CPLXMLNode **) CPLMalloc(
 
222
            (m_nGeometryCount + 2) * sizeof(CPLXMLNode *));
 
223
        m_papsGeometry[0] = m_apsGeometry[0];
 
224
        m_apsGeometry[0] = NULL;
 
225
        m_papsGeometry[m_nGeometryCount] = psGeom;
 
226
        m_papsGeometry[m_nGeometryCount + 1] = NULL;
 
227
    }
 
228
    else
 
229
    {
 
230
        m_papsGeometry = (CPLXMLNode **) CPLRealloc(m_papsGeometry,
 
231
            (m_nGeometryCount + 2) * sizeof(CPLXMLNode *));
 
232
        m_papsGeometry[m_nGeometryCount] = psGeom;
 
233
        m_papsGeometry[m_nGeometryCount + 1] = NULL;
 
234
    }
 
235
    m_nGeometryCount ++;
157
236
}
158
237
 
159
238
/************************************************************************/