[QGIS Commit] r8161 - in branches/gdalogr-capi-branch/qgis: src/app src/core src/plugins/spit src/providers/mysql src/providers/ogr tests/algorithms/projections

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Feb 15 18:37:51 EST 2008


Author: warmerdam
Date: 2008-02-15 18:37:51 -0500 (Fri, 15 Feb 2008)
New Revision: 8161

Removed:
   branches/gdalogr-capi-branch/qgis/src/providers/ogr/qgsogrfactory.cpp
   branches/gdalogr-capi-branch/qgis/src/providers/ogr/qgsogrfactory.h
Modified:
   branches/gdalogr-capi-branch/qgis/src/app/qgisapp.cpp
   branches/gdalogr-capi-branch/qgis/src/core/qgsspatialrefsys.cpp
   branches/gdalogr-capi-branch/qgis/src/core/qgsvectorfilewriter.cpp
   branches/gdalogr-capi-branch/qgis/src/core/qgsvectorfilewriter.h
   branches/gdalogr-capi-branch/qgis/src/plugins/spit/qgsshapefile.cpp
   branches/gdalogr-capi-branch/qgis/src/plugins/spit/qgsshapefile.h
   branches/gdalogr-capi-branch/qgis/src/providers/mysql/qgsmysqlprovider.cpp
   branches/gdalogr-capi-branch/qgis/src/providers/ogr/qgsogrprovider.cpp
   branches/gdalogr-capi-branch/qgis/src/providers/ogr/qgsogrprovider.h
   branches/gdalogr-capi-branch/qgis/tests/algorithms/projections/projectioncshandlingtest.h
Log:
convert use of OGR and OGRSpatialReference to C API

Modified: branches/gdalogr-capi-branch/qgis/src/app/qgisapp.cpp
===================================================================
--- branches/gdalogr-capi-branch/qgis/src/app/qgisapp.cpp	2008-02-15 21:20:17 UTC (rev 8160)
+++ branches/gdalogr-capi-branch/qgis/src/app/qgisapp.cpp	2008-02-15 23:37:51 UTC (rev 8161)
@@ -129,7 +129,7 @@
 //
 // Gdal/Ogr includes
 //
-#include <ogrsf_frmts.h>
+#include <ogr_api.h>
 
 //
 // Other includes
@@ -1701,20 +1701,10 @@
     return;
   }
 
-  // first get the GDAL driver manager
-
-  OGRSFDriverRegistrar *driverRegistrar = OGRSFDriverRegistrar::GetRegistrar();
-
-  if (!driverRegistrar)
-  {
-    QMessageBox::warning(this,tr("OGR Driver Manager"),tr("unable to get OGRDriverManager"));
-    return;                 // XXX good place to throw exception if we
-  }                           // XXX decide to do exceptions
-
   // then iterate through all of the supported drivers, adding the
   // corresponding file filter
 
-  OGRSFDriver *driver;          // current driver
+  OGRSFDriverH driver;          // current driver
 
   QString driverName;           // current driver name
 
@@ -1726,9 +1716,9 @@
   // open datasets with no explicitly defined file name extension.
   QgsDebugMsg("Driver count: " + QString::number(driverRegistrar->GetDriverCount()));
 
-  for (int i = 0; i < driverRegistrar->GetDriverCount(); ++i)
+  for (int i = 0; i < OGRGetDriverCount(); ++i)
   {
-    driver = driverRegistrar->GetDriver(i);
+    driver = OGRGetDriver(i);
 
     Q_CHECK_PTR(driver);
 
@@ -1738,10 +1728,8 @@
       continue;
     }
 
-    driverName = driver->GetName();
+    driverName = OGR_Dr_GetName(driver);
 
