minor updates

git-svn-id: http://svn.osgeo.org/qgis/trunk@31 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
gsherman 2002-07-16 04:55:37 +00:00
parent 8183abe60d
commit 022574f6a4
6 changed files with 104 additions and 36 deletions

View File

@ -1,11 +1,11 @@
#include <qstring.h> #include <qstring.h>
#include <qrect.h> #include "qgsrect.h"
#include <libpq++.h> #include <libpq++.h>
#include <qmessagebox.h> #include <qmessagebox.h>
#include "qgsdatabaselayer.h" #include "qgsdatabaselayer.h"
QgsDatabaseLayer::QgsDatabaseLayer(const char *conninfo, QString table) : QgsDatabaseLayer::QgsDatabaseLayer(const char *conninfo, QString table) :
QgsMapLayer(QgsMapLayer::DATABASE, table), tableName(table){ QgsMapLayer(QgsMapLayer::DATABASE, table),tableName(table){
// create the database layer and get the needed information // create the database layer and get the needed information
// about it from the database // about it from the database
dataSource = conninfo; dataSource = conninfo;
@ -39,6 +39,7 @@ QgsDatabaseLayer::QgsDatabaseLayer(const char *conninfo, QString table) :
QTextOStream(&xMsg) << "Set extents to: " << layerExtent.xMin() << ", " << QTextOStream(&xMsg) << "Set extents to: " << layerExtent.xMin() << ", " <<
layerExtent.yMin() << " " << layerExtent.xMax() << ", " << layerExtent.yMax(); layerExtent.yMin() << " " << layerExtent.xMax() << ", " << layerExtent.yMax();
qWarning(xMsg); qWarning(xMsg);
}else{ }else{
QString msg = "Unable to access " + tableName; QString msg = "Unable to access " + tableName;
//QMessageBox::warning(this,"Connection Problem",msg); //QMessageBox::warning(this,"Connection Problem",msg);
@ -53,17 +54,52 @@ QgsDatabaseLayer::QgsDatabaseLayer(const char *conninfo, QString table) :
delete pd; delete pd;
} }
} }
QgsDatabaseLayer::~QgsDatabaseLayer(){ QgsDatabaseLayer::~QgsDatabaseLayer(){
} }
void QgsDatabaseLayer::calculateExtent(){ QgsRect QgsDatabaseLayer::calculateExtent(){
} return layerExtent;
void QgsDatabaseLayer::draw(QPainter *p, QRect *viewExtent){ }
// painter is active (begin has been called void QgsDatabaseLayer::draw(QPainter *p, QgsRect *viewExtent){
/* Steps to draw the layer // painter is active (begin has been called
1. get the features in the view extent by SQL query /* Steps to draw the layer
2. read WKB for a feature 1. get the features in the view extent by SQL query
3. transform 2. read WKB for a feature
4. draw 3. transform
*/ 4. draw
*/
PgCursor pgs(dataSource, "drawCursor");
QString sql = "select asbinary(" + geometryColumn + ",'" + endianString() +
"') as features from " + tableName + " where " + geometryColumn +
" && GeometryFromText('BOX3D(" + viewExtent->xMin() + " " + viewExtent->yMin()
+ "," + viewExtent->xMax() + " " + viewExtent->yMax() + ")'::box3d,-1)";
pgs.Declare((const char *)sql, true);
int res = pgs.Fetch();
cout << "Number of matching records: " << pgs.Tuples() << endl;
for (int idx = 0; idx < pgs.Tuples (); idx++)
{
// read each feature based on its type
}
}
}
int QgsDatabaseLayer::endian(){
char *chkEndian = new char[4];
memset (chkEndian, '\0', 4);
chkEndian[0] = 0xE8;
int *ce = (int *) chkEndian;
if(232 == *ce)
return NDR;
else
return XDR;
}
QString QgsDatabaseLayer::endianString(){
char *chkEndian = new char[4];
memset (chkEndian, '\0', 4);
chkEndian[0] = 0xE8;
int *ce = (int *) chkEndian;
if(232 == *ce)
return QString("NDR");
else
return QString("XDR");
}

View File

