[Qgis-developer] updating vector attribute tables

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Fri May 16 03:51:52 EDT 2008


Jürgen E. Fischer wrote:
 > Hi Carson,
 >
 > On Thu, 15. May 2008 at 15:15:20 -0700, Carson Farmer wrote:
 >> Does anyone know of a way to force a vector layer to reload it's
 >> attribute table?
 >
 > calling the vector data providers reset() might help.
 >

  The reset() operation seems rather dependent on the underlying 
provider, and as such might not be specified too well.

  For Postgres, it claims:

void QgsPostgresProvider::reset  	(  	  	 )   	 [virtual]

Reset the layer - for a PostgreSQL layer, this means clearing the 
PQresult pointer, setting it to 0 and reloading the field list

  - which sounds like it will notice new attributes added to a layer,

And for delimited text layers it does:

Restart reading features from previous select operation

00481   // Reset feature id to 0
00482   mFid = 0;
00483   // Skip ahead one line since first record is always assumed to be
00484   // the header record
00485   mStream->seek(0);
00486   mStream->readLine();

  - which could end up getting confused if the file has changed, since 
the skipped over header record is now describing data with (say) extra 
attributes than the layer thinks are there.

   But for OGR layers reset() calls OGR_L_ResetReading(ogrLayer); which 
just resets the reading position without re-reading the attribute 
information.

   The only reliable way to reflect changes in a layer would seem to be 
to close it and open in again...

Barry


More information about the Qgis-developer mailing list