mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-22 00:06:12 -05:00
minor updates
git-svn-id: http://svn.osgeo.org/qgis/trunk@31 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
8183abe60d
commit
022574f6a4
@ -1,11 +1,11 @@
|
||||
#include <qstring.h>
|
||||
#include <qrect.h>
|
||||
#include "qgsrect.h"
|
||||
#include <libpq++.h>
|
||||
#include <qmessagebox.h>
|
||||
#include "qgsdatabaselayer.h"
|
||||
|
||||
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
|
||||
// about it from the database
|
||||
dataSource = conninfo;
|
||||
@ -39,6 +39,7 @@ QgsDatabaseLayer::QgsDatabaseLayer(const char *conninfo, QString table) :
|
||||
QTextOStream(&xMsg) << "Set extents to: " << layerExtent.xMin() << ", " <<
|
||||
layerExtent.yMin() << " " << layerExtent.xMax() << ", " << layerExtent.yMax();
|
||||
qWarning(xMsg);
|
||||
|
||||
}else{
|
||||
QString msg = "Unable to access " + tableName;
|
||||
//QMessageBox::warning(this,"Connection Problem",msg);
|
||||
@ -53,17 +54,52 @@ QgsDatabaseLayer::QgsDatabaseLayer(const char *conninfo, QString table) :
|
||||
delete pd;
|
||||
}
|
||||
}
|
||||
QgsDatabaseLayer::~QgsDatabaseLayer(){
|
||||
}
|
||||
void QgsDatabaseLayer::calculateExtent(){
|
||||
}
|
||||
void QgsDatabaseLayer::draw(QPainter *p, QRect *viewExtent){
|
||||
// painter is active (begin has been called
|
||||
/* Steps to draw the layer
|
||||
1. get the features in the view extent by SQL query
|
||||
2. read WKB for a feature
|
||||
3. transform
|
||||
4. draw
|
||||
*/
|
||||
QgsDatabaseLayer::~QgsDatabaseLayer(){
|
||||
}
|
||||
QgsRect QgsDatabaseLayer::calculateExtent(){
|
||||
return layerExtent;
|
||||
}
|
||||
void QgsDatabaseLayer::draw(QPainter *p, QgsRect *viewExtent){
|
||||
// painter is active (begin has been called
|
||||
/* Steps to draw the layer
|
||||
1. get the features in the view extent by SQL query
|
||||
2. read WKB for a feature
|
||||
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");
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
#ifndef QGSDATABASELAYER_H
|
||||
#define QGSDATABASELAYER_H
|
||||
class QString;
|
||||
class QgsRect;
|
||||
|
||||
#include "qgsmaplayer.h"
|
||||
|
||||
@ -37,10 +38,10 @@ class QgsDatabaseLayer : public QgsMapLayer {
|
||||
QgsDatabaseLayer(const char *conninfo=0, QString table=QString::null);
|
||||
//! Destructor
|
||||
~QgsDatabaseLayer();
|
||||
void draw(QPainter *p, QRect *viewExtent=0);
|
||||
void draw(QPainter *p, QgsRect *viewExtent=0);
|
||||
private:
|
||||
//! 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
|
||||
QString type;
|
||||
//! WKB type
|
||||
@ -60,7 +61,13 @@ class QgsDatabaseLayer : public QgsMapLayer {
|
||||
WKBMultiLineString,
|
||||
WKBMultiPolygon
|
||||
};
|
||||
|
||||
enum ENDIAN{
|
||||
NDR,
|
||||
XDR
|
||||
};
|
||||
// Returns the endian type for the client
|
||||
int endian();
|
||||
QString endianString();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -37,7 +37,7 @@ void QgsMapLayer::setlayerName( const QString& _newVal){
|
||||
const QString QgsMapLayer::name(){
|
||||
return layerName;
|
||||
}
|
||||
void QgsMapLayer::calculateExtent(){
|
||||
QgsRect QgsMapLayer::calculateExtent(){
|
||||
}
|
||||
void QgsMapLayer::draw(QPainter *, QRect *){
|
||||
void QgsMapLayer::draw(QPainter *, QgsRect *){
|
||||
}
|
||||
|
@ -54,8 +54,8 @@ class QgsMapLayer : public QgsDataSource {
|
||||
* This function must be overridden in all child classes and implemented
|
||||
* based on the layer type
|
||||
*/
|
||||
virtual void calculateExtent();
|
||||
virtual void draw(QPainter *, QRect * = 0);
|
||||
virtual QgsRect calculateExtent();
|
||||
virtual void draw(QPainter *, QgsRect * = 0);
|
||||
/*! Return the extent of the layer as a QRect
|
||||
*/
|
||||
const QgsRect extent();
|
||||
|
@ -16,16 +16,16 @@ void QgsRect::setYmin(double y){
|
||||
void QgsRect::setYmax(double y){
|
||||
ymax = y;
|
||||
}
|
||||
double QgsRect::xMax(){
|
||||
double QgsRect::xMax() const {
|
||||
return xmax;
|
||||
}
|
||||
double QgsRect::xMin(){
|
||||
double QgsRect::xMin() const {
|
||||
return xmin;
|
||||
}
|
||||
double QgsRect::yMax(){
|
||||
double QgsRect::yMax() const {
|
||||
return ymax;
|
||||
}
|
||||
double QgsRect::yMin(){
|
||||
double QgsRect::yMin() const {
|
||||
return ymin;
|
||||
}
|
||||
void QgsRect::normalize(){
|
||||
@ -41,3 +41,20 @@ void QgsRect::normalize(){
|
||||
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;
|
||||
|
||||
|
||||
}
|
||||
|
@ -16,20 +16,28 @@ class QgsRect{
|
||||
void setXmin(double x);
|
||||
//! Set the maximum x value
|
||||
void setXmax(double x);
|
||||
//! Set the maximum y value
|
||||
//! Set the maximum y value
|
||||
void setYmin(double y);
|
||||
//! Set the maximum y value
|
||||
//! Set the maximum y value
|
||||
void setYmax(double y);
|
||||
//! Get the x maximum value (right side of rectangle)
|
||||
double xMax();
|
||||
//! Get the x maximum value (right side of rectangle)
|
||||
double xMin();
|
||||
//! Get the x minimum value (left side of rectangle)
|
||||
double yMax();
|
||||
//! Get the y maximum value (top side of rectangle)
|
||||
double yMin();
|
||||
//! Normalize the rectangle so it has non-negative width/height
|
||||
double xMax() const;
|
||||
//! Get the x maximum value (right side of rectangle)
|
||||
double xMin() const;
|
||||
//! Get the x minimum value (left side of rectangle)
|
||||
double yMax() const;
|
||||
//! Get the y maximum value (top side of rectangle)
|
||||
double yMin() const;
|
||||
//! Normalize the rectangle so it has non-negative width/height
|
||||
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:
|
||||
double xmax;
|
||||
double xmin;
|
||||
|
Loading…
x
Reference in New Issue
Block a user