Adding a feature to an offline geodatabase using GeodatabaseFeatureTable::addFeature

3468
9
03-23-2016 09:07 AM
KenGorton
Esri Contributor

In my app I have enabled adding features to a hosted feature service by following the examples of the sample apps "Add and edit features" and "Local geodatabase editing". Based on the example of "Add and edit features" if I edit the service directly using  GeodatabaseFeatureServiceTable::addFeature passing in the feature JSON I create for the feature to be added, it works. The result is the OBJECTID of the new feature.

However, if I create an offline geodatabase of the same feature service as in "Local geodatabase editing" and add a feature to it using GeodatabaseFeatureTable::addFeature passing in the same feature JSON, it fails. The result is always -1.

What am I doing wrong?

Thanks.

0 Kudos
9 Replies
LucasDanzinger
Esri Frequent Contributor

Tough to say what the issue is without seeing any code or data. Perhaps you can share? Also, have you tried creating the feature with ArcGISRuntime.createObject(), and then setting the geometry and any required attributes? I personally find this to be a more reliable method of creating objects than creating the JSON representation of the object, as this method seems more error prone (IMO).

0 Kudos
KenGorton
Esri Contributor

Thanks for the suggestion. I’ll give that a try and if I still have trouble I am happy to share my code if you’re inclined to have a look at it. Thanks.

0 Kudos
KenGorton
Esri Contributor

So I tried that but there's still something I'm doing wrong. My app implements a local geodatabase with a single FeatureTable. I enabled a function where if the user taps the screen, it will add a point to the GeodatabaseFeatureTable in the offline geodatabase. When I run this app  directly from Qt Creator on my development machine I can successfully add a point which later gets syncronized and appears in my hosted feature service. Then I upload the app to my AGOL account, download it to my iPhone and run it in Player. I attempt to perform the same action of adding a point by tapping the screen but it won't add the new feature to the offline table.

This is the code:

   if (local.featureTableStatus === Enums.FeatureTableStatusInitialized) {

                var newFeature = local.createNewFeature();
                var newPoint = ArcGISRuntime.createObject("Point",{x:pointX,y:pointY,spatialReference:{wkid:102100}})
                newFeature.geometry = newPoint
                newFeature.setAttributeValue("ID","pointID")
                newFeature.setAttributeValue("Name","manual point")
                var ms = new Date().getTime();
                newFeature.setAttributeValue("Time",ms)
                newFeature.setAttributeValue("Longitude",pointX)
                newFeature.setAttributeValue("Latitude",pointY)
                var newFeatId = local.addFeature(newFeature)
                gpsDetails.text += "Manually added:\n" + JSON.stringify(newFeature.json) + "\n\n";
                statusText.text = "Offline. Point added to offline geodatabase: " + newFeatId;
                syncButton.enabled = true;
            }

local is a GeodatabaseFeatureTable in the offline geodatabase. pointX and  pointY are the mouse.mapX and mouse.mapY of the screen tap event.

The result of local.addFeature(newFeature) in the iOS deployment is always -1 (no feature was added)

Any other suggestions are very welcome.

Thanks,

Ken

0 Kudos
LucasDanzinger
Esri Frequent Contributor

Hi Ken,

It seems like you are doing everything right, and if it works on the desktop, then it seems like your code is generally correct. The only things I can think of that could be different on desktop vs iOS is where you are saving the data. Perhaps it doesn't have the correct permissions or something like that? It might be worth while to contact Esri Support to help you troubleshoot this further to help narrow down the issue.

-Luke

0 Kudos
KenGorton
Esri Contributor

Something additional: In the interest of thoroughness I modified the sample "Local geodatabase editing" to allow adding features instead of only editing existing ones. Then I tested it on Windows, iOS and Android with the same results: I could add features on the desktop but not when the app was deployed on an iPhone or an Android phone.

A difference is that when running on iOS and Android it was running within Player. So I installed Player for windows on my development machine and when I ran the apps, I got the same result as on iOS and Android - no feature added to the offline geodatabase.So it would seem there is something about Player that is getting in the way. Not sure what to do next, but thought I'd add this to the conversation.

0 Kudos
LucasDanzinger
Esri Frequent Contributor

Interesting... When you say you ran from Qt Creator in the desktop, were you doing a local build and run, or how did you run it from the desktop? Many people using AppStudio still just run the app through the player from Qt Creator. It is invoked differently than when used through the AppStudio app, but it is still invoking the same player app.

0 Kudos
KenGorton
Esri Contributor

AltShiftR or Tools>External>AppStudio>Run

I was wondering if it also uses Player when running that way. I would be happy to do a screen share and show you what I did just to make I am explaining myself correctly.

0 Kudos
TobiasFimpel1
Occasional Contributor III

Ken, I have the same issue. When I capture the error it points me to a licensing issue. (I don't have my code with me right now but I think this is how you can capture the error.).

0 Kudos
LucasDanzinger
Esri Frequent Contributor

It is probably a good question to post in the AppStudio space. I am not sure how they handle licensing in the player app, and if it changes depending on how it is run (through the desktop or from a mobile device).