-
-
     if (driverName.startsWith("ESRI"))
     {
       myFileFilters += createFileFilter_("ESRI Shapefiles", "*.shp");

Modified: branches/gdalogr-capi-branch/qgis/src/core/qgsspatialrefsys.cpp
===================================================================
--- branches/gdalogr-capi-branch/qgis/src/core/qgsspatialrefsys.cpp	2008-02-15 21:20:17 UTC (rev 8160)
+++ branches/gdalogr-capi-branch/qgis/src/core/qgsspatialrefsys.cpp	2008-02-15 23:37:51 UTC (rev 8161)
@@ -33,8 +33,7 @@
 #include <sqlite3.h>
 
 //gdal and ogr includes (needed for == operator)
-#include <ogr_api.h>
-#include <ogr_spatialref.h>
+#include <ogr_srs_api.h>
 #include <cpl_error.h>
 #include <cpl_conv.h>
 
@@ -164,9 +163,13 @@
     //this is really ugly but we need to get a QString to a char**
     const char *mySourceCharArrayPointer = mProj4String.latin1();
     //create the sr and populate it from a wkt proj definition
-    OGRSpatialReference myOgrSpatialRef;
-    OGRErr myInputResult = myOgrSpatialRef.importFromProj4( mySourceCharArrayPointer );
+    OGRSpatialReferenceH myOgrSpatialRef = OSRNewSpatialReference(NULL);
+    
+    OGRErr myInputResult = 
+        OSRImportFromProj4( myOgrSpatialRef, mySourceCharArrayPointer );
 
+    OSRDestroySpatialReference( myOgrSpatialRef );
+
     if (myInputResult==OGRERR_NONE)
     {
       //srs is valid so nothing more to do...
@@ -187,9 +190,11 @@
   //this is really ugly but we need to get a QString to a char**
   const char *mySourceCharArrayPointer = mProj4String.latin1();
   //create the sr and populate it from a wkt proj definition
-  OGRSpatialReference myOgrSpatialRef;
-  OGRErr myInputResult = myOgrSpatialRef.importFromProj4( mySourceCharArrayPointer );
+  OGRSpatialReferenceH myOgrSpatialRef = OSRNewSpatialReference(NULL);
+  OGRErr myInputResult = OSRImportFromProj4( myOgrSpatialRef, mySourceCharArrayPointer );
 
+  OSRDestroySpatialReference( myOgrSpatialRef );
+
   if (! myInputResult==OGRERR_NONE)
   {
     //default to proj 4..if all else fails we will use that for this srs
@@ -290,9 +295,9 @@
      #define OGRERR_UNSUPPORTED_SRS     7 
   */
 
-  OGRSpatialReference myOgrSpatialRef;
+  OGRSpatialReferenceH myOgrSpatialRef = OSRNewSpatialReference( NULL );
 
-  OGRErr myInputResult = myOgrSpatialRef.importFromWkt( &pWkt );
+  OGRErr myInputResult = OSRImportFromWkt( myOgrSpatialRef, &pWkt );
   if (myInputResult != OGRERR_NONE)
   {
     QgsDebugMsg("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv");
@@ -301,15 +306,19 @@
     QgsDebugMsg("INPUT: " + theWkt);
     QgsDebugMsg("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
     mIsValidFlag = false;
+    OSRDestroySpatialReference( myOgrSpatialRef );
     return false;
   }
 
 
   // always morph from esri as it doesn't hurt anything
-  myOgrSpatialRef.morphFromESRI();
+  // FW: Hey, that's not right!  It can screw stuff up! Disable
+  //myOgrSpatialRef.morphFromESRI();
+
   // create the proj4 structs needed for transforming
-  char *proj4src;
-  myOgrSpatialRef.exportToProj4(&proj4src);
+  char *proj4src = NULL;
+  OSRExportToProj4(myOgrSpatialRef, &proj4src);
+  OSRDestroySpatialReference( myOgrSpatialRef );
 
   //now that we have the proj4string, delegate to createFromProj4String so
   // that we can try to fill in the remaining class members...
@@ -467,8 +476,9 @@
   //this is really ugly but we need to get a QString to a char**
   const char *mySourceCharArrayPointer = mProj4String.latin1();
   //create the sr and populate it from a wkt proj definition
-  OGRSpatialReference myOgrSpatialRef;
-  OGRErr myResult = myOgrSpatialRef.importFromProj4( mySourceCharArrayPointer );
+  OGRSpatialReferenceH myOgrSpatialRef = OSRNewSpatialReference( NULL );
+  OGRErr myResult = OSRImportFromProj4( myOgrSpatialRef, mySourceCharArrayPointer );
+  OSRDestroySpatialReference( myOgrSpatialRef );
   if (myResult==OGRERR_NONE)
   {
     //QgsDebugMsg("The OGRe says it's a valid SRS with proj4 string: " +  mProj4String);
@@ -903,16 +913,16 @@
   }
 
   char *unitName;
-  OGRSpatialReference myOgrSpatialRef;
-  myOgrSpatialRef.importFromProj4(mProj4String.latin1());
+  OGRSpatialReferenceH myOgrSpatialRef = OSRNewSpatialReference(NULL);
+  OSRImportFromProj4(myOgrSpatialRef, mProj4String.latin1());
 
   // Of interest to us is that this call adds in a unit parameter if
   // one doesn't already exist.
-  myOgrSpatialRef.Fixup();
+  OSRFixup(myOgrSpatialRef);
 
-  if (myOgrSpatialRef.IsProjected())
+  if (OSRIsProjected(myOgrSpatialRef))
   {
-    double toMeter = myOgrSpatialRef.GetLinearUnits(&unitName);
+    double toMeter = OSRGetLinearUnits(myOgrSpatialRef,&unitName);
     QString unit(unitName);
 
     // If the units parameter was created during the Fixup() call
@@ -940,7 +950,7 @@
   }
   else
   {
-    myOgrSpatialRef.GetAngularUnits(&unitName);
+    OSRGetAngularUnits(myOgrSpatialRef, &unitName);
     QString unit(unitName);
     if (unit == "degree")
       mMapUnits = QGis::DEGREES;
@@ -951,6 +961,7 @@
     }
     QgsDebugMsg("Projection has angular units of " + unit);
   }
+  OSRDestroySpatialReference( myOgrSpatialRef );
 }
 
 
@@ -1104,10 +1115,10 @@
 
 
   //create the sr and populate it from a wkt proj definition
-  OGRSpatialReference myOgrSpatialRef1;
-  OGRSpatialReference myOgrSpatialRef2;
-  OGRErr myInputResult1 = myOgrSpatialRef1.importFromProj4(  myCharArrayPointer1 );
-  OGRErr myInputResult2 = myOgrSpatialRef2.importFromProj4(  theProj4CharArray.latin1() );
+  OGRSpatialReferenceH myOgrSpatialRef1 = OSRNewSpatialReference( NULL );
+  OGRSpatialReferenceH myOgrSpatialRef2 = OSRNewSpatialReference( NULL );
+  OGRErr myInputResult1 = OSRImportFromProj4( myOgrSpatialRef1, myCharArrayPointer1 );
+  OGRErr myInputResult2 = OSRImportFromProj4( myOgrSpatialRef1, theProj4CharArray.latin1() );
 
   // Could do some error reporting here...
   if (myInputResult1 != OGRERR_NONE)
@@ -1115,62 +1126,45 @@
   if (myInputResult2 != OGRERR_NONE)
     {}
 
-  if (myOgrSpatialRef1.IsGeographic() && myOgrSpatialRef2.IsGeographic())
+  if (OSRIsGeographic(myOgrSpatialRef1) && OSRIsGeographic(myOgrSpatialRef2))
   {
 //    qWarning("QgsSpatialRefSys::operator== srs1 and srs2 are geographic ");
-    myMatchFlag = myOgrSpatialRef1.IsSameGeogCS(&myOgrSpatialRef2);
+    myMatchFlag = OSRIsSameGeogCS(myOgrSpatialRef1,myOgrSpatialRef2);
   }
-  else if (myOgrSpatialRef1.IsProjected() && myOgrSpatialRef2.IsProjected())
+  else if (OSRIsProjected(myOgrSpatialRef1) && OSRIsProjected(myOgrSpatialRef2))
   {
 //    qWarning("QgsSpatialRefSys::operator== srs1 and srs2 are projected ");
-    myMatchFlag = myOgrSpatialRef1.IsSame(&myOgrSpatialRef2);
+    myMatchFlag = OSRIsSame(myOgrSpatialRef1,myOgrSpatialRef2);
   } else {
 //    qWarning("QgsSpatialRefSys::operator== srs1 and srs2 are different types ");
     myMatchFlag = false;
   }
 
-  //find out the units:
-  /* Not needed anymore here - keeping here as a note because I am gonna use it elsewhere
-  const char *myUnitsArrayPointer1;
-  const char *myUnitsArrayPointer2;
-  OGRErr myUnitsValid1 = myOgrSpatialRef1.GetLinearUnits(&myUnitsArrayPointer1 );
-  OGRErr myUnitsValid2 = myOgrSpatialRef2.GetLinearUnits(&myUnitsArrayPointer2 );
-  QString myUnitsString1(myUnitsArrayPointer1);
-  QString myUnitsString2(myUnitsArrayPointer2);
-  */
+  OSRDestroySpatialReference( myOgrSpatialRef1 );
+  OSRDestroySpatialReference( myOgrSpatialRef2 );
 
-
-
-
-  //placeholder to be replaced with ogr tests
-  if (myMatchFlag)
-  {
-//    qWarning("QgsSpatialRefSys::operator== result: srs's are equal ");
-  }
-  else
-  {
-//    qWarning("QgsSpatialRefSys::operator== result: srs's are not equal ");
-  }
   return myMatchFlag;
 }
 
 QString QgsSpatialRefSys::toWkt() const
 {
-  OGRSpatialReference myOgrSpatialRef;
-  OGRErr myInputResult = myOgrSpatialRef.importFromProj4(mProj4String.latin1());
+  OGRSpatialReferenceH myOgrSpatialRef;
+  OGRErr myInputResult = OSRImportFromProj4(myOgrSpatialRef,mProj4String.latin1());
   
   QString myWkt;
 
   if (myInputResult == OGRERR_NONE)
   {
     char* WKT;
-    if(myOgrSpatialRef.exportToWkt(&WKT) == OGRERR_NONE)
+    if(OSRExportToWkt(myOgrSpatialRef,&WKT) == OGRERR_NONE)
     {
       myWkt = WKT;
       OGRFree(WKT);
     }    
   }
-    
+
+  OSRDestroySpatialReference( myOgrSpatialRef );
+
   return myWkt;
 }
 

Modified: branches/gdalogr-capi-branch/qgis/src/core/qgsvectorfilewriter.cpp
===================================================================
--- branches/gdalogr-capi-branch/qgis/src/core/qgsvectorfilewriter.cpp	2008-02-15 21:20:17 UTC (rev 8160)
+++ branches/gdalogr-capi-branch/qgis/src/core/qgsvectorfilewriter.cpp	2008-02-15 23:37:51 UTC (rev 8161)
@@ -31,7 +31,8 @@
 
 #include <cassert>
 
-#include <ogrsf_frmts.h>
+#include <ogr_api.h>
+#include <ogr_srs_api.h>
 
 
 QgsVectorFileWriter::QgsVectorFileWriter(const QString& shapefileName,
@@ -45,11 +46,9 @@
   QString driverName = "ESRI Shapefile";
   
   // find driver in OGR
-  OGRSFDriver *poDriver;
+  OGRSFDriverH poDriver;
   OGRRegisterAll();
-  poDriver =
-      OGRSFDriverRegistrar::GetRegistrar()->
-      GetDriverByName(driverName.toLocal8Bit().data());
+  poDriver = OGRGetDriverByName(driverName.toLocal8Bit().data());
   
   if (poDriver == NULL)
   {
@@ -58,7 +57,7 @@
   }
 
   // create the data source
-  mDS = poDriver->CreateDataSource(shapefileName, NULL);
+  mDS = OGR_Dr_CreateDataSource(poDriver,shapefileName, NULL);
   if (mDS == NULL)
   {
     mError = ErrCreateDataSource;
@@ -76,20 +75,22 @@
   }
   
   // consider spatial reference system of the layer
-  OGRSpatialReference* ogrRef = NULL;
+  OGRSpatialReferenceH ogrRef = NULL;
   if (srs)
   {
     QString srsWkt = srs->toWkt();
-    ogrRef = new OGRSpatialReference(srsWkt.toLocal8Bit().data());
+    ogrRef = OSRNewSpatialReference(srsWkt.toLocal8Bit().data());
   }
  
   // datasource created, now create the output layer
   QString layerName = shapefileName.left(shapefileName.find(".shp"));
   OGRwkbGeometryType wkbType = static_cast<OGRwkbGeometryType>(geometryType);
-  mLayer = mDS->CreateLayer(QFile::encodeName(layerName).data(), ogrRef, wkbType, NULL);
+  mLayer = OGR_DS_CreateLayer(mDS,QFile::encodeName(layerName).data(), ogrRef, wkbType, NULL);
   
   if (srs)
-    delete ogrRef;
+  {
+    OSRDestroySpatialReference( ogrRef );
+  }
   
   if (mLayer == NULL)
   {
@@ -128,15 +129,15 @@
     }
 
     // create field definition
-    OGRFieldDefn fld(mCodec->fromUnicode(attrField.name()), ogrType);
-    fld.SetWidth(attrField.length());
-    fld.SetPrecision(attrField.precision());
+    OGRFieldDefnH fld = OGR_Fld_Create(mCodec->fromUnicode(attrField.name()), ogrType);
+    OGR_Fld_SetWidth(fld,attrField.length());
+    OGR_Fld_SetPrecision(fld,attrField.precision());
 
     // create the field
     QgsDebugMsg("creating field " + attrField.name() +
                 " type " + QString(QVariant::typeToName(attrField.type())) +
                 " width length " + QString::number(attrField.length()));
-    if (mLayer->CreateField(&fld) != OGRERR_NONE)
+    if (OGR_L_CreateField(mLayer,fld,TRUE) != OGRERR_NONE)
     {
       QgsDebugMsg("error creating field " + attrField.name());
     }
@@ -149,33 +150,9 @@
   mGeom = createEmptyGeometry(mWkbType);
 }
 
-OGRGeometry* QgsVectorFileWriter::createEmptyGeometry(QGis::WKBTYPE wkbType)
+OGRGeometryH QgsVectorFileWriter::createEmptyGeometry(QGis::WKBTYPE wkbType)
 {
-  // create instance of OGR geometry (will be used to import from WKB)
-  switch (wkbType)
-  {
-    case QGis::WKBPoint:
-    case QGis::WKBPoint25D:
-      return new OGRPoint;
-    case QGis::WKBLineString:
-    case QGis::WKBLineString25D:
-      return new OGRLineString;
-    case QGis::WKBPolygon:
-    case QGis::WKBPolygon25D:
-      return new OGRPolygon;
-    case QGis::WKBMultiPoint:
-    case QGis::WKBMultiPoint25D:
-      return new OGRMultiPoint;
-    case QGis::WKBMultiLineString:
-    case QGis::WKBMultiLineString25D:
-      return new OGRMultiLineString;
-    case QGis::WKBMultiPolygon:
-    case QGis::WKBMultiPolygon25D:
-      return new OGRMultiPolygon;
-    default:
-      assert(0 && "invalid WKB type");
-      return NULL;
-  }
+  return OGR_G_CreateGeometry( (OGRwkbGeometryType) wkbType );
 }
 
 
@@ -192,7 +169,7 @@
   QgsAttributeMap::const_iterator it;
 
     // create the feature
-  OGRFeature *poFeature = new OGRFeature(mLayer->GetLayerDefn());
+  OGRFeatureH poFeature = OGR_F_Create(OGR_L_GetLayerDefn(mLayer));
 
     // attribute handling
   const QgsAttributeMap& attributes = feature.attributeMap();
@@ -209,17 +186,18 @@
     QString attrName = mFields[it.key()].name();
     QByteArray encAttrName = mCodec->fromUnicode(attrName);
     const QVariant& attrValue = it.value();
+    int ogrField = OGR_F_GetFieldIndex( poFeature, encAttrName.data() );
 
     switch (attrValue.type())
     {
       case QVariant::Int:
-        poFeature->SetField(encAttrName.data(), attrValue.toInt());
+        OGR_F_SetFieldInteger(poFeature, ogrField, attrValue.toInt());
         break;
       case QVariant::Double:
-        poFeature->SetField(encAttrName.data(), attrValue.toDouble());
+        OGR_F_SetFieldDouble(poFeature, ogrField, attrValue.toDouble());
         break;
       case QVariant::String:
-        poFeature->SetField(encAttrName.data(), mCodec->fromUnicode(attrValue.toString()).data());
+        OGR_F_SetFieldString(poFeature, ogrField, mCodec->fromUnicode(attrValue.toString()).data());
         break;
       default:
         //assert(0 && "invalid variant type");
@@ -241,42 +219,42 @@
     // Btw. OGRGeometry must be exactly of the type of the geometry which it will receive
     // i.e. Polygons can't be imported to OGRMultiPolygon
     
-    OGRGeometry* mGeom2 = createEmptyGeometry(geom->wkbType());
+    OGRGeometryH mGeom2 = createEmptyGeometry(geom->wkbType());
     
-    OGRErr err = mGeom2->importFromWkb(geom->wkbBuffer(), geom->wkbSize());
+    OGRErr err = OGR_G_ImportFromWkb(mGeom2,geom->wkbBuffer(), geom->wkbSize());
     if (err != OGRERR_NONE)
     {
       QgsDebugMsg("Failed to import geometry from WKB: " + QString::number(err));
-      OGRFeature::DestroyFeature(poFeature);
+      OGR_F_Destroy( poFeature );
       return false;
     }
     
     // pass ownership to geometry
-    poFeature->SetGeometryDirectly(mGeom2);
+    OGR_F_SetGeometryDirectly(poFeature,mGeom2);
   }
   else
   {
-    OGRErr err = mGeom->importFromWkb(geom->wkbBuffer(), geom->wkbSize());
+    OGRErr err = OGR_G_ImportFromWkb(mGeom,geom->wkbBuffer(), geom->wkbSize());
     if (err != OGRERR_NONE)
     {
       QgsDebugMsg("Failed to import geometry from WKB: " + QString::number(err));
-      OGRFeature::DestroyFeature(poFeature);
+      OGR_F_Destroy( poFeature );
       return false;
     }
     
     // set geometry (ownership is not passed to OGR)
-    poFeature->SetGeometry(mGeom);
+    OGR_F_SetGeometryDirectly(poFeature,mGeom);
   }
     
   // put the created feature to layer
-  if (mLayer->CreateFeature(poFeature) != OGRERR_NONE)
+  if (OGR_L_CreateFeature(mLayer,poFeature) != OGRERR_NONE)
   {
     QgsDebugMsg("Failed to create feature in shapefile");
-    OGRFeature::DestroyFeature(poFeature);
+    OGR_F_Destroy( poFeature );
     return false;
   }
 
-  OGRFeature::DestroyFeature(poFeature);
+  OGR_F_Destroy( poFeature );
   
   return true;
 }
@@ -284,10 +262,14 @@
 QgsVectorFileWriter::~QgsVectorFileWriter()
 {
   if (mGeom)
-    delete mGeom;
+  {
+    OGR_G_DestroyGeometry( mGeom );
+  }
   
   if (mDS)
-    OGRDataSource::DestroyDataSource(mDS);
+  {
+    OGR_DS_Destroy( mDS );
+  }
 }
 
 

Modified: branches/gdalogr-capi-branch/qgis/src/core/qgsvectorfilewriter.h
===================================================================
--- branches/gdalogr-capi-branch/qgis/src/core/qgsvectorfilewriter.h	2008-02-15 21:20:17 UTC (rev 8160)
+++ branches/gdalogr-capi-branch/qgis/src/core/qgsvectorfilewriter.h	2008-02-15 23:37:51 UTC (rev 8161)
@@ -24,9 +24,9 @@
 
 #include <QString>
 
