Our application matches business keys against feature attributes: it reads the id and two
or three key columns of every feature in a layer, then fetches only the matching features by
id. QueryTools.GetAllFeatures(columnNames) always loads and converts geometry as well, and
geometry dominates that read for polygon layers. We now read keys ourselves: ShapeFileFeatureSource.GetDataFromDbf for shapefiles and ExecuteQuery with our own SELECT id, keys FROM table for SQL Server and PostgreSQL. To do that we had to reproduce
each source’s id and value formatting from its implementation. Requests:
Attribute-only reads. Could GetAllFeatures (and QueryTools) accept an option to
skip geometry, or could a method return only ids and the requested column values?
Native implementations seem straightforward: DBF only for shapefiles, no STAsBinary()/st_asbinary() for SQL Server/PostgreSQL, SetIgnoredFields("OGR_GEOMETRY")
for GDAL, and subfields without the shape field for FileGDB. The GetAllFeatures
documentation could also mention that geometry is always loaded.
GDAL ExecuteQuery omits the FID.GdalFeatureSource.ExecuteQuery copies only
attribute fields, so its rows cannot be related to GetAllFeatures ids (GetFID()). Its
typed values also differ from ParseOgrFeatureField; for example, a NULL integer becomes "0" through GetAllFeatures. Could the result include the FID and document its value
conversion?
FileGDB null geometry and geometry field name.FileGeoDatabaseFeatureSource's GetAllFeatures skips rows whose shape is NULL, but GetFeaturesByIds returns them. GeometryFieldName also stays null until the first feature query resolves it. Could GetFeaturesByIds apply the same filter and could Open resolve the geometry field?
Empty-geometry behaviour differs between sources. Shapefile GetAllFeatures and GetFeaturesByIds omit records without geometry, while GetFeatureIds without a FeatureIdColumn still lists them. SQL Server and PostgreSQL return such rows with empty
WKB. Could the intended behaviour be documented, ideally made consistent?
Identifier quoting.SqlServerFeatureSource writes [ + name + ] without doubling ], and leaves an unqualified table name unquoted. PostgreSqlFeatureSource writes " + name + " without doubling ". Names containing those characters produce invalid
SQL.
Change detection (lower priority). A cheap data version or last-modified value on
file-based sources would let applications cache indexes derived from attributes.
Thanks for the detail! We went through all six and here is where each one stands; everything below is in 15.0.0-beta207.
Attribute-only reads — recorded, not added yet. The requirement makes sense and we are discussing what the API should look like. We will keep you posted.
GDAL
NULL integer — fixed. ParseOgrFeatureField guarded only OFTReal against the ambiguity of GetFieldAs* returning 0 for both an unset field and a field set to 0, so a NULL integer reached GetAllFeatures as “0” while the typed path behind ExecuteQuery reported DBNull. The integer cases now carry the same guard: a NULL comes back as an empty value, and a field genuinely set to 0 still reads “0”.
ExecuteQuery and the FID — no change needed; name it in the statement. The FID is not part of a layer’s field definitions; OGR treats it as a property of the feature, and a wildcard does not expand to it. Naming it does: SELECT FID, * FROM your_layer. The result set then carries an FID column and ExecuteQuery returns it like any other field. With a driver that brings its own SQL dialect (GPKG/SQLite, PostgreSQL) you select that dialect’s own id column instead, for example SELECT rowid, * FROM …
Value conversion — documented. A feature from GetAllFeatures or GetFeaturesByIds carries its column values as strings, with an empty string for an unset or NULL field — except a date, which comes back as null; a row from ExecuteQuery carries typed values taken from the result set’s own field definitions, with DBNull. That and the FID are both on GdalFeatureSource now.
FileGDB
Null geometry — fixed. GetAllFeatures and GetFeaturesInsideBoundingBox skipped a row whose shape is NULL while GetFeaturesByIds and GetFeaturesByColumnValue returned it, so the same row was a feature or not depending on how you asked for it. Both now skip it. One difference worth knowing: they test for the shape field first, so a table that has none keeps its rows rather than coming back empty.
GeometryFieldName — not changed, and we would like your view. Resolving it during Open is what the code used to do; it was taken out because it throws for a geodatabase whose table has no geometry column. Resolving it again means deciding what Open should do in that case. If your tables always have a shape field, a GeometryFieldName populated after the first feature query is reachable; tell us what behaviour you would want for the other case and we will take it from there.
Empty-geometry behavior — Shapefile GetFeatureIds disagreeing with itself is the part we should fix, and it turns out to be cheap: the null-shape test comes from the SHX content length, which costs 8 bytes per record and never touches the SHP. We will align it. What we are not changing is the difference between the families — the file sources leaving such a record out while SQL Server and PostgreSQL return it carrying empty well-known binary — because dropping those rows would take away exactly the data an attribute-only read wants, and returning them from the file sources would change every drawing and query path. That difference stays documented.
Identifier quoting — fixed, with one part left alone. A quoted identifier now doubles its own closing quote: PostgreSqlFeatureSource doubles the double quote, and SqlServerFeatureSource doubles the closing bracket at every site that writes a bracketed name. An unqualified SQL Server table name is still written unquoted. Bracketing it would break the common TableName = “dbo.Parcels”, which works today only because the name is passed through as written. If you need a quoted schema-qualified name, set the two separately — SchemaName = “dbo” and TableName = “Parcels” — and both are bracketed.
Change detection — recorded, with a caveat about what is available. These formats carry no revision of their own and we will not add a field to a format we do not own, so anything we expose would be derived from the files: last write time and length. That is a hint rather than a version. It can say cheaply that something probably changed; it cannot promise that nothing did. If a conservative answer is usable for you, go ahead and add the check yourself; if you need certainty it means hashing the attribute file, which is no longer the cheap check you asked for.
Let me know if you have any questions, happy to go deeper on any of these.
Thank you for going through all six. We checked the beta207 assemblies: the GDAL NULL-integer
guard, the FileGDB NULL-shape filter in GetFeaturesByIds/GetFeaturesByColumnValue, and the
identifier quoting in both SQL sources are there. With those, we now read keys without geometry
from FileGDB and from single-layer GeoPackages (SELECT rowid, …) as well.
GeometryFieldName. We no longer need it: the NULL-shape fix removed our reason to filter
rows ourselves. If you revisit it, we would keep Open from throwing and resolve the name on
first access instead, returning an empty string for a table without a shape field, the same
test your readers already apply.
Two things we noticed while checking:
FileGDB tables without a shape field.GetFeaturesByIds and GetFeaturesByColumnValue
keep such a table’s rows, but GetAllFeatures still returns none: it only enumerates when
the shape field name is non-empty. So the same row is still a feature or not depending on
how it is requested.
GDAL GetFeaturesByIds ignores ActiveLayerName.GetAllFeatures reads only the
active layer when one is set, but GetFeaturesByIds looks up each id in every layer of LayerNames. FIDs are per layer, so one id can return features from several layers, and
an id read from one layer can fetch a different layer’s feature. GetFeaturesByColumnValue
inherits this: it finds ids in the active layer, then fetches them through GetFeaturesByIds. Could GetFeaturesByIds honour ActiveLayerName? Until then we keep
the full read for multi-layer files.
Attribute-only API. What we would use: the feature id plus the requested column values,
formatted exactly as GetAllFeatures formats them, without reading geometry, ideally as an
enumerable so large layers need not be materialized, and honouring ActiveLayerName.
Change detection. Understood; we will not cache on file timestamps.
Both of your findings are fixed, in 15.0.0-beta208.
GDAL GetFeaturesByIds and ActiveLayerName.GetFeaturesByIdsCore and GetAllFeaturesCore now take their layers from one place, so a read scoped to the active layer stays there and GetFeaturesByColumnValue is correct as a result. A test reproduces what you described — two layers sharing FID 0, active layer set — which returned two features before.
FileGDB tables without a shape field. Both GetAllFeatures overloads now make the same per-row test as GetFeaturesByIds, so such a table reads the same way however it is asked for. GetFeaturesInsideBoundingBox keeps the outer test on purpose, since a table with no shape field has nothing inside a box. This one has no test behind it: CreateTable always writes a shape field, so we cannot author such a table, and one made through FileGDB SQL is not readable through this path either. If you can share a small geodatabase carrying one of your attribute-only tables, we will pin it.
We also aligned GetFeatureIds, which we owed you: a row without geometry no longer gets an id reported, since those ids resolved to nothing.
GeometryFieldName. Recorded with the behaviour you described.
Attribute-only reads. Still being discussed, here are some concerns we have:
The enumerable. This is our real difficulty. Each source holds something for the length of a read — FileGDB and the shapefile take a lock, GDAL holds a layer handle, the SQL sources hold a reader — and a lazy sequence hands control back to you while that is held. A caller who stops early or keeps the enumerator would park a FileGDB lock, which blocks every other read on that source, and a sequence that spans a CommitTransaction has no defined answer. We are leaning towards an enumerable that pages underneath, so each actual read is a bounded call and nothing is held between pages. That means a page boundary is a point where a concurrent edit could make you miss or repeat a row.
The values. You asked for them formatted exactly as GetAllFeatures formats them, which means strings, and that is what we would ship. Worth saying why we are not offering typed values instead: each source already has both a string path and a typed one, they disagree — your item 2 was one instance of that — and a typed attribute read would mean first making the typed paths agree across every source.
The sources. We can implement the native path for shapefile, SQL Server, PostgreSQL, GDAL and FileGDB. The base class would still need a default for every other source, and the only honest default reads the geometry and discards it — correct everywhere, faster nowhere. So is it really good to provide a heavy default implementation?
We checked the installed beta208 assemblies: GDAL now reads the same layers for GetAllFeatures and GetFeaturesByIds, FileGDB applies one per-row geometry test, and
shapefile GetFeatureIds skips records without geometry. Our GeoPackage key read now follows ActiveLayerName the same way.
FileGDB sample. We have no attribute-only table to share - as this is a customer request to guard against it, not a scenario I ran into.
The enumerable. Paging underneath works for us, with one condition. We read a layer
once to build a key index, then fetch the matches by id. A row repeated at a page boundary is
harmless, because we collect ids in a set. A skipped row is not: with offset paging
(Skip(start).Take(count) over a fresh read, as the current paged GetAllFeatures does), a
concurrent delete in an earlier page shifts the next page and skips an unchanged row, and we
would fail to find that object. Could the pages continue after the last id read instead of at
an offset? A method returning a materialized collection, like GetAllFeatures, would also
serve us: it would hold only ids and a few short strings per feature.
The values. Strings formatted as GetAllFeatures formats them are what we need. We agree
that typed values would first require the typed paths to agree.
The default. We would keep the default that reads and discards geometry: callers get one
call path that is correct on every source. Please pair it with a capability check, in the
style of CanGetCountQuickly() and CanGetBoundingBoxQuickly(), so a caller can tell a native
implementation from the fallback, for example before deciding whether caching is worthwhile.
Everything from this thread, including the attribute-only read, is in 15.0.0-beta210 now.
// FeatureSource, and the same three on QueryTools
Collection<FeatureAttributes> GetAllFeatureAttributes(IEnumerable<string> returningColumnNames);
Collection<FeatureAttributes> GetAllFeatureAttributes(ReturningColumnsType returningColumnNamesType);
bool CanGetFeatureAttributesQuickly();
public class FeatureAttributes
{
public string Id { get; } // the id the feature reads report
public Dictionary<string, string> ColumnValues { get; } // formatted as GetAllFeatures formats them
}
Native on shapefile, GDAL, FileGDB, SQL Server and PostgreSQL: the DBF alone, OGR_GEOMETRY ignored, the shape field out of the subfields, and a select list without STAsBinary() / st_asbinary(). Other sources answer through the base implementation and report false. ActiveLayerName is honored.
Three things to know:
FeatureAttributes, not Feature. Every public read drops a feature without geometry, so a Feature from a read is expected to have one; answering with geometry-less Features would hand the layers, the edit tools and the spatial queries something that draws and intersects nothing. Id goes straight to GetFeaturesByIds. Same reason we did not add an option to GetAllFeatures.
A record with no geometry is reported here, unlike the feature reads, so its id will not resolve. Deliberate: with the GDAL geometry ignored we cannot know it is missing, and dropping those rows would remove them from your index silently, which is the failure you called fatal.
Materialized, not an enumerable.
Two more in beta210 that touch you:
Attribute values were formatted in the machine’s culture — 1,5 on a German desktop and 1.5 on an English one out of the same data. FileGDB, the GDAL date case, and SQL Server, PostgreSQL and SQLite through dataReader[i].ToString(). Invariant now. You match business keys against these values, so a non-English installation was silently costing you matches.
A correction to post 2: an unset or NULL field is an empty string for every type except a date, which comes back null. And the quoting fix covers the sites that quote the name; several identifiers in both SQL sources are still concatenated unquoted.
Sweet, thanks Ben! No more open points, we’re happy here, thanks for the info about the attribute value changes in beta210, we will write a workaround for that!