How to access file geodatabase(.gdb extension) created from Arc Map in ArcGIS Runtime Qt 10.2.6.

6822
10
07-16-2015 08:14 PM
Bhargav_KumarK
New Contributor

I created file geodatabase in Arc Map consisting of feature classes. These feature classes I want to access in ArcGIS Qt Runtime and see in application.

0 Kudos
10 Replies
Bhargav_KumarK
New Contributor

There is function EsriRuntimeQt::WorkspaceInfo::CreateFileGeoDatabaseConnection in ArcGis Qt Runtime, is this related to file geodatabase?

0 Kudos
LucasDanzinger
Esri Frequent Contributor

Yes, that static method should allow you to connect to a file geodatabase. You will need to use this in conjunction with Local Server in C++. I recommend you take a look at the Local Server > Shapefile sample and base your code off that.

Thanks,

Luke

0 Kudos
Bhargav_KumarK
New Contributor

I tried using this static method but not able to access layers present in file geodatabase(*.gdb). Can you please  give more  insight on how to achieve this in Qt SDK and also if possible any code snippets.

Thanks,Bhargav

0 Kudos
ThomasDunn
Occasional Contributor

Bhargav, I have a couple of questions for you:

  • Are you planning to only read the file GDB?
  • Do you receive any messages when you try to read from the file geodatabase?

Thank you.

0 Kudos
Bhargav_KumarK
New Contributor

1. I am planning to read only file geodatabase, editing is not required.

2. When I tried using  EsriRuntimeQt::WorkspaceInfo::CreateFileGeoDatabaseConnection, where to give layers name  to load.

0 Kudos
ThomasDunn
Occasional Contributor

WRT

> 2. When I tried using  EsriRuntimeQt::WorkspaceInfo::CreateFileGeoDatabaseConnection, where to give layers name  to load.

What messages did you receive?

0 Kudos
Bhargav_KumarK
New Contributor

I used like this in my code..

  try

  {

    // You can't modify the dynamic workspaces on a running local map service.

    m_localMapService.stopAndWait();

    // get dynamic workspaces from service

    EsriRuntimeQt::WorkspaceInfoSet& workspaceInfoSet = m_localMapService.dynamicWorkspaces();

    // create a workspace info via the static method according to data type

    // e.g. shapefile folder connection

    //EsriRuntimeQt::WorkspaceInfo workspaceInfo = EsriRuntimeQt::WorkspaceInfo::CreateShapefileFolderConnection(m_workspaceId, fileDir);//shapefile

    EsriRuntimeQt::WorkspaceInfo workspaceInfo = EsriRuntimeQt::WorkspaceInfo::CreateFileGeoDatabaseConnection(m_workspaceId, "/home/sau/Downloads/Sample.gdb");

    workspaceInfo.setEditable(true);

    // set dynamic workspaces for our local map service

    workspaceInfoSet.add(workspaceInfo);

    m_localMapService.start();

  }

  catch (EsriRuntimeQt::Exception ex)

  {

    QMessageBox::warning(this, "Error", ex.what(), QMessageBox::Ok);

  }

I am not getting messages for this part of code. When m_localMapService.start() is called onLocalServiceCreationSuccess() slot is called.

void ShapeFile::onLocalServiceCreationSuccess(const QString& url, const QString& name)

{

  Q_UNUSED(url);

  Q_UNUSED(name);

//   // create the ArcGISDynamicMapServiceLayer using the LocalMapService's url

//   m_dynamicLocalServiceLayer = new EsriRuntimeQt::ArcGISDynamicMapServiceLayer(m_localMapService.urlMapService(), this);

//   m_map->addLayer(m_dynamicLocalServiceLayer);

    m_dynamicLayer = new EsriRuntimeQt::ArcGISDynamicMapServiceLayer(m_localMapService.urlMapService(), this);

    connect(m_dynamicLayer, SIGNAL(layerCreateComplete()), this, SLOT(onLayerCreateComplete()));

    connect(m_dynamicLayer, SIGNAL(layerCreateError(QString)), this, SLOT(onLayerCreateError(QString)));

    m_map->addLayer(m_dynamicLayer);

}