-class OGRDataSource;
-class OGRLayer;
-class OGRGeometry;
+typedef void *OGRDataSourceH;
+typedef void *OGRLayerH;
+typedef void *OGRGeometryH;
 
 class QTextCodec;
 
@@ -81,11 +81,11 @@
     static bool deleteShapeFile(QString theFileName);
   protected:
     
-    OGRGeometry* createEmptyGeometry(QGis::WKBTYPE wkbType);
+    OGRGeometryH createEmptyGeometry(QGis::WKBTYPE wkbType);
     
-    OGRDataSource* mDS;
-    OGRLayer* mLayer;
-    OGRGeometry* mGeom;
+    OGRDataSourceH mDS;
+    OGRLayerH mLayer;
+    OGRGeometryH mGeom;
     
     QgsFieldMap mFields;
     

Modified: branches/gdalogr-capi-branch/qgis/src/plugins/spit/qgsshapefile.cpp
===================================================================
--- branches/gdalogr-capi-branch/qgis/src/plugins/spit/qgsshapefile.cpp	2008-02-15 21:20:17 UTC (rev 8160)
+++ branches/gdalogr-capi-branch/qgis/src/plugins/spit/qgsshapefile.cpp	2008-02-15 23:37:51 UTC (rev 8161)
@@ -17,8 +17,7 @@
 /* $Id$ */
 
 #include <QApplication>
-#include <ogrsf_frmts.h>
-#include <ogr_geometry.h>
+#include <ogr_api.h>
 #include <string>
 #include <iostream>
 #include <fstream>
@@ -49,11 +48,11 @@
   filename = name;
   features = 0;
   OGRRegisterAll();
-  ogrDataSource = OGRSFDriverRegistrar::Open(QFile::encodeName(filename).constData());
+  ogrDataSource = OGROpen(QFile::encodeName(filename).constData(),FALSE,NULL);
   if (ogrDataSource != NULL){
     valid = true;
-    ogrLayer = ogrDataSource->GetLayer(0);
-    features = ogrLayer->GetFeatureCount();
+    ogrLayer = OGR_DS_GetLayer(ogrDataSource,0);
+    features = OGR_L_GetFeatureCount(ogrLayer,TRUE);
   }
   else
     valid = false;
@@ -68,12 +67,7 @@
 }
 
 QgsShapeFile::~QgsShapeFile(){
-  if(ogrDataSource != 0)
-  {
-    // don't delete the layer if the datasource is bad -- (causes crash)
-    delete ogrLayer;
-  }
-  delete ogrDataSource;
+  OGR_DS_Destroy( ogrDataSource );
   delete filename;
   delete geom_type;
 }
@@ -92,26 +86,26 @@
   sg->show();
   qApp->processEvents();
 
-  OGRFeature *feat;
+  OGRFeatureH feat;
   OGRwkbGeometryType currentType = wkbUnknown;
   bool multi = false;
