Skip to content

Commit

Permalink
Insert 0 for missing geometries in postgres provider. Plus little per…
Browse files Browse the repository at this point in the history
…formance enhancement by avoiding unnecessary copies

git-svn-id: http://svn.osgeo.org/qgis/trunk@8101 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Feb 4, 2008
1 parent 4e6a87d commit 88caf17
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,10 @@ bool QgsPostgresProvider::getNextFeature(QgsFeature& feature)

if (swapEndian)
oid = ntohl(oid); // convert oid to opposite endian


mFeatureQueue.push(QgsFeature());
// set ID
feature.setFeatureId(oid);
mFeatureQueue.back().setFeatureId(oid);

// fetch attributes
std::list<QString>::const_iterator name_it = mFetchAttributeNames.begin();
Expand All @@ -389,13 +390,13 @@ bool QgsPostgresProvider::getNextFeature(QgsFeature& feature)
switch (attributeFields[*index_it].type())
{
case QVariant::Int:
feature.addAttribute(*index_it, val.toInt());
mFeatureQueue.back().addAttribute(*index_it, val.toInt());
break;
case QVariant::Double:
feature.addAttribute(*index_it, val.toDouble());
mFeatureQueue.back().addAttribute(*index_it, val.toDouble());
break;
case QVariant::String:
feature.addAttribute(*index_it, val);
mFeatureQueue.back().addAttribute(*index_it, val);
break;
default:
assert(0 && "unsupported field type");
Expand All @@ -411,20 +412,14 @@ bool QgsPostgresProvider::getNextFeature(QgsFeature& feature)
unsigned char *featureGeom = new unsigned char[returnedLength + 1];
memset(featureGeom, '\0', returnedLength + 1);
memcpy(featureGeom, PQgetvalue(queryResult, row, PQfnumber(queryResult,"qgs_feature_geometry")), returnedLength);
feature.setGeometryAndOwnership(featureGeom, returnedLength + 1);
mFeatureQueue.back().setGeometryAndOwnership(featureGeom, returnedLength + 1);
}
else
{
mFeatureQueue.back().setGeometryAndOwnership(0, 0);
QgsDebugMsg("Couldn't get the feature geometry in binary form");
}
}

//don't copy the geometry. Just pass a pointer instead
mFeatureQueue.push(QgsFeature());
mFeatureQueue.back().setGeometry(feature.geometryAndOwnership());
mFeatureQueue.back().setFeatureId(feature.featureId());
mFeatureQueue.back().setAttributeMap(feature.attributeMap());

} // for each row in queue

PQclear(queryResult);
Expand All @@ -437,8 +432,15 @@ bool QgsPostgresProvider::getNextFeature(QgsFeature& feature)
} // if new queue is required

// Now return the next feature from the queue
//don't copy the geometry. Just pass a pointer instead
feature.setGeometry(mFeatureQueue.front().geometryAndOwnership());
if(mFetchGeom)
{
QgsGeometry* featureGeom = mFeatureQueue.front().geometryAndOwnership();
feature.setGeometryAndOwnership(featureGeom->wkbBuffer(), featureGeom->wkbSize());
}
else
{
feature.setGeometryAndOwnership(0, 0);
}
feature.setFeatureId(mFeatureQueue.front().featureId());
feature.setAttributeMap(mFeatureQueue.front().attributeMap());

Expand Down

0 comments on commit 88caf17

Please sign in to comment.