Skip to content

File tree

1 file changed

+491
-504
lines changed

1 file changed

+491
-504
lines changed
 

‎src/providers/ogr/qgsogrprovider.cpp

Lines changed: 491 additions & 504 deletions
Original file line numberDiff line numberDiff line change
@@ -157,62 +157,62 @@ QgsOgrProvider::~QgsOgrProvider()
157157

158158
void QgsOgrProvider::setEncoding(const QString& e)
159159
{
160-
QgsVectorDataProvider::setEncoding(e);
161-
loadFields();
160+
QgsVectorDataProvider::setEncoding(e);
161+
loadFields();
162162
}
163163

164164
void QgsOgrProvider::loadFields()
165165
{
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)
170176
{
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)
192180
{
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)
197183
{
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;
202202
#if GDAL_VERSION_NUM >= 1400
203-
case OFTString: varType = QVariant::String; break;
203+
case OFTString: varType = QVariant::String; break;
204204
#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
214206
}
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) ));
215214
}
215+
}
216216
}
217217

218218

@@ -223,7 +223,6 @@ QString QgsOgrProvider::storageType() const
223223
}
224224

225225

226-
227226
bool QgsOgrProvider::getFeatureAtId(int featureId,
228227
QgsFeature& feature,
229228
bool fetchGeometry,
@@ -232,18 +231,18 @@ bool QgsOgrProvider::getFeatureAtId(int featureId,
232231
OGRFeatureH fet = OGR_L_GetFeature(ogrLayer,featureId);
233232
if (fet == NULL)
234233
return false;
235-
234+
236235
feature.setFeatureId(OGR_F_GetFID(fet));
237236

238237
/* fetch geometry */
239238
if (fetchGeometry)
240239
{
241240
OGRGeometryH geom = OGR_F_GetGeometryRef(fet);
242-
241+
243242
// get the wkb representation
244243
unsigned char *wkb = new unsigned char[OGR_G_WkbSize(geom)];
245244
OGR_G_ExportToWkb(geom,(OGRwkbByteOrder) QgsApplication::endian(), wkb);
246-
245+
247246
feature.setGeometryAndOwnership(wkb, OGR_G_WkbSize(geom));
248247
}
249248

@@ -252,90 +251,90 @@ bool QgsOgrProvider::getFeatureAtId(int featureId,
252251
{
253252
getFeatureAttribute(fet,feature,*it);
254253
}
255-
254+
256255
return true;
257256
}
258257

259258
bool QgsOgrProvider::getNextFeature(QgsFeature& feature)
260259
{
261260
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+
267266
OGRFeatureH fet;
268267
QgsRect selectionRect;
269-
268+
270269
while ((fet = OGR_L_GetNextFeature(ogrLayer)) != NULL)
270+
{
271+
// skip features without geometry
272+
if (OGR_F_GetGeometryRef(fet) == NULL && !mFetchFeaturesWithoutGeom)
271273
{
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
299298
OGREnvelope env;
300299
memset( &env, 0, sizeof(env) );
301300
if(mSelectionRectangle)
302301
OGR_G_GetEnvelope(mSelectionRectangle,&env);
303302
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+
}
331313
}
332-
else
314+
315+
/* fetch attributes */
316+
for(QgsAttributeList::iterator it = mAttributesToFetch.begin(); it != mAttributesToFetch.end(); ++it)
333317
{
334-
QgsDebugMsg("Feature is null");
335-
// probably should reset reading here
336-
OGR_L_ResetReading(ogrLayer);
337-
return false;
318+
getFeatureAttribute(fet,feature,*it);
338319
}
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+
}
339338
}
340339

341340
void QgsOgrProvider::select(QgsAttributeList fetchAttributes, QgsRect rect, bool fetchGeometry, \
@@ -347,32 +346,32 @@ void QgsOgrProvider::select(QgsAttributeList fetchAttributes, QgsRect rect, bool
347346

348347
// spatial query to select features
349348
if(rect.isEmpty())
350-
{
351-
OGR_L_SetSpatialFilter(ogrLayer,0);
352-
}
349+
{
350+
OGR_L_SetSpatialFilter(ogrLayer,0);
351+
}
353352
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)
354359
{
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+
}
376375
}
377376

378377

@@ -382,7 +381,7 @@ unsigned char * QgsOgrProvider::getGeometryPointer(OGRFeatureH fet)
382381
unsigned char *gPtr=0;
383382

384383
if( geom == NULL )
385-
return NULL;
384+
return NULL;
386385

387386
// get the wkb representation
388387
gPtr = new unsigned char[OGR_G_WkbSize(geom)];
@@ -402,7 +401,7 @@ QgsRect QgsOgrProvider::extent()
402401

403402
size_t QgsOgrProvider::layerCount() const
404403
{
405-
return OGR_DS_GetLayerCount(ogrDataSource);
404+
return OGR_DS_GetLayerCount(ogrDataSource);
406405
} // QgsOgrProvider::layerCount()
407406

408407

@@ -444,14 +443,14 @@ void QgsOgrProvider::getFeatureAttribute(OGRFeatureH ogrFet, QgsFeature & f, int
444443
QByteArray cstr(OGR_F_GetFieldAsString(ogrFet,attindex));
445444
QString str = mEncoding->toUnicode(cstr);
446445
QVariant value;
447-
446+
448447
switch (mAttributeFields[attindex].type())
449448
{
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;
453452
//case QVariant::DateTime: value = QVariant(QDateTime::fromString(str)); break;
454-
default: assert(NULL && "unsupported field type");
453+
default: assert(NULL && "unsupported field type");
455454
}
456455

457456
f.addAttribute(attindex, value);
@@ -488,54 +487,54 @@ bool QgsOgrProvider::addFeature(QgsFeature& f)
488487

489488
if( f.geometry()->wkbSize() > 0 )
490489
{
491-
OGRGeometryH geom = NULL;
490+
OGRGeometryH geom = NULL;
492491

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+
}
498497

499-
OGR_F_SetGeometryDirectly( feature, geom );
498+
OGR_F_SetGeometryDirectly( feature, geom );
500499
}
501-
500+
502501
QgsAttributeMap attrs = f.attributeMap();
503502

504503
//add possible attribute information
505504
for(QgsAttributeMap::iterator it = attrs.begin(); it != attrs.end(); ++it)
506505
{
507506
int targetAttributeId = it.key();
508-
507+
509508
// don't try to set field from attribute map if it's not present in layer
510509
if (targetAttributeId >= OGR_FD_GetFieldCount(fdef))
511510
continue;
512511

513512
//if(!s.isEmpty())
514513
// continue;
515-
514+
516515
OGRFieldDefnH fldDef = OGR_FD_GetFieldDefn( fdef, targetAttributeId );
517516

518517
switch( OGR_Fld_GetType(fldDef) )
519518
{
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;
523522

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;
527526

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;
535534

536-
default:
537-
QgsLogger::warning("QgsOgrProvider::addFeature, no type found");
538-
break;
535+
default:
536+
QgsLogger::warning("QgsOgrProvider::addFeature, no type found");
537+
break;
539538
}
540539
}
541540

@@ -569,41 +568,41 @@ bool QgsOgrProvider::addFeatures(QgsFeatureList & flist)
569568

570569
bool QgsOgrProvider::addAttributes(const QgsNewAttributesMap & attributes)
571570
{
572-
bool returnvalue=true;
571+
bool returnvalue=true;
573572

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")
575579
{
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+
}
597596

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;
604601
}
602+
OGR_Fld_Destroy( fielddefn );
603+
}
605604