-  while((feat = ogrLayer->GetNextFeature()))
+  while((feat = OGR_L_GetNextFeature(ogrLayer)))
   {
       qApp->processEvents();
 
     //    feat->DumpReadable(NULL);
-    OGRGeometry *geom = feat->GetGeometryRef();
+    OGRGeometryH geom = OGR_F_GetGeometryRef(feat);
     if(geom)
     {
-      QString gml =  geom->exportToGML();
+      QString gml =  OGR_G_ExportToGML(geom);
       //      std::cerr << gml << std::endl; 
       if(gml.find("gml:Multi") > -1)
       {
         //   std::cerr << "MULTI Part Feature detected" << std::endl; 
         multi = true;
       }
-      OGRFeatureDefn *fDef = feat->GetDefnRef();
-      OGRwkbGeometryType gType = fDef->GetGeomType();
+      OGRFeatureDefnH fDef = OGR_F_GetDefnRef(feat);
+      OGRwkbGeometryType gType = OGR_FD_GetGeomType(fDef);
       //      std::cerr << fDef->GetGeomType() << std::endl; 
       if(gType > currentType)
       {
@@ -135,7 +129,7 @@
     hasMoreDimensions = true;
   }
   
-  ogrLayer->ResetReading();
+  OGR_L_ResetReading(ogrLayer);
   geom_type = geometries[currentType];
   if(multi && (geom_type.find("MULTI") == -1))
   {
@@ -151,14 +145,14 @@
   // type. 
   qApp->processEvents();
   isMulti = scanGeometries();
-  OGRFeature *feat;
+  OGRFeatureH feat;
   // skip features without geometry
-  while ((feat = ogrLayer->GetNextFeature()) != NULL) {
-    if (feat->GetGeometryRef())
+  while ((feat = OGR_L_GetNextFeature(ogrLayer)) != NULL) {
+    if (OGR_F_GetGeometryRef(feat))
       break;
   }
   if(feat){
-    OGRGeometry *geom = feat->GetGeometryRef();
+    OGRGeometryH geom = OGR_F_GetGeometryRef(feat);
     if(geom){
       /* OGR doesn't appear to report geometry type properly
        * for a layer containing both polygon and multipolygon
@@ -222,18 +216,18 @@
         }
       }
       dbf.close();
-      int numFields = feat->GetFieldCount();
+      int numFields = OGR_F_GetFieldCount(feat);
       for(int n=0; n<numFields; n++)
       {
-        QString s = codec->toUnicode(feat->GetFieldDefnRef(n)->GetNameRef());
+          QString s = codec->toUnicode(OGR_Fld_GetNameRef(OGR_F_GetFieldDefnRef(feat,n)));
         column_names.push_back(s);
       }
       
     }else valid = false;
-    delete feat;
+    OGR_F_Destroy( feat );
   }else valid = false;
   
-  ogrLayer->ResetReading();    
+  OGR_L_ResetReading(ogrLayer);
   return valid?geom_type:QString::null;
 }
 
@@ -380,20 +374,20 @@
       break;
     }
 
-    OGRFeature *feat = ogrLayer->GetNextFeature();
+    OGRFeatureH feat = OGR_L_GetNextFeature(ogrLayer);
     if(feat){
-      OGRGeometry *geom = feat->GetGeometryRef();
+      OGRGeometryH geom = OGR_F_GetGeometryRef(feat);
       if(geom){
         query = "INSERT INTO \"" + schema + "\".\"" + table_name + "\"" +
           QString(" VALUES( %1, ").arg(m);
 
-        int num = geom->WkbSize();
+        int num = OGR_G_WkbSize(geom);
         char * geo_temp = new char[num*3];
         // 'GeometryFromText' supports only 2D coordinates
         // TODO for proper 2.5D support we would need to use 'GeomFromEWKT'
         if (hasMoreDimensions)
-          geom->setCoordinateDimension(2);
-        geom->exportToWkt(&geo_temp);
+          OGR_G_SetCoordinateDimension(geom,2);
+        OGR_G_ExportToWkt(geom,&geo_temp);
         QString geometry(geo_temp);
 
         QString quotes;
@@ -409,7 +403,7 @@
           query += quotes;
 
           // escape the string value and cope with blank data
-          QString val = codec->toUnicode(feat->GetFieldAsString(n));
+          QString val = codec->toUnicode(OGR_F_GetFieldAsString(feat,n));
           if (val.isEmpty() && numericType)
           {
             val = "NULL";
@@ -452,7 +446,7 @@
         qApp->processEvents();
         delete[] geo_temp;
       }
-      delete feat;
+      OGR_F_Destroy( feat );
     }
   }
   // create the GIST index if the the load was successful
@@ -461,7 +455,7 @@
     // prompt user to see if they want to build the index and warn
     // them about the potential time-cost
   }
-  ogrLayer->ResetReading();
+  OGR_L_ResetReading(ogrLayer);
   return result;
 }
 

Modified: branches/gdalogr-capi-branch/qgis/src/plugins/spit/qgsshapefile.h
===================================================================
--- branches/gdalogr-capi-branch/qgis/src/plugins/spit/qgsshapefile.h	2008-02-15 21:20:17 UTC (rev 8160)
+++ branches/gdalogr-capi-branch/qgis/src/plugins/spit/qgsshapefile.h	2008-02-15 23:37:51 UTC (rev 8161)
@@ -23,7 +23,7 @@
 #include <QString>
 #include <QStringList>
 #include <QObject>
-#include <ogrsf_frmts.h>
+#include <ogr_api.h>
 
 class QProgressDialog;
 class QTextCodec;
@@ -62,8 +62,8 @@
 
   private:
   QString table_name;
-  OGRDataSource *ogrDataSource;
-  OGRLayer * ogrLayer;
+  OGRDataSourceH ogrDataSource;
+  OGRLayerH ogrLayer;
   bool import_canceled;
   bool valid;
   //! Flag to indicate the file contains multiple geometry types

Modified: branches/gdalogr-capi-branch/qgis/src/providers/mysql/qgsmysqlprovider.cpp
===================================================================
--- branches/gdalogr-capi-branch/qgis/src/providers/mysql/qgsmysqlprovider.cpp	2008-02-15 21:20:17 UTC (rev 8160)
+++ branches/gdalogr-capi-branch/qgis/src/providers/mysql/qgsmysqlprovider.cpp	2008-02-15 23:37:51 UTC (rev 8161)
@@ -31,8 +31,6 @@
 #include <QUrl>
 #include <qglobal.h>
 
-#include <ogrsf_frmts.h>
-
 #include "../../src/qgsdataprovider.h"
 #include "../../src/qgsencodingfiledialog.h"
 #include "../../src/qgsfeature.h"
@@ -790,199 +788,8 @@
 
 bool QgsMySQLProvider::saveAsShapefile()
 {
-  // save the layer as a shapefile
-  QString driverName = "ESRI Shapefile";
-  OGRSFDriver *poDriver;
-  OGRRegisterAll();
-  poDriver =
-    OGRSFDriverRegistrar::GetRegistrar()->
-    GetDriverByName((const char *)driverName.toLocal8Bit().data());
-  bool returnValue = true;
-  if (poDriver != NULL)
-  {
-    // get a name for the shapefile
-    // Get a file to process, starting at the current directory
-    // Set inital dir to last used in MySQL plugin
-    QSettings settings;
-    QString enc;
-    QString shapefileName;
-    QString filter =  QString("Shapefiles (*.shp)");
-    QString dirName = settings.readEntry("/Plugin-MySQL/text_path", "./");
-
-    QgsEncodingFileDialog* openFileDialog = new QgsEncodingFileDialog(0,
-                                                                      tr("Save layer as..."),
-                                                                      dirName,
-                                                                      filter,
-                                                                      QString("UTF-8"));
-
-    // allow for selection of more than one file
-    openFileDialog->setMode(QFileDialog::AnyFile);
-
-
-    if (openFileDialog->exec() == QDialog::Accepted)
-    {
-        shapefileName = openFileDialog->selectedFile();
-        enc = openFileDialog->encoding();
-    }
-    else
-    {
-      return returnValue;
-    }
-
-    if (!shapefileName.isNull())
-    {
-      // add the extension if not present
-      if (shapefileName.find(".shp") == -1)
-      {
-        shapefileName += ".shp";
-      }
-      OGRDataSource *poDS;
-      // create the data source
-      poDS = poDriver->CreateDataSource(QFile::encodeName(shapefileName).constData(), NULL);
-      if (poDS != NULL)
-      {
-        QTextCodec* saveCodec = QTextCodec::codecForName(enc.toLocal8Bit().data());
-        if(!saveCodec)
-        {
-#ifdef QGISDEBUG
-          qWarning("error finding QTextCodec in QgsMySQLProvider::saveAsShapefile()");
-#endif
-          saveCodec = QTextCodec::codecForLocale();
-        }
- 
-        std::cerr << "created datasource" << std::endl;
-        // datasource created, now create the output layer, use utf8() for now.
-        OGRLayer *poLayer;
-        poLayer =
-           poDS->CreateLayer((const char *) (shapefileName.
-                             left(shapefileName.find(".shp"))).utf8(), NULL,
-                              static_cast < OGRwkbGeometryType > (1), NULL);
-        if (poLayer != NULL)
-        {
-          std::cerr << "created layer" << std::endl;
-          // calculate the field lengths
-          int *lengths = getFieldLengths();
-          // create the fields
-          std::cerr << "creating " << attributeFields.
-            size() << " fields" << std::endl;
-          for (int i = 0; i < attributeFields.size(); i++)
-          {
-            // check the field length - if > 10 we need to truncate it
-            QgsField attrField = attributeFields[i];
-            if (attrField.name().length() > 10)
-            {
-              attrField = attrField.name().left(10);
-            }
-            // all fields are created as string (for now)
-            OGRFieldDefn fld(saveCodec->fromUnicode(attrField.name()), OFTString);
-            // set the length for the field -- but we don't know what it is...
-            fld.SetWidth(lengths[i]);
-            // create the field
-            std::cerr << "creating field " << (const char *)attrField.
-              name().toLocal8Bit().data() << " width length " << lengths[i] << std::endl;
-            if (poLayer->CreateField(&fld) != OGRERR_NONE)
-            {
-              QMessageBox::warning(0, tr("Error"),
-                                   tr("Error creating field ") + attrField.name());
-            }
-          }
-          // read the MySQL file and create the features
-          std::cerr << "Done creating fields" << std::endl;
-          // read the line
-          reset();
-          QTextStream stream(mFile);
-          QString line;
-          while (!stream.atEnd())
-          {
-            line = stream.readLine(); // line of text excluding '\n'
-            std::cerr << (const char *)line.toLocal8Bit().data() << std::endl;
-            // split the line
-            QStringList parts =
-              QStringList::split(QRegExp(mDelimiter), line, true);
-            std::cerr << "Split line into " << parts.size() << std::endl;
-
-            // create the feature
-            OGRFeature *poFeature;
-
-            poFeature = new OGRFeature(poLayer->GetLayerDefn());
-
-            // iterate over the parts and set the fields
-            std::cerr << "Setting the field values" << std::endl;
-            // set limit - we will ignore extra fields on the line
-            int limit = attributeFields.size();
-
-            if (parts.size() < limit)
-            {
-
-              // this is bad - not enough values where supplied on the line
-              // TODO We should inform the user about this...
-            }
-            else
-            {
-
-              for (int i = 0; i < limit; i++)
-              {
-                if (parts[i] != QString::null)
-                {
-                  std::cerr << "Setting " << i << " " << (const char *)attributeFields[i].
-                    name().toLocal8Bit().data() << " to " << (const char *)parts[i].toLocal8Bit().data() << std::endl;
-                  poFeature->SetField(saveCodec->fromUnicode(attributeFields[i].name()).data(),
-                                      saveCodec->fromUnicode(parts[i]).data());
-
-                }
-                else
-                {
-                  poFeature->SetField(saveCodec->fromUnicode(attributeFields[i].name()).data(), "");
-                }
-              }
-              std::cerr << "Field values set" << std::endl;
-              // create the point
-              OGRPoint *poPoint = new OGRPoint();
-              QString sX = parts[fieldPositions[mXField]];
-              QString sY = parts[fieldPositions[mYField]];
-              poPoint->setX(sX.toDouble());
-              poPoint->setY(sY.toDouble());
-              std::cerr << "Setting geometry" << std::endl;
-
-              poFeature->SetGeometryDirectly(poPoint);
-              if (poLayer->CreateFeature(poFeature) != OGRERR_NONE)
-              {
-                std::cerr << "Failed to create feature in shapefile" << std::
-                  endl;
-              }
-              else
-              {
-                std::cerr << "Added feature" << std::endl;
-              }
-
-              delete poFeature;
-            }
-          }
-          delete poDS;
-        }
-        else
-        {
-          QMessageBox::warning(0, tr("Error"), tr("Layer creation failed"));
-        }
-
-      }
-      else
-      {
-        QMessageBox::warning(0, tr("Error creating shapefile"),
-                             tr("The shapefile could not be created (") +
-                             shapefileName + ")");
-      }
-
-    }
-    //std::cerr << "Saving to " << shapefileName << std::endl; 
-  }
-  else
-  {
-    QMessageBox::warning(0, tr("Driver not found"),
-                         driverName + tr(" driver is not available"));
-    returnValue = false;
-  }
-  return returnValue;
+  // OGR based save to shapefile method removed, unused?
+  return false;
 }
 
 

Deleted: branches/gdalogr-capi-branch/qgis/src/providers/ogr/qgsogrfactory.cpp
===================================================================
--- branches/gdalogr-capi-branch/qgis/src/providers/ogr/qgsogrfactory.cpp	2008-02-15 21:20:17 UTC (rev 8160)
+++ branches/gdalogr-capi-branch/qgis/src/providers/ogr/qgsogrfactory.cpp	2008-02-15 23:37:51 UTC (rev 8161)
@@ -1,121 +0,0 @@
-/***************************************************************************
-     qgsogrfactory.cpp
-     --------------------------------------
-    Date                 : Sun Sep 16 12:18:21 AKDT 2007
-    Copyright            : (C) 2004 Christoph Spoerri 
-    Email                : <spoerri at sourceforge.net>
- ***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#include <iostream>
-#include <qmessagebox.h>
-
-#include "qgis.h"
-#include "qgsogrfactory.h"
-
-QgsOGRFactory::QgsOGRFactory()
-{
-}
-
-
-QgsOGRFactory::~QgsOGRFactory()
-{
-}
-
-bool QgsOGRFactory::testCapability(int t)
-{
-  switch (t)
-  {
-  case QgsDataProviderFactory::Copy:
-    return TRUE;
-  case QgsDataProviderFactory::Rename:
-    return FALSE;
-  case QgsDataProviderFactory::Move:
-    return TRUE;
-  default:
-    return FALSE;
-  }
-}
-
-void QgsOGRFactory::setURI(QString uri)
-{
-  dataSourceURI = uri;
-  OGRRegisterAll();
-
-  // make connection to the data source
-  std::cerr << "Data source uri is " << dataSourceURI << std::endl;
-  // try to open for read
-  ogrDS = OGRSFDriverRegistrar::Open(QFile::encodeName(dataSourceURI).constData(), FALSE, &ogrDriver);
-  if(ogrDS != NULL)
-  {
-#ifdef QGISDEBUG
-    std::cerr << "Data source is valid" << std::endl;
-#endif
-    valid = true;
-  } else
-  {
-    QMessageBox::warning(NULL, tr("Wrong Path/URI"), tr("The provided path for the dataset is not valid."));
-    valid = false;
-  }
-}
-
-bool QgsOGRFactory::create(QString newLocation, QString newName, QString type)
-{
-    
-}
-
-QgsDataProvider* QgsOGRFactory::open( QString name)
-{
-  QgsDataProvider *d = (QgsDataProvider *) new QgsShapeFileProvider(dataSourceURI+QString("/")+name);
-  return d;
-}
-
-QStringList QgsOGRFactory::getLayers()
-{
-  OGRLayer *lyr;
-  OGRFeatureDefn *lyrDef;
-  QStringList lyrList = QStringList();
-  
-  if (valid) {
-    for (int i = 0 ; i < ogrDS->GetLayerCount(); i++) 
-    {
-      lyr = ogrDS->GetLayer(i);
-      lyrDef = lyr->GetLayerDefn();
-      std::cerr << "Layer " << i << " is: " << lyrDef->GetName() << "\n";
-      //TODO append extension to name, so that it can be opened properly
-      lyrList.append(lyrDef->GetName());
-    }
-  }
-  return lyrList;
-}
-
-bool QgsOGRFactory::copy(QString oldName, QString newName)
-{
-  OGRLayer *oldLyr;
-  std::cout << "Copy ogr datasource" << std::endl;
-  
-  if (valid)
-  {
-    oldLyr = ogrDS->GetLayerByName((const char*) oldName);
-    std::cout << "datasource is " << ogrDriver->GetName() << std::endl;
-    if (QString::compare(ogrDriver->GetName(),"ESRI Shapefile")==0) {
-      std::cout << "Copy shapefile" << std::endl;
-      
-    }
-  }
-}
-
-/**
- * Class factory to return a pointer to a newly created 
- * QgsShapeFileProvider object
- */
-QGISEXTERN QgsOGRFactory * classFactory_Fact()
-{
-  return new QgsOGRFactory();
-}

Deleted: branches/gdalogr-capi-branch/qgis/src/providers/ogr/qgsogrfactory.h
===================================================================
--- branches/gdalogr-capi-branch/qgis/src/providers/ogr/qgsogrfactory.h	2008-02-15 21:20:17 UTC (rev 8160)
+++ branches/gdalogr-capi-branch/qgis/src/providers/ogr/qgsogrfactory.h	2008-02-15 23:37:51 UTC (rev 8161)
@@ -1,59 +0,0 @@
-/***************************************************************************
-     qgsogrfactory.h
-     --------------------------------------
-    Date                 : Sun Sep 16 12:18:58 AKDT 2007
-    Copyright            : (C) 2004 Christoph Spoerri 
-    Email                : <spoerri at sourceforge.net>
- ***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#ifndef QGSOGRFACTORY_H
-#define QGSOGRFACTORY_H
-
-#include <qstring.h>
-#include <qstringlist.h>
-
-#include <ogrsf_frmts.h>
-
-#include "qgsshapefileprovider.h"
-#include "../../src/qgsdataproviderfactory.h"
-#include "../../src/qgsdataprovider.h"
-
-
-
-/**
- at author Christoph Spoerri
-*/
-class QgsOGRFactory : public QgsDataProviderFactory
-{
-public:
-    QgsOGRFactory();
-    virtual ~QgsOGRFactory();
-    
-    QString getFactoryType() { return "OGR Dataprovider Factory"; }
-    bool testCapability(int);
-    void setURI(QString uri);
-    QStringList getLayers();
-    bool create(QString newLocation, QString newName, QString type);
-    QgsDataProvider* open(QString name);
-
-    bool copy(QString oldName, QString newName);
-    bool copy(QString oldName, QString newLocation, QString newName) {};
-    bool move(QString newLocation) {};
-    bool rename(QString newName) {};
-
-private:
-    bool valid;
-    QString dataSourceURI;
-    OGRDataSource * ogrDS;
-    OGRSFDriver * ogrDriver;
-
-};
-
-#endif

Modified: branches/gdalogr-capi-branch/qgis/src/providers/ogr/qgsogrprovider.cpp
===================================================================
--- branches/gdalogr-capi-branch/qgis/src/providers/ogr/qgsogrprovider.cpp	2008-02-15 21:20:17 UTC (rev 8160)
+++ branches/gdalogr-capi-branch/qgis/src/providers/ogr/qgsogrprovider.cpp	2008-02-15 23:37:51 UTC (rev 8161)
@@ -22,13 +22,11 @@
 #include <iostream>
 #include <cassert>
 
+#define CPL_SUPRESS_CPLUSPLUS
 #include <gdal.h>         // to collect version information
-
-#include <ogrsf_frmts.h>
-#include <ogr_geometry.h>
-#include <ogr_spatialref.h>
+#include <ogr_api.h>
+#include <ogr_srs_api.h>
 #include <cpl_error.h>
-#include "ogr_api.h"//only for a test
 
 #include <QtDebug>
 #include <QFile>
@@ -83,14 +81,14 @@
   // try to open for update, but disable error messages to avoid a
   // message if the file is read only, because we cope with that
   // ourselves.
-  CPLPushErrorHandler(&CPLQuietErrorHandler);
-  ogrDataSource = OGRSFDriverRegistrar::Open(QFile::encodeName(uri).constData(), TRUE, &ogrDriver);
+  CPLPushErrorHandler(CPLQuietErrorHandler);
+  ogrDataSource = OGROpen(QFile::encodeName(uri).constData(), TRUE, &ogrDriver);
   CPLPopErrorHandler();
 
   if(ogrDataSource == NULL)
   {
     // try to open read-only
-    ogrDataSource = OGRSFDriverRegistrar::Open(QFile::encodeName(uri).constData(), FALSE, &ogrDriver);
+    ogrDataSource = OGROpen(QFile::encodeName(uri).constData(), FALSE, &ogrDriver);
 
     //TODO Need to set a flag or something to indicate that the layer
     //TODO is in read-only mode, otherwise edit ops will fail
@@ -99,25 +97,29 @@
   if (ogrDataSource != NULL) {
 
     QgsDebugMsg("Data source is valid");
-    QgsDebugMsg("OGR Driver was " + QString(ogrDriver->GetName()));
+    QgsDebugMsg("OGR Driver was " + QString(OGR_Dr_GetName(ogrDriver)));
 
     valid = true;
 
-    ogrDriverName = ogrDriver->GetName();
+    ogrDriverName = OGR_Dr_GetName(ogrDriver);
 
-    ogrLayer = ogrDataSource->GetLayer(0);
+    ogrLayer = OGR_DS_GetLayer(ogrDataSource,0);
 
     // get the extent_ (envelope) of the layer
 
     QgsDebugMsg("Starting get extent\n");
 
-    extent_ = new OGREnvelope();
-    ogrLayer->GetExtent(extent_);
+    // TODO: This can be expensive, do we really need it!
 
+    extent_ = calloc(sizeof(OGREnvelope),1);
+    OGR_L_GetExtent(ogrLayer,(OGREnvelope *) extent_, TRUE );
+
     QgsDebugMsg("Finished get extent\n");
 
     // getting the total number of features in the layer
-    numberFeatures = ogrLayer->GetFeatureCount();   
+    // TODO: This can be expensive, do we really need it!
+    numberFeatures = OGR_L_GetFeatureCount(ogrLayer, TRUE);
+
     // check the validity of the layer
 
     QgsDebugMsg("checking validity\n");
@@ -141,12 +143,16 @@
 
 QgsOgrProvider::~QgsOgrProvider()
 {
-  OGRDataSource::DestroyDataSource(ogrDataSource);
+  OGR_DS_Destroy(ogrDataSource);
   ogrDataSource = 0;
-  delete extent_;
+  free(extent_);
   extent_ = 0;
   delete geometryFactory;
-  delete mSelectionRectangle;
+  if( mSelectionRectangle )
+  {
+    OGR_G_DestroyGeometry( mSelectionRectangle );
+    mSelectionRectangle = 0;
+  }
 }
 
 void QgsOgrProvider::setEncoding(const QString& e)
@@ -159,32 +165,33 @@
 {
     //the attribute fields need to be read again when the encoding changes
     mAttributeFields.clear();
-    OGRFeatureDefn* fdef = ogrLayer->GetLayerDefn();
+    OGRFeatureDefnH fdef = OGR_L_GetLayerDefn(ogrLayer);
     if(fdef)
     {
-      geomType = fdef->GetGeomType();
+      geomType = OGR_FD_GetGeomType(fdef);
 
       //Some ogr drivers (e.g. GML) are not able to determine the geometry type of a layer like this.
       //In such cases, we examine the first feature 
       if(geomType == wkbUnknown) 
 	{
-	  ogrLayer->ResetReading();
-	  OGRFeature* firstFeature = ogrLayer->GetNextFeature();
+          OGR_L_ResetReading(ogrLayer);
+	  OGRFeatureH firstFeature = OGR_L_GetNextFeature(ogrLayer);
 	  if(firstFeature)
 	    {
-	      OGRGeometry* firstGeometry = firstFeature->GetGeometryRef();
+	      OGRGeometryH firstGeometry = OGR_F_GetGeometryRef(firstFeature);
 	      if(firstGeometry)
-		{
-		  geomType = firstGeometry->getGeometryType();
-		}
+                {
+                  geomType = OGR_G_GetGeometryType(firstGeometry);
+                }
+              OGR_F_Destroy( firstFeature );
 	    }
-	  ogrLayer->ResetReading();
+	  OGR_L_ResetReading(ogrLayer);
 	}
       
-      for(int i=0;i<fdef->GetFieldCount();++i)
+      for(int i=0;i<OGR_FD_GetFieldCount(fdef);++i)
       {
-        OGRFieldDefn *fldDef = fdef->GetFieldDefn(i);
-        OGRFieldType ogrType = fldDef->GetType();
+        OGRFieldDefnH fldDef = OGR_FD_GetFieldDefn(fdef,i);
+        OGRFieldType ogrType = OGR_Fld_GetType(fldDef);
         QVariant::Type varType;
         switch (ogrType)
         {
@@ -192,15 +199,18 @@
           case OFTReal: varType = QVariant::Double; break;
           // unsupported in OGR 1.3
           //case OFTDateTime: varType = QVariant::DateTime; break;
+#if GDAL_VERSION_NUM >= 1400
           case OFTString: varType = QVariant::String; break;
+#endif
           default: varType = QVariant::String; // other unsupported, leave it as a string
         }
         
-        mAttributeFields.insert(i, QgsField(
-              mEncoding->toUnicode(fldDef->GetNameRef()), varType,
-              mEncoding->toUnicode(fldDef->GetFieldTypeName(ogrType)),
-              fldDef->GetWidth(),
-              fldDef->GetPrecision() ));
+        mAttributeFields.insert(
+            i, QgsField(
+                mEncoding->toUnicode(OGR_Fld_GetNameRef(fldDef)), varType,
+                mEncoding->toUnicode(OGR_GetFieldTypeName(ogrType)),
+                OGR_Fld_GetWidth(fldDef),
+                OGR_Fld_GetPrecision(fldDef) ));
       }
     }
 }
@@ -219,22 +229,22 @@
                                     bool fetchGeometry,
                                     QgsAttributeList fetchAttributes)
 {
-  OGRFeature *fet = ogrLayer->GetFeature(featureId);
+  OGRFeatureH fet = OGR_L_GetFeature(ogrLayer,featureId);
   if (fet == NULL)
     return false;
   
-  feature.setFeatureId(fet->GetFID());
+  feature.setFeatureId(OGR_F_GetFID(fet));
 
   /* fetch geometry */
   if (fetchGeometry)
   {
-    OGRGeometry *geom = fet->GetGeometryRef();
+    OGRGeometryH geom = OGR_F_GetGeometryRef(fet);
       
     // get the wkb representation
-    unsigned char *wkb = new unsigned char[geom->WkbSize()];
-    geom->exportToWkb((OGRwkbByteOrder) QgsApplication::endian(), wkb);
+    unsigned char *wkb = new unsigned char[OGR_G_WkbSize(geom)];
+    OGR_G_ExportToWkb(geom,(OGRwkbByteOrder) QgsApplication::endian(), wkb);
       
-    feature.setGeometryAndOwnership(wkb, geom->WkbSize());
+    feature.setGeometryAndOwnership(wkb, OGR_G_WkbSize(geom));
   }
 
   /* fetch attributes */
@@ -254,47 +264,48 @@
       return false;
     }
   
-  OGRFeature *fet;
+  OGRFeatureH fet;
   QgsRect selectionRect;
   
-  while ((fet = ogrLayer->GetNextFeature()) != NULL)
+  while ((fet = OGR_L_GetNextFeature(ogrLayer)) != NULL)
     {
       // skip features without geometry
-      if (fet->GetGeometryRef() == NULL && !mFetchFeaturesWithoutGeom)
+      if (OGR_F_GetGeometryRef(fet) == NULL && !mFetchFeaturesWithoutGeom)
 	{
-	  delete fet;
+          OGR_F_Destroy( fet );
 	  continue;
 	}
       
-      OGRFeatureDefn * featureDefinition = fet->GetDefnRef();
-      QString featureTypeName = featureDefinition ? QString(featureDefinition->GetName()) : QString("");
-      feature.setFeatureId(fet->GetFID());
+      OGRFeatureDefnH featureDefinition = OGR_F_GetDefnRef(fet);
+      QString featureTypeName = featureDefinition ? QString(OGR_FD_GetName(featureDefinition)) : QString("");
+      feature.setFeatureId(OGR_F_GetFID(fet));
       feature.setTypeName(featureTypeName);
       
       /* fetch geometry */
       if (mFetchGeom)
 	{
-	  OGRGeometry *geom = fet->GetGeometryRef();
+	  OGRGeometryH geom = OGR_F_GetGeometryRef(fet);
 	  
 	  // get the wkb representation
-	  unsigned char *wkb = new unsigned char[geom->WkbSize()];
-	  geom->exportToWkb((OGRwkbByteOrder) QgsApplication::endian(), wkb);
+	  unsigned char *wkb = new unsigned char[OGR_G_WkbSize(geom)];
+	  OGR_G_ExportToWkb(geom,(OGRwkbByteOrder) QgsApplication::endian(), wkb);
 	  
-	  feature.setGeometryAndOwnership(wkb, geom->WkbSize());
+	  feature.setGeometryAndOwnership(wkb, OGR_G_WkbSize(geom));
 	  
 	  if (mUseIntersect)
 	    {
 	      //precise test for intersection with search rectangle
 	      //first make QgsRect from OGRPolygon
-	      OGREnvelope env;
+        OGREnvelope env;
+        memset( &env, 0, sizeof(env) );
         if(mSelectionRectangle)
-	        mSelectionRectangle->getEnvelope(&env);
-	      if(env.IsInit()) //if envelope is invalid, skip the precise intersection test
+          OGR_G_GetEnvelope(mSelectionRectangle,&env);
+        if(env.MinX != 0 || env.MinY != 0 || env.MaxX != 0 || env.MaxY != 0 ) //if envelope is invalid, skip the precise intersection test
 		{
 		  selectionRect.set(env.MinX, env.MinY, env.MaxX, env.MaxY);
 		  if(!feature.geometry()->intersects(selectionRect))
 		    {
-		      delete fet;
+                      OGR_F_Destroy( fet );
 		      continue;
 		    }
 		}
@@ -315,14 +326,14 @@
   
   if (fet)
     {
-      delete fet;
+      OGR_F_Destroy( fet );
       return true;
     }
   else
     {
       QgsDebugMsg("Feature is null");  
       // probably should reset reading here
-      ogrLayer->ResetReading();
+      OGR_L_ResetReading(ogrLayer);
       return false;
     }
 }
@@ -337,12 +348,11 @@
   // spatial query to select features
   if(rect.isEmpty())
     {
-        ogrLayer->SetSpatialFilter(0);
+        OGR_L_SetSpatialFilter(ogrLayer,0);
     }
   else
     {
-      OGRGeometry *filter = 0;
-      filter = OGRGeometryFactory::createGeometry(wkbPolygon);
+      OGRGeometryH filter = 0;
       QString wktExtent = QString("POLYGON ((%1))").arg(rect.asPolygon());
       const char *wktText = (const char *)wktExtent;
       
@@ -350,56 +360,49 @@
 	{
 	  // store the selection rectangle for use in filtering features during
 	  // an identify and display attributes
-	  delete mSelectionRectangle;
-	  mSelectionRectangle = new OGRPolygon();
-	  mSelectionRectangle->importFromWkt((char **)&wktText);
+          if( mSelectionRectangle )
+            OGR_G_DestroyGeometry( mSelectionRectangle );
+
+	  OGR_G_CreateFromWkt( (char **)&wktText,
+                               NULL, &mSelectionRectangle);
 	}
-      
-      // reset the extent for the ogr filter
-      wktExtent = QString("POLYGON ((%1))").arg(rect.asPolygon());
-      wktText = (const char *)wktExtent;
-      
-      OGRErr result = ((OGRPolygon *) filter)->importFromWkt((char **)&wktText);
-      //TODO - detect an error in setting the filter and figure out what to
-      //TODO   about it. If setting the filter fails, all records will be returned
-      if (result == OGRERR_NONE) 
-	{
-	  QgsDebugMsg("Setting spatial filter using " + wktExtent);
-	  ogrLayer->SetSpatialFilter(filter);
-	  //ogrLayer->SetSpatialFilterRect(rect->xMin(), rect->yMin(), rect->xMax(), rect->yMax());
-	}
-      else
-	{
-	  QgsDebugMsg("Setting spatial filter failed!");
-	}
-      OGRGeometryFactory::destroyGeometry(filter);
+
+      wktText = (const char *) wktExtent;
+      OGR_G_CreateFromWkt( (char **)&wktText, NULL, &filter );
+      QgsDebugMsg("Setting spatial filter using " + wktExtent);
+      OGR_L_SetSpatialFilter( ogrLayer, filter );
+      OGR_G_DestroyGeometry( filter );
     }  
 }
 
 
-unsigned char * QgsOgrProvider::getGeometryPointer(OGRFeature *fet)
+unsigned char * QgsOgrProvider::getGeometryPointer(OGRFeatureH fet)
 {
-  OGRGeometry *geom = fet->GetGeometryRef();
+  OGRGeometryH geom = OGR_F_GetGeometryRef(fet);
   unsigned char *gPtr=0;
+
+  if( geom == NULL )
+      return NULL;
+
   // get the wkb representation
-  gPtr = new unsigned char[geom->WkbSize()];
+  gPtr = new unsigned char[OGR_G_WkbSize(geom)];
 
-  geom->exportToWkb((OGRwkbByteOrder) QgsApplication::endian(), gPtr);
+  OGR_G_ExportToWkb(geom,(OGRwkbByteOrder) QgsApplication::endian(), gPtr);
   return gPtr;
-
 }
 
 
 QgsRect QgsOgrProvider::extent()
 {
-  mExtentRect.set(extent_->MinX, extent_->MinY, extent_->MaxX, extent_->MaxY);
+  OGREnvelope *ext = (OGREnvelope *) extent_;
+  mExtentRect.set(ext->MinX, ext->MinY, ext->MaxX, ext->MaxY);
   return mExtentRect;
 }
 
 
 size_t QgsOgrProvider::layerCount() const
 {
-    return ogrDataSource->GetLayerCount();
+    return OGR_DS_GetLayerCount(ogrDataSource);
 } // QgsOgrProvider::layerCount()
 
 
@@ -427,9 +430,9 @@
   return mAttributeFields.size();
 }
 
-void QgsOgrProvider::getFeatureAttribute(OGRFeature * ogrFet, QgsFeature & f, int attindex)
+void QgsOgrProvider::getFeatureAttribute(OGRFeatureH ogrFet, QgsFeature & f, int attindex)
 {
-  OGRFieldDefn *fldDef = ogrFet->GetFieldDefnRef(attindex);
+  OGRFieldDefnH fldDef = OGR_F_GetFieldDefnRef(ogrFet, attindex);
 
   if ( ! fldDef )
   {
@@ -438,7 +441,7 @@
   }
 
   //QString fld = mEncoding->toUnicode(fldDef->GetNameRef());
-  QByteArray cstr(ogrFet->GetFieldAsString(attindex));
+  QByteArray cstr(OGR_F_GetFieldAsString(ogrFet,attindex));
   QString str = mEncoding->toUnicode(cstr);
   QVariant value;
   
@@ -462,7 +465,7 @@
 
 void QgsOgrProvider::reset()
 {
-  ogrLayer->ResetReading();
+  OGR_L_ResetReading(ogrLayer);
 }
 
 
@@ -477,151 +480,23 @@
 bool QgsOgrProvider::addFeature(QgsFeature& f)
 { 
   bool returnValue = true;
-  OGRFeatureDefn* fdef=ogrLayer->GetLayerDefn();
-  OGRFeature* feature=new OGRFeature(fdef);
+  OGRFeatureDefnH fdef=OGR_L_GetLayerDefn(ogrLayer);
+  OGRFeatureH feature= OGR_F_Create(fdef);
   QGis::WKBTYPE ftype = f.geometry()->wkbType();
   unsigned char* wkb = f.geometry()->wkbBuffer();
   OGRErr err;
-  
-  switch(ftype)
+
+  if( f.geometry()->wkbSize() > 0 )
   {
-    case QGis::WKBPoint:
-      {
-        OGRPoint* p=new OGRPoint();
-        p->importFromWkb(wkb,1+sizeof(int)+2*sizeof(double));
-        err = feature->SetGeometry(p);
-	if(err != OGRERR_NONE)
-	  {
-	    delete p;
-	    return false;
-	  }
-        break;
-      }
-    case QGis::WKBLineString:
-      {
-        OGRLineString* l=new OGRLineString();
-        int length;
-        memcpy(&length,wkb+1+sizeof(int),sizeof(int));
-        l->importFromWkb(wkb,1+2*sizeof(int)+2*length*sizeof(double));
-        err = feature->SetGeometry(l);
-	if(err != OGRERR_NONE)
-	  {
-	    delete l;
-	    return false;
-	  }
-        break;
-      }
-    case QGis::WKBPolygon:
-      {
-        OGRPolygon* pol=new OGRPolygon();
-        int numrings;
-        int totalnumpoints=0;
-        int numpoints;//number of points in one ring
-        unsigned char* ptr=wkb+1+sizeof(int);
-        memcpy(&numrings,ptr,sizeof(int));
-        ptr+=sizeof(int);
-        for(int i=0;i<numrings;++i)
-        {
-          memcpy(&numpoints,ptr,sizeof(int));
-          ptr+=sizeof(int);
-          totalnumpoints+=numpoints;
-          ptr+=(2*sizeof(double));
-        }
-        pol->importFromWkb(wkb,1+2*sizeof(int)+numrings*sizeof(int)+totalnumpoints*2*sizeof(double));
-        err = feature->SetGeometry(pol);
-	if(err != OGRERR_NONE)
-	  {
-	    delete pol;
-	    return false;
-	  }
-        break;
-      }
-    case QGis::WKBMultiPoint:
-      {
-        OGRMultiPoint* multip= new OGRMultiPoint();
-        int count;
-        //determine how many points
-        memcpy(&count,wkb+1+sizeof(int),sizeof(int));
-        multip->importFromWkb(wkb,1+2*sizeof(int)+count*2*sizeof(double));
-        err = feature->SetGeometry(multip);
-	if(err != OGRERR_NONE)
-	  {
-	    delete multip;
-	    return false;
-	  }
-        break;
-      }
-    case QGis::WKBMultiLineString:
-      {
-        OGRMultiLineString* multil=new OGRMultiLineString();
-        int numlines;
-        memcpy(&numlines,wkb+1+sizeof(int),sizeof(int));
-        int totalpoints=0;
-        int numpoints;//number of point in one line
-        unsigned char* ptr=wkb+9;
-        for(int i=0;i<numlines;++i)
-        {
-          memcpy(&numpoints,ptr,sizeof(int));
-          ptr+=4;
-          for(int j=0;j<numpoints;++j)
-          {
-            ptr+=16;
-            totalpoints+=2;
-          }
-        }
-        int size=1+2*sizeof(int)+numlines*sizeof(int)+totalpoints*2*sizeof(double);
-        multil->importFromWkb(wkb,size);
-        err = feature->SetGeometry(multil);
-	if(err != OGRERR_NONE)
-	  {
-	    delete multil;
-	    return false;
-	  }
-        break;
-      }
-    case QGis::WKBMultiPolygon:
-      {
-        OGRMultiPolygon* multipol=new OGRMultiPolygon();
-        int numpolys;
-        memcpy(&numpolys,wkb+1+sizeof(int),sizeof(int));
-        int numrings;//number of rings in one polygon
-        int totalrings=0;
-        int totalpoints=0;
-        int numpoints;//number of points in one ring
-        unsigned char* ptr=wkb+9;
+      OGRGeometryH geom = NULL;
 
-        for(int i=0;i<numpolys;++i)
-        {
-          memcpy(&numrings,ptr,sizeof(int));
-          ptr+=4;
-          for(int j=0;j<numrings;++j)
-          {
-            totalrings++;
-            memcpy(&numpoints,ptr,sizeof(int));
-            for(int k=0;k<numpoints;++k)
-            {
-              ptr+=16;
-              totalpoints+=2;
-            }
-          }
-        }
-        int size=1+2*sizeof(int)+numpolys*sizeof(int)+totalrings*sizeof(int)+totalpoints*2*sizeof(double);
-        multipol->importFromWkb(wkb,size);
-        err = feature->SetGeometry(multipol);
-	if(err != OGRERR_NONE)
-	  {
-	    delete multipol;
-	    return false;
-	  }
-        break;
-      }
-    default:
+      if( OGR_G_CreateFromWkb( wkb, NULL, &geom, f.geometry()->wkbSize() )
+          != OGRERR_NONE )
       {
-        QgsLogger::debug("Unknown feature type of: ", (int)(ftype), 1, 
-                         __FILE__, __FUNCTION__, __LINE__);
-	return false;
-	break;
+          return false;
       }
+
+      OGR_F_SetGeometryDirectly( feature, geom );
   }
   
   QgsAttributeMap attrs = f.attributeMap();
@@ -632,41 +507,45 @@
     int targetAttributeId = it.key();
     
     // don't try to set field from attribute map if it's not present in layer
-    if (targetAttributeId >= fdef->GetFieldCount())
+    if (targetAttributeId >= OGR_FD_GetFieldCount(fdef))
       continue;
 
     //if(!s.isEmpty())
     // continue;
       
-    if(fdef->GetFieldDefn(targetAttributeId)->GetType()==OFTInteger)
+    OGRFieldDefnH fldDef = OGR_FD_GetFieldDefn( fdef, targetAttributeId );
+
+    switch( OGR_Fld_GetType(fldDef) )
     {
-      feature->SetField(targetAttributeId,it->toInt());
+      case OFTInteger:
+        OGR_F_SetFieldInteger(feature,targetAttributeId,it->toInt());
+        break;
+
+      case OFTReal:
+        OGR_F_SetFieldDouble(feature,targetAttributeId,it->toDouble());
+        break;
+
+      case OFTString:
+        QgsDebugMsg( QString("Writing string attribute %1 with %2, encoding %3")
+                     .arg( targetAttributeId )
+                     .arg( it->toString() )
+                     .arg( mEncoding->name().data() ) );
+        OGR_F_SetFieldString(feature,targetAttributeId,mEncoding->fromUnicode(it->toString()).constData());
+        break;
+
+      default:
+        QgsLogger::warning("QgsOgrProvider::addFeature, no type found");
+        break;
     }
-    else if(fdef->GetFieldDefn(targetAttributeId)->GetType()==OFTReal)
-    {
-      feature->SetField(targetAttributeId,it->toDouble());
-    }
-    else if(fdef->GetFieldDefn(targetAttributeId)->GetType()==OFTString)
-    {
-      QgsDebugMsg( QString("Writing string attribute %1 with %2, encoding %3")
-	           .arg( targetAttributeId )
-		   .arg( it->toString() )
-		   .arg( mEncoding->name().data() ) );
-      feature->SetField(targetAttributeId,mEncoding->fromUnicode(it->toString()).constData());
-    }
-    else
-    {
-      QgsLogger::warning("QgsOgrProvider::addFeature, no type found");
-    }
   }
 
-  if(ogrLayer->CreateFeature(feature)!=OGRERR_NONE)
+  if( OGR_L_CreateFeature(ogrLayer,feature) != OGRERR_NONE)
   {
     QgsLogger::warning("Writing of the feature failed");
     returnValue = false;
   }
   ++numberFeatures;
-  delete feature;
+  OGR_F_Destroy( feature );
   return returnValue;
 }
 
@@ -683,8 +562,8 @@
   }
 
   // flush features
-  ogrLayer->SyncToDisk();
-  numberFeatures = ogrLayer->GetFeatureCount(); //new feature count
+  OGR_L_SyncToDisk(ogrLayer);
+  numberFeatures = OGR_L_GetFeatureCount(ogrLayer,TRUE); //new feature count
   return returnvalue;
 }
 
@@ -694,39 +573,36 @@
 
     for(QgsNewAttributesMap::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter)
     {
+        OGRFieldDefnH fielddefn = 
+            OGR_Fld_Create(mEncoding->fromUnicode(iter.key()).data(),OFTInteger);
+
 	if(*iter=="OFTInteger")
 	{
-      OGRFieldDefn fielddefn(mEncoding->fromUnicode(iter.key()).data(),OFTInteger);
-	    if(ogrLayer->CreateField(&fielddefn)!=OGRERR_NONE)
-	    {
-		QgsLogger::warning("QgsOgrProvider.cpp: writing of OFTInteger field failed");	
-		returnvalue=false;
-	    }
+            OGR_Fld_SetType( fielddefn, OFTInteger );
 	}
-  else if(*iter=="OFTReal")
+        else if(*iter=="OFTReal")
 	{
-      OGRFieldDefn fielddefn(mEncoding->fromUnicode(iter.key()).data(),OFTReal);
-	    if(ogrLayer->CreateField(&fielddefn)!=OGRERR_NONE)
-	    {
-		QgsLogger::warning("QgsOgrProvider.cpp: writing of OFTReal field failed");
-		returnvalue=false;
-	    }
+            OGR_Fld_SetType( fielddefn, OFTReal );
 	}
-  else if(*iter=="OFTString")
+        else if(*iter=="OFTString")
 	{
-      OGRFieldDefn fielddefn(mEncoding->fromUnicode(iter.key()).data(),OFTString);
-	    if(ogrLayer->CreateField(&fielddefn)!=OGRERR_NONE)
-	    {
-		QgsLogger::warning("QgsOgrProvider.cpp: writing of OFTString field failed");
-		returnvalue=false;
-	    }
+            OGR_Fld_SetType( fielddefn, OFTString );
 	}
 	else
 	{
 	    QgsLogger::warning("QgsOgrProvider::addAttributes, type not found");
 	    returnvalue=false;
+            continue;
 	}
+
+        if( OGR_L_CreateField(ogrLayer,fielddefn,TRUE) != OGRERR_NONE)
+        {
+            QgsLogger::warning("QgsOgrProvider.cpp: writing of OFTInteger field failed");	
+            returnvalue=false;
+        }
+        OGR_Fld_Destroy( fielddefn );
     }
+
     return returnvalue;
 }
 
@@ -736,7 +612,7 @@
   {
     long fid = (long) it.key();
 
-    OGRFeature *of = ogrLayer->GetFeature ( fid );
+    OGRFeatureH of = OGR_L_GetFeature( ogrLayer, fid );
 
     if ( !of )
     {
@@ -749,25 +625,25 @@
     for( QgsAttributeMap::const_iterator it2 = attr.begin(); it2 != attr.end(); ++it2 )
     {
       int f = it2.key();
-		
-      OGRFieldDefn *fd = of->GetFieldDefnRef ( f );
+      
+      OGRFieldDefnH fd = OGR_F_GetFieldDefnRef( of, f );
       if (fd == NULL)
       {
         QgsLogger::warning("QgsOgrProvider::changeAttributeValues, Field " + QString::number(f) + " doesn't exist");
         continue;
       }
       
-      OGRFieldType type = fd->GetType();
+      OGRFieldType type = OGR_Fld_GetType( fd );
       switch ( type )
       {
         case OFTInteger:
-          of->SetField ( f, it2->toInt() );
+          OGR_F_SetFieldInteger ( of, f, it2->toInt() );
           break;
         case OFTReal:
-          of->SetField ( f, it2->toDouble() );
+          OGR_F_SetFieldDouble ( of, f, it2->toDouble() );
           break;
         case OFTString:
-          of->SetField ( f, mEncoding->fromUnicode(it2->toString()).constData() );
+          OGR_F_SetFieldString ( of, f, mEncoding->fromUnicode(it2->toString()).constData() );
           break;
         default:
           QgsLogger::warning("QgsOgrProvider::changeAttributeValues, Unknown field type, cannot change attribute");
@@ -776,22 +652,22 @@
 
     }
 
-    ogrLayer->SetFeature ( of );
+    OGR_L_SetFeature( ogrLayer, of );
   }
 
-  ogrLayer->SyncToDisk();
+  OGR_L_SyncToDisk( ogrLayer );
 
   return true;
 }
 
 bool QgsOgrProvider::changeGeometryValues(QgsGeometryMap & geometry_map)
 {
-  OGRFeature* theOGRFeature = 0;
-  OGRGeometry* theNewGeometry = 0;
+  OGRFeatureH theOGRFeature = 0;
+  OGRGeometryH theNewGeometry = 0;
 
   for (QgsGeometryMap::iterator it = geometry_map.begin(); it != geometry_map.end(); ++it)
   {
-    theOGRFeature = ogrLayer->GetFeature(it.key());
+    theOGRFeature = OGR_L_GetFeature(ogrLayer,it.key());
     if(!theOGRFeature)
     {
       QgsLogger::warning("QgsOgrProvider::changeGeometryValues, cannot find feature");
@@ -799,13 +675,13 @@
     }
 
     //create an OGRGeometry
-    if (OGRGeometryFactory::createFromWkb(it->wkbBuffer(),
-                                          ogrLayer->GetSpatialRef(),
-                                          &theNewGeometry,
-                                          it->wkbSize()) != OGRERR_NONE)
+    if (OGR_G_CreateFromWkb(it->wkbBuffer(),
+                            OGR_L_GetSpatialRef(ogrLayer),
+                            &theNewGeometry,
+                            it->wkbSize()) != OGRERR_NONE)
     {
       QgsLogger::warning("QgsOgrProvider::changeGeometryValues, error while creating new OGRGeometry");
-      delete theNewGeometry;
+      OGR_G_DestroyGeometry( theNewGeometry );
       theNewGeometry = 0;
       continue;
     }
@@ -817,17 +693,18 @@
     }
       
     //set the new geometry
-    if(theOGRFeature->SetGeometryDirectly(theNewGeometry) != OGRERR_NONE)
+    if(OGR_F_SetGeometryDirectly(theOGRFeature, theNewGeometry) != OGRERR_NONE)
     {
       QgsLogger::warning("QgsOgrProvider::changeGeometryValues, error while replacing geometry");
-      delete theNewGeometry;
+      OGR_G_DestroyGeometry( theNewGeometry );
       theNewGeometry = 0;
       continue;
     }
     
-    ogrLayer->SetFeature(theOGRFeature);
+    OGR_L_SetFeature(ogrLayer,theOGRFeature);
+    OGR_F_Destroy( theOGRFeature);
   }
-  ogrLayer->SyncToDisk();
+  OGR_L_SyncToDisk(ogrLayer);
   return true;
 }
 
@@ -836,7 +713,7 @@
     QString filename=dataSourceUri().section('/',-1,-1);//find out the filename from the uri
     QString layername=filename.section('.',0,0);
     QString sql="CREATE SPATIAL INDEX ON "+layername;
-    ogrDataSource->ExecuteSQL (sql.ascii(), ogrLayer->GetSpatialFilter(),"");
+    OGR_DS_ExecuteSQL (ogrDataSource,sql.ascii(), OGR_L_GetSpatialFilter(ogrLayer),"");
     //find out, if the .qix file is there
     QString indexname = dataSourceUri();
     indexname.truncate(dataSourceUri().length()-filename.length());
@@ -863,18 +740,18 @@
     }
   }
 
-  ogrLayer->SyncToDisk();
+  OGR_L_SyncToDisk(ogrLayer);
   QString filename=dataSourceUri().section('/',-1,-1);//find out the filename from the uri
   QString layername=filename.section('.',0,0);
   QString sql="REPACK " + layername;
-  ogrDataSource->ExecuteSQL(sql.toLocal8Bit().data(), NULL, NULL);
-  numberFeatures = ogrLayer->GetFeatureCount(); //new feature count
+  OGR_DS_ExecuteSQL(ogrDataSource,sql.toLocal8Bit().data(), NULL, NULL);
+  numberFeatures = OGR_L_GetFeatureCount(ogrLayer,TRUE); //new feature count
   return returnvalue;
 }
 
 bool QgsOgrProvider::deleteFeature(int id)
 {
-  OGRErr res = ogrLayer->DeleteFeature(id);
+  OGRErr res = OGR_L_DeleteFeature(ogrLayer,id);
   return (res == OGRERR_NONE);
 }
 
@@ -892,7 +769,7 @@
     // here.  This is because older versions of OGR don't always have all
     // the #defines we want to test for here.
 
-    if (ogrLayer->TestCapability("RandomRead"))
+    if (OGR_L_TestCapability(ogrLayer,"RandomRead"))
     // TRUE if the GetFeature() method works *efficiently* for this layer.
     // TODO: Perhaps influence if QGIS caches into memory 
     //       (vs read from disk every time) based on this setting.
@@ -905,19 +782,19 @@
     }
     ability |= QgsVectorDataProvider::SelectGeometryAtId;
 
