I am using Gdal Node.js interface to read features of a layer from a Esri Geodatabase. My javascript code looks like this:

var dataset = gdal.open(inputPath);
var layer = dataset.layers.get(layerName);
layer.features.forEach(function (feature, featureId) {
    var geom;
    var recordId = null;
    var routeId = null;
    try {
        var geomWKB = feature.getGeometry().toWKB();
        var geomWKBString = geomWKB.toString("hex");
        geom = geomWKBString;
        if (recordColumn) {
            let names = feature.fields.getNames();
            recordId = feature.fields.get(recordColumn);
       if (routeIdColumn) {
           routeId = feature.fields.get(routeIdColumn);
    catch (err) {

This layer has 12 fields. However, gdal only gets 11 fields missing OBJECTID when extract fields of a feature. Therefore recordId = feature.fields.get('OBJECTID') does not work.

I inspected the layer and noticed OBJECTID was assigned to FIDColumn, which means gdal can access to OBJECTID field but doesn't add it to features' schema.

What could cause the issue?

  • I guess that OBJECTID is a fid field that is not exposed as a normal attribute. GetFID seems to be for reading it gdal.org/classOGRFeature.html#a696f6e0c7f9a7025020b8ecf71cbd7a8. I thing I would try to use SQL in ExecuteSQL gdal.org/python/osgeo.ogr.DataSource-class.html#ExecuteSQL for reading the features, something like select geometry, OBJECTID as id_attribute, attr_1, attr_2 from my_layer – user30184 May 21 '18 at 20:37
  • @user30184 Thank you for the response. The problem is that my code used to be working for exactly same scenario last week. I have to make sure gdal providing consistent output. Hope we can get some solid source regarding how gdal handle 'OBJECTID'. The reason I don't use query is that I don't know how many fields there will be. Therefore I have to make the process dynamic and flexible. – zhangjinzhou May 21 '18 at 22:41
  • There was a change recently that changed the default or "preserve_fid" to "yes" in ogr2ogr. This may be related. Search an option that forces GDAL to create a new fid and have a try. – user30184 May 22 '18 at 5:10
  • Probably this is the reason. Do you know how to add this option when using node-gdal? I am new to this library and have never added any option. – zhangjinzhou May 22 '18 at 16:51
  • How about checking the fid column with layer.GetFIDColumn gdal.org/classOGRLayer.html#af0cb9a05310d7b17d9dfec9e83a18e61 and then using SQL as select *, my_fid_column as fid_attribute? In your case select *, OBJECTID should work because I guess that geodatabase has always the same name for fid. – user30184 May 22 '18 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.