开发者

ArcGis Engine, how to select objects?

I'm trying to create a standalone application, which loads a ArcGis map, selects a few objects in one layer and zooms to them.

Loading and displaying the map does work, using something like this:

AxMapControl _mapControl;

// in constructor:
_mapControl = new AxMapControl();

// in loading
_mapControl.LoadMxFile(@"C:\Users\me\Documents\TestProject.mxd");

This does work nicely and does display the map as full extent (of course the AxMapControl is embedded into a WindowsFormsHost, but this shouldn't be a problem).

But now I need to select one or more objects and zoom to them. I tried to select in one layer for testing, but this does not work at all:

IFeatureSelection features = _mapControl.Map.Layer[0] as IFeatureSelection;
if (features != null)
{
  QueryFilter qf = new QueryFilterClass();
  qf.WhereClause = "[Name]='FS4711000'";
  features.SelectFeatures(qf, esriSelectionResultEnum.esriSelectionResultNew, false);
}

on the SelectFeatures call I get an COM error 80004005 (E_Fail) in ESRI.ArcGIS.Carto, without much more explanation. Probably I'm doing it all wrong.

Maybe someone has开发者_运维问答 a sample how to select objects in a layer?


I think your issue is as simple as the [square brackets] around your field name in the query string.

This works:

IFeatureSelection features = _currentLayer as IFeatureSelection;
if (features != null)
{
    QueryFilter qf = new QueryFilter();
    qf.WhereClause = "Type='1'";

    features.SelectFeatures(qf, esriSelectionResultEnum.esriSelectionResultNew, false);
}
_axMapControl.Refresh();

Whereas this fails with COM-error E_FAIL:

IFeatureSelection features = _currentLayer as IFeatureSelection;
if (features != null)
{
    QueryFilter qf = new QueryFilter();
    qf.WhereClause = "[Type]='1'";

    features.SelectFeatures(qf, esriSelectionResultEnum.esriSelectionResultNew, false);
}
_axMapControl.Refresh();

Also, notice that the map (or at least the IActiveView returned by AxMapControl.ActiveView) needs to be manually refreshed, or the selection is not displayed before the map is redrawn.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