-    if (ogrLayer->TestCapability("SequentialWrite"))
+    if (OGR_L_TestCapability(ogrLayer,"SequentialWrite"))
     // TRUE if the CreateFeature() method works for this layer.
     {
       ability |= QgsVectorDataProvider::AddFeatures;
     }
 
-    if (ogrLayer->TestCapability("DeleteFeature"))
+    if (OGR_L_TestCapability(ogrLayer,"DeleteFeature"))
     // TRUE if this layer can delete its features
     {
       ability |= DeleteFeatures;
     }
     
-    if (ogrLayer->TestCapability("RandomWrite"))
+    if (OGR_L_TestCapability(ogrLayer,"RandomWrite"))
     // TRUE if the SetFeature() method is operational on this layer.
     {
       // TODO According to http://shapelib.maptools.org/ (Shapefile C Library V1.2)
@@ -929,7 +806,7 @@
       ability |= QgsVectorDataProvider::ChangeGeometries;
     }
 
-    if (ogrLayer->TestCapability("FastSpatialFilter"))
+    if (OGR_L_TestCapability(ogrLayer,"FastSpatialFilter"))
     // TRUE if this layer implements spatial filtering efficiently.
     // Layers that effectively read all features, and test them with the 
     // OGRFeature intersection methods should return FALSE.