606-
return returnvalue;
605+
return returnvalue;
607606
}
608607

609608
bool QgsOgrProvider::changeAttributeValues(const QgsChangedAttributesMap & attr_map)
@@ -625,29 +624,29 @@ bool QgsOgrProvider::changeAttributeValues(const QgsChangedAttributesMap & attr_
625624
for( QgsAttributeMap::const_iterator it2 = attr.begin(); it2 != attr.end(); ++it2 )
626625
{
627626
int f = it2.key();
628-
627+
629628
OGRFieldDefnH fd = OGR_F_GetFieldDefnRef( of, f );
630629
if (fd == NULL)
631630
{
632631
QgsLogger::warning("QgsOgrProvider::changeAttributeValues, Field " + QString::number(f) + " doesn't exist");
633632
continue;
634633
}
635-
634+
636635
OGRFieldType type = OGR_Fld_GetType( fd );
637636
switch ( type )
638637
{
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;
651650
}
652651

653652
}
@@ -676,9 +675,9 @@ bool QgsOgrProvider::changeGeometryValues(QgsGeometryMap & geometry_map)
676675

677676
//create an OGRGeometry
678677
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)
682681
{
683682
QgsLogger::warning("QgsOgrProvider::changeGeometryValues, error while creating new OGRGeometry");
684683
OGR_G_DestroyGeometry( theNewGeometry );
@@ -691,7 +690,7 @@ bool QgsOgrProvider::changeGeometryValues(QgsGeometryMap & geometry_map)
691690
QgsLogger::warning("QgsOgrProvider::changeGeometryValues, new geometry is NULL");
692691
continue;
693692
}
694-
693+
695694
//set the new geometry
696695
if(OGR_F_SetGeometryDirectly(theOGRFeature, theNewGeometry) != OGRERR_NONE)
697696
{
@@ -700,7 +699,7 @@ bool QgsOgrProvider::changeGeometryValues(QgsGeometryMap & geometry_map)
700699
theNewGeometry = 0;
701700
continue;
702701
}
703-
702+
704703
OGR_L_SetFeature(ogrLayer,theOGRFeature);
705704
OGR_F_Destroy( theOGRFeature);
706705
}
@@ -710,23 +709,23 @@ bool QgsOgrProvider::changeGeometryValues(QgsGeometryMap & geometry_map)
710709

