Skip to content

Commit

Permalink
Merge of C-API into trunk
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@8222 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Mar 14, 2008
1 parent 98e2e4f commit fb8424d
Show file tree
Hide file tree
Showing 15 changed files with 531 additions and 1,082 deletions.
22 changes: 5 additions & 17 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
//
// Gdal/Ogr includes
//
#include <ogrsf_frmts.h>
#include <ogr_api.h>

//
// Other includes
Expand Down Expand Up @@ -1743,20 +1743,10 @@ static void buildSupportedVectorFileFilter_(QString & fileFilters)
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

Expand All @@ -1768,9 +1758,9 @@ static void buildSupportedVectorFileFilter_(QString & fileFilters)
// 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);

Expand All @@ -1780,9 +1770,7 @@ static void buildSupportedVectorFileFilter_(QString & fileFilters)
continue;
}

driverName = driver->GetName();


driverName = OGR_Dr_GetName(driver);

if (driverName.startsWith("ESRI"))
{
Expand Down
98 changes: 46 additions & 52 deletions src/core/qgsspatialrefsys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -164,8 +163,12 @@ void QgsSpatialRefSys::validate()
//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)
{
Expand All @@ -187,8 +190,10 @@ void QgsSpatialRefSys::validate()
//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)
{
Expand Down Expand Up @@ -290,9 +295,9 @@ bool QgsSpatialRefSys::createFromWkt(QString theWkt)
#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");
Expand All @@ -301,15 +306,19 @@ bool QgsSpatialRefSys::createFromWkt(QString theWkt)
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...
Expand Down Expand Up @@ -467,8 +476,9 @@ bool QgsSpatialRefSys::isValid() const
//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);
Expand Down Expand Up @@ -903,16 +913,16 @@ void QgsSpatialRefSys::setMapUnits()
}

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
Expand Down Expand Up @@ -940,7 +950,7 @@ void QgsSpatialRefSys::setMapUnits()
}
else
{
myOgrSpatialRef.GetAngularUnits(&unitName);
OSRGetAngularUnits(myOgrSpatialRef, &unitName);
QString unit(unitName);
if (unit == "degree")
mMapUnits = QGis::DEGREES;
Expand All @@ -951,6 +961,7 @@ void QgsSpatialRefSys::setMapUnits()
}
QgsDebugMsg("Projection has angular units of " + unit);
}
OSRDestroySpatialReference( myOgrSpatialRef );
}


Expand Down Expand Up @@ -1104,73 +1115,56 @@ bool QgsSpatialRefSys::equals(QString theProj4CharArray)


//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)
{}
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 = OSRNewSpatialReference(NULL);
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;
}

Expand Down
Loading

0 comments on commit fb8424d

Please sign in to comment.