@@ -939,7 +816,7 @@
       // TODO: Perhaps use as a clue by QGIS whether it should build and maintain it's own spatial index for features in this layer.
     }
 
-    if (ogrLayer->TestCapability("FastFeatureCount"))
+    if (OGR_L_TestCapability(ogrLayer,"FastFeatureCount"))
     // TRUE if this layer can return a feature count
     // (via OGRLayer::GetFeatureCount()) efficiently ... ie. without counting
     // the features. In some cases this will return TRUE until a spatial
@@ -948,7 +825,7 @@
       // TODO: Perhaps use as a clue by QGIS whether it should spawn a thread to count features.
     }
 
-    if (ogrLayer->TestCapability("FastGetExtent"))
+    if (OGR_L_TestCapability(ogrLayer,"FastGetExtent"))
     // TRUE if this layer can return its data extent 
     // (via OGRLayer::GetExtent()) efficiently ... ie. without scanning
     // all the features. In some cases this will return TRUE until a
@@ -957,7 +834,7 @@
       // TODO: Perhaps use as a clue by QGIS whether it should spawn a thread to calculate extent.
     }
 
-    if (ogrLayer->TestCapability("FastSetNextByIndex"))
+    if (OGR_L_TestCapability(ogrLayer,"FastSetNextByIndex"))
     // TRUE if this layer can perform the SetNextByIndex() call efficiently.
     {
       // No use required for this QGIS release.
@@ -1049,19 +926,8 @@
 
     // first get the GDAL driver manager
 
-    OGRSFDriverRegistrar *driverRegistrar = OGRSFDriverRegistrar::GetRegistrar();
+    OGRSFDriverH driver;          // current driver
 
-    if (!driverRegistrar)
-    {
-	QgsLogger::warning("OGR Driver Manager, unable to get OGRDriverManager");
-        return "";              // XXX good place to throw exception if we
-    }                           // XXX decide to do exceptions
-
-    // then iterate through all of the supported drivers, adding the
-    // corresponding file filter
-
-    OGRSFDriver *driver;          // current driver
-
     QString driverName;           // current driver name
 
     // Grind through all the drivers and their respective metadata.
@@ -1070,11 +936,11 @@
     // theoreticaly we can open those files because there exists a
     // driver for them, the user will have to use the "All Files" to
     // open datasets with no explicitly defined file name extension.
-    QgsDebugMsg( QString("Driver count: %1").arg( driverRegistrar->GetDriverCount() ) );
+    QgsDebugMsg( QString("Driver count: %1").arg( OGRGetDriverCount() ) );
 
-    for (int i = 0; i < driverRegistrar->GetDriverCount(); ++i)
+    for (int i = 0; i < OGRGetDriverCount(); ++i)
     {
-        driver = driverRegistrar->GetDriver(i);
+        driver = OGRGetDriver(i);
 
         Q_CHECK_PTR(driver);
 
@@ -1084,7 +950,7 @@
             continue;
         }
 
-        driverName = driver->GetName();
+        driverName = OGR_Dr_GetName(driver);
 
 
         if (driverName.startsWith("ESRI"))
@@ -1253,30 +1119,30 @@
                                       QGis::WKBTYPE vectortype,
                                       const std::list<std::pair<QString, QString> >& attributes)
 {
-    OGRSFDriver* driver;
+    OGRSFDriverH driver;
     OGRRegisterAll();
-    driver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(format);
+    driver = OGRGetDriverByName(format);
     if(driver == NULL)
     {
 	return false;
     }
 
-    OGRDataSource* dataSource;
-    dataSource = driver->CreateDataSource(QFile::encodeName(uri).constData(), NULL);
+    OGRDataSourceH dataSource;
+    dataSource = OGR_Dr_CreateDataSource(driver,QFile::encodeName(uri).constData(), NULL);
     if(dataSource == NULL)
     {
 	return false;
     }
 
     //consider spatial reference system
-    OGRSpatialReference* reference = NULL;
+    OGRSpatialReferenceH reference = NULL;
     QgsSpatialRefSys mySpatialRefSys;
     mySpatialRefSys.validate();
     QString myWKT = mySpatialRefSys.toWkt();
     
     if( !myWKT.isNull()  &&  myWKT.length() != 0 )
     {
-	reference = new OGRSpatialReference(myWKT.toLocal8Bit().data());
+	reference = OSRNewSpatialReference(myWKT.toLocal8Bit().data());
     }
 
     // Map the qgis geometry type to the OGR geometry type
@@ -1310,8 +1176,8 @@
       }
     }
 
