@@ -157,62 +157,62 @@ QgsOgrProvider::~QgsOgrProvider()
157
157
158
158
void QgsOgrProvider::setEncoding (const QString& e)
159
159
{
160
- QgsVectorDataProvider::setEncoding (e);
161
- loadFields ();
160
+ QgsVectorDataProvider::setEncoding (e);
161
+ loadFields ();
162
162
}
163
163
164
164
void QgsOgrProvider::loadFields ()
165
165
{
166
- // the attribute fields need to be read again when the encoding changes
167
- mAttributeFields .clear ();
168
- OGRFeatureDefnH fdef = OGR_L_GetLayerDefn (ogrLayer);
169
- if (fdef)
166
+ // the attribute fields need to be read again when the encoding changes
167
+ mAttributeFields .clear ();
168
+ OGRFeatureDefnH fdef = OGR_L_GetLayerDefn (ogrLayer);
169
+ if (fdef)
170
+ {
171
+ geomType = OGR_FD_GetGeomType (fdef);
172
+
173
+ // Some ogr drivers (e.g. GML) are not able to determine the geometry type of a layer like this.
174
+ // In such cases, we examine the first feature
175
+ if (geomType == wkbUnknown)
170
176
{
171
- geomType = OGR_FD_GetGeomType (fdef);
172
-
173
- // Some ogr drivers (e.g. GML) are not able to determine the geometry type of a layer like this.
174
- // In such cases, we examine the first feature
175
- if (geomType == wkbUnknown)
176
- {
177
- OGR_L_ResetReading (ogrLayer);
178
- OGRFeatureH firstFeature = OGR_L_GetNextFeature (ogrLayer);
179
- if (firstFeature)
180
- {
181
- OGRGeometryH firstGeometry = OGR_F_GetGeometryRef (firstFeature);
182
- if (firstGeometry)
183
- {
184
- geomType = OGR_G_GetGeometryType (firstGeometry);
185
- }
186
- OGR_F_Destroy ( firstFeature );
187
- }
188
- OGR_L_ResetReading (ogrLayer);
189
- }
190
-
191
- for (int i=0 ;i<OGR_FD_GetFieldCount (fdef);++i)
177
+ OGR_L_ResetReading (ogrLayer);
178
+ OGRFeatureH firstFeature = OGR_L_GetNextFeature (ogrLayer);
179
+ if (firstFeature)
192
180
{
193
- OGRFieldDefnH fldDef = OGR_FD_GetFieldDefn (fdef,i);
194
- OGRFieldType ogrType = OGR_Fld_GetType (fldDef);
195
- QVariant::Type varType;
196
- switch (ogrType)
181
+ OGRGeometryH firstGeometry = OGR_F_GetGeometryRef (firstFeature);
182
+ if (firstGeometry)
197
183
{
198
- case OFTInteger: varType = QVariant::Int; break ;
199
- case OFTReal: varType = QVariant::Double; break ;
200
- // unsupported in OGR 1.3
201
- // case OFTDateTime: varType = QVariant::DateTime; break;
184
+ geomType = OGR_G_GetGeometryType (firstGeometry);
185
+ }
186
+ OGR_F_Destroy ( firstFeature );
187
+ }
188
+ OGR_L_ResetReading (ogrLayer);
189
+ }
190
+
191
+ for (int i=0 ;i<OGR_FD_GetFieldCount (fdef);++i)
192
+ {
193
+ OGRFieldDefnH fldDef = OGR_FD_GetFieldDefn (fdef,i);
194
+ OGRFieldType ogrType = OGR_Fld_GetType (fldDef);
195
+ QVariant::Type varType;
196
+ switch (ogrType)
197
+ {
198
+ case OFTInteger: varType = QVariant::Int; break ;
199
+ case OFTReal: varType = QVariant::Double; break ;
200
+ // unsupported in OGR 1.3
201
+ // case OFTDateTime: varType = QVariant::DateTime; break;
202
202
#if GDAL_VERSION_NUM >= 1400
203
- case OFTString: varType = QVariant::String; break ;
203
+ case OFTString: varType = QVariant::String; break ;
204
204
#endif
205
- default : varType = QVariant::String; // other unsupported, leave it as a string
206
- }
207
-
208
- mAttributeFields .insert (
209
- i, QgsField (
210
- mEncoding ->toUnicode (OGR_Fld_GetNameRef (fldDef)), varType,
211
- mEncoding ->toUnicode (OGR_GetFieldTypeName (ogrType)),
212
- OGR_Fld_GetWidth (fldDef),
213
- OGR_Fld_GetPrecision (fldDef) ));
205
+ default : varType = QVariant::String; // other unsupported, leave it as a string
214
206
}
207
+
208
+ mAttributeFields .insert (
209
+ i, QgsField (
210
+ mEncoding ->toUnicode (OGR_Fld_GetNameRef (fldDef)), varType,
211
+ mEncoding ->toUnicode (OGR_GetFieldTypeName (ogrType)),
212
+ OGR_Fld_GetWidth (fldDef),
213
+ OGR_Fld_GetPrecision (fldDef) ));
215
214
}
215
+ }
216
216
}
217
217
218
218
@@ -223,7 +223,6 @@ QString QgsOgrProvider::storageType() const
223
223
}
224
224
225
225
226
-
227
226
bool QgsOgrProvider::getFeatureAtId (int featureId,
228
227
QgsFeature& feature,
229
228
bool fetchGeometry,
@@ -232,18 +231,18 @@ bool QgsOgrProvider::getFeatureAtId(int featureId,
232
231
OGRFeatureH fet = OGR_L_GetFeature (ogrLayer,featureId);
233
232
if (fet == NULL )
234
233
return false ;
235
-
234
+
236
235
feature.setFeatureId (OGR_F_GetFID (fet));
237
236
238
237
/* fetch geometry */
239
238
if (fetchGeometry)
240
239
{
241
240
OGRGeometryH geom = OGR_F_GetGeometryRef (fet);
242
-
241
+
243
242
// get the wkb representation
244
243
unsigned char *wkb = new unsigned char [OGR_G_WkbSize (geom)];
245
244
OGR_G_ExportToWkb (geom,(OGRwkbByteOrder) QgsApplication::endian (), wkb);
246
-
245
+
247
246
feature.setGeometryAndOwnership (wkb, OGR_G_WkbSize (geom));
248
247
}
249
248
@@ -252,90 +251,90 @@ bool QgsOgrProvider::getFeatureAtId(int featureId,
252
251
{
253
252
getFeatureAttribute (fet,feature,*it);
254
253
}
255
-
254
+
256
255
return true ;
257
256
}
258
257
259
258
bool QgsOgrProvider::getNextFeature (QgsFeature& feature)
260
259
{
261
260
if (!valid)
262
- {
263
- QgsLogger::warning (" Read attempt on an invalid shapefile data source" );
264
- return false ;
265
- }
266
-
261
+ {
262
+ QgsLogger::warning (" Read attempt on an invalid shapefile data source" );
263
+ return false ;
264
+ }
265
+
267
266
OGRFeatureH fet;
268
267
QgsRect selectionRect;
269
-
268
+
270
269
while ((fet = OGR_L_GetNextFeature (ogrLayer)) != NULL )
270
+ {
271
+ // skip features without geometry
272
+ if (OGR_F_GetGeometryRef (fet) == NULL && !mFetchFeaturesWithoutGeom )
271
273
{
272
- // skip features without geometry
273
- if (OGR_F_GetGeometryRef (fet) == NULL && !mFetchFeaturesWithoutGeom )
274
- {
275
- OGR_F_Destroy ( fet );
276
- continue ;
277
- }
278
-
279
- OGRFeatureDefnH featureDefinition = OGR_F_GetDefnRef (fet);
280
- QString featureTypeName = featureDefinition ? QString (OGR_FD_GetName (featureDefinition)) : QString (" " );
281
- feature.setFeatureId (OGR_F_GetFID (fet));
282
- feature.setTypeName (featureTypeName);
283
-
284
- /* fetch geometry */
285
- if (mFetchGeom )
286
- {
287
- OGRGeometryH geom = OGR_F_GetGeometryRef (fet);
288
-
289
- // get the wkb representation
290
- unsigned char *wkb = new unsigned char [OGR_G_WkbSize (geom)];
291
- OGR_G_ExportToWkb (geom,(OGRwkbByteOrder) QgsApplication::endian (), wkb);
292
-
293
- feature.setGeometryAndOwnership (wkb, OGR_G_WkbSize (geom));
294
-
295
- if (mUseIntersect )
296
- {
297
- // precise test for intersection with search rectangle
298
- // first make QgsRect from OGRPolygon
274
+ OGR_F_Destroy ( fet );
275
+ continue ;
276
+ }
277
+
278
+ OGRFeatureDefnH featureDefinition = OGR_F_GetDefnRef (fet);
279
+ QString featureTypeName = featureDefinition ? QString (OGR_FD_GetName (featureDefinition)) : QString (" " );
280
+ feature.setFeatureId (OGR_F_GetFID (fet));
281
+ feature.setTypeName (featureTypeName);
282
+
283
+ /* fetch geometry */
284
+ if (mFetchGeom )
285
+ {
286
+ OGRGeometryH geom = OGR_F_GetGeometryRef (fet);
287
+
288
+ // get the wkb representation
289
+ unsigned char *wkb = new unsigned char [OGR_G_WkbSize (geom)];
290
+ OGR_G_ExportToWkb (geom,(OGRwkbByteOrder) QgsApplication::endian (), wkb);
291
+
292
+ feature.setGeometryAndOwnership (wkb, OGR_G_WkbSize (geom));
293
+
294
+ if (mUseIntersect )
295
+ {
296
+ // precise test for intersection with search rectangle
297
+ // first make QgsRect from OGRPolygon
299
298
OGREnvelope env;
300
299
memset ( &env, 0 , sizeof (env) );
301
300
if (mSelectionRectangle )
302
301
OGR_G_GetEnvelope (mSelectionRectangle ,&env);
303
302
if (env.MinX != 0 || env.MinY != 0 || env.MaxX != 0 || env.MaxY != 0 ) // if envelope is invalid, skip the precise intersection test
304
- {
305
- selectionRect.set (env.MinX , env.MinY , env.MaxX , env.MaxY );
306
- if (!feature.geometry ()->intersects (selectionRect))
307
- {
308
- OGR_F_Destroy ( fet );
309
- continue ;
310
- }
311
- }
312
-
313
- }
314
- }
315
-
316
- /* fetch attributes */
317
- for (QgsAttributeList::iterator it = mAttributesToFetch .begin (); it != mAttributesToFetch .end (); ++it)
318
- {
319
- getFeatureAttribute (fet,feature,*it);
320
- }
321
-
322
- /* we have a feature, end this cycle */
323
- break ;
324
-
325
- } /* while */
326
-
327
- if (fet)
328
- {
329
- OGR_F_Destroy ( fet );
330
- return true ;
303
+ {
304
+ selectionRect.set (env.MinX , env.MinY , env.MaxX , env.MaxY );
305
+ if (!feature.geometry ()->intersects (selectionRect))
306
+ {
307
+ OGR_F_Destroy ( fet );
308
+ continue ;
309
+ }
310
+ }
311
+
312
+ }
331
313
}
332
- else
314
+
315
+ /* fetch attributes */
316
+ for (QgsAttributeList::iterator it = mAttributesToFetch .begin (); it != mAttributesToFetch .end (); ++it)
333
317
{
334
- QgsDebugMsg (" Feature is null" );
335
- // probably should reset reading here
336
- OGR_L_ResetReading (ogrLayer);
337
- return false ;
318
+ getFeatureAttribute (fet,feature,*it);
338
319
}
320
+
321
+ /* we have a feature, end this cycle */
322
+ break ;
323
+
324
+ } /* while */
325
+
326
+ if (fet)
327
+ {
328
+ OGR_F_Destroy ( fet );
329
+ return true ;
330
+ }
331
+ else
332
+ {
333
+ QgsDebugMsg (" Feature is null" );
334
+ // probably should reset reading here
335
+ OGR_L_ResetReading (ogrLayer);
336
+ return false ;
337
+ }
339
338
}
340
339
341
340
void QgsOgrProvider::select (QgsAttributeList fetchAttributes, QgsRect rect, bool fetchGeometry, \
@@ -347,32 +346,32 @@ void QgsOgrProvider::select(QgsAttributeList fetchAttributes, QgsRect rect, bool
347
346
348
347
// spatial query to select features
349
348
if (rect.isEmpty ())
350
- {
351
- OGR_L_SetSpatialFilter (ogrLayer,0 );
352
- }
349
+ {
350
+ OGR_L_SetSpatialFilter (ogrLayer,0 );
351
+ }
353
352
else
353
+ {
354
+ OGRGeometryH filter = 0 ;
355
+ QString wktExtent = QString (" POLYGON ((%1))" ).arg (rect.asPolygon ());
356
+ const char *wktText = (const char *)wktExtent;
357
+
358
+ if (useIntersect)
354
359
{
355
- OGRGeometryH filter = 0 ;
356
- QString wktExtent = QString (" POLYGON ((%1))" ).arg (rect.asPolygon ());
357
- const char *wktText = (const char *)wktExtent;
358
-
359
- if (useIntersect)
360
- {
361
- // store the selection rectangle for use in filtering features during
362
- // an identify and display attributes
363
- if ( mSelectionRectangle )
364
- OGR_G_DestroyGeometry ( mSelectionRectangle );
365
-
366
- OGR_G_CreateFromWkt ( (char **)&wktText,
367
- NULL , &mSelectionRectangle );
368
- }
369
-
370
- wktText = (const char *) wktExtent;
371
- OGR_G_CreateFromWkt ( (char **)&wktText, NULL , &filter );
372
- QgsDebugMsg (" Setting spatial filter using " + wktExtent);
373
- OGR_L_SetSpatialFilter ( ogrLayer, filter );
374
- OGR_G_DestroyGeometry ( filter );
375
- }
360
+ // store the selection rectangle for use in filtering features during
361
+ // an identify and display attributes
362
+ if ( mSelectionRectangle )
363
+ OGR_G_DestroyGeometry ( mSelectionRectangle );
364
+
365
+ OGR_G_CreateFromWkt ( (char **)&wktText,
366
+ NULL , &mSelectionRectangle );
367
+ }
368
+
369
+ wktText = (const char *) wktExtent;
370
+ OGR_G_CreateFromWkt ( (char **)&wktText, NULL , &filter );
371
+ QgsDebugMsg (" Setting spatial filter using " + wktExtent);
372
+ OGR_L_SetSpatialFilter ( ogrLayer, filter );
373
+ OGR_G_DestroyGeometry ( filter );
374
+ }
376
375
}
377
376
378
377
@@ -382,7 +381,7 @@ unsigned char * QgsOgrProvider::getGeometryPointer(OGRFeatureH fet)
382
381
unsigned char *gPtr =0 ;
383
382
384
383
if ( geom == NULL )
385
- return NULL ;
384
+ return NULL ;
386
385
387
386
// get the wkb representation
388
387
gPtr = new unsigned char [OGR_G_WkbSize (geom)];
@@ -402,7 +401,7 @@ QgsRect QgsOgrProvider::extent()
402
401
403
402
size_t QgsOgrProvider::layerCount () const
404
403
{
405
- return OGR_DS_GetLayerCount (ogrDataSource);
404
+ return OGR_DS_GetLayerCount (ogrDataSource);
406
405
} // QgsOgrProvider::layerCount()
407
406
408
407
@@ -444,14 +443,14 @@ void QgsOgrProvider::getFeatureAttribute(OGRFeatureH ogrFet, QgsFeature & f, int
444
443
QByteArray cstr (OGR_F_GetFieldAsString (ogrFet,attindex));
445
444
QString str = mEncoding ->toUnicode (cstr);
446
445
QVariant value;
447
-
446
+
448
447
switch (mAttributeFields [attindex].type ())
449
448
{
450
- case QVariant::String: value = QVariant (str); break ;
451
- case QVariant::Int: value = QVariant (str.toInt ()); break ;
452
- case QVariant::Double: value = QVariant (str.toDouble ()); break ;
449
+ case QVariant::String: value = QVariant (str); break ;
450
+ case QVariant::Int: value = QVariant (str.toInt ()); break ;
451
+ case QVariant::Double: value = QVariant (str.toDouble ()); break ;
453
452
// case QVariant::DateTime: value = QVariant(QDateTime::fromString(str)); break;
454
- default : assert (NULL && " unsupported field type" );
453
+ default : assert (NULL && " unsupported field type" );
455
454
}
456
455
457
456
f.addAttribute (attindex, value);
@@ -488,54 +487,54 @@ bool QgsOgrProvider::addFeature(QgsFeature& f)
488
487
489
488
if ( f.geometry ()->wkbSize () > 0 )
490
489
{
491
- OGRGeometryH geom = NULL ;
490
+ OGRGeometryH geom = NULL ;
492
491
493
- if ( OGR_G_CreateFromWkb ( wkb, NULL , &geom, f.geometry ()->wkbSize () )
494
- != OGRERR_NONE )
495
- {
496
- return false ;
497
- }
492
+ if ( OGR_G_CreateFromWkb ( wkb, NULL , &geom, f.geometry ()->wkbSize () )
493
+ != OGRERR_NONE )
494
+ {
495
+ return false ;
496
+ }
498
497
499
- OGR_F_SetGeometryDirectly ( feature, geom );
498
+ OGR_F_SetGeometryDirectly ( feature, geom );
500
499
}
501
-
500
+
502
501
QgsAttributeMap attrs = f.attributeMap ();
503
502
504
503
// add possible attribute information
505
504
for (QgsAttributeMap::iterator it = attrs.begin (); it != attrs.end (); ++it)
506
505
{
507
506
int targetAttributeId = it.key ();
508
-
507
+
509
508
// don't try to set field from attribute map if it's not present in layer
510
509
if (targetAttributeId >= OGR_FD_GetFieldCount (fdef))
511
510
continue ;
512
511
513
512
// if(!s.isEmpty())
514
513
// continue;
515
-
514
+
516
515
OGRFieldDefnH fldDef = OGR_FD_GetFieldDefn ( fdef, targetAttributeId );
517
516
518
517
switch ( OGR_Fld_GetType (fldDef) )
519
518
{
520
- case OFTInteger:
521
- OGR_F_SetFieldInteger (feature,targetAttributeId,it->toInt ());
522
- break ;
519
+ case OFTInteger:
520
+ OGR_F_SetFieldInteger (feature,targetAttributeId,it->toInt ());
521
+ break ;
523
522
524
- case OFTReal:
525
- OGR_F_SetFieldDouble (feature,targetAttributeId,it->toDouble ());
526
- break ;
523
+ case OFTReal:
524
+ OGR_F_SetFieldDouble (feature,targetAttributeId,it->toDouble ());
525
+ break ;
527
526
528
- case OFTString:
529
- QgsDebugMsg ( QString (" Writing string attribute %1 with %2, encoding %3" )
530
- .arg ( targetAttributeId )
531
- .arg ( it->toString () )
532
- .arg ( mEncoding ->name ().data () ) );
533
- OGR_F_SetFieldString (feature,targetAttributeId,mEncoding ->fromUnicode (it->toString ()).constData ());
534
- break ;
527
+ case OFTString:
528
+ QgsDebugMsg ( QString (" Writing string attribute %1 with %2, encoding %3" )
529
+ .arg ( targetAttributeId )
530
+ .arg ( it->toString () )
531
+ .arg ( mEncoding ->name ().data () ) );
532
+ OGR_F_SetFieldString (feature,targetAttributeId,mEncoding ->fromUnicode (it->toString ()).constData ());
533
+ break ;
535
534
536
- default :
537
- QgsLogger::warning (" QgsOgrProvider::addFeature, no type found" );
538
- break ;
535
+ default :
536
+ QgsLogger::warning (" QgsOgrProvider::addFeature, no type found" );
537
+ break ;
539
538
}
540
539
}
541
540
@@ -569,41 +568,41 @@ bool QgsOgrProvider::addFeatures(QgsFeatureList & flist)
569
568
570
569
bool QgsOgrProvider::addAttributes (const QgsNewAttributesMap & attributes)
571
570
{
572
- bool returnvalue=true ;
571
+ bool returnvalue=true ;
573
572
574
- for (QgsNewAttributesMap::const_iterator iter = attributes.begin (); iter != attributes.end (); ++iter)
573
+ for (QgsNewAttributesMap::const_iterator iter = attributes.begin (); iter != attributes.end (); ++iter)
574
+ {
575
+ OGRFieldDefnH fielddefn =
576
+ OGR_Fld_Create (mEncoding ->fromUnicode (iter.key ()).data (),OFTInteger);
577
+
578
+ if (*iter==" OFTInteger" )
575
579
{
576
- OGRFieldDefnH fielddefn =
577
- OGR_Fld_Create (mEncoding ->fromUnicode (iter.key ()).data (),OFTInteger);
578
-
579
- if (*iter==" OFTInteger" )
580
- {
581
- OGR_Fld_SetType ( fielddefn, OFTInteger );
582
- }
583
- else if (*iter==" OFTReal" )
584
- {
585
- OGR_Fld_SetType ( fielddefn, OFTReal );
586
- }
587
- else if (*iter==" OFTString" )
588
- {
589
- OGR_Fld_SetType ( fielddefn, OFTString );
590
- }
591
- else
592
- {
593
- QgsLogger::warning (" QgsOgrProvider::addAttributes, type not found" );
594
- returnvalue=false ;
595
- continue ;
596
- }
580
+ OGR_Fld_SetType ( fielddefn, OFTInteger );
581
+ }
582
+ else if (*iter==" OFTReal" )
583
+ {
584
+ OGR_Fld_SetType ( fielddefn, OFTReal );
585
+ }
586
+ else if (*iter==" OFTString" )
587
+ {
588
+ OGR_Fld_SetType ( fielddefn, OFTString );
589
+ }
590
+ else
591
+ {
592
+ QgsLogger::warning (" QgsOgrProvider::addAttributes, type not found" );
593
+ returnvalue=false ;
594
+ continue ;
595
+ }
597
596
598
- if ( OGR_L_CreateField (ogrLayer,fielddefn,TRUE ) != OGRERR_NONE)
599
- {
600
- QgsLogger::warning (" QgsOgrProvider.cpp: writing of OFTInteger field failed" );
601
- returnvalue=false ;
602
- }
603
- OGR_Fld_Destroy ( fielddefn );
597
+ if ( OGR_L_CreateField (ogrLayer,fielddefn,TRUE ) != OGRERR_NONE)
598
+ {
599
+ QgsLogger::warning (" QgsOgrProvider.cpp: writing of OFTInteger field failed" );
600
+ returnvalue=false ;
604
601
}
602
+ OGR_Fld_Destroy ( fielddefn );
603
+ }
605
604
606
- return returnvalue;
605
+ return returnvalue;
607
606
}
608
607
609
608
bool QgsOgrProvider::changeAttributeValues (const QgsChangedAttributesMap & attr_map)
@@ -625,29 +624,29 @@ bool QgsOgrProvider::changeAttributeValues(const QgsChangedAttributesMap & attr_
625
624
for ( QgsAttributeMap::const_iterator it2 = attr.begin (); it2 != attr.end (); ++it2 )
626
625
{
627
626
int f = it2.key ();
628
-
627
+
629
628
OGRFieldDefnH fd = OGR_F_GetFieldDefnRef ( of, f );
630
629
if (fd == NULL )
631
630
{
632
631
QgsLogger::warning (" QgsOgrProvider::changeAttributeValues, Field " + QString::number (f) + " doesn't exist" );
633
632
continue ;
634
633
}
635
-
634
+
636
635
OGRFieldType type = OGR_Fld_GetType ( fd );
637
636
switch ( type )
638
637
{
639
- case OFTInteger:
640
- OGR_F_SetFieldInteger ( of, f, it2->toInt () );
641
- break ;
642
- case OFTReal:
643
- OGR_F_SetFieldDouble ( of, f, it2->toDouble () );
644
- break ;
645
- case OFTString:
646
- OGR_F_SetFieldString ( of, f, mEncoding ->fromUnicode (it2->toString ()).constData () );
647
- break ;
648
- default :
649
- QgsLogger::warning (" QgsOgrProvider::changeAttributeValues, Unknown field type, cannot change attribute" );
650
- break ;
638
+ case OFTInteger:
639
+ OGR_F_SetFieldInteger ( of, f, it2->toInt () );
640
+ break ;
641
+ case OFTReal:
642
+ OGR_F_SetFieldDouble ( of, f, it2->toDouble () );
643
+ break ;
644
+ case OFTString:
645
+ OGR_F_SetFieldString ( of, f, mEncoding ->fromUnicode (it2->toString ()).constData () );
646
+ break ;
647
+ default :
648
+ QgsLogger::warning (" QgsOgrProvider::changeAttributeValues, Unknown field type, cannot change attribute" );
649
+ break ;
651
650
}
652
651
653
652
}
@@ -676,9 +675,9 @@ bool QgsOgrProvider::changeGeometryValues(QgsGeometryMap & geometry_map)
676
675
677
676
// create an OGRGeometry
678
677
if (OGR_G_CreateFromWkb (it->wkbBuffer (),
679
- OGR_L_GetSpatialRef (ogrLayer),
680
- &theNewGeometry,
681
- it->wkbSize ()) != OGRERR_NONE)
678
+ OGR_L_GetSpatialRef (ogrLayer),
679
+ &theNewGeometry,
680
+ it->wkbSize ()) != OGRERR_NONE)
682
681
{
683
682
QgsLogger::warning (" QgsOgrProvider::changeGeometryValues, error while creating new OGRGeometry" );
684
683
OGR_G_DestroyGeometry ( theNewGeometry );
@@ -691,7 +690,7 @@ bool QgsOgrProvider::changeGeometryValues(QgsGeometryMap & geometry_map)
691
690
QgsLogger::warning (" QgsOgrProvider::changeGeometryValues, new geometry is NULL" );
692
691
continue ;
693
692
}
694
-
693
+
695
694
// set the new geometry
696
695
if (OGR_F_SetGeometryDirectly (theOGRFeature, theNewGeometry) != OGRERR_NONE)
697
696
{
@@ -700,7 +699,7 @@ bool QgsOgrProvider::changeGeometryValues(QgsGeometryMap & geometry_map)
700
699
theNewGeometry = 0 ;
701
700
continue ;
702
701
}
703
-
702
+
704
703
OGR_L_SetFeature (ogrLayer,theOGRFeature);
705
704
OGR_F_Destroy ( theOGRFeature);
706
705
}
@@ -710,23 +709,23 @@ bool QgsOgrProvider::changeGeometryValues(QgsGeometryMap & geometry_map)
710
709
711
710
bool QgsOgrProvider::createSpatialIndex ()
712
711
{
713
- QString filename=dataSourceUri ().section (' /' ,-1 ,-1 );// find out the filename from the uri
714
- QString layername=filename.section (' .' ,0 ,0 );
715
- QString sql=" CREATE SPATIAL INDEX ON " +layername;
716
- OGR_DS_ExecuteSQL (ogrDataSource,sql.ascii (), OGR_L_GetSpatialFilter (ogrLayer)," " );
717
- // find out, if the .qix file is there
718
- QString indexname = dataSourceUri ();
719
- indexname.truncate (dataSourceUri ().length ()-filename.length ());
720
- indexname=indexname+layername+" .qix" ;
721
- QFile indexfile (indexname);
722
- if (indexfile.exists ())
723
- {
724
- return true ;
725
- }
726
- else
727
- {
728
- return false ;
729
- }
712
+ QString filename=dataSourceUri ().section (' /' ,-1 ,-1 );// find out the filename from the uri
713
+ QString layername=filename.section (' .' ,0 ,0 );
714
+ QString sql=" CREATE SPATIAL INDEX ON " +layername;
715
+ OGR_DS_ExecuteSQL (ogrDataSource,sql.ascii (), OGR_L_GetSpatialFilter (ogrLayer)," " );
716
+ // find out, if the .qix file is there
717
+ QString indexname = dataSourceUri ();
718
+ indexname.truncate (dataSourceUri ().length ()-filename.length ());
719
+ indexname=indexname+layername+" .qix" ;
720
+ QFile indexfile (indexname);
721
+ if (indexfile.exists ())
722
+ {
723
+ return true ;
724
+ }
725
+ else
726
+ {
727
+ return false ;
728
+ }
730
729
}
731
730
732
731
bool QgsOgrProvider::deleteFeatures (const QgsFeatureIds & id)
@@ -770,9 +769,9 @@ int QgsOgrProvider::capabilities() const
770
769
// the #defines we want to test for here.
771
770
772
771
if (OGR_L_TestCapability (ogrLayer," RandomRead" ))
773
- // TRUE if the GetFeature() method works *efficiently* for this layer.
774
- // TODO: Perhaps influence if QGIS caches into memory
775
- // (vs read from disk every time) based on this setting.
772
+ // TRUE if the GetFeature() method works *efficiently* for this layer.
773
+ // TODO: Perhaps influence if QGIS caches into memory
774
+ // (vs read from disk every time) based on this setting.
776
775
{
777
776
ability |= QgsVectorDataProvider::RandomSelectGeometryAtId;
778
777
}
@@ -783,19 +782,19 @@ int QgsOgrProvider::capabilities() const
783
782
ability |= QgsVectorDataProvider::SelectGeometryAtId;
784
783
785
784
if (OGR_L_TestCapability (ogrLayer," SequentialWrite" ))
786
- // TRUE if the CreateFeature() method works for this layer.
785
+ // TRUE if the CreateFeature() method works for this layer.
787
786
{
788
787
ability |= QgsVectorDataProvider::AddFeatures;
789
788
}
790
789
791
790
if (OGR_L_TestCapability (ogrLayer," DeleteFeature" ))
792
- // TRUE if this layer can delete its features
791
+ // TRUE if this layer can delete its features
793
792
{
794
793
ability |= DeleteFeatures;
795
794
}
796
-
795
+
797
796
if (OGR_L_TestCapability (ogrLayer," RandomWrite" ))
798
- // TRUE if the SetFeature() method is operational on this layer.
797
+ // TRUE if the SetFeature() method is operational on this layer.
799
798
{
800
799
// TODO According to http://shapelib.maptools.org/ (Shapefile C Library V1.2)
801
800
// TODO "You can't modify the vertices of existing structures".
@@ -807,35 +806,35 @@ int QgsOgrProvider::capabilities() const
807
806
}
808
807
809
808
if (OGR_L_TestCapability (ogrLayer," FastSpatialFilter" ))
810
- // TRUE if this layer implements spatial filtering efficiently.
811
- // Layers that effectively read all features, and test them with the
812
- // OGRFeature intersection methods should return FALSE.
813
- // This can be used as a clue by the application whether it should build
814
- // and maintain it's own spatial index for features in this layer.
809
+ // TRUE if this layer implements spatial filtering efficiently.
810
+ // Layers that effectively read all features, and test them with the
811
+ // OGRFeature intersection methods should return FALSE.
812
+ // This can be used as a clue by the application whether it should build
813
+ // and maintain it's own spatial index for features in this layer.
815
814
{
816
815
// TODO: Perhaps use as a clue by QGIS whether it should build and maintain it's own spatial index for features in this layer.
817
816
}
818
817
819
818
if (OGR_L_TestCapability (ogrLayer," FastFeatureCount" ))
820
- // TRUE if this layer can return a feature count
821
- // (via OGRLayer::GetFeatureCount()) efficiently ... ie. without counting
822
- // the features. In some cases this will return TRUE until a spatial
823
- // filter is installed after which it will return FALSE.
819
+ // TRUE if this layer can return a feature count
820
+ // (via OGRLayer::GetFeatureCount()) efficiently ... ie. without counting
821
+ // the features. In some cases this will return TRUE until a spatial
822
+ // filter is installed after which it will return FALSE.
824
823
{
825
824
// TODO: Perhaps use as a clue by QGIS whether it should spawn a thread to count features.
826
825
}
827
826
828
827
if (OGR_L_TestCapability (ogrLayer," FastGetExtent" ))
829
- // TRUE if this layer can return its data extent
830
- // (via OGRLayer::GetExtent()) efficiently ... ie. without scanning
831
- // all the features. In some cases this will return TRUE until a
832
- // spatial filter is installed after which it will return FALSE.
828
+ // TRUE if this layer can return its data extent
829
+ // (via OGRLayer::GetExtent()) efficiently ... ie. without scanning
830
+ // all the features. In some cases this will return TRUE until a
831
+ // spatial filter is installed after which it will return FALSE.
833
832
{
834
833
// TODO: Perhaps use as a clue by QGIS whether it should spawn a thread to calculate extent.
835
834
}
836
835
837
836
if (OGR_L_TestCapability (ogrLayer," FastSetNextByIndex" ))
838
- // TRUE if this layer can perform the SetNextByIndex() call efficiently.
837
+ // TRUE if this layer can perform the SetNextByIndex() call efficiently.
839
838
{
840
839
// No use required for this QGIS release.
841
840
}
@@ -857,32 +856,26 @@ int QgsOgrProvider::capabilities() const
857
856
858
857
return ability;
859
858
860
- /*
861
- return (QgsVectorDataProvider::AddFeatures
862
- | QgsVectorDataProvider::ChangeAttributeValues
863
- | QgsVectorDataProvider::CreateSpatialIndex);
864
- */
859
+ /*
860
+ return (QgsVectorDataProvider::AddFeatures
861
+ | QgsVectorDataProvider::ChangeAttributeValues
862
+ | QgsVectorDataProvider::CreateSpatialIndex);
863
+ */
865
864
}
866
865
867
866
868
-
869
-
870
- QString QgsOgrProvider::name () const
867
+ QString QgsOgrProvider::name () const
871
868
{
872
- return TEXT_PROVIDER_KEY;
869
+ return TEXT_PROVIDER_KEY;
873
870
} // QgsOgrProvider::name()
874
871
875
872
876
-
877
873
QString QgsOgrProvider::description () const
878
874
{
879
- return TEXT_PROVIDER_DESCRIPTION;
875
+ return TEXT_PROVIDER_DESCRIPTION;
880
876
} // QgsOgrProvider::description()
881
877
882
878
883
-
884
-
885
-
886
879
/* *
887
880
888
881
Convenience function for readily creating file filters.
@@ -902,8 +895,8 @@ QString QgsOgrProvider::description() const
902
895
*/
903
896
static QString createFileFilter_ (QString const &longName, QString const &glob)
904
897
{
905
- return " [OGR] " +
906
- longName + " (" + glob.lower () + " " + glob.upper () + " );;" ;
898
+ return " [OGR] " +
899
+ longName + " (" + glob.lower () + " " + glob.upper () + " );;" ;
907
900
} // createFileFilter_
908
901
909
902
@@ -912,164 +905,159 @@ static QString createFileFilter_(QString const &longName, QString const &glob)
912
905
913
906
QGISEXTERN QString fileVectorFilters ()
914
907
{
915
- static QString myFileFilters;
908
+ static QString myFileFilters;
916
909
917
- // if we've already built the supported vector string, just return what
918
- // we've already built
919
- if ( ! ( myFileFilters.isEmpty () || myFileFilters.isNull () ) )
920
- {
921
- return myFileFilters;
922
- }
923
-
924
- // register ogr plugins
925
- OGRRegisterAll ();
910
+ // if we've already built the supported vector string, just return what
911
+ // we've already built
912
+ if ( ! ( myFileFilters.isEmpty () || myFileFilters.isNull () ) )
913
+ {
914
+ return myFileFilters;
915
+ }
926
916
927
- // first get the GDAL driver manager
917
+ // register ogr plugins
918
+ OGRRegisterAll ();
928
919
929
- OGRSFDriverH driver; // current driver
920
+ // first get the GDAL driver manager
930
921
931
- QString driverName ; // current driver name
922
+ OGRSFDriverH driver ; // current driver
932
923
933
- // Grind through all the drivers and their respective metadata.
934
- // We'll add a file filter for those drivers that have a file
935
- // extension defined for them; the others, welll, even though
936
- // theoreticaly we can open those files because there exists a
937
- // driver for them, the user will have to use the "All Files" to
938
- // open datasets with no explicitly defined file name extension.
939
- QgsDebugMsg ( QString (" Driver count: %1" ).arg ( OGRGetDriverCount () ) );
924
+ QString driverName; // current driver name
940
925
941
- for (int i = 0 ; i < OGRGetDriverCount (); ++i)
942
- {
943
- driver = OGRGetDriver (i);
926
+ // Grind through all the drivers and their respective metadata.
927
+ // We'll add a file filter for those drivers that have a file
928
+ // extension defined for them; the others, welll, even though
929
+ // theoreticaly we can open those files because there exists a
930
+ // driver for them, the user will have to use the "All Files" to
931
+ // open datasets with no explicitly defined file name extension.
932
+ QgsDebugMsg ( QString (" Driver count: %1" ).arg ( OGRGetDriverCount () ) );
944
933
945
- Q_CHECK_PTR (driver);
934
+ for (int i = 0 ; i < OGRGetDriverCount (); ++i)
935
+ {
936
+ driver = OGRGetDriver (i);
946
937
947
- if (!driver)
948
- {
949
- QgsLogger::warning (" unable to get driver " + QString::number (i));
950
- continue ;
951
- }
938
+ Q_CHECK_PTR (driver);
952
939
953
- driverName = OGR_Dr_GetName (driver);
940
+ if (!driver)
941
+ {
942
+ QgsLogger::warning (" unable to get driver " + QString::number (i));
943
+ continue ;
944
+ }
954
945
946
+ driverName = OGR_Dr_GetName (driver);
955
947
956
- if (driverName.startsWith (" ESRI" ))
957
- {
958
- myFileFilters += createFileFilter_ (" ESRI Shapefiles" , " *.shp" );
959
- }
960
- else if (driverName.startsWith (" UK" ))
961
- {
962
- // XXX needs file filter extension
963
- }
964
- else if (driverName.startsWith (" SDTS" ))
965
- {
966
- myFileFilters += createFileFilter_ ( " Spatial Data Transfer Standard" ,
967
- " *catd.ddf" );
968
- }
969
- else if (driverName.startsWith (" TIGER" ))
970
- {
971
- // XXX needs file filter extension
972
- }
973
- else if (driverName.startsWith (" S57" ))
974
- {
975
- // XXX needs file filter extension
976
- }
977
- else if (driverName.startsWith (" MapInfo" ))
978
- {
979
- myFileFilters += createFileFilter_ (" MapInfo" , " *.mif *.tab" );
980
- // XXX needs file filter extension
981
- }
982
- else if (driverName.startsWith (" DGN" ))
983
- {
984
- // XXX needs file filter extension
985
- }
986
- else if (driverName.startsWith (" VRT" ))
987
- {
988
- // XXX needs file filter extension
989
- }
990
- else if (driverName.startsWith (" AVCBin" ))
991
- {
992
- // XXX needs file filter extension
993
- }
994
- else if (driverName.startsWith (" REC" ))
995
- {
996
- // XXX needs file filter extension
997
- }
998
- else if (driverName.startsWith (" Memory" ))
999
- {
1000
- // XXX needs file filter extension
1001
- }
1002
- else if (driverName.startsWith (" Jis" ))
1003
- {
1004
- // XXX needs file filter extension
1005
- }
1006
- else if (driverName.startsWith (" GML" ))
1007
- {
1008
- // XXX not yet supported; post 0.1 release task
1009
- myFileFilters += createFileFilter_ ( " Geography Markup Language" ,
1010
- " *.gml" );
1011
- }
1012
- else if (driverName.startsWith (" CSV" ))
1013
- {
1014
- // XXX needs file filter extension
1015
- }
1016
- else if (driverName.startsWith (" PostgreSQL" ))
1017
- {
1018
- // XXX needs file filter extension
1019
- }
1020
- else if (driverName.startsWith (" GRASS" ))
1021
- {
1022
- // XXX needs file filter extension
1023
- }
1024
- else if (driverName.startsWith (" KML" ))
1025
- {
1026
- // XXX needs file filter extension
1027
- }
1028
- else if (driverName.startsWith (" Interlis 1" ))
1029
- {
1030
- // XXX needs file filter extension
1031
- }
1032
- else if (driverName.startsWith (" Interlis 2" ))
1033
- {
1034
- // XXX needs file filter extension
1035
- }
1036
- else if (driverName.startsWith (" SQLite" ))
1037
- {
1038
- // XXX needs file filter extension
1039
- }
1040
- else if (driverName.startsWith (" MySQL" ))
1041
- {
1042
- // XXX needs file filter extension
1043
- }
1044
- else
1045
- {
1046
- // NOP, we don't know anything about the current driver
1047
- // with regards to a proper file filter string
1048
- QgsLogger::debug (" fileVectorFilters, unknown driver: " + driverName);
1049
- }
1050
948
1051
- } // each loaded GDAL driver
949
+ if (driverName.startsWith (" ESRI" ))
950
+ {
951
+ myFileFilters += createFileFilter_ (" ESRI Shapefiles" , " *.shp" );
952
+ }
953
+ else if (driverName.startsWith (" UK" ))
954
+ {
955
+ // XXX needs file filter extension
956
+ }
957
+ else if (driverName.startsWith (" SDTS" ))
958
+ {
959
+ myFileFilters += createFileFilter_ ( " Spatial Data Transfer Standard" ,
960
+ " *catd.ddf" );
961
+ }
962
+ else if (driverName.startsWith (" TIGER" ))
963
+ {
964
+ // XXX needs file filter extension
965
+ }
966
+ else if (driverName.startsWith (" S57" ))
967
+ {
968
+ // XXX needs file filter extension
969
+ }
970
+ else if (driverName.startsWith (" MapInfo" ))
971
+ {
972
+ myFileFilters += createFileFilter_ (" MapInfo" , " *.mif *.tab" );
973
+ // XXX needs file filter extension
974
+ }
975
+ else if (driverName.startsWith (" DGN" ))
976
+ {
977
+ // XXX needs file filter extension
978
+ }
979
+ else if (driverName.startsWith (" VRT" ))
980
+ {
981
+ // XXX needs file filter extension
982
+ }
983
+ else if (driverName.startsWith (" AVCBin" ))
984
+ {
985
+ // XXX needs file filter extension
986
+ }
987
+ else if (driverName.startsWith (" REC" ))
988
+ {
989
+ // XXX needs file filter extension
990
+ }
991
+ else if (driverName.startsWith (" Memory" ))
992
+ {
993
+ // XXX needs file filter extension
994
+ }
995
+ else if (driverName.startsWith (" Jis" ))
996
+ {
997
+ // XXX needs file filter extension
998
+ }
999
+ else if (driverName.startsWith (" GML" ))
1000
+ {
1001
+ // XXX not yet supported; post 0.1 release task
1002
+ myFileFilters += createFileFilter_ ( " Geography Markup Language" ,
1003
+ " *.gml" );
1004
+ }
1005
+ else if (driverName.startsWith (" CSV" ))
1006
+ {
1007
+ // XXX needs file filter extension
1008
+ }
1009
+ else if (driverName.startsWith (" PostgreSQL" ))
1010
+ {
1011
+ // XXX needs file filter extension
1012
+ }
1013
+ else if (driverName.startsWith (" GRASS" ))
1014
+ {
1015
+ // XXX needs file filter extension
1016
+ }
1017
+ else if (driverName.startsWith (" KML" ))
1018
+ {
1019
+ // XXX needs file filter extension
1020
+ }
1021
+ else if (driverName.startsWith (" Interlis 1" ))
1022
+ {
1023
+ // XXX needs file filter extension
1024
+ }
1025
+ else if (driverName.startsWith (" Interlis 2" ))
1026
+ {
1027
+ // XXX needs file filter extension
1028
+ }
1029
+ else if (driverName.startsWith (" SQLite" ))
1030
+ {
1031
+ // XXX needs file filter extension
1032
+ }
1033
+ else if (driverName.startsWith (" MySQL" ))
1034
+ {
1035
+ // XXX needs file filter extension
1036
+ }
1037
+ else
1038
+ {
1039
+ // NOP, we don't know anything about the current driver
1040
+ // with regards to a proper file filter string
1041
+ QgsLogger::debug (" fileVectorFilters, unknown driver: " + driverName);
1042
+ }
1052
1043
1053
- // can't forget the default case
1044
+ } // each loaded GDAL driver
1054
1045
1055
- myFileFilters += " All files (*.*) " ;
1046
+ // can't forget the default case
1056
1047
1057
- return myFileFilters ;
1048
+ myFileFilters += " All files (*.*) " ;
1058
1049
1059
- } // fileVectorFilters() const
1050
+ return myFileFilters;
1060
1051
1052
+ } // fileVectorFilters() const
1061
1053
1062
1054
1063
1055
QString QgsOgrProvider::fileVectorFilters () const
1064
1056
{
1065
- return fileVectorFilters ();
1057
+ return fileVectorFilters ();
1066
1058
} // QgsOgrProvider::fileVectorFilters() const
1067
1059
1068
1060
1069
-
1070
-
1071
-
1072
-
1073
1061
/* *
1074
1062
* Class factory to return a pointer to a newly created
1075
1063
* QgsOgrProvider object
@@ -1094,7 +1082,7 @@ QGISEXTERN QString providerKey()
1094
1082
*/
1095
1083
QGISEXTERN QString description ()
1096
1084
{
1097
- return TEXT_PROVIDER_DESCRIPTION;
1085
+ return TEXT_PROVIDER_DESCRIPTION;
1098
1086
}
1099
1087
1100
1088
/* *
@@ -1119,124 +1107,123 @@ QGISEXTERN bool createEmptyDataSource(const QString& uri,
1119
1107
QGis::WKBTYPE vectortype,
1120
1108
const std::list<std::pair<QString, QString> >& attributes)
1121
1109
{
1122
- OGRSFDriverH driver;
1123
- OGRRegisterAll ();
1124
- driver = OGRGetDriverByName (format);
1125
- if (driver == NULL )
1126
- {
1127
- return false ;
1128
- }
1110
+ OGRSFDriverH driver;
1111
+ OGRRegisterAll ();
1112
+ driver = OGRGetDriverByName (format);
1113
+ if (driver == NULL )
1114
+ {
1115
+ return false ;
1116
+ }
1129
1117
1130
- OGRDataSourceH dataSource;
1131
- dataSource = OGR_Dr_CreateDataSource (driver,QFile::encodeName (uri).constData (), NULL );
1132
- if (dataSource == NULL )
1133
- {
1134
- return false ;
1135
- }
1118
+ OGRDataSourceH dataSource;
1119
+ dataSource = OGR_Dr_CreateDataSource (driver,QFile::encodeName (uri).constData (), NULL );
1120
+ if (dataSource == NULL )
1121
+ {
1122
+ return false ;
1123
+ }
1124
+
1125
+ // consider spatial reference system
1126
+ OGRSpatialReferenceH reference = NULL ;
1127
+ QgsSpatialRefSys mySpatialRefSys;
1128
+ mySpatialRefSys.validate ();
1129
+ QString myWKT = mySpatialRefSys.toWkt ();
1130
+
1131
+ if ( !myWKT.isNull () && myWKT.length () != 0 )
1132
+ {
1133
+ reference = OSRNewSpatialReference (myWKT.toLocal8Bit ().data ());
1134
+ }
1136
1135
1137
- // consider spatial reference system
1138
- OGRSpatialReferenceH reference = NULL ;
1139
- QgsSpatialRefSys mySpatialRefSys;
1140
- mySpatialRefSys.validate ();
1141
- QString myWKT = mySpatialRefSys.toWkt ();
1142
-
1143
- if ( !myWKT.isNull () && myWKT.length () != 0 )
1136
+ // Map the qgis geometry type to the OGR geometry type
1137
+ OGRwkbGeometryType OGRvectortype = wkbUnknown;
1138
+ switch (vectortype)
1139
+ {
1140
+ case QGis::WKBPoint:
1141
+ OGRvectortype = wkbPoint;
1142
+ break ;
1143
+ case QGis::WKBLineString:
1144
+ OGRvectortype = wkbLineString;
1145
+ break ;
1146
+ case QGis::WKBPolygon:
1147
+ OGRvectortype = wkbPolygon;
1148
+ break ;
1149
+ case QGis::WKBMultiPoint:
1150
+ OGRvectortype = wkbMultiPoint;
1151
+ break ;
1152
+ case QGis::WKBMultiLineString:
1153
+ OGRvectortype = wkbMultiLineString;
1154
+ break ;
1155
+ case QGis::WKBMultiPolygon:
1156
+ OGRvectortype = wkbMultiPolygon;
1157
+ break ;
1158
+ default :
1144
1159
{
1145
- reference = OSRNewSpatialReference (myWKT.toLocal8Bit ().data ());
1160
+ QgsLogger::debug (" Unknown vector type of: " , (int )(vectortype), 1 ,
1161
+ __FILE__, __FUNCTION__, __LINE__);
1162
+ return false ;
1163
+ break ;
1146
1164
}
1165
+ }
1166
+
1167
+ OGRLayerH layer;
1168
+ layer = OGR_DS_CreateLayer (dataSource,QFile::encodeName (QFileInfo (uri).baseName ()).constData (), reference, OGRvectortype, NULL );
1169
+ if (layer == NULL )
1170
+ {
1171
+ return false ;
1172
+ }
1147
1173
1148
- // Map the qgis geometry type to the OGR geometry type
1149
- OGRwkbGeometryType OGRvectortype = wkbUnknown;
1150
- switch (vectortype)
1174
+ // create the attribute fields
1175
+
1176
+ QTextCodec* codec=QTextCodec::codecForName (encoding.toLocal8Bit ().data ());
1177
+
1178
+ for (std::list<std::pair<QString, QString> >::const_iterator it= attributes.begin (); it != attributes.end (); ++it)
1179
+ {
1180
+ if (it->second == " Real" )
1151
1181
{
1152
- case QGis::WKBPoint:
1153
- OGRvectortype = wkbPoint;
1154
- break ;
1155
- case QGis::WKBLineString:
1156
- OGRvectortype = wkbLineString;
1157
- break ;
1158
- case QGis::WKBPolygon:
1159
- OGRvectortype = wkbPolygon;
1160
- break ;
1161
- case QGis::WKBMultiPoint:
1162
- OGRvectortype = wkbMultiPoint;
1163
- break ;
1164
- case QGis::WKBMultiLineString:
1165
- OGRvectortype = wkbMultiLineString;
1166
- break ;
1167
- case QGis::WKBMultiPolygon:
1168
- OGRvectortype = wkbMultiPolygon;
1169
- break ;
1170
- default :
1182
+ OGRFieldDefnH field = OGR_Fld_Create (codec->fromUnicode (it->first ).data (), OFTReal);
1183
+ OGR_Fld_SetPrecision (field,3 );
1184
+ OGR_Fld_SetWidth (field,32 );
1185
+ if ( OGR_L_CreateField (layer,field,TRUE ) != OGRERR_NONE)
1171
1186
{
1172
- QgsLogger::debug (" Unknown vector type of: " , (int )(vectortype), 1 ,
1173
- __FILE__, __FUNCTION__, __LINE__);
1174
- return false ;
1175
- break ;
1187
+ QgsLogger::warning (" creation of OFTReal field failed" );
1176
1188
}
1177
1189
}
1178
-
1179
- OGRLayerH layer;
1180
- layer = OGR_DS_CreateLayer (dataSource,QFile::encodeName (QFileInfo (uri).baseName ()).constData (), reference, OGRvectortype, NULL );
1181
- if (layer == NULL )
1190
+ else if (it->second == " Integer" )
1182
1191
{
1183
- return false ;
1192
+ OGRFieldDefnH field = OGR_Fld_Create (codec->fromUnicode (it->first ).data (), OFTInteger);
1193
+ if (OGR_L_CreateField (layer,field,TRUE ) != OGRERR_NONE)
1194
+ {
1195
+ QgsLogger::warning (" creation of OFTInteger field failed" );
1196
+ }
1184
1197
}
1185
-
1186
- // create the attribute fields
1187
-
1188
- QTextCodec* codec=QTextCodec::codecForName (encoding.toLocal8Bit ().data ());
1189
-
1190
- for (std::list<std::pair<QString, QString> >::const_iterator it= attributes.begin (); it != attributes.end (); ++it)
1198
+ else if (it->second == " String" )
1191
1199
{
1192
- if (it->second == " Real" )
1193
- {
1194
- OGRFieldDefnH field = OGR_Fld_Create (codec->fromUnicode (it->first ).data (), OFTReal);
1195
- OGR_Fld_SetPrecision (field,3 );
1196
- OGR_Fld_SetWidth (field,32 );
1197
- if ( OGR_L_CreateField (layer,field,TRUE ) != OGRERR_NONE)
1198
- {
1199
- QgsLogger::warning (" creation of OFTReal field failed" );
1200
- }
1201
- }
1202
- else if (it->second == " Integer" )
1203
- {
1204
- OGRFieldDefnH field = OGR_Fld_Create (codec->fromUnicode (it->first ).data (), OFTInteger);
1205
- if (OGR_L_CreateField (layer,field,TRUE ) != OGRERR_NONE)
1206
- {
1207
- QgsLogger::warning (" creation of OFTInteger field failed" );
1208
- }
1209
- }
1210
- else if (it->second == " String" )
1211
- {
1212
- OGRFieldDefnH field = OGR_Fld_Create (codec->fromUnicode (it->first ).data (), OFTString);
1213
- if (OGR_L_CreateField (layer,field,TRUE ) != OGRERR_NONE)
1214
- {
1215
- QgsLogger::warning (" creation of OFTString field failed" );
1216
- }
1217
- }
1200
+ OGRFieldDefnH field = OGR_Fld_Create (codec->fromUnicode (it->first ).data (), OFTString);
1201
+ if (OGR_L_CreateField (layer,field,TRUE ) != OGRERR_NONE)
1202
+ {
1203
+ QgsLogger::warning (" creation of OFTString field failed" );
1204
+ }
1218
1205
}
1206
+ }
1219
1207
1220
- OGR_DS_Destroy (dataSource);
1208
+ OGR_DS_Destroy (dataSource);
1221
1209
1222
- QgsDebugMsg ( QString (" GDAL Version number %1" ).arg ( GDAL_VERSION_NUM ) );
1210
+ QgsDebugMsg ( QString (" GDAL Version number %1" ).arg ( GDAL_VERSION_NUM ) );
1223
1211
#if GDAL_VERSION_NUM >= 1310
1224
- if (reference)
1225
- {
1226
- OSRRelease ( reference );
1227
- }
1212
+ if (reference)
1213
+ {
1214
+ OSRRelease ( reference );
1215
+ }
1228
1216
#endif // GDAL_VERSION_NUM
1229
- return true ;
1217
+ return true ;
1230
1218
}
1231
1219
1232
1220
1233
-
1234
1221
QgsSpatialRefSys QgsOgrProvider::getSRS ()
1235
1222
{
1236
1223
QgsDebugMsg (" QgsOgrProvider::getSRS()" );
1237
1224
1238
1225
QgsSpatialRefSys srs;
1239
-
1226
+
1240
1227
OGRSpatialReferenceH mySpatialRefSys = OGR_L_GetSpatialRef (ogrLayer);
1241
1228
if (mySpatialRefSys == NULL )
1242
1229
{
@@ -1252,7 +1239,7 @@ QgsSpatialRefSys QgsOgrProvider::getSRS()
1252
1239
OSRExportToWkt (mySpatialRefSys, &pszWKT );
1253
1240
QString myWKTString = QString (pszWKT);
1254
1241
OGRFree (pszWKT);
1255
-
1242
+
1256
1243
// create SRS from WKT
1257
1244
srs.createFromWkt ( myWKTString );
1258
1245
}
0 commit comments