711710
bool QgsOgrProvider::createSpatialIndex()
712711
{
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+
}
730729
}
731730

732731
bool QgsOgrProvider::deleteFeatures(const QgsFeatureIds & id)
@@ -770,9 +769,9 @@ int QgsOgrProvider::capabilities() const
770769
// the #defines we want to test for here.
771770

772771
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.
776775
{
777776
ability |= QgsVectorDataProvider::RandomSelectGeometryAtId;
778777
}
@@ -783,19 +782,19 @@ int QgsOgrProvider::capabilities() const
783782
ability |= QgsVectorDataProvider::SelectGeometryAtId;
784783

785784
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.
787786
{
788787
ability |= QgsVectorDataProvider::AddFeatures;
789788
}
790789

791790
if (OGR_L_TestCapability(ogrLayer,"DeleteFeature"))
792-
// TRUE if this layer can delete its features
791+
// TRUE if this layer can delete its features
793792
{
794793
ability |= DeleteFeatures;
795794
}
796-
795+
797796
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.
799798
{
800799
// TODO According to http://shapelib.maptools.org/ (Shapefile C Library V1.2)
801800
// TODO "You can't modify the vertices of existing structures".
@@ -807,35 +806,35 @@ int QgsOgrProvider::capabilities() const
807806
}
808807

809808
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.
815814
{
816815
// TODO: Perhaps use as a clue by QGIS whether it should build and maintain it's own spatial index for features in this layer.
817816
}
818817

819818
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.
824823
{
825824
// TODO: Perhaps use as a clue by QGIS whether it should spawn a thread to count features.
826825
}
827826

828827
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.
833832
{
834833
// TODO: Perhaps use as a clue by QGIS whether it should spawn a thread to calculate extent.
835834
}
836835

837836
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.
839838
{
840839
// No use required for this QGIS release.
841840
}
@@ -857,32 +856,26 @@ int QgsOgrProvider::capabilities() const
857856

858857
return ability;
859858

860-
/*
861-
return (QgsVectorDataProvider::AddFeatures
862-
| QgsVectorDataProvider::ChangeAttributeValues
863-
| QgsVectorDataProvider::CreateSpatialIndex);
864-
*/
859+
/*
860+
return (QgsVectorDataProvider::AddFeatures
861+
| QgsVectorDataProvider::ChangeAttributeValues
862+
| QgsVectorDataProvider::CreateSpatialIndex);
863+
*/
865864
}
866865

867866

868-
869-
870-
QString QgsOgrProvider::name() const
867+
QString QgsOgrProvider::name() const
871868
{
872-
return TEXT_PROVIDER_KEY;
869+
return TEXT_PROVIDER_KEY;
873870
} // QgsOgrProvider::name()
874871

875872

876-
877873
QString QgsOgrProvider::description() const
878874
{
879-
return TEXT_PROVIDER_DESCRIPTION;
875+
return TEXT_PROVIDER_DESCRIPTION;
880876
} // QgsOgrProvider::description()
881877

882878

883-
884-
885-
886879
/**
887880
888881
Convenience function for readily creating file filters.
@@ -902,8 +895,8 @@ QString QgsOgrProvider::description() const
902895
*/
903896
static QString createFileFilter_(QString const &longName, QString const &glob)
904897
{
905-
return "[OGR] " +
906-
longName + " (" + glob.lower() + " " + glob.upper() + ");;";
898+
return "[OGR] " +
899+
longName + " (" + glob.lower() + " " + glob.upper() + ");;";
907900
} // createFileFilter_
908901

909902

@@ -912,164 +905,159 @@ static QString createFileFilter_(QString const &longName, QString const &glob)
912905