-    OGRLayer* layer;	
-    layer = dataSource->CreateLayer(QFile::encodeName(QFileInfo(uri).baseName()).constData(), reference, OGRvectortype, NULL);
+    OGRLayerH layer;	
+    layer = OGR_DS_CreateLayer(dataSource,QFile::encodeName(QFileInfo(uri).baseName()).constData(), reference, OGRvectortype, NULL);
     if(layer == NULL)
     {
 	return false;
@@ -1325,39 +1191,39 @@
     {
 	if(it->second == "Real")
 	{
-	    OGRFieldDefn field(codec->fromUnicode(it->first).data(), OFTReal);
-	    field.SetPrecision(3);
-	    field.SetWidth(32);
-	    if(layer->CreateField(&field) != OGRERR_NONE)
+	    OGRFieldDefnH field = OGR_Fld_Create(codec->fromUnicode(it->first).data(), OFTReal);
+	    OGR_Fld_SetPrecision(field,3);
+	    OGR_Fld_SetWidth(field,32);
+	    if( OGR_L_CreateField(layer,field,TRUE) != OGRERR_NONE)
 	    {
 		QgsLogger::warning("creation of OFTReal field failed");
 	    }
 	}
 	else if(it->second == "Integer")
 	{
-	    OGRFieldDefn field(codec->fromUnicode(it->first).data(), OFTInteger);
-	    if(layer->CreateField(&field) != OGRERR_NONE)
+	    OGRFieldDefnH field = OGR_Fld_Create(codec->fromUnicode(it->first).data(), OFTInteger);
+	    if(OGR_L_CreateField(layer,field,TRUE) != OGRERR_NONE)
 	    {
 		QgsLogger::warning("creation of OFTInteger field failed");
 	    }
 	}
 	else if(it->second == "String")
 	{
-	    OGRFieldDefn field(codec->fromUnicode(it->first).data(), OFTString);
-	    if(layer->CreateField(&field) != OGRERR_NONE)
+	    OGRFieldDefnH field = OGR_Fld_Create(codec->fromUnicode(it->first).data(), OFTString);
+	    if(OGR_L_CreateField(layer,field,TRUE) != OGRERR_NONE)
 	    {
 	      QgsLogger::warning("creation of OFTString field failed");
 	    }
 	}
     }
 
-    OGRDataSource::DestroyDataSource(dataSource);
+    OGR_DS_Destroy(dataSource);
 
     QgsDebugMsg( QString("GDAL Version number %1").arg( GDAL_VERSION_NUM ) );
 #if GDAL_VERSION_NUM >= 1310
     if(reference)
     {
-    reference->Release();
+        OSRRelease( reference );
     }
 #endif //GDAL_VERSION_NUM
     return true;
@@ -1371,28 +1237,19 @@
 
   QgsSpatialRefSys srs;
   
-  OGRSpatialReference * mySpatialRefSys = ogrLayer->GetSpatialRef();
+  OGRSpatialReferenceH mySpatialRefSys = OGR_L_GetSpatialRef(ogrLayer);
   if (mySpatialRefSys == NULL)
   {
     QgsDebugMsg("no spatial reference found"); 
   }
   else
   {
-    // if appropriate, morph the projection from ESRI form
-    QString fileName = ogrDataSource->GetName();
-    QgsDebugMsg("Data source file name is : " + fileName); 
-    if(fileName.contains(".shp"))
-    {
-      QgsDebugMsg("Morphing " + fileName + " WKT from ESRI"); 
-      // morph it
-      mySpatialRefSys->morphFromESRI();
-    }
     // get the proj4 text
     char * ppszProj4;
-    mySpatialRefSys->exportToProj4   ( &ppszProj4 );
+    OSRExportToProj4(mySpatialRefSys, &ppszProj4 );
     QgsDebugMsg(ppszProj4); 
     char    *pszWKT = NULL;
-    mySpatialRefSys->exportToWkt( &pszWKT );
+    OSRExportToWkt(mySpatialRefSys, &pszWKT );
     QString myWKTString = QString(pszWKT);
     OGRFree(pszWKT);  
     

Modified: branches/gdalogr-capi-branch/qgis/src/providers/ogr/qgsogrprovider.h
===================================================================
--- branches/gdalogr-capi-branch/qgis/src/providers/ogr/qgsogrprovider.h	2008-02-15 21:20:17 UTC (rev 8160)
+++ branches/gdalogr-capi-branch/qgis/src/providers/ogr/qgsogrprovider.h	2008-02-15 23:37:51 UTC (rev 8161)
@@ -30,13 +30,13 @@
 
 class QgsFeature;
 class QgsField;
-class OGRDataSource;
-class OGRSFDriver;
-class OGRLayer;
-class OGRFeature;
-class OGREnvelope;
-class OGRPolygon;
 
+typedef void *OGRDataSourceH;
+typedef void *OGRSFDriverH;
+typedef void *OGRLayerH;
+typedef void *OGRFeatureH;
+typedef void *OGRGeometryH;
+
 /**
   \class QgsOgrProvider
   \brief Data provider for ESRI shapefiles
@@ -188,7 +188,7 @@
     void loadFields();
 
     /**Get an attribute associated with a feature*/
-    void getFeatureAttribute(OGRFeature * ogrFet, QgsFeature & f, int attindex);
+    void getFeatureAttribute(OGRFeatureH ogrFet, QgsFeature & f, int attindex);
 
       /** return a provider name
 
@@ -222,19 +222,20 @@
 
 
   private:
-    unsigned char *getGeometryPointer(OGRFeature * fet);
+    unsigned char *getGeometryPointer(OGRFeatureH fet);
     
     QgsFieldMap mAttributeFields;
 
-    OGRDataSource *ogrDataSource;
-    OGREnvelope *extent_;
+    OGRDataSourceH ogrDataSource;
+    void *extent_;
+
     /**This member variable receives the same value as extent_
      in the method QgsOgrProvider::extent(). The purpose is to prevent a memory leak*/
     QgsRect mExtentRect;
-    OGRLayer *ogrLayer;
+    OGRLayerH ogrLayer;
 
     // OGR Driver that was actually used to open the layer
-    OGRSFDriver *ogrDriver;
+    OGRSFDriverH ogrDriver;
 
     // Friendly name of the OGR Driver that was actually used to open the layer
     QString ogrDriverName;
@@ -246,12 +247,11 @@
     long numberFeatures;
     
     //! Selection rectangle 
-    OGRPolygon * mSelectionRectangle;
+    OGRGeometryH mSelectionRectangle;
     /**Adds one feature*/
     bool addFeature(QgsFeature& f);
     /**Deletes one feature*/
     bool deleteFeature(int id);
     //! The geometry factory
     GEOS_GEOM::GeometryFactory *geometryFactory;
-
 };

Modified: branches/gdalogr-capi-branch/qgis/tests/algorithms/projections/projectioncshandlingtest.h
===================================================================
--- branches/gdalogr-capi-branch/qgis/tests/algorithms/projections/projectioncshandlingtest.h	2008-02-15 21:20:17 UTC (rev 8160)
+++ branches/gdalogr-capi-branch/qgis/tests/algorithms/projections/projectioncshandlingtest.h	2008-02-15 23:37:51 UTC (rev 8161)
@@ -22,7 +22,7 @@
 #include <qstring.h>
 //gdal and ogr includes
 #include <ogr_api.h>
-#include <ogr_spatialref.h>
+#include <ogr_srs_api.h>
 #include <cpl_error.h>
 class ProjectionCsHandlingTest : public CppUnit::TestCase { 
   public: 
@@ -94,9 +94,10 @@
     void testProjImportWkt() {
       // create a spatial reference system object
       std::cout << "\n\nCreating and OGRSpatialReference object from WKT" << std::endl; 
-      OGRSpatialReference myInputSpatialRefSys;
+      OGRSpatialReferenceH myInputSpatialRefSys = OSRNewSpatialReference(NULL);
       char *pWkt = (char*)wkt.ascii();
-      CPPUNIT_ASSERT(myInputSpatialRefSys.importFromWkt(&pWkt)== OGRERR_NONE);
+      CPPUNIT_ASSERT(OSRImportFromWkt(myInputSpatialRefSys,&pWkt)== OGRERR_NONE);
+      OSRDestroySpatialReference( myInputSpatialRefSys );
     }
     //
     // Test fetch of proj4 parameters from an OGRSpatialReference object
@@ -106,7 +107,7 @@
     {
       std::cout << "\n\nGetting proj4 parameters from OGRSpatialReference object" << std::endl; 
       // set up the spatial ref
-      OGRSpatialReference myInputSpatialRefSys;
+      OGRSpatialReferenceH myInputSpatialRefSys;
       char *pWkt = (char*)wkt.ascii();
       CPPUNIT_ASSERT(myInputSpatialRefSys.importFromWkt(&pWkt)== OGRERR_NONE);
       // get the proj4 for the projection



More information about the QGIS-commit mailing list