Problem Adding Features to Qt Local GDB - QML

2694
9
Jump to solution
08-30-2016 08:25 AM
Marco_AlejandroBonilla
Occasional Contributor

I'm having troubles adding features to a Local GDB in Qt. Following this code:

Geodatabase {

        id: gdb

        path: "Test/FS_SNM_ALS_LimpiezaSumideros.geodatabase"        onValidChanged: {

            if (valid) {

                var gdbtables = gdb.geodatabaseFeatureTables;

                for(var i in gdbtables) {

                    console.log (gdbtables.featureServiceLayerName);

                }

            }

        }

    }

FeatureLayer {

                id: featureLayer

                featureTable: gdb.geodatabaseFeatureTableByLayerId(0)

}

function addFeature(mapPoint) {

            console.log("x", mapPoint.x);

            var featureJson = {

                geometry: {

                    x: mapPoint.x,

                    y: mapPoint.y,

                    spatialReference: mapPoint.spatialReference

                },

                attributes: {

                              <attributes>                        

                             }

                }

if (featureLayer.featureTable.featureTableStatus === Enums.FeatureTableStatusInitialized) {

featureLayer.featureTable.addFeature(featureJson);

                }

}

When running the code, it seems like the feature was added, but it can't be queried or be seen on the map

Any comment is helpful! Thank you!

cc: jumypansas

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
LucasDanzinger
Esri Frequent Contributor

Is it related to spatial reference perhaps? What spatial reference is your map and your geodatabase, and where on the earth are you adding your new feature?

View solution in original post

9 Replies
LucasDanzinger
Esri Frequent Contributor

What does addFeature return? If -1, then there was an error adding it. Otherwise, it will return the new object id - ArcGIS Runtime SDK for Qt QML API: FeatureTable Class Reference 

A common issue is not matching the required schema of the table you are trying to add to.

0 Kudos
Marco_AlejandroBonilla
Occasional Contributor

Lucas,

Thanks for your help

In deed the function response is -1. Actually, we're giving these attributes:

var featureJson = {

                geometry: {

                    x: mapPoint.x,

                    y: mapPoint.y,

                    spatialReference: mapPoint.spatialReference

                },

                attributes: {

                    IDInstalacion: "1111111",

                    TipoSumidero: "CAL",

                    Largo: 1,

                    Ancho: 1,

                    MaterialTaza: "HSI",

                    MaterialAccesorio: "OTR"

                }

            }

To these schema:

Fields:

  • OBJECTID ( type: esriFieldTypeOID , alias: OBJECTID , editable: false , nullable: false )
  • IDInstalacion ( type: esriFieldTypeString , alias: ID Instalación , editable: true , nullable: true , length: 20 )
  • TipoSumidero ( type: esriFieldTypeString , alias: Tipo Sumidero , editable: true , nullable: true , length: 3 , Coded Values: [CAL: Calzada] , [LON: LonguitudinalA] , [LN2: LonguitudinalB] , ...4 more... )
  • Largo ( type: esriFieldTypeDouble , alias: Largo Total (m) , editable: true , nullable: true )
  • Ancho ( type: esriFieldTypeDouble , alias: Ancho (m) , editable: true , nullable: true )
  • MaterialTaza ( type: esriFieldTypeString , alias: Material Taza , editable: true , nullable: true , length: 50 , Coded Values: [HSI: Hormigón Simple] , [HAR: Hormigón Armado] , [HND: Hormigón No Definido] , ...1 more... )
  • MaterialAccesorio ( type: esriFieldTypeString , alias: Material Accesorio , editable: true , nullable: true , length: 50 , Coded Values: [OTR: Otro] , [HFU: Hierro Fundido] , [HAC: Hormigón Acrílico] , ...3 more... )
  • created_user ( type: esriFieldTypeString , alias: created_user , editable: false , nullable: true , length: 255 )
  • created_date ( type: esriFieldTypeDate , alias: created_date , editable: false , nullable: true , length: 36 )
  • last_edited_user ( type: esriFieldTypeString , alias: last_edited_user , editable: false , nullable: true , length: 255 )
  • last_edited_date ( type: esriFieldTypeDate , alias: last_edited_date , editable: false , nullable: true , length: 36 )
  • GlobalID ( type: esriFieldTypeGlobalID , alias: GlobalID , editable: false , nullable: false , length: 38 )
  • FechaLimpieza ( type: esriFieldTypeDate , alias: FechaLimpieza , editable: true , nullable: true , length: 36 )

Is a weird thing cause when adding features directly to the feature service (URL) it works just fine.

The problem arises when adding features to a local GDB

0 Kudos
LucasDanzinger
Esri Frequent Contributor

Can you connect to the error signal, and see if you get any indication of what the problem is? - ArcGIS Runtime SDK for Qt QML API: RuntimeObject Class Reference 

Something like the following might do:

featureLayer.featureTable.error.connect(function(error) {
    console.log(error.description);
});
0 Kudos
Marco_AlejandroBonilla
Occasional Contributor

I'm sorry but we can't find the error signal in the function!

So far we have managed to get the OBJECTID for the function response (AddFeature is working) but the point doesn't display on the map.

It's like the feature is created with its attributes but without Geometry. A weird thing is that after exiting the function the feature count corresponds to originalfeaturecount + 1 but when we try to query that feature by its OBJECTID it dosen't seem to be there.

Thanks for your help!

0 Kudos
LucasDanzinger
Esri Frequent Contributor

Is it related to spatial reference perhaps? What spatial reference is your map and your geodatabase, and where on the earth are you adding your new feature?

Marco_AlejandroBonilla
Occasional Contributor

Lucas, We've figured out what was happening.

The editions must be made inside the extents in which the Local GDB was set. So features outside of that extent won't be drawn (obviously :/).

Thanks for your help and your time.

0 Kudos
JackChan
New Contributor

Hi

   I got the similar issue to unable to add feature to local geodatabase, will you be able to show the example code that is working for you?

0 Kudos
Marco_AlejandroBonilla
Occasional Contributor

Jack, the code goes like this:

Geodatabase {
        id: gdb
        path: "Test/FS_SNM_ALS_LimpiezaSumideros.geodatabase"        onValidChanged: {
            if (valid) {
                var gdbtables = gdb.geodatabaseFeatureTables;
                for(var i in gdbtables) {
                    console.log (gdbtables[i].featureServiceLayerName);
                }
            }
        }
    }
FeatureLayer {
                id: featureLayer
                featureTable: gdb.geodatabaseFeatureTableByLayerId(0)
}
function addFeature(mapPoint) {
            console.log("x", mapPoint.x);
            var featureJson = {
                geometry: {
                    x: mapPoint.x,
                    y: mapPoint.y,
                    spatialReference: mapPoint.spatialReference
                },
 attributes: {
                    IDInstalacion: "1111111",
                    TipoSumidero: "CAL",
                    Largo: 1,
                    Ancho: 1,
                    MaterialTaza: "HSI",
                    MaterialAccesorio: "OTR"
                }
                }
if (featureLayer.featureTable.featureTableStatus === Enums.FeatureTableStatusInitialized) {
featureLayer.featureTable.addFeature(featureJson);
                }
}
0 Kudos
JackChan
New Contributor

Thank you Marco, you saved my day. Is there anyway that we can captured the add feature error detail? For example when you add new feature outside the local GB extent, how do you get the error message? I only can get addfeatureStatus = 3 (that means error happened when add feature), but it does not give me more information

0 Kudos