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
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?
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...
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...
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.
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();
}
Can you try setting your where clause to "1=1" to see if you can get anything/everything back?
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.