Add feature with attributes and geometry to mobile geodatabase

634
3
Jump to solution
08-31-2017 04:20 AM
JanWillemsen
New Contributor

Hi,

I have an editable mobile geodatabase (simulation.geodatabase, generated from a feature service) which has a table "Result" with a field "Value" (float64/double) and a Geometry (a polyline).

I want to add some features to this table, but I only succeed in adding empty features (with null for Value and SHAPE).

Below is the relevant code:

...
Esri::ArcGISRuntime::Geodatabase* geodatabase = new Esri::ArcGISRuntime::Geodatabase(QString::fromStdString(_simulationGeodatabasePath));
geodatabase->load();

Esri::ArcGISRuntime::LoadStatus ls = geodatabase->loadStatus();

while (ls != Esri::ArcGISRuntime::LoadStatus::Loaded)
{
    boost::interprocess::winapi::sleep(100);
    ls = geodatabase->loadStatus();
}
 _simTable = EsriContext::getInstance()->getSimulationGeodatabase()->geodatabaseFeatureTable("Result");
if (_simTable)
{
    _simTable->load();
    while (_simTable->loadStatus() != Esri::ArcGISRuntime::LoadStatus::Loaded)
    {
        boost::interprocess::winapi::sleep(100);
    }
    QList<Esri::ArcGISRuntime::Feature*> simResults;

    std::vector<std::shared_ptr<Esri::ArcGISRuntime::PolylineBuilder> >::iterator it = _polylineBuilders.begin();
    int i = 1;
    for (it; it != _polylineBuilders.end(); ++it, ++i)
    {
        std::string index = boost::lexical_cast<std::string>(i);

        QMap<QString, QVariant> featureAttributes;
        featureAttributes.insert("Value", 1.0);
        Esri::ArcGISRuntime::Feature* feature = _simTable->createFeature(featureAttributes, (*it)->toGeometry(), geodatabase);
        simResults.append(feature);
    }


    if (_simTable->canAdd())
    {
        Esri::ArcGISRuntime::TaskWatcher& taskWatcher = _simTable->addFeatures(simResults);

        while (!(taskWatcher.isDone()))
        {
            boost::interprocess::winapi::sleep(100);
        }
    }
}
...

The wkid of the polylines from the polylinebuilders is the same as the one of the .geodatabase.

When I just create an empty feature (_simTable->createFeature(_geodatabase);) and add them, they are added to the geodatabase (I check it with "db browser for sqlite"). When I try to assign an attribute and geometry like in the code above, nothing is added. Anybody has any idea what I'm doing wrong?

Kind regards,

Jan

0 Kudos
1 Solution

Accepted Solutions
JanWillemsen
New Contributor

Hi James,

thanks for the suggestion. It didn't give me any error though (valid pointer and the code didn't arrive in the slot either).

We found out that the spatial reference of the exported .geodatabase was still wrong, now it seems to work.

Thanks,

Jan

View solution in original post

0 Kudos
3 Replies
JamesBallard1
Esri Regular Contributor

Hi Jan,

    This is difficult to diagnose without the geodatabase. Here are some things to try.

Can you verify this is returning a valid, non-null feature? It's possible there's a schema mismatch or maybe there's a missing required field.

Esri::ArcGISRuntime::Feature* feature = _simTable->createFeature(featureAttributes, (*it)->toGeometry(), geodatabase);

You could also connect to the errorOccurred signal to see if any errors are being reported on the table.

if (_simTable)
{
    connect(_simTable, &FeatureTable::errorOccurred, this, [](Error e)
    {
        qDebug() << "Error:" << e.message() << e.additionalMessage();
    });
...

Please let us know if that helps.

0 Kudos
JanWillemsen
New Contributor

Hi James,

thanks for the suggestion. It didn't give me any error though (valid pointer and the code didn't arrive in the slot either).

We found out that the spatial reference of the exported .geodatabase was still wrong, now it seems to work.

Thanks,

Jan

0 Kudos
JamesBallard1
Esri Regular Contributor

Jan,

     Thanks for the update. It's good to hear it's working now.

0 Kudos