mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-22 00:06:12 -05:00
mods to support reading wkb
git-svn-id: http://svn.osgeo.org/qgis/trunk@17 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
7a4d54278d
commit
e8cff84809
@ -25,6 +25,9 @@
|
||||
#include <qlayout.h>
|
||||
#include <qwmatrix.h>
|
||||
#include <qfiledialog.h>
|
||||
#include <libpq++.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include "qgsmapcanvas.h"
|
||||
#include "qgsdbsourceselect.h"
|
||||
#include "qgisapp.h"
|
||||
@ -66,12 +69,12 @@ void QgisApp::addLayer(){
|
||||
QString connInfo = dbs->connInfo();
|
||||
// for each selected table, connect to the datbase, parse the WKT geometry,
|
||||
// and build a cavnasitem for it
|
||||
QStringList::Iterator it = tables.begin();
|
||||
while( it != tables.end() ) {
|
||||
QStringList::Iterator it = tables.begin();
|
||||
while( it != tables.end() ) {
|
||||
|
||||
|
||||
++it;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
|
||||
}
|
||||
// show the file dialog
|
||||
@ -100,4 +103,53 @@ void QgisApp::zoomOut()
|
||||
m.scale( 0.5, 0.5 );
|
||||
cv->setWorldMatrix( m );
|
||||
}
|
||||
void QgisApp::readWKB(const char *connInfo){
|
||||
PgCursor pgc(connInfo, "testcursor");
|
||||
// get "endianness"
|
||||
char *chkEndian = new char[4];
|
||||
memset(chkEndian,'\0',4);
|
||||
chkEndian[0] = 0xE8;
|
||||
int *ce = (int *)chkEndian;
|
||||
bool isNDR = (232 == *ce);
|
||||
/* if(*ce != 232)
|
||||
cout << "Big endian" << endl;
|
||||
else
|
||||
cout << "Little endian" << endl;
|
||||
*/
|
||||
string sql = "select asbinary(the_geom,";
|
||||
if(isNDR)
|
||||
sql += "'NDR'";
|
||||
else
|
||||
sql += "'XDR'";
|
||||
sql += ") as features from towns";
|
||||
cout << sql.c_str() << endl;
|
||||
pgc.Declare(sql.c_str(), true);
|
||||
int res = pgc.Fetch();
|
||||
cout << "Number of binary records: " << pgc.Tuples() << endl;
|
||||
|
||||
// process each record
|
||||
for(int idx = 0; idx < pgc.Tuples(); idx++){
|
||||
cout << "Size of this record: " << pgc.GetLength(idx,0) << endl;
|
||||
// allocate memory for the item
|
||||
char *feature = new char[pgc.GetLength(idx,0) +1];
|
||||
memset(feature,'\0',pgc.GetLength(idx,0) +1);
|
||||
memcpy(feature,pgc.GetValue(idx,0),pgc.GetLength(idx,0) );
|
||||
char endian;
|
||||
endian = *feature;
|
||||
int *geotype;
|
||||
geotype =(int *) (feature + 1);
|
||||
|
||||
|
||||
cout << "Endian is: " << (int)feature[0] << endl;
|
||||
cout << "Geometry type is: " << (int)feature[1] << endl;
|
||||
// print the x,y coordinates
|
||||
double *x = (double *)(feature+5);
|
||||
double *y = (double*)(feature+5 + sizeof(double));
|
||||
cout << "x,y: " << setprecision(16) << *x << ", " << *y << endl;
|
||||
// free it
|
||||
delete[] feature;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -35,6 +35,7 @@ public:
|
||||
void fileExit();
|
||||
void zoomOut();
|
||||
void zoomIn();
|
||||
void readWKB(const char *);
|
||||
private:
|
||||
QCanvasView *cv;
|
||||
QCanvas *canvas;
|
||||
|
@ -60,6 +60,7 @@ void QgsDbSourceSelect::dbConnect(){
|
||||
QString username = "user="+settings.readEntry(key+"/username");
|
||||
QString password = "password="+settings.readEntry(key+"/password");
|
||||
m_connInfo = host +" " + database + " " + username + " " + password;
|
||||
qDebug(m_connInfo);
|
||||
PgDatabase *pd = new PgDatabase((const char *)m_connInfo);
|
||||
cout << pd->ErrorMessage();
|
||||
if(pd->Status()==CONNECTION_OK){
|
||||
|
Loading…
x
Reference in New Issue
Block a user