USDAForestService / gdalraster

R Bindings to GDAL (Geospatial Data Abstraction Library)
https://usdaforestservice.github.io/gdalraster/
Other
41 stars 7 forks source link

`GDALVector`: remove the exposed field `$featureTemplate` as not needed / not useful (and fixing Valgrind errors) #520

Closed ctoney closed 3 weeks ago

ctoney commented 3 weeks ago

GDALVector::featureTemplate was exposed to R as a read-only field, containing a list object meant to be a template for a feature in the layer with field values initialized to NA. It turned out not to be very helpful for its intended purpose. It is redundant with simply reading a feature from the layer and examining its structure (with str()), or examining the structure of the feature class definition returned by the method getLayerDefn(). Also, the class method fetch() can be called with n = 0 to return a 0-row data frame that is fully typed.

The internal class method setFeatureTemplate_(), called in the constructor, assumed that the data frame returned by initDF_() was initialized to NA values. PR #516 changed the data frame creation to use Rcpp::no_init() for creation of the column vectors, for performance. This resulted in setFeatureTemplate_() causing "Conditional jump or move depends on uninitialised value(s)" reported by Valgrind.

Rather than fix setFeatureTemplate_() to handle the initialization, it is being removed instead, on the rationale that the featureTemplate field mainly adds clutter with minimal utility.

This PR also renames the method initDF_() to createDF_() to better reflect its purpose, and the fact that it no longer actually initializes (which is done in fetch(), now the only method that directly uses createDF_()).