mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Merge of C-API into trunk
git-svn-id: http://svn.osgeo.org/qgis/trunk@8222 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
98e2e4f267
commit
fb8424dbfa
@ -130,7 +130,7 @@
|
||||
//
|
||||
// Gdal/Ogr includes
|
||||
//
|
||||
#include <ogrsf_frmts.h>
|
||||
#include <ogr_api.h>
|
||||
|
||||
//
|
||||
// Other includes
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -1780,9 +1770,7 @@ static void buildSupportedVectorFileFilter_(QString & fileFilters)
|
||||
continue;
|
||||
}
|
||||
|
||||
driverName = driver->GetName();
|
||||
|
||||
|
||||
driverName = OGR_Dr_GetName(driver);
|
||||
|
||||
if (driverName.startsWith("ESRI"))
|
||||
{
|
||||
|
@ -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,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)
|
||||
{
|
||||
@ -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)
|
||||
{
|
||||
@ -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");
|
||||
@ -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...
|
||||
@ -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);
|
||||
@ -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
|
||||
@ -940,7 +950,7 @@ void QgsSpatialRefSys::setMapUnits()
|
||||
}
|
||||
else
|
||||
{
|
||||
myOgrSpatialRef.GetAngularUnits(&unitName);
|
||||
OSRGetAngularUnits(myOgrSpatialRef, &unitName);
|
||||
QString unit(unitName);
|
||||
if (unit == "degree")
|
||||
mMapUnits = QGis::DEGREES;
|
||||
@ -951,6 +961,7 @@ void QgsSpatialRefSys::setMapUnits()
|
||||
}
|
||||
QgsDebugMsg("Projection has angular units of " + unit);
|
||||
}
|
||||
OSRDestroySpatialReference( myOgrSpatialRef );
|
||||
}
|
||||
|
||||
|
||||
@ -1104,10 +1115,10 @@ 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)
|
||||
@ -1115,62 +1126,45 @@ bool QgsSpatialRefSys::equals(QString theProj4CharArray)
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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 @@ QgsVectorFileWriter::QgsVectorFileWriter(const QString& shapefileName,
|
||||
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 @@ QgsVectorFileWriter::QgsVectorFileWriter(const QString& shapefileName,
|
||||
}
|
||||
|
||||
// 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 @@ QgsVectorFileWriter::QgsVectorFileWriter(const QString& shapefileName,
|
||||
}
|
||||
|
||||
// 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 @@ QgsVectorFileWriter::QgsVectorFileWriter(const QString& shapefileName,
|
||||
}
|
||||
|
||||
// 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 @@ QgsVectorFileWriter::QgsVectorFileWriter(const QString& shapefileName,
|
||||
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 @@ bool QgsVectorFileWriter::addFeature(QgsFeature& feature)
|
||||
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 @@ bool QgsVectorFileWriter::addFeature(QgsFeature& feature)
|
||||
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 @@ bool QgsVectorFileWriter::addFeature(QgsFeature& feature)
|
||||
// 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_SetGeometry(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 @@ bool QgsVectorFileWriter::addFeature(QgsFeature& feature)
|
||||
QgsVectorFileWriter::~QgsVectorFileWriter()
|
||||
{
|
||||
if (mGeom)
|
||||
delete mGeom;
|
||||
{
|
||||
OGR_G_DestroyGeometry( mGeom );
|
||||
}
|
||||
|
||||
if (mDS)
|
||||
OGRDataSource::DestroyDataSource(mDS);
|
||||
{
|
||||
OGR_DS_Destroy( mDS );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 @@ class CORE_EXPORT QgsVectorFileWriter
|
||||
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;
|
||||
|
||||
|
@ -28,7 +28,9 @@ email : tim at linfiniti.com
|
||||
#include "qgsrasterviewport.h"
|
||||
#include "qgsrect.h"
|
||||
#include "qgsspatialrefsys.h"
|
||||
|
||||
#include "gdalwarper.h"
|
||||
#include "cpl_conv.h"
|
||||
|
||||
#include "qgspseudocolorshader.h"
|
||||
#include "qgsfreakoutshader.h"
|
||||
@ -121,18 +123,10 @@ void QgsRasterLayer::buildSupportedRasterFileFilter(QString & theFileFiltersStri
|
||||
// first get the GDAL driver manager
|
||||
registerGdalDrivers();
|
||||
|
||||
GDALDriverManager *myGdalDriverManager = GetGDALDriverManager();
|
||||
|
||||
if (!myGdalDriverManager)
|
||||
{
|
||||
QgsLogger::warning("unable to get GDALDriverManager");
|
||||
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
|
||||
|
||||
GDALDriver *myGdalDriver; // current driver
|
||||
GDALDriverH myGdalDriver; // current driver
|
||||
|
||||
char **myGdalDriverMetadata; // driver metadata strings
|
||||
|
||||
@ -145,7 +139,7 @@ void QgsRasterLayer::buildSupportedRasterFileFilter(QString & theFileFiltersStri
|
||||
QStringList catchallFilter; // for Any file(*.*), but also for those
|
||||
// drivers with no specific file filter
|
||||
|
||||
GDALDriver *jp2Driver = NULL; // first JPEG2000 driver found
|
||||
GDALDriverH jp2Driver = NULL; // first JPEG2000 driver found
|
||||
|
||||
// Grind through all the drivers and their respective metadata.
|
||||
// We'll add a file filter for those drivers that have a file
|
||||
@ -158,9 +152,9 @@ void QgsRasterLayer::buildSupportedRasterFileFilter(QString & theFileFiltersStri
|
||||
// driver, which will be found in DMD_LONGNAME, which will have the
|
||||
// same form.
|
||||
|
||||
for (int i = 0; i < myGdalDriverManager->GetDriverCount(); ++i)
|
||||
for (int i = 0; i < GDALGetDriverCount(); ++i)
|
||||
{
|
||||
myGdalDriver = myGdalDriverManager->GetDriver(i);
|
||||
myGdalDriver = GDALGetDriver(i);
|
||||
|
||||
Q_CHECK_PTR(myGdalDriver);
|
||||
|
||||
@ -172,17 +166,17 @@ void QgsRasterLayer::buildSupportedRasterFileFilter(QString & theFileFiltersStri
|
||||
// now we need to see if the driver is for something currently
|
||||
// supported; if not, we give it a miss for the next driver
|
||||
|
||||
myGdalDriverDescription = myGdalDriver->GetDescription();
|
||||
myGdalDriverDescription = GDALGetDescription(myGdalDriver);
|
||||
|
||||
if (!isSupportedRasterDriver(myGdalDriverDescription))
|
||||
{
|
||||
// not supported, therefore skip
|
||||
QgsDebugMsg("skipping unsupported driver " + QString(myGdalDriver->GetDescription()));
|
||||
QgsDebugMsg("skipping unsupported driver " + QString(GDALGetDescription(myGdalDriver)));
|
||||
continue;
|
||||
}
|
||||
// std::cerr << "got driver string " << myGdalDriver->GetDescription() << "\n";
|
||||
|
||||
myGdalDriverMetadata = myGdalDriver->GetMetadata();
|
||||
myGdalDriverMetadata = GDALGetMetadata(myGdalDriver,NULL);
|
||||
|
||||
// presumably we know we've run out of metadta if either the
|
||||
// address is 0, or the first character is null
|
||||
@ -275,7 +269,7 @@ void QgsRasterLayer::buildSupportedRasterFileFilter(QString & theFileFiltersStri
|
||||
}
|
||||
else
|
||||
{
|
||||
catchallFilter << QString(myGdalDriver->GetDescription());
|
||||
catchallFilter << QString(GDALGetDescription(myGdalDriver));
|
||||
}
|
||||
}
|
||||
|
||||
@ -439,7 +433,7 @@ QgsRasterLayer::~QgsRasterLayer()
|
||||
{
|
||||
if ( mGdalBaseDataset )
|
||||
{
|
||||
mGdalBaseDataset->Dereference();
|
||||
GDALDereferenceDataset( mGdalBaseDataset );
|
||||
GDALClose(mGdalDataset);
|
||||
}
|
||||
}
|
||||
@ -454,7 +448,7 @@ bool QgsRasterLayer::readFile( QString const & fileName )
|
||||
mGdalDataset = NULL;
|
||||
|
||||
//open the dataset making sure we handle char encoding of locale properly
|
||||
mGdalBaseDataset = (GDALDataset *) GDALOpen(QFile::encodeName(fileName).constData(), GA_ReadOnly);
|
||||
mGdalBaseDataset = GDALOpen(QFile::encodeName(fileName).constData(), GA_ReadOnly);
|
||||
|
||||
if (mGdalBaseDataset == NULL)
|
||||
{
|
||||
@ -466,23 +460,29 @@ bool QgsRasterLayer::readFile( QString const & fileName )
|
||||
mLastModified = lastModified ( fileName );
|
||||
|
||||
// Check if we need a warped VRT for this file.
|
||||
if( (mGdalBaseDataset->GetGeoTransform(mGeoTransform) == CE_None
|
||||
if( (GDALGetGeoTransform(mGdalBaseDataset,mGeoTransform) == CE_None
|
||||
&& (mGeoTransform[1] < 0.0
|
||||
|| mGeoTransform[2] != 0.0
|
||||
|| mGeoTransform[4] != 0.0
|
||||
|| mGeoTransform[5] > 0.0))
|
||||
|| mGdalBaseDataset->GetGCPCount() > 0 )
|
||||
|| GDALGetGCPCount(mGdalBaseDataset) > 0 )
|
||||
{
|
||||
QgsLogger::warning("Creating Warped VRT.");
|
||||
|
||||
mGdalDataset = (GDALDataset *)
|
||||
mGdalDataset =
|
||||
GDALAutoCreateWarpedVRT( mGdalBaseDataset, NULL, NULL,
|
||||
GRA_NearestNeighbour, 0.2, NULL );
|
||||
if( mGdalDataset == NULL )
|
||||
{
|
||||
QgsLogger::warning("Warped VRT Creation failed.");
|
||||
mGdalDataset = mGdalBaseDataset;
|
||||
GDALReferenceDataset( mGdalDataset );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mGdalDataset = mGdalBaseDataset;
|
||||
mGdalDataset->Reference();
|
||||
GDALReferenceDataset( mGdalDataset );
|
||||
}
|
||||
|
||||
//check f this file has pyramids
|
||||
@ -532,11 +532,11 @@ bool QgsRasterLayer::readFile( QString const & fileName )
|
||||
// Use the affine transform to get geo coordinates for
|
||||
// the corners of the raster
|
||||
double myXMax = mGeoTransform[0] +
|
||||
mGdalDataset->GetRasterXSize() * mGeoTransform[1] +
|
||||
mGdalDataset->GetRasterYSize() * mGeoTransform[2];
|
||||
GDALGetRasterXSize(mGdalDataset) * mGeoTransform[1] +
|
||||
GDALGetRasterYSize(mGdalDataset) * mGeoTransform[2];
|
||||
double myYMin = mGeoTransform[3] +
|
||||
mGdalDataset->GetRasterXSize() * mGeoTransform[4] +
|
||||
mGdalDataset->GetRasterYSize() * mGeoTransform[5];
|
||||
GDALGetRasterXSize(mGdalDataset) * mGeoTransform[4] +
|
||||
GDALGetRasterYSize(mGdalDataset) * mGeoTransform[5];
|
||||
|
||||
mLayerExtent.setXmax(myXMax);
|
||||
// The affine transform reduces to these values at the
|
||||
@ -548,8 +548,8 @@ bool QgsRasterLayer::readFile( QString const & fileName )
|
||||
//
|
||||
// Set up the x and y dimensions of this raster layer
|
||||
//
|
||||
mRasterXDim = mGdalDataset->GetRasterXSize();
|
||||
mRasterYDim = mGdalDataset->GetRasterYSize();
|
||||
mRasterXDim = GDALGetRasterXSize(mGdalDataset);
|
||||
mRasterYDim = GDALGetRasterYSize(mGdalDataset);
|
||||
|
||||
//
|
||||
// Determin the nodatavalue
|
||||
@ -557,7 +557,7 @@ bool QgsRasterLayer::readFile( QString const & fileName )
|
||||
mNoDataValue = -9999; //Standard default?
|
||||
mValidNoDataValue = false;
|
||||
int isValid = false;
|
||||
double myNoDataValue = mGdalDataset->GetRasterBand(1)->GetNoDataValue(&isValid);
|
||||
double myNoDataValue = GDALGetRasterNoDataValue(GDALGetRasterBand(mGdalDataset,1),&isValid);
|
||||
if(isValid)
|
||||
{
|
||||
mNoDataValue = myNoDataValue;
|
||||
@ -571,10 +571,10 @@ bool QgsRasterLayer::readFile( QString const & fileName )
|
||||
}
|
||||
|
||||
//initialise the raster band stats and contrast enhancement vector
|
||||
for (int i = 1; i <= mGdalDataset->GetRasterCount(); i++)
|
||||
for (int i = 1; i <= GDALGetRasterCount(mGdalDataset); i++)
|
||||
{
|
||||
GDALRasterBand *myGdalBand = mGdalDataset->GetRasterBand(i);
|
||||
QString myColorQString = GDALGetColorInterpretationName(myGdalBand->GetColorInterpretation());
|
||||
GDALRasterBandH myGdalBand = GDALGetRasterBand(mGdalDataset,i);
|
||||
QString myColorQString = GDALGetColorInterpretationName(GDALGetRasterColorInterpretation(myGdalBand));
|
||||
QgsRasterBandStats myRasterBandStats;
|
||||
//myRasterBandStats.bandName = myColorQString ;
|
||||
myRasterBandStats.bandName=QString::number(i) + " : " + myColorQString;
|
||||
@ -587,7 +587,7 @@ bool QgsRasterLayer::readFile( QString const & fileName )
|
||||
mRasterStatsList.push_back(myRasterBandStats);
|
||||
|
||||
//Build a new contrast enhancement for the band and store in list
|
||||
QgsContrastEnhancement myContrastEnhancement((QgsContrastEnhancement::QgsRasterDataType)myGdalBand->GetRasterDataType());
|
||||
QgsContrastEnhancement myContrastEnhancement((QgsContrastEnhancement::QgsRasterDataType)GDALGetRasterDataType(myGdalBand));
|
||||
mContrastEnhancementList.append(myContrastEnhancement);
|
||||
}
|
||||
|
||||
@ -597,7 +597,7 @@ bool QgsRasterLayer::readFile( QString const & fileName )
|
||||
//decide what type of layer this is...
|
||||
//note that multiband images can have one or more 'undefindd' bands,
|
||||
//so we must do this check first!
|
||||
if ((mGdalDataset->GetRasterCount() > 1))
|
||||
if ((GDALGetRasterCount(mGdalDataset) > 1))
|
||||
{
|
||||
rasterLayerType = MULTIBAND;
|
||||
}
|
||||
@ -626,7 +626,7 @@ bool QgsRasterLayer::readFile( QString const & fileName )
|
||||
mRedBandName = getRasterBandName(1); // sensible default
|
||||
mGreenBandName = getRasterBandName(2); // sensible default
|
||||
//for the third layer we cant be sure so..
|
||||
if (mGdalDataset->GetRasterCount() > 2)
|
||||
if (GDALGetRasterCount(mGdalDataset) > 2)
|
||||
{
|
||||
mBlueBandName = getRasterBandName(3); // sensible default
|
||||
}
|
||||
@ -669,12 +669,12 @@ QString QgsRasterLayer::getProjectionWKT()
|
||||
{
|
||||
QString myWKTString;
|
||||
QgsSpatialRefSys mySRS;
|
||||
myWKTString=QString (mGdalDataset->GetProjectionRef());
|
||||
myWKTString=QString (GDALGetProjectionRef(mGdalDataset));
|
||||
mySRS.createFromWkt(myWKTString);
|
||||
if (!mySRS.isValid())
|
||||
{
|
||||
//try to get the gcp srs from the raster layer if available
|
||||
myWKTString=QString(mGdalDataset->GetGCPProjection());
|
||||
myWKTString=QString(GDALGetGCPProjection(mGdalDataset));
|
||||
|
||||
// What is the purpose of this piece of code?
|
||||
// Sideeffects from validate()?
|
||||
@ -695,7 +695,7 @@ void QgsRasterLayer::closeDataset()
|
||||
if ( !mValid ) return;
|
||||
mValid = FALSE;
|
||||
|
||||
mGdalBaseDataset->Dereference();
|
||||
GDALDereferenceDataset(mGdalBaseDataset);
|
||||
mGdalBaseDataset = NULL;
|
||||
|
||||
GDALClose(mGdalDataset);
|
||||
@ -884,10 +884,10 @@ bool QgsRasterLayer::hasBand(QString const & theBandName)
|
||||
{
|
||||
QgsDebugMsg("Looking for band : " + theBandName);
|
||||
|
||||
for (int i = 1; i <= mGdalDataset->GetRasterCount(); i++)
|
||||
for (int i = 1; i <= GDALGetRasterCount(mGdalDataset); i++)
|
||||
{
|
||||
GDALRasterBand *myGdalBand = mGdalDataset->GetRasterBand(i);
|
||||
QString myColorQString = GDALGetColorInterpretationName(myGdalBand->GetColorInterpretation());
|
||||
GDALRasterBandH myGdalBand = GDALGetRasterBand(mGdalDataset,i);
|
||||
QString myColorQString = GDALGetColorInterpretationName(GDALGetRasterColorInterpretation(myGdalBand));
|
||||
#ifdef QGISDEBUG
|
||||
QgsLogger::debug("band", i, __FILE__, __FUNCTION__, __LINE__, 2);
|
||||
#endif
|
||||
@ -951,7 +951,7 @@ QPixmap QgsRasterLayer::getPaletteAsPixmap()
|
||||
{
|
||||
QgsDebugMsg("....found paletted image");
|
||||
QgsColorTable *myColorTable = colorTable ( 1 );
|
||||
GDALRasterBandH myGdalBand = mGdalDataset->GetRasterBand(1);
|
||||
GDALRasterBandH myGdalBand = GDALGetRasterBand(mGdalDataset,1);
|
||||
if( GDALGetRasterColorInterpretation(myGdalBand) == GCI_PaletteIndex && myColorTable->defined() )
|
||||
{
|
||||
QgsDebugMsg("....found GCI_PaletteIndex");
|
||||
@ -1437,8 +1437,8 @@ void QgsRasterLayer::drawSingleBandGray(QPainter * theQPainter, QgsRasterViewPor
|
||||
return;
|
||||
}
|
||||
|
||||
GDALRasterBand *myGdalBand = mGdalDataset->GetRasterBand(theBandNo);
|
||||
GDALDataType myDataType = myGdalBand->GetRasterDataType();
|
||||
GDALRasterBandH myGdalBand = GDALGetRasterBand(mGdalDataset,theBandNo);
|
||||
GDALDataType myDataType = GDALGetRasterDataType(myGdalBand);
|
||||
void *myGdalScanData = readData ( myGdalBand, theRasterViewPort );
|
||||
|
||||
/* Check for out of memory error */
|
||||
@ -1541,8 +1541,8 @@ void QgsRasterLayer::drawSingleBandPseudoColor(QPainter * theQPainter,
|
||||
}
|
||||
|
||||
QgsRasterBandStats myRasterBandStats = getRasterBandStats(theBandNo);
|
||||
GDALRasterBand *myGdalBand = mGdalDataset->GetRasterBand(theBandNo);
|
||||
GDALDataType myDataType = myGdalBand->GetRasterDataType();
|
||||
GDALRasterBandH myGdalBand = GDALGetRasterBand(mGdalDataset,theBandNo);
|
||||
GDALDataType myDataType = GDALGetRasterDataType(myGdalBand);
|
||||
void *myGdalScanData = readData ( myGdalBand, theRasterViewPort );
|
||||
|
||||
/* Check for out of memory error */
|
||||
@ -1644,8 +1644,8 @@ void QgsRasterLayer::drawPalettedSingleBandColor(QPainter * theQPainter, QgsRast
|
||||
return;
|
||||
}
|
||||
|
||||
GDALRasterBand *myGdalBand = mGdalDataset->GetRasterBand(theBandNo);
|
||||
GDALDataType myDataType = myGdalBand->GetRasterDataType();
|
||||
GDALRasterBandH myGdalBand = GDALGetRasterBand(mGdalDataset,theBandNo);
|
||||
GDALDataType myDataType = GDALGetRasterDataType(myGdalBand);
|
||||
void *myGdalScanData = readData ( myGdalBand, theRasterViewPort );
|
||||
|
||||
/* Check for out of memory error */
|
||||
@ -1730,8 +1730,8 @@ void QgsRasterLayer::drawPalettedSingleBandGray(QPainter * theQPainter, QgsRaste
|
||||
}
|
||||
|
||||
QgsRasterBandStats myRasterBandStats = getRasterBandStats(theBandNo);
|
||||
GDALRasterBand *myGdalBand = mGdalDataset->GetRasterBand(theBandNo);
|
||||
GDALDataType myDataType = myGdalBand->GetRasterDataType();
|
||||
GDALRasterBandH myGdalBand = GDALGetRasterBand(mGdalDataset,theBandNo);
|
||||
GDALDataType myDataType = GDALGetRasterDataType(myGdalBand);
|
||||
void *myGdalScanData = readData ( myGdalBand, theRasterViewPort );
|
||||
|
||||
/* Check for out of memory error */
|
||||
@ -1829,8 +1829,8 @@ void QgsRasterLayer::drawPalettedSingleBandPseudoColor(QPainter * theQPainter, Q
|
||||
}
|
||||
|
||||
QgsRasterBandStats myRasterBandStats = getRasterBandStats(theBandNo);
|
||||
GDALRasterBand *myGdalBand = mGdalDataset->GetRasterBand(theBandNo);
|
||||
GDALDataType myDataType = myGdalBand->GetRasterDataType();
|
||||
GDALRasterBandH myGdalBand = GDALGetRasterBand(mGdalDataset,theBandNo);
|
||||
GDALDataType myDataType = GDALGetRasterDataType(myGdalBand);
|
||||
void *myGdalScanData = readData ( myGdalBand, theRasterViewPort );
|
||||
|
||||
/* Check for out of memory error */
|
||||
@ -1957,8 +1957,8 @@ void QgsRasterLayer::drawPalettedMultiBandColor(QPainter * theQPainter, QgsRaste
|
||||
return;
|
||||
}
|
||||
|
||||
GDALRasterBand *myGdalBand = mGdalDataset->GetRasterBand(theBandNo);
|
||||
GDALDataType myDataType = myGdalBand->GetRasterDataType();
|
||||
GDALRasterBandH myGdalBand = GDALGetRasterBand(mGdalDataset,theBandNo);
|
||||
GDALDataType myDataType = GDALGetRasterDataType(myGdalBand);
|
||||
void *myGdalScanData = readData ( myGdalBand, theRasterViewPort );
|
||||
|
||||
/* Check for out of memory error */
|
||||
@ -2094,13 +2094,13 @@ void QgsRasterLayer::drawMultiBandColor(QPainter * theQPainter, QgsRasterViewPor
|
||||
{
|
||||
return;
|
||||
}
|
||||
GDALRasterBand *myGdalRedBand = mGdalDataset->GetRasterBand(myRedBandNo);
|
||||
GDALRasterBand *myGdalGreenBand = mGdalDataset->GetRasterBand(myGreenBandNo);
|
||||
GDALRasterBand *myGdalBlueBand = mGdalDataset->GetRasterBand(myBlueBandNo);
|
||||
GDALRasterBandH myGdalRedBand = GDALGetRasterBand(mGdalDataset,myRedBandNo);
|
||||
GDALRasterBandH myGdalGreenBand = GDALGetRasterBand(mGdalDataset,myGreenBandNo);
|
||||
GDALRasterBandH myGdalBlueBand = GDALGetRasterBand(mGdalDataset,myBlueBandNo);
|
||||
|
||||
GDALDataType myRedType = myGdalRedBand->GetRasterDataType();
|
||||
GDALDataType myGreenType = myGdalGreenBand->GetRasterDataType();
|
||||
GDALDataType myBlueType = myGdalBlueBand->GetRasterDataType();
|
||||
GDALDataType myRedType = GDALGetRasterDataType(myGdalRedBand);
|
||||
GDALDataType myGreenType = GDALGetRasterDataType(myGdalGreenBand);
|
||||
GDALDataType myBlueType = GDALGetRasterDataType(myGdalBlueBand);
|
||||
|
||||
void *myGdalRedData = readData ( myGdalRedBand, theRasterViewPort );
|
||||
void *myGdalGreenData = readData ( myGdalGreenBand, theRasterViewPort );
|
||||
@ -2294,7 +2294,7 @@ const QgsRasterBandStats QgsRasterLayer::getRasterBandStats(QString const & theB
|
||||
|
||||
//we cant use a vector iterator because the iterator is astruct not a class
|
||||
//and the qvector model does not like this.
|
||||
for (int i = 1; i <= mGdalDataset->GetRasterCount(); i++)
|
||||
for (int i = 1; i <= GDALGetRasterCount(mGdalDataset); i++)
|
||||
{
|
||||
QgsRasterBandStats myRasterBandStats = getRasterBandStats(i);
|
||||
if (myRasterBandStats.bandName == theBandNameQString)
|
||||
@ -2395,7 +2395,7 @@ That this is a cpu intensive and slow task!
|
||||
const QgsRasterBandStats QgsRasterLayer::getRasterBandStats(int theBandNo)
|
||||
{
|
||||
// check if we have received a valid band number
|
||||
if ((mGdalDataset->GetRasterCount() < theBandNo) && rasterLayerType != PALETTE)
|
||||
if ((GDALGetRasterCount(mGdalDataset) < theBandNo) && rasterLayerType != PALETTE)
|
||||
{
|
||||
// invalid band id, return nothing
|
||||
QgsRasterBandStats myNullReturnStats;
|
||||
@ -2421,10 +2421,10 @@ const QgsRasterBandStats QgsRasterLayer::getRasterBandStats(int theBandNo)
|
||||
emit setStatus(QString("Retrieving stats for ")+name());
|
||||
qApp->processEvents();
|
||||
QgsDebugMsg("QgsRasterLayer::retrieve stats for band " + QString::number(theBandNo));
|
||||
GDALRasterBand *myGdalBand = mGdalDataset->GetRasterBand(theBandNo);
|
||||
GDALRasterBandH myGdalBand = GDALGetRasterBand(mGdalDataset,theBandNo);
|
||||
|
||||
|
||||
QString myColorerpretation = GDALGetColorInterpretationName(myGdalBand->GetColorInterpretation());
|
||||
QString myColorerpretation = GDALGetColorInterpretationName(GDALGetRasterColorInterpretation(myGdalBand));
|
||||
|
||||
//declare a colorTable to hold a palette - will only be used if the layer color interp is palette ???
|
||||
//get the palette colour table
|
||||
@ -2477,13 +2477,13 @@ const QgsRasterBandStats QgsRasterLayer::getRasterBandStats(int theBandNo)
|
||||
// let the user know we're going to possibly be taking a while
|
||||
//QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
||||
|
||||
GDALDataType myDataType = myGdalBand->GetRasterDataType();
|
||||
GDALDataType myDataType = GDALGetRasterDataType(myGdalBand);
|
||||
|
||||
int myNXBlocks, myNYBlocks, myXBlockSize, myYBlockSize;
|
||||
myGdalBand->GetBlockSize( &myXBlockSize, &myYBlockSize );
|
||||
GDALGetBlockSize( myGdalBand, &myXBlockSize, &myYBlockSize );
|
||||
|
||||
myNXBlocks = (myGdalBand->GetXSize() + myXBlockSize - 1) / myXBlockSize;
|
||||
myNYBlocks = (myGdalBand->GetYSize() + myYBlockSize - 1) / myYBlockSize;
|
||||
myNXBlocks = (GDALGetRasterXSize(myGdalBand) + myXBlockSize - 1) / myXBlockSize;
|
||||
myNYBlocks = (GDALGetRasterYSize(myGdalBand) + myYBlockSize - 1) / myYBlockSize;
|
||||
|
||||
void *myData = CPLMalloc ( myXBlockSize * myYBlockSize * GDALGetDataTypeSize(myDataType)/8 );
|
||||
|
||||
@ -2499,21 +2499,21 @@ const QgsRasterBandStats QgsRasterLayer::getRasterBandStats(int theBandNo)
|
||||
//ifdefs below to remove compiler warning about unused vars
|
||||
#ifdef QGISDEBUG
|
||||
int success;
|
||||
double GDALminimum = myGdalBand->GetMinimum( &success );
|
||||
double GDALminimum = GDALGetRasterMinimum( myGdalBand, &success );
|
||||
|
||||
if ( ! success )
|
||||
{
|
||||
QgsDebugMsg("myGdalBand->GetMinimum() failed");
|
||||
}
|
||||
|
||||
double GDALmaximum = myGdalBand->GetMaximum( &success );
|
||||
double GDALmaximum = GDALGetRasterMaximum( myGdalBand, &success );
|
||||
|
||||
if ( ! success )
|
||||
{
|
||||
QgsDebugMsg("myGdalBand->GetMaximum() failed");
|
||||
}
|
||||
|
||||
double GDALnodata = myGdalBand->GetNoDataValue( &success );
|
||||
double GDALnodata = GDALGetRasterNoDataValue( myGdalBand, &success );
|
||||
|
||||
if ( ! success )
|
||||
{
|
||||
@ -2538,8 +2538,8 @@ const QgsRasterBandStats QgsRasterLayer::getRasterBandStats(int theBandNo)
|
||||
QgsDebugMsg("starting manual stat computation");
|
||||
#endif
|
||||
|
||||
int myGdalBandXSize = myGdalBand->GetXSize();
|
||||
int myGdalBandYSize = myGdalBand->GetYSize();
|
||||
int myGdalBandXSize = GDALGetRasterXSize(myGdalBand);
|
||||
int myGdalBandYSize = GDALGetRasterYSize(myGdalBand);
|
||||
for( int iYBlock = 0; iYBlock < myNYBlocks; iYBlock++ )
|
||||
{
|
||||
emit drawingProgress ( iYBlock, myNYBlocks * 2 );
|
||||
@ -2547,7 +2547,7 @@ const QgsRasterBandStats QgsRasterLayer::getRasterBandStats(int theBandNo)
|
||||
for( int iXBlock = 0; iXBlock < myNXBlocks; iXBlock++ )
|
||||
{
|
||||
int nXValid, nYValid;
|
||||
myGdalBand->ReadBlock( iXBlock, iYBlock, myData );
|
||||
GDALReadBlock( myGdalBand, iXBlock, iYBlock, myData );
|
||||
|
||||
// Compute the portion of the block that is valid
|
||||
// for partial edge blocks.
|
||||
@ -2617,8 +2617,8 @@ const QgsRasterBandStats QgsRasterLayer::getRasterBandStats(int theBandNo)
|
||||
for( int iXBlock = 0; iXBlock < myNXBlocks; iXBlock++ )
|
||||
{
|
||||
int nXValid, nYValid;
|
||||
|
||||
myGdalBand->ReadBlock( iXBlock, iYBlock, myData );
|
||||
|
||||
GDALReadBlock( myGdalBand, iXBlock, iYBlock, myData );
|
||||
|
||||
// Compute the portion of the block that is valid
|
||||
// for partial edge blocks.
|
||||
@ -2926,8 +2926,8 @@ QPixmap QgsRasterLayer::getLegendQPixmap(bool theWithNameFlag)
|
||||
//
|
||||
// Get the adjusted matrix stats
|
||||
//
|
||||
GDALRasterBand *myGdalBand = mGdalDataset->GetRasterBand(1);
|
||||
QString myColorerpretation = GDALGetColorInterpretationName(myGdalBand->GetColorInterpretation());
|
||||
GDALRasterBandH myGdalBand = GDALGetRasterBand(mGdalDataset,1);
|
||||
QString myColorerpretation = GDALGetColorInterpretationName(GDALGetRasterColorInterpretation(myGdalBand));
|
||||
|
||||
|
||||
|
||||
@ -3178,8 +3178,8 @@ QPixmap QgsRasterLayer::getDetailedLegendQPixmap(int theLabelCount=3)
|
||||
//
|
||||
// Get the adjusted matrix stats
|
||||
//
|
||||
GDALRasterBand *myGdalBand = mGdalDataset->GetRasterBand(1);
|
||||
QString myColorerpretation = GDALGetColorInterpretationName(myGdalBand->GetColorInterpretation());
|
||||
GDALRasterBandH myGdalBand = GDALGetRasterBand(mGdalDataset,1);
|
||||
QString myColorerpretation = GDALGetColorInterpretationName(GDALGetRasterColorInterpretation(myGdalBand));
|
||||
QPixmap myLegendQPixmap; //will be initialised once we know what drawing style is active
|
||||
QPainter myQPainter;
|
||||
//
|
||||
@ -3502,9 +3502,9 @@ QString QgsRasterLayer::getMetadata()
|
||||
myMetadataQString += "<tr><td>";
|
||||
if (mProviderKey.isEmpty())
|
||||
{
|
||||
myMetadataQString += QString(mGdalDataset->GetDriver()->GetDescription());
|
||||
myMetadataQString += QString(GDALGetDescription(GDALGetDatasetDriver(mGdalDataset)));
|
||||
myMetadataQString += "<br>";
|
||||
myMetadataQString += QString(mGdalDataset->GetDriver()->GetMetadataItem(GDAL_DMD_LONGNAME));
|
||||
myMetadataQString += QString(GDALGetMetadataItem(GDALGetDatasetDriver(mGdalDataset),GDAL_DMD_LONGNAME,NULL));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -3526,11 +3526,11 @@ QString QgsRasterLayer::getMetadata()
|
||||
myMetadataQString += tr("Dataset Description");
|
||||
myMetadataQString += "</td></tr>";
|
||||
myMetadataQString += "<tr><td>";
|
||||
myMetadataQString += QFile::decodeName(mGdalDataset->GetDescription());
|
||||
myMetadataQString += QFile::decodeName(GDALGetDescription(mGdalDataset));
|
||||
myMetadataQString += "</td></tr>";
|
||||
|
||||
|
||||
char ** GDALmetadata = mGdalDataset->GetMetadata();
|
||||
char ** GDALmetadata = GDALGetMetadata(mGdalDataset,NULL);
|
||||
|
||||
if ( GDALmetadata )
|
||||
{
|
||||
@ -3542,9 +3542,10 @@ QString QgsRasterLayer::getMetadata()
|
||||
QgsDebugMsg("dataset has no metadata");
|
||||
}
|
||||
|
||||
for ( int i = 1; i <= mGdalDataset->GetRasterCount(); ++i )
|
||||
for ( int i = 1; i <= GDALGetRasterCount(mGdalDataset); ++i )
|
||||
{
|
||||
mGdalDataset->GetRasterBand(i)->GetMetadata();
|
||||
GDALRasterBandH gdalBand = GDALGetRasterBand(mGdalDataset,i);
|
||||
GDALmetadata = GDALGetMetadata(gdalBand,NULL);
|
||||
|
||||
if ( GDALmetadata )
|
||||
{
|
||||
@ -3556,7 +3557,7 @@ QString QgsRasterLayer::getMetadata()
|
||||
QgsDebugMsg("band " + QString::number(i) + "has no metadata");
|
||||
}
|
||||
|
||||
char ** GDALcategories = mGdalDataset->GetRasterBand(i)->GetCategoryNames();
|
||||
char ** GDALcategories = GDALGetRasterCategoryNames(gdalBand);
|
||||
|
||||
if ( GDALcategories )
|
||||
{
|
||||
@ -3576,12 +3577,12 @@ QString QgsRasterLayer::getMetadata()
|
||||
myMetadataQString += tr("Dimensions:");
|
||||
myMetadataQString += "</td></tr>";
|
||||
myMetadataQString += "<tr><td>";
|
||||
myMetadataQString += tr("X: ") + QString::number(mGdalDataset->GetRasterXSize()) +
|
||||
tr(" Y: ") + QString::number(mGdalDataset->GetRasterYSize()) + tr(" Bands: ") + QString::number(mGdalDataset->GetRasterCount());
|
||||
myMetadataQString += tr("X: ") + QString::number(GDALGetRasterXSize(mGdalDataset)) +
|
||||
tr(" Y: ") + QString::number(GDALGetRasterYSize(mGdalDataset)) + tr(" Bands: ") + QString::number(GDALGetRasterCount(mGdalDataset));
|
||||
myMetadataQString += "</td></tr>";
|
||||
|
||||
//just use the first band
|
||||
GDALRasterBand *myGdalBand = mGdalDataset->GetRasterBand(1);
|
||||
GDALRasterBandH myGdalBand = GDALGetRasterBand(mGdalDataset,1);
|
||||
|
||||
myMetadataQString += "<tr><td class=\"glossy\">";
|
||||
myMetadataQString += tr("No Data Value");
|
||||
@ -3602,7 +3603,7 @@ QString QgsRasterLayer::getMetadata()
|
||||
myMetadataQString += tr("Data Type:");
|
||||
myMetadataQString += "</td></tr>";
|
||||
myMetadataQString += "<tr><td>";
|
||||
switch (myGdalBand->GetRasterDataType())
|
||||
switch (GDALGetRasterDataType(myGdalBand))
|
||||
{
|
||||
case GDT_Byte:
|
||||
myMetadataQString += tr("GDT_Byte - Eight bit unsigned integer");
|
||||
@ -3683,7 +3684,7 @@ QString QgsRasterLayer::getMetadata()
|
||||
|
||||
if (mProviderKey.isEmpty())
|
||||
{
|
||||
if (mGdalDataset->GetGeoTransform(mGeoTransform) != CE_None)
|
||||
if (GDALGetGeoTransform(mGdalDataset,mGeoTransform) != CE_None)
|
||||
{
|
||||
// if the raster does not have a valid transform we need to use
|
||||
// a pixel size of (1,-1), but GDAL returns (1,1)
|
||||
@ -3858,14 +3859,14 @@ QString QgsRasterLayer::buildPyramids(RasterPyramidList const & theRasterPyramid
|
||||
registerGdalDrivers();
|
||||
|
||||
//close the gdal dataset and reopen it in read / write mode
|
||||
delete mGdalDataset;
|
||||
mGdalDataset = (GDALDataset *) GDALOpen(QFile::encodeName(mDataSource).constData(), GA_Update);
|
||||
GDALClose( mGdalDataset );
|
||||
mGdalDataset = GDALOpen(QFile::encodeName(mDataSource).constData(), GA_Update);
|
||||
|
||||
// if the dataset couldn't be opened in read / write mode, tell the user
|
||||
if (!mGdalDataset)
|
||||
{
|
||||
emit drawingProgress(0,0);
|
||||
mGdalDataset = (GDALDataset *) GDALOpen(QFile::encodeName(mDataSource).constData(), GA_ReadOnly);
|
||||
mGdalDataset = GDALOpen(QFile::encodeName(mDataSource).constData(), GA_ReadOnly);
|
||||
return "ERROR_WRITE_FORMAT";
|
||||
}
|
||||
|
||||
@ -3912,26 +3913,26 @@ QString QgsRasterLayer::buildPyramids(RasterPyramidList const & theRasterPyramid
|
||||
//see ticket #284
|
||||
if(theResamplingMethod==tr("Average Magphase"))
|
||||
{
|
||||
myError = mGdalDataset->BuildOverviews( "MODE", 1, myOverviewLevelsArray, 0, NULL,
|
||||
myError = GDALBuildOverviews( mGdalDataset, "MODE", 1, myOverviewLevelsArray, 0, NULL,
|
||||
GDALDummyProgress, NULL );
|
||||
}
|
||||
else if(theResamplingMethod==tr("Average"))
|
||||
|
||||
{
|
||||
myError = mGdalDataset->BuildOverviews( "AVERAGE", 1, myOverviewLevelsArray, 0, NULL,
|
||||
myError = GDALBuildOverviews( mGdalDataset, "AVERAGE", 1, myOverviewLevelsArray, 0, NULL,
|
||||
GDALDummyProgress, NULL );
|
||||
}
|
||||
else // fall back to nearest neighbor
|
||||
{
|
||||
myError = mGdalDataset->BuildOverviews( "NEAREST", 1, myOverviewLevelsArray, 0, NULL,
|
||||
myError = GDALBuildOverviews( mGdalDataset, "NEAREST", 1, myOverviewLevelsArray, 0, NULL,
|
||||
GDALDummyProgress, NULL );
|
||||
}
|
||||
if (myError == CE_Failure || CPLGetLastErrorNo()==CPLE_NotSupported )
|
||||
{
|
||||
//something bad happenend
|
||||
//QString myString = QString (CPLGetLastError());
|
||||
delete mGdalDataset;
|
||||
mGdalDataset = (GDALDataset *) GDALOpen(QFile::encodeName(mDataSource).constData(), GA_ReadOnly);
|
||||
GDALClose( mGdalDataset );
|
||||
mGdalDataset = GDALOpen(QFile::encodeName(mDataSource).constData(), GA_ReadOnly);
|
||||
emit drawingProgress(0,0);
|
||||
return "FAILED_NOT_SUPPORTED";
|
||||
}
|
||||
@ -3947,8 +3948,8 @@ QString QgsRasterLayer::buildPyramids(RasterPyramidList const & theRasterPyramid
|
||||
}
|
||||
QgsDebugMsg("Pyramid overviews built");
|
||||
//close the gdal dataset and reopen it in read only mode
|
||||
delete mGdalDataset;
|
||||
mGdalDataset = (GDALDataset *) GDALOpen(QFile::encodeName(mDataSource).constData(), GA_ReadOnly);
|
||||
GDALClose( mGdalDataset );
|
||||
mGdalDataset = GDALOpen(QFile::encodeName(mDataSource).constData(), GA_ReadOnly);
|
||||
emit drawingProgress(0,0);
|
||||
return NULL; // returning null on success
|
||||
}
|
||||
@ -4043,12 +4044,12 @@ bool QgsRasterLayer::isEditable() const
|
||||
|
||||
|
||||
|
||||
void QgsRasterLayer::readColorTable ( GDALRasterBand *gdalBand, QgsColorTable *theColorTable )
|
||||
void QgsRasterLayer::readColorTable ( GDALRasterBandH gdalBand, QgsColorTable *theColorTable )
|
||||
{
|
||||
QgsDebugMsg("QgsRasterLayer::readColorTable()");
|
||||
|
||||
// First try to read color table from metadata
|
||||
char **metadata = gdalBand->GetMetadata();
|
||||
char **metadata = GDALGetMetadata(gdalBand,NULL);
|
||||
theColorTable->clear();
|
||||
bool found = false;
|
||||
while ( metadata && metadata[0] )
|
||||
@ -4079,15 +4080,15 @@ void QgsRasterLayer::readColorTable ( GDALRasterBand *gdalBand, QgsColorTable *t
|
||||
// If no color table was found, try to read it from GDALColorTable
|
||||
if ( !found )
|
||||
{
|
||||
GDALColorTable *gdalColorTable = gdalBand->GetColorTable();
|
||||
GDALColorTableH gdalColorTable = GDALGetRasterColorTable(gdalBand);
|
||||
|
||||
if ( gdalColorTable )
|
||||
{
|
||||
int count = gdalColorTable->GetColorEntryCount();
|
||||
int count = GDALGetColorEntryCount(gdalColorTable);
|
||||
|
||||
for ( int i = 0; i < count; i++ )
|
||||
{
|
||||
const GDALColorEntry *colorEntry = gdalColorTable->GetColorEntry ( i );
|
||||
const GDALColorEntry *colorEntry = GDALGetColorEntry(gdalColorTable,i);
|
||||
|
||||
if ( !colorEntry ) continue;
|
||||
|
||||
@ -4109,9 +4110,9 @@ QgsColorTable *QgsRasterLayer::colorTable ( int theBandNo )
|
||||
}
|
||||
|
||||
|
||||
void *QgsRasterLayer::readData ( GDALRasterBand *gdalBand, QgsRasterViewPort *viewPort )
|
||||
void *QgsRasterLayer::readData ( GDALRasterBandH gdalBand, QgsRasterViewPort *viewPort )
|
||||
{
|
||||
GDALDataType type = gdalBand->GetRasterDataType();
|
||||
GDALDataType type = GDALGetRasterDataType(gdalBand);
|
||||
int size = GDALGetDataTypeSize ( type ) / 8;
|
||||
|
||||
QgsDebugMsg("QgsRasterLayer::readData: calling RasterIO with " +\
|
||||
@ -4131,15 +4132,15 @@ void *QgsRasterLayer::readData ( GDALRasterBand *gdalBand, QgsRasterViewPort *vi
|
||||
}
|
||||
else
|
||||
{
|
||||
CPLErr myErr = gdalBand->RasterIO ( GF_Read,
|
||||
viewPort->rectXOffset,
|
||||
viewPort->rectYOffset,
|
||||
viewPort->clippedWidth,
|
||||
viewPort->clippedHeight,
|
||||
data,
|
||||
viewPort->drawableAreaXDim,
|
||||
viewPort->drawableAreaYDim,
|
||||
type, 0, 0 );
|
||||
CPLErr myErr = GDALRasterIO( gdalBand, GF_Read,
|
||||
viewPort->rectXOffset,
|
||||
viewPort->rectYOffset,
|
||||
viewPort->clippedWidth,
|
||||
viewPort->clippedHeight,
|
||||
data,
|
||||
viewPort->drawableAreaXDim,
|
||||
viewPort->drawableAreaYDim,
|
||||
type, 0, 0 );
|
||||
if (myErr != CPLE_None)
|
||||
{
|
||||
QgsLogger::warning("RaterIO error: " + QString(CPLGetLastErrorMsg()));
|
||||
@ -4793,7 +4794,7 @@ void QgsRasterLayer::identify(const QgsPoint& point, std::map<QString,QString>&
|
||||
if ( x < mLayerExtent.xMin() || x > mLayerExtent.xMax() || y < mLayerExtent.yMin() || y > mLayerExtent.yMax() )
|
||||
{
|
||||
// Outside the raster
|
||||
for ( int i = 1; i <= mGdalDataset->GetRasterCount(); i++ )
|
||||
for ( int i = 1; i <= GDALGetRasterCount(mGdalDataset); i++ )
|
||||
{
|
||||
results[tr("Band") + QString::number(i)] = tr("out of extent");
|
||||
}
|
||||
@ -4810,14 +4811,15 @@ void QgsRasterLayer::identify(const QgsPoint& point, std::map<QString,QString>&
|
||||
|
||||
QgsDebugMsg( "row = " + QString::number(row) + " col = " + QString::number(col));
|
||||
|
||||
for ( int i = 1; i <= mGdalDataset->GetRasterCount(); i++ )
|
||||
for ( int i = 1; i <= GDALGetRasterCount(mGdalDataset); i++ )
|
||||
{
|
||||
GDALRasterBand *gdalBand = mGdalDataset->GetRasterBand(i);
|
||||
GDALDataType type = gdalBand->GetRasterDataType();
|
||||
GDALRasterBandH gdalBand = GDALGetRasterBand(mGdalDataset,i);
|
||||
GDALDataType type = GDALGetRasterDataType(gdalBand);
|
||||
int size = GDALGetDataTypeSize ( type ) / 8;
|
||||
void *data = CPLMalloc ( size );
|
||||
|
||||
CPLErr err = gdalBand->RasterIO ( GF_Read, col, row, 1, 1, data, 1, 1, type, 0, 0 );
|
||||
CPLErr err = GDALRasterIO( gdalBand, GF_Read, col, row, 1, 1,
|
||||
data, 1, 1, type, 0, 0 );
|
||||
|
||||
if (err != CPLE_None)
|
||||
{
|
||||
@ -4861,7 +4863,7 @@ QString QgsRasterLayer::identifyAsText(const QgsPoint& point)
|
||||
void QgsRasterLayer::populateHistogram(int theBandNo, int theBinCount,bool theIgnoreOutOfRangeFlag,bool theHistogramEstimatedFlag)
|
||||
{
|
||||
|
||||
GDALRasterBand *myGdalBand = mGdalDataset->GetRasterBand(theBandNo);
|
||||
GDALRasterBandH myGdalBand = GDALGetRasterBand(mGdalDataset,theBandNo);
|
||||
QgsRasterBandStats myRasterBandStats = getRasterBandStats(theBandNo);
|
||||
//calculate the histogram for this band
|
||||
//we assume that it only needs to be calculated if the lenght of the histogram
|
||||
@ -4891,7 +4893,7 @@ void QgsRasterLayer::populateHistogram(int theBandNo, int theBinCount,bool theIg
|
||||
* )
|
||||
*/
|
||||
double myerval = (myRasterBandStats.maxVal-myRasterBandStats.minVal)/theBinCount;
|
||||
myGdalBand->GetHistogram( myRasterBandStats.minVal-0.1*myerval, myRasterBandStats.maxVal+0.1*myerval, theBinCount, myHistogramArray ,theIgnoreOutOfRangeFlag ,theHistogramEstimatedFlag , GDALDummyProgress, NULL );
|
||||
GDALGetRasterHistogram( myGdalBand, myRasterBandStats.minVal-0.1*myerval, myRasterBandStats.maxVal+0.1*myerval, theBinCount, myHistogramArray ,theIgnoreOutOfRangeFlag ,theHistogramEstimatedFlag , GDALDummyProgress, NULL );
|
||||
|
||||
for (int myBin = 0; myBin <theBinCount; myBin++)
|
||||
{
|
||||
|
@ -150,7 +150,9 @@
|
||||
* END
|
||||
*/
|
||||
|
||||
#include <gdal_priv.h>
|
||||
#define CPL_SUPRESS_CPLUSPLUS
|
||||
|
||||
#include <gdal.h>
|
||||
|
||||
//
|
||||
// Forward declarations
|
||||
@ -163,9 +165,6 @@ class QgsRasterLayerProperties;
|
||||
struct QgsRasterViewPort;
|
||||
class QImage;
|
||||
class QPixmap;
|
||||
|
||||
class GDALDataset;
|
||||
class GDALRasterBand;
|
||||
class QSlider;
|
||||
class QLibrary;
|
||||
|
||||
@ -316,10 +315,12 @@ public:
|
||||
void resetNoDataValue()
|
||||
{
|
||||
mNoDataValue = -9999;
|
||||
if(mGdalDataset != NULL && mGdalDataset->GetRasterCount() > 0)
|
||||
if(mGdalDataset != NULL && GDALGetRasterCount(mGdalDataset) > 0)
|
||||
{
|
||||
int myRequestValid;
|
||||
double myValue = mGdalDataset->GetRasterBand(1)->GetNoDataValue(&myRequestValid);
|
||||
double myValue = GDALGetRasterNoDataValue(
|
||||
GDALGetRasterBand( mGdalDataset, 1 ), &myRequestValid);
|
||||
|
||||
if(0 != myRequestValid)
|
||||
{
|
||||
setNoDataValue(myValue);
|
||||
@ -947,13 +948,13 @@ private:
|
||||
QgsMapToPixel * theQgsMapToPixel, QImage* theImage);
|
||||
|
||||
/** \brief Read color table from GDAL raster band */
|
||||
void readColorTable ( GDALRasterBand *gdalBand, QgsColorTable *theColorTable );
|
||||
void readColorTable ( GDALRasterBandH gdalBand, QgsColorTable *theColorTable );
|
||||
|
||||
/** \brief Allocate memory and load data to that allocated memory, data type is the same
|
||||
* as raster band. The memory must be released later!
|
||||
* \return pointer to the memory
|
||||
*/
|
||||
void *readData ( GDALRasterBand *gdalBand, QgsRasterViewPort *viewPort );
|
||||
void *readData ( GDALRasterBandH gdalBand, QgsRasterViewPort *viewPort );
|
||||
|
||||
/** \brief Read a raster value on given position from memory block created by readData()
|
||||
* \param index index in memory block
|
||||
@ -992,9 +993,9 @@ private:
|
||||
/** \brief Flag to indicate whether debug infor overlay should be rendered onto the raster. */
|
||||
bool mDebugOverlayFlag;
|
||||
/** \brief Pointer to the gdaldataset. */
|
||||
GDALDataset * mGdalBaseDataset;
|
||||
GDALDatasetH mGdalBaseDataset;
|
||||
/** \brief Pointer to the gdaldataset (possibly warped vrt). */
|
||||
GDALDataset * mGdalDataset;
|
||||
GDALDatasetH mGdalDataset;
|
||||
/** \brief Values for mapping pixel to world coordinates. Contents of
|
||||
* this array are the same as the gdal adfGeoTransform */
|
||||
double mGeoTransform[6];
|
||||
|
@ -19,9 +19,7 @@
|
||||
#include <cpl_conv.h>
|
||||
#include <cpl_string.h>
|
||||
#include <gdal.h>
|
||||
#include <gdal_priv.h>
|
||||
#include <gdalwarper.h>
|
||||
#include <gdal_frmts.h>
|
||||
|
||||
#include <QFile>
|
||||
|
||||
@ -32,12 +30,11 @@ void QgsImageWarper::warp(const QString& input, const QString& output,
|
||||
ResamplingMethod resampling, bool useZeroAsTrans, const QString& compression) {
|
||||
// Open input file
|
||||
GDALAllRegister();
|
||||
GDALDataset* hSrcDS = static_cast<GDALDataset*>(GDALOpen(QFile::encodeName(input).constData(),
|
||||
GA_ReadOnly));
|
||||
GDALDatasetH hSrcDS = GDALOpen(QFile::encodeName(input).constData(),GA_ReadOnly);
|
||||
// Setup warp options.
|
||||
GDALWarpOptions *psWarpOptions = GDALCreateWarpOptions();
|
||||
psWarpOptions->hSrcDS = hSrcDS;
|
||||
psWarpOptions->nBandCount = hSrcDS->GetRasterCount();
|
||||
psWarpOptions->nBandCount = GDALGetRasterCount(hSrcDS);
|
||||
psWarpOptions->panSrcBands =
|
||||
(int *) CPLMalloc(sizeof(int) * psWarpOptions->nBandCount);
|
||||
psWarpOptions->panDstBands =
|
||||
@ -52,8 +49,8 @@ void QgsImageWarper::warp(const QString& input, const QString& output,
|
||||
|
||||
// check the bounds for the warped raster
|
||||
// order: upper right, lower right, lower left (y points down)
|
||||
double x[] = { hSrcDS->GetRasterXSize(), hSrcDS->GetRasterXSize(), 0 };
|
||||
double y[] = { 0, hSrcDS->GetRasterYSize(), hSrcDS->GetRasterYSize() };
|
||||
double x[] = { GDALGetRasterXSize(hSrcDS), GDALGetRasterXSize(hSrcDS), 0 };
|
||||
double y[] = { 0, GDALGetRasterYSize(hSrcDS), GDALGetRasterYSize(hSrcDS) };
|
||||
int s[] = { 0, 0, 0 };
|
||||
TransformParameters tParam = { mAngle, 0, 0 };
|
||||
transform(&tParam, FALSE, 3, x, y, NULL, s);
|
||||
@ -73,32 +70,37 @@ void QgsImageWarper::warp(const QString& input, const QString& output,
|
||||
psWarpOptions->pTransformerArg = &tParam;
|
||||
|
||||
// create the output file
|
||||
GDALDriver* driver = static_cast<GDALDriver*>(GDALGetDriverByName("GTiff"));
|
||||
GDALDriverH driver = GDALGetDriverByName("GTiff");
|
||||
char **papszOptions = NULL;
|
||||
papszOptions = CSLSetNameValue(papszOptions, "INIT_DEST", "NO_DATA");
|
||||
papszOptions = CSLSetNameValue(papszOptions, "COMPRESS", compression);
|
||||
GDALDataset* hDstDS =
|
||||
driver->Create(QFile::encodeName(output).constData(), newXSize, newYSize,
|
||||
hSrcDS->GetRasterCount(),
|
||||
hSrcDS->GetRasterBand(1)->GetRasterDataType(),
|
||||
papszOptions);
|
||||
for (int i = 0; i < hSrcDS->GetRasterCount(); ++i)
|
||||
GDALDatasetH hDstDS =
|
||||
GDALCreate(driver,
|
||||
QFile::encodeName(output).constData(), newXSize, newYSize,
|
||||
GDALGetRasterCount(hSrcDS),
|
||||
GDALGetRasterDataType(GDALGetRasterBand(hSrcDS,1)),
|
||||
papszOptions );
|
||||
|
||||
for( int i = 0; i < GDALGetRasterCount(hSrcDS); ++i )
|
||||
{
|
||||
GDALRasterBandH hSrcBand = GDALGetRasterBand(hSrcDS,i+1);
|
||||
GDALRasterBandH hDstBand = GDALGetRasterBand(hDstDS,i+1);
|
||||
GDALColorTableH cTable = GDALGetRasterColorTable(hSrcDS);
|
||||
if (cTable)
|
||||
{
|
||||
GDALColorTable* cTable = hSrcDS->GetRasterBand(i+1)->GetColorTable();
|
||||
if (cTable)
|
||||
{
|
||||
hDstDS->GetRasterBand(i+1)->SetColorTable(cTable);
|
||||
}
|
||||
double noData = hSrcDS->GetRasterBand(i+1)->GetNoDataValue();
|
||||
if (noData == -1e10 && useZeroAsTrans)
|
||||
{
|
||||
hDstDS->GetRasterBand(i+1)->SetNoDataValue(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
hDstDS->GetRasterBand(i+1)->SetNoDataValue(noData);
|
||||
}
|
||||
GDALSetRasterColorTable(hDstDS,cTable);
|
||||
}
|
||||
|
||||
double noData = GDALGetRasterNoDataValue(hSrcBand,NULL);
|
||||
if (noData == -1e10 && useZeroAsTrans)
|
||||
{
|
||||
GDALSetRasterNoDataValue(hDstBand,0);
|
||||
}
|
||||
else
|
||||
{
|
||||
GDALSetRasterNoDataValue(hDstBand,noData);
|
||||
}
|
||||
}
|
||||
psWarpOptions->hDstDS = hDstDS;
|
||||
|
||||
// Initialize and execute the warp operation.
|
||||
@ -107,8 +109,9 @@ void QgsImageWarper::warp(const QString& input, const QString& output,
|
||||
oOperation.ChunkAndWarpImage(0, 0, GDALGetRasterXSize(hDstDS),
|
||||
GDALGetRasterYSize(hDstDS));
|
||||
GDALDestroyWarpOptions(psWarpOptions);
|
||||
delete hSrcDS;
|
||||
delete hDstDS;
|
||||
|
||||
GDALClose( hSrcDS );
|
||||
GDALClose( hDstDS );
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 @@ QgsShapeFile::QgsShapeFile(QString name, QString encoding){
|
||||
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(QString name, QString encoding){
|
||||
}
|
||||
|
||||
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 @@ bool QgsShapeFile::scanGeometries()
|
||||
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 @@ bool QgsShapeFile::scanGeometries()
|
||||
hasMoreDimensions = true;
|
||||
}
|
||||
|
||||
ogrLayer->ResetReading();
|
||||
OGR_L_ResetReading(ogrLayer);
|
||||
geom_type = geometries[currentType];
|
||||
if(multi && (geom_type.find("MULTI") == -1))
|
||||
{
|
||||
@ -151,14 +145,14 @@ QString QgsShapeFile::getFeatureClass(){
|
||||
// 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 @@ QString QgsShapeFile::getFeatureClass(){
|
||||
}
|
||||
}
|
||||
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 @@ bool QgsShapeFile::insertLayer(QString dbname, QString schema, QString geom_col,
|
||||
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 @@ bool QgsShapeFile::insertLayer(QString dbname, QString schema, QString geom_col,
|
||||
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 @@ bool QgsShapeFile::insertLayer(QString dbname, QString schema, QString geom_col,
|
||||
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 @@ bool QgsShapeFile::insertLayer(QString dbname, QString schema, QString geom_col,
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
@ -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 @@ class QgsShapeFile : public QObject
|
||||
|
||||
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
|
||||
|
@ -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 @@ int QgsMySQLProvider::capabilities() const
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,121 +0,0 @@
|
||||
/***************************************************************************
|
||||
qgsogrfactory.cpp
|
||||
--------------------------------------
|
||||
Date : Sun Sep 16 12:18:21 AKDT 2007
|
||||
Copyright : (C) 2004 Christoph Spoerri
|
||||
Email : <spoerri@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();
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
/***************************************************************************
|
||||
qgsogrfactory.h
|
||||
--------------------------------------
|
||||
Date : Sun Sep 16 12:18:58 AKDT 2007
|
||||
Copyright : (C) 2004 Christoph Spoerri
|
||||
Email : <spoerri@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"
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@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
|
File diff suppressed because it is too large
Load Diff
@ -30,12 +30,12 @@ email : sherman at mrcc.com
|
||||
|
||||
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
|
||||
@ -188,7 +188,7 @@ class QgsOgrProvider : public QgsVectorDataProvider
|
||||
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 @@ class QgsOgrProvider : public QgsVectorDataProvider
|
||||
|
||||
|
||||
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 @@ class QgsOgrProvider : public QgsVectorDataProvider
|
||||
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;
|
||||
|
||||
};
|
||||
|
@ -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 @@ class ProjectionCsHandlingTest : public CppUnit::TestCase {
|
||||
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 @@ class ProjectionCsHandlingTest : public CppUnit::TestCase {
|
||||
{
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user