Query an ArcGisDynamicMapServiceLayer

4700
8
04-18-2016 10:31 AM
DanielBachmann1
New Contributor

Hi,

I created an ArcGisDynamicMapServiceLayer on a local map service and opened a shapefile. Is it possible to query the attributes of this layer? I set a DefinitionExpression through DynamicLayerInfo but how can I access the attributes of the visible features?

Using a QueryTask always results in 0 features, I used the blocking and non blocking methods. Are querys on local services not allowed?

kind regards,

Daniel

0 Kudos
8 Replies
LucasDanzinger
Esri Frequent Contributor

A QueryTask should work just fine. If you print out the URL to your local service once it starts, you should be able to see it in the browser, and execute a query from there as well. Are you making sure to point the url to the individual layer, and not the root of the service?

0 Kudos
DanielBachmann1
New Contributor

In order to add the shapefile to the local service, I created an mpk-File "blank.mpk" with ArcMap which includes only an empty Polyline-Shapefile. As shown in the examples, I added the shapefile to the associated ArcGisDynamicMapServiceLayer (after modifying the dynamic workspaces) like this

EsriRuntimeQt::SimpleRenderer* simpleRenderer;

simpleRenderer = new EsriRuntimeQt::SimpleRenderer(EsriRuntimeQt::SimpleLineSymbol(QColor(0, 100, 250), 3.0), this);
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(m_dataSourceFileName);
// Set the data source
EsriRuntimeQt::LayerDataSource* layerDataSource = new EsriRuntimeQt::LayerDataSource(this);
layerDataSource->setDataSource(dataSource);
layerInfo->setLayerSource(layerDataSource);
layerInfo->setDefinitionExpression(m_queryString);
m_dynamicLocalServiceLayer2->refresh();

After this the Polylines from the shapefile are drawn, but the url shows the old attributes of the "blank.mpk"! A query on that empty package will always return zero results...

0 Kudos
DanielBachmann1
New Contributor

Just tried a QueryTask with tha data of the shapefile in an mpk-File and it works, so I'll be missing something!?

Queried the shapefile using gdal-api for now (bit ugly) but it seams to work...

0 Kudos
LucasDanzinger
Esri Frequent Contributor

One more thing to try. In your Query object (that you will pass into the Query Task), can you try calling setDynamicLayerInfo (ArcGIS Runtime SDK for Qt C++ API: EsriRuntimeQt::Query Class Reference)). Then, pass in a DynamicLayerInfo created from your LayerSource.

0 Kudos
DanielBachmann1
New Contributor

Used the code below, but again only the empty layer in the mpk-File is queried not the one loaded from the shapefile. If queried for the field "id" set->count() is 0. A query for a field which is only defined in the shapefile restults in (set == NULL).

EsriRuntimeQt::Query query;

query.setWhere("id >= 0");

query.setDynamicLayerInfo(layerInfo);

m_queryTask = new EsriRuntimeQt::QueryTask(m_dynamicLocalServiceLayer2->url()+"/0",this);

EsriRuntimeQt::FeatureSet* set = m_queryTask->executeAndWait(query);

if ( set )

{

     qDebug()<<set->count();

}

0 Kudos
LucasDanzinger
Esri Frequent Contributor

Can you try setting your where clause to "1=1" to see if you can get anything/everything back?

0 Kudos
DanielBachmann1
New Contributor

Query "1=1" returns no results, which means (set != 0), but (set->count() == 0). Which is only correct for the "empty" mpk-File before adding the shapefile dynamically.

0 Kudos
DanielBachmann1
New Contributor

Hi Luke,

Found some time to make a minimal example using only files from the sdk samples. Maybe this will leads to new insights 🙂

kr,

Daniel

0 Kudos