mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
inserting files into db code
git-svn-id: http://svn.osgeo.org/qgis/trunk@353 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
19cb56cc08
commit
6c5601ade8
@ -113,6 +113,8 @@ const char * QgsShapeFile::getName(){
|
||||
}
|
||||
|
||||
bool QgsShapeFile::insertLayer(QString dbname, QString srid, PgDatabase * conn, QProgressDialog * pro, int tot=0){
|
||||
bool result = true;
|
||||
char * geo_temp;
|
||||
QString table(filename);
|
||||
table = table.section('/', -1);
|
||||
table = table.section('.', 0, 0);
|
||||
@ -121,17 +123,17 @@ bool QgsShapeFile::insertLayer(QString dbname, QString srid, PgDatabase * conn,
|
||||
query += QString(column_names[n]).lower() + " " + QString(column_types[n]) + ",";
|
||||
query += "the_geom geometry)";
|
||||
|
||||
//conn->ExecTuplesOk((const char *)query);
|
||||
conn->ExecTuplesOk((const char *)query);
|
||||
|
||||
query = QString("SELECT AddGeometryColumn(\'") + dbname + "\', \'" + table + "\', \'the_geom\', " + srid +
|
||||
query = "SELECT AddGeometryColumn(\'" + dbname + "\', \'" + table + "\', \'the_geom\', " + srid +
|
||||
", \'" + QString(geom_type) + "\', 2)";
|
||||
//conn->ExecTuplesOk((const char *)query);
|
||||
conn->ExecTuplesOk((const char *)query);
|
||||
|
||||
//adding the data into the table
|
||||
for(int m=0;OGRFeature *feat = ogrLayer->GetNextFeature(); m++){
|
||||
std::stringstream out;
|
||||
out << m;
|
||||
query = QString("INSERT INTO ")+table+QString("values( "+out.str());
|
||||
query = "INSERT INTO "+table+"values( "+out.str()+", ";
|
||||
OGRGeometry *geom = feat->GetGeometryRef();
|
||||
|
||||
int num = geom->WkbSize();
|
||||
@ -142,12 +144,12 @@ bool QgsShapeFile::insertLayer(QString dbname, QString srid, PgDatabase * conn,
|
||||
int numFields = feat->GetFieldCount();
|
||||
for(int n=0; n<numFields; n++)
|
||||
query += QString("\'")+QString(feat->GetFieldAsString(n))+QString("\', ");
|
||||
query += QString("GeometryFromText(\'")+QString(geom_type)+QString("(")+geometry+
|
||||
QString(")\', ")+srid+QString("))");
|
||||
query += QString("GeometryFromText(\'")+QString(geometry)+QString("\', ")+srid+QString("))");
|
||||
|
||||
conn->ExecTuplesOk((const char *)query);
|
||||
|
||||
std::cout << (const char *)query << std::endl;
|
||||
delete[] geo_temp;
|
||||
}
|
||||
|
||||
return true;
|
||||
return result;
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ void QgsSpit::import(){
|
||||
PgDatabase *pd = new PgDatabase((const char *) connInfo);
|
||||
|
||||
if (pd->Status() == CONNECTION_OK) {
|
||||
QProgressDialog * pro = new QProgressDialog("Importing files", "Cancel", 100, this, "Progress");
|
||||
QProgressDialog * pro = new QProgressDialog("Importing files", "Cancel", 10000, this, "Progress");
|
||||
pro->setAutoClose(true);
|
||||
pro->exec();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user