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

« back to all changes in this revision

Viewing changes to ogr/ogrsf_frmts/pcidsk/ogrpcidskdatasource.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:
34
34
 
35
35
CPL_CVSID("$Id: ogrcsvdatasource.cpp 17806 2009-10-13 17:27:54Z rouault $");
36
36
 
 
37
const PCIDSK::PCIDSKInterfaces *PCIDSK2GetInterfaces(void);
 
38
 
37
39
/************************************************************************/
38
40
/*                        OGRPCIDSKDataSource()                         */
39
41
/************************************************************************/
41
43
OGRPCIDSKDataSource::OGRPCIDSKDataSource()
42
44
 
43
45
{
 
46
    poFile = NULL;
44
47
    bUpdate = FALSE;
45
48
}
46
49
 
56
59
        delete apoLayers.back();
57
60
        apoLayers.pop_back();
58
61
    }
 
62
    
 
63
    if( poFile != NULL )
 
64
    {
 
65
        delete poFile;
 
66
        poFile = NULL;
 
67
    }
59
68
}
60
69
 
61
70
/************************************************************************/
65
74
int OGRPCIDSKDataSource::TestCapability( const char * pszCap )
66
75
 
67
76
{
68
 
    return FALSE;
 
77
    if( EQUAL(pszCap,ODsCCreateLayer) )
 
78
        return bUpdate;
 
79
    else
 
80
        return FALSE;
69
81
}
70
82
 
71
83
/************************************************************************/
92
104
        return FALSE;
93
105
 
94
106
    osName = pszFilename;
95
 
    bUpdate = bUpdateIn;
 
107
    if( bUpdateIn )
 
108
        bUpdate = true;
 
109
    else
 
110
        bUpdate = false;
96
111
 
97
112
/* -------------------------------------------------------------------- */
98
113
/*      Open the file, and create layer for each vector segment.        */
100
115
    try 
101
116
    {
102
117
        PCIDSK::PCIDSKSegment *segobj;
103
 
 
104
 
        poFile = PCIDSK::Open( pszFilename, "r", NULL );
 
118
        const char *pszAccess = "r";
 
119
 
 
120
        if( bUpdateIn )
 
121
            pszAccess = "r+";
 
122
 
 
123
        poFile = PCIDSK::Open( pszFilename, pszAccess,
 
124
                               PCIDSK2GetInterfaces() );
105
125
 
106
126
        for( segobj = poFile->GetSegment( PCIDSK::SEG_VEC, "" );
107
127
             segobj != NULL;
108
128
             segobj = poFile->GetSegment( PCIDSK::SEG_VEC, "",
109
129
                                          segobj->GetSegmentNumber() ) )
110
130
        {
111
 
            apoLayers.push_back( new OGRPCIDSKLayer( segobj ) );
 
131
            apoLayers.push_back( new OGRPCIDSKLayer( segobj, bUpdate ) );
112
132
        }
 
133
 
 
134
        /* Check if this is a raster-only PCIDSK file */
 
135
        if ( !bUpdate && apoLayers.size() == 0 && poFile->GetChannels() != 0 )
 
136
            return FALSE;
113
137
    }
114
138
 
115
139
/* -------------------------------------------------------------------- */
128
152
        return FALSE;
129
153
    }
130
154
 
131
 
/* -------------------------------------------------------------------- */
132
 
/*      We presume that this is indeed intended to be a PCIDSK             */
133
 
/*      datasource if over half the files were .csv files.              */
134
 
/* -------------------------------------------------------------------- */
135
155
    return TRUE;
136
156
}
137
157
 
 
158
/************************************************************************/
 
159
/*                            CreateLayer()                             */
 
160
/************************************************************************/
 
161
 
 
162
OGRLayer *
 
163
OGRPCIDSKDataSource::CreateLayer( const char * pszLayerName,
 
164
                                  OGRSpatialReference *poSRS,
 
165
                                  OGRwkbGeometryType eType,
 
166
                                  char ** papszOptions )
 