913906
QGISEXTERN QString fileVectorFilters()
914907
{
915-
static QString myFileFilters;
908+
static QString myFileFilters;
916909

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+
}
926916

927-
// first get the GDAL driver manager
917+
// register ogr plugins
918+
OGRRegisterAll();
928919

929-
OGRSFDriverH driver; // current driver
920+
// first get the GDAL driver manager
930921

931-
QString driverName; // current driver name
922+
OGRSFDriverH driver; // current driver
932923

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
940925

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() ) );
944933

945-
Q_CHECK_PTR(driver);
934+
for (int i = 0; i < OGRGetDriverCount(); ++i)
935+
{
936+
driver = OGRGetDriver(i);
946937

947-
if (!driver)
948-
{
949-
QgsLogger::warning("unable to get driver " + QString::number(i));
950-
continue;
951-
}
938+
Q_CHECK_PTR(driver);
952939

953-
driverName = OGR_Dr_GetName(driver);
940+
if (!driver)
941+
{
942+
QgsLogger::warning("unable to get driver " + QString::number(i));
943+
continue;
944+
}
954945

946+
driverName = OGR_Dr_GetName(driver);
955947

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-
}
1050948

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+
}
10521043

1053-
// can't forget the default case
1044+
} // each loaded GDAL driver
10541045

1055-
myFileFilters += "All files (*.*)";
1046+
// can't forget the default case
10561047

1057-
return myFileFilters;
1048+
myFileFilters += "All files (*.*)";
10581049

1059-
} // fileVectorFilters() const
1050+
return myFileFilters;
10601051

1052+
} // fileVectorFilters() const
10611053

10621054

10631055
QString QgsOgrProvider::fileVectorFilters() const
10641056
{
1065-
return fileVectorFilters();
1057+
return fileVectorFilters();
10661058
} // QgsOgrProvider::fileVectorFilters() const
10671059

10681060

1069-
1070-
1071-
1072-
10731061
/**
10741062
* Class factory to return a pointer to a newly created
10751063
* QgsOgrProvider object
@@ -1094,7 +1082,7 @@ QGISEXTERN QString providerKey()
10941082
*/
10951083
QGISEXTERN QString description()
10961084
{
1097-
return TEXT_PROVIDER_DESCRIPTION;
1085+
return TEXT_PROVIDER_DESCRIPTION;
10981086
}
10991087

11001088
/**
@@ -1119,124 +1107,123 @@ QGISEXTERN bool createEmptyDataSource(const QString& uri,
11191107
QGis::WKBTYPE vectortype,
11201108
const std::list<std::pair<QString, QString> >& attributes)
11211109
{
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+
}
11291117

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+
}
11361135

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:
11441159
{
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;
11461164
}
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+
}
11471173

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")
11511181
{
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)
11711186
{
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");
11761188
}
11771189
}
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")
11821191
{
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+
}
11841197
}
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")
11911199
{
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+
}
12181205
}
1206+
}
12191207

1220-
OGR_DS_Destroy(dataSource);
1208+
OGR_DS_Destroy(dataSource);
12211209

1222-
QgsDebugMsg( QString("GDAL Version number %1").arg( GDAL_VERSION_NUM ) );
1210+
QgsDebugMsg( QString("GDAL Version number %1").arg( GDAL_VERSION_NUM ) );
12231211
#if GDAL_VERSION_NUM >= 1310
1224-
if(reference)
1225-
{
1226-
OSRRelease( reference );
1227-
}
1212+
if(reference)
1213+
{
1214+
OSRRelease( reference );
1215+
}
12281216
#endif //GDAL_VERSION_NUM
1229-
return true;
1217+
return true;
12301218
}
12311219

12321220

1233-
12341221
QgsSpatialRefSys QgsOgrProvider::getSRS()
12351222
{
12361223
QgsDebugMsg("QgsOgrProvider::getSRS()");
12371224

12381225
QgsSpatialRefSys srs;
1239-
1226+
12401227
OGRSpatialReferenceH mySpatialRefSys = OGR_L_GetSpatialRef(ogrLayer);
12411228
if (mySpatialRefSys == NULL)
12421229
{
@@ -1252,7 +1239,7 @@ QgsSpatialRefSys QgsOgrProvider::getSRS()
12521239
OSRExportToWkt(mySpatialRefSys, &pszWKT );
12531240
QString myWKTString = QString(pszWKT);
12541241
OGRFree(pszWKT);
1255-
1242+
12561243
// create SRS from WKT
12571244
srs.createFromWkt( myWKTString );
12581245
}

0 commit comments

Comments
 (0)
Please sign in to comment.