From e8cff8480904088153b512fe79e31c227b50f038 Mon Sep 17 00:00:00 2001 From: gsherman Date: Mon, 8 Jul 2002 03:20:50 +0000 Subject: [PATCH] mods to support reading wkb git-svn-id: http://svn.osgeo.org/qgis/trunk@17 c8812cc2-4d05-0410-92ff-de0c093fc19c --- src/qgisapp.cpp | 60 ++++++++++++++++++++++++++++++++++++--- src/qgisapp.h | 1 + src/qgsdbsourceselect.cpp | 1 + 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/qgisapp.cpp b/src/qgisapp.cpp index 7c752a34aa2..a1b777b8381 100644 --- a/src/qgisapp.cpp +++ b/src/qgisapp.cpp @@ -25,6 +25,9 @@ #include #include #include +#include +#include +#include #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; + } +} + + diff --git a/src/qgisapp.h b/src/qgisapp.h index 1814330bbe8..96b248a0731 100644 --- a/src/qgisapp.h +++ b/src/qgisapp.h @@ -35,6 +35,7 @@ public: void fileExit(); void zoomOut(); void zoomIn(); + void readWKB(const char *); private: QCanvasView *cv; QCanvas *canvas; diff --git a/src/qgsdbsourceselect.cpp b/src/qgsdbsourceselect.cpp index 49714cdee9a..4ba12119585 100644 --- a/src/qgsdbsourceselect.cpp +++ b/src/qgsdbsourceselect.cpp @@ -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){