on dynamic layer creation onLayerCreateComplete() slot called.

void ShapeFile::onLayerCreateComplete()

{

  m_dynamicLayer->setVisible(true);

  EsriRuntimeQt::DynamicLayerInfoCollection& layerInfos = m_dynamicLayer->dynamicLayerInfos();

  EsriRuntimeQt::DynamicLayerInfo* layerInfo = layerInfos[0];

  if (!layerInfo)

    return;

  /* Apply a renderer for vector layers.

   * Note: It is always necessary to provide a renderer, but the renderer provided does

   * not need to be valid with regard to the actual layer and geometry type, it simply

   * needs to be a valid renderer. If the renderer specified here is not appropriate for

   * the geometry type of the layer the symbology will fall back to a default

   * SimpleMarkerSymbol, SimpleLineSymbol or SimpleFillSymbol.

   */

  EsriRuntimeQt::SimpleRenderer* simpleRenderer;

  //simpleRenderer = new EsriRuntimeQt::SimpleRenderer(EsriRuntimeQt::SimpleLineSymbol(QColor(1, 1, 1), 6.0), this);//0, 100, 250

  simpleRenderer = new EsriRuntimeQt::SimpleRenderer(EsriRuntimeQt::SimpleMarkerSymbol(Qt::blue, 16, EsriRuntimeQt::SimpleMarkerSymbolStyle::Diamond));

  EsriRuntimeQt::DrawingInfo* drawingInfo = new EsriRuntimeQt::DrawingInfo(simpleRenderer, 20, this);

  layerInfo->setDrawingInfo(drawingInfo);

  // Create the table data source

  EsriRuntimeQt::TableDataSource* dataSource = new EsriRuntimeQt::TableDataSource(this);

  dataSource->setWorkspaceId(m_workspaceId);

  dataSource->setDataSourceName("Cities");

  qDebug() << "DataSource JSON" << dataSource->toJson();

  // Set the data source

  EsriRuntimeQt::LayerDataSource* layerDataSource = new EsriRuntimeQt::LayerDataSource(this);

  layerDataSource->setDataSource(dataSource);

  layerInfo->setLayerSource(layerDataSource);

  m_dynamicLayer->refresh();

}

0 Kudos
ThomasDunn
Occasional Contributor

Bhargav,

To access a file geodatabase, you must use local server. As an alternative, you can move your to a Runtime geodatabase authored in ArcMap. There are many advantages of Runtime geodatabases over file geodatabases in the context of a Runtime SDK app. Here are a few.

  • Access does not require local server.
  • Code for accessing a geodatabase can be written in C++ or QML. You can use QML to write apps that across the five platforms that QML supports.
  • Runtime geodatabase maintains feature symbology, which can be overridden by your app.
  • The code becomes simpler.

To access a Runtime geodatabase with the SDK:

  1. Create a Geodatabase object that references the Runtime geodatabase file.
  2. Create GeodatabaseFeatureTable that references a feature class in the Geodatabase object.
  3. Create a FeatureLayer object and set its feature table to the GeodatabaseFeatureTable object.
  4. Add the FeatureLayer to your Map object.

Where does the Runtime geodatabase come from?

  • You create it using ArcMap. To see how to do this, read Creating ArcGIS Runtime content​.
  • You can script it using the geoprocessing tool available in ArcToolbox at Data Management > Packages > Create Runtime Content. The script can be reused to update your Runtime geodatabase from the file geodatabase if that is necessary.
0 Kudos
Bhargav_KumarK
New Contributor

Thank you. I have idea of accessing runtime geodatabase from Qt Application. How to access a file geodatabase( *.gdb) using local server, can you give some more idea how to achieve this?

Regards,

Bhargav

0 Kudos