@ -18,6 +18,7 @@
#ifndef QGSDATABASELAYER_H #ifndef QGSDATABASELAYER_H
#define QGSDATABASELAYER_H #define QGSDATABASELAYER_H
class QString; class QString;
class QgsRect;
#include "qgsmaplayer.h" #include "qgsmaplayer.h"
@ -37,10 +38,10 @@ class QgsDatabaseLayer : public QgsMapLayer {
QgsDatabaseLayer(const char *conninfo=0, QString table=QString::null); QgsDatabaseLayer(const char *conninfo=0, QString table=QString::null);
//! Destructor //! Destructor
~QgsDatabaseLayer(); ~QgsDatabaseLayer();
void draw(QPainter *p, QRect *viewExtent=0); void draw(QPainter *p, QgsRect *viewExtent=0);
private: private:
//! Calculates extent of the layer using SQL and PostGIS functions //! Calculates extent of the layer using SQL and PostGIS functions
void calculateExtent(); QgsRect calculateExtent();
//! Type geometry contained in the layer. This corresponds to one of the OGIS Simple geometry types //! Type geometry contained in the layer. This corresponds to one of the OGIS Simple geometry types
QString type; QString type;
//! WKB type //! WKB type
@ -60,7 +61,13 @@ class QgsDatabaseLayer : public QgsMapLayer {
WKBMultiLineString, WKBMultiLineString,
WKBMultiPolygon WKBMultiPolygon
}; };
enum ENDIAN{
NDR,
XDR
};
// Returns the endian type for the client
int endian();
QString endianString();
}; };
#endif #endif

View File

@ -37,7 +37,7 @@ void QgsMapLayer::setlayerName( const QString& _newVal){
const QString QgsMapLayer::name(){ const QString QgsMapLayer::name(){
return layerName; return layerName;
} }
void QgsMapLayer::calculateExtent(){ QgsRect QgsMapLayer::calculateExtent(){
} }
void QgsMapLayer::draw(QPainter *, QRect *){ void QgsMapLayer::draw(QPainter *, QgsRect *){
} }

View File

@ -54,8 +54,8 @@ class QgsMapLayer : public QgsDataSource {
* This function must be overridden in all child classes and implemented * This function must be overridden in all child classes and implemented
* based on the layer type * based on the layer type
*/ */
virtual void calculateExtent(); virtual QgsRect calculateExtent();
virtual void draw(QPainter *, QRect * = 0); virtual void draw(QPainter *, QgsRect * = 0);
/*! Return the extent of the layer as a QRect /*! Return the extent of the layer as a QRect
*/ */
const QgsRect extent(); const QgsRect extent();

View File

@ -16,16 +16,16 @@ void QgsRect::setYmin(double y){
void QgsRect::setYmax(double y){ void QgsRect::setYmax(double y){
ymax = y; ymax = y;
} }
double QgsRect::xMax(){ double QgsRect::xMax() const {
return xmax; return xmax;
} }
double QgsRect::xMin(){ double QgsRect::xMin() const {
return xmin; return xmin;
} }
double QgsRect::yMax(){ double QgsRect::yMax() const {
return ymax; return ymax;
} }
double QgsRect::yMin(){ double QgsRect::yMin() const {
return ymin; return ymin;
} }
void QgsRect::normalize(){ void QgsRect::normalize(){
@ -41,3 +41,20 @@ void QgsRect::normalize(){
ymax = temp; ymax = temp;
} }
} }
bool QgsRect::operator==(const QgsRect &r1){
return (r1.xMax() == this->xMax() && r1.xMin() == this->xMin() &&
r1.yMax() == this->yMax() && r1.yMin() == this->yMin());
}
QgsRect & QgsRect::operator=(const QgsRect &r){
if(&r != this){
xmax = r.xMax();
xmin = r.xMin();
ymax = r.yMax();
ymin = r.yMin();
}
return *this;
}

View File

@ -16,20 +16,28 @@ class QgsRect{
void setXmin(double x); void setXmin(double x);
//! Set the maximum x value //! Set the maximum x value
void setXmax(double x); void setXmax(double x);
//! Set the maximum y value //! Set the maximum y value
void setYmin(double y); void setYmin(double y);
//! Set the maximum y value //! Set the maximum y value
void setYmax(double y); void setYmax(double y);
//! Get the x maximum value (right side of rectangle) //! Get the x maximum value (right side of rectangle)
double xMax(); double xMax() const;
//! Get the x maximum value (right side of rectangle) //! Get the x maximum value (right side of rectangle)
double xMin(); double xMin() const;
//! Get the x minimum value (left side of rectangle) //! Get the x minimum value (left side of rectangle)
double yMax(); double yMax() const;
//! Get the y maximum value (top side of rectangle) //! Get the y maximum value (top side of rectangle)
double yMin(); double yMin() const;
//! Normalize the rectangle so it has non-negative width/height //! Normalize the rectangle so it has non-negative width/height
void normalize(); void normalize();
/*! Comparison operator
@return True if rectangles are equal
*/
bool operator==(const QgsRect &r1);
/*! Assignment operator
* @param r1 QgsRect to assign from
*/
QgsRect & operator=(const QgsRect &r1);
private: private:
double xmax; double xmax;
double xmin; double xmin;