167
    
 
168
{
 
169
/* -------------------------------------------------------------------- */
 
170
/*      Verify we are in update mode.                                   */
 
171
/* -------------------------------------------------------------------- */
 
172
    if( !bUpdate )
 
173
    {
 
174
        CPLError( CE_Failure, CPLE_NoWriteAccess,
 
175
                  "Data source %s opened read-only.\n"
 
176
                  "New layer %s cannot be created.\n",
 
177
                  osName.c_str(), pszLayerName );
 
178
        
 
179
        return NULL;
 
180
    }
 
181
    
 
182
/* -------------------------------------------------------------------- */
 
183
/*      Figure out what type of layer we need.                          */
 
184
/* -------------------------------------------------------------------- */
 
185
    std::string osLayerType;
 
186
 
 
187
    switch( wkbFlatten(eType) )
 
188
    {
 
189
      case wkbPoint:
 
190
        osLayerType = "POINTS";
 
191
        break;
 
192
    
 
193
      case wkbLineString:
 
194
        osLayerType = "ARCS";
 
195
        break;
 
196
 
 
197
      case wkbPolygon:
 
198
        osLayerType = "WHOLE_POLYGONS";
 
199
        break;
 
200
        
 
201
      case wkbNone:
 
202
        osLayerType = "TABLE";
 
203
        break;
 
204
 
 
205
      default:
 
206
        break;
 
207
    }
 
208
 
 
209
/* -------------------------------------------------------------------- */
 
210
/*      Create the segment.                                             */
 
211
/* -------------------------------------------------------------------- */
 
212
    int     nSegNum = poFile->CreateSegment( pszLayerName, "", 
 
213
                                             PCIDSK::SEG_VEC, 0L );
 
214
    PCIDSK::PCIDSKSegment *poSeg = poFile->GetSegment( nSegNum );
 
215
    PCIDSK::PCIDSKVectorSegment *poVecSeg = 
 
216
        dynamic_cast<PCIDSK::PCIDSKVectorSegment*>( poSeg );
 
217
 
 
218
    if( osLayerType != "" )
 
219
        poSeg->SetMetadataValue( "LAYER_TYPE", osLayerType );
 
220
 
 
221
/* -------------------------------------------------------------------- */
 
222
/*      Do we need to apply a coordinate system?                        */
 
223
/* -------------------------------------------------------------------- */
 
224
    char *pszGeosys = NULL;
 
225
    char *pszUnits = NULL;
 
226
    double *padfPrjParams = NULL;
 
227
 
 
228
    if( poSRS != NULL 
 
229
        && poSRS->exportToPCI( &pszGeosys, &pszUnits, 
 
230
                               &padfPrjParams ) == OGRERR_NONE )
 
231
    {
 
232
        try
 
233
        {
 
234
            std::vector<double> adfPCIParameters;
 
235
            int i;
 
236
 
 
237
            for( i = 0; i < 17; i++ )
 
238
                adfPCIParameters.push_back( padfPrjParams[i] );
 
239
            
 
240
            if( EQUALN(pszUnits,"FOOT",4) )
 
241
                adfPCIParameters.push_back( 
 
242
                    (double)(int) PCIDSK::UNIT_US_FOOT );
 
243
            else if( EQUALN(pszUnits,"INTL FOOT",9) )
 
244
                adfPCIParameters.push_back( 
 
245
                    (double)(int) PCIDSK::UNIT_INTL_FOOT );
 
246
            else if( EQUALN(pszUnits,"DEGREE",6) )
 
247
                adfPCIParameters.push_back( 
 
248
                    (double)(int) PCIDSK::UNIT_DEGREE );
 
249
            else 
 
250
                adfPCIParameters.push_back( 
 
251
                    (double)(int) PCIDSK::UNIT_METER );
 
252
            
 
253
            poVecSeg->SetProjection( pszGeosys, adfPCIParameters );
 
254
        }
 
255
        catch( PCIDSK::PCIDSKException ex )
 
256
        {
 
257
            CPLError( CE_Failure, CPLE_AppDefined,
 
258
                      "%s", ex.what() );
 
259
        }
 
260
        
 
261
        CPLFree( pszGeosys );
 
262
        CPLFree( pszUnits );
 
263
        CPLFree( padfPrjParams );
 
264
    }
 
265
 
 
266
/* -------------------------------------------------------------------- */
 
267
/*      Create the layer object.                                        */
 
268
/* -------------------------------------------------------------------- */
 
269
    apoLayers.push_back( new OGRPCIDSKLayer( poSeg, TRUE ) );
 
270
 
 
271
    return apoLayers[apoLayers.size()-1];
 
272
}
 
273