ArcGIS Runtime for .Net Quartz开发探秘(六):空间查询与识别

0
分享 2017-11-08
空间查询 ArcGIS Runtime 100.0中,空间查询发生了很大的变化,之前的QueryTask、FindTask、IdentifyTask统统不见了。取而代之的是FeatureTable的QueryFeaturesAsync()方法。
FeatureTable一个抽象类,FeatureTable有两个子类:ArcGISFeatureTable和FeatureCollectionTable。而ArcGISFeatureTable又有两个子类,分别是GeodatabaseFeatureTable和ServiceFeatureTable。他们分别来自.geodatabase文件和网络地图服务的要素表,并且都实现了QueryFeaturesAsync()方法。
下面就来看FeatureTable的QueryFeaturesAsync()方法怎么使用。其中,fl为FeatureLayer实例。
FeatureTable ft = fl.FeatureTable;
QueryParameters queryParameters = new QueryParameters();
FeatureQueryResult queryResult = await ft.QueryFeaturesAsync(queryParameters);
QueryResult是一个实现了IEnumerable接口的类,因此,我们可以这样操作它,获取查询结果。
foreach (var feature in queryResult)
{
var geometry = feature.Geometry;
var value = feature.Attributes["fieldname"];
}

当然,feature的geometry属性并不是总是返回的,如果不对QueryParameters做设置,查询默认是不返回要素的geometry属性的,毕竟geometry属性的查询、传输代价还是挺大的。
接下来看看QueryParameters的其他参数。

Geometry属性,用于空间过滤,设置了这个属性值后,将只在Geometry对象的范围内查询要素。 MaxAllowableOffset属性,用于设置最大偏离值,这个用于配合Geometry使用。 MaxFeatures属性,设置最大返回要素数。 OutSpatialReference属性,要素输出时的坐标系。 SpatialRelationship属性,返回要素与空间过滤要素的空间关系,有Relate、Equals、Within等等。 WhereClause属性,查询时所用的Where语句。
要素识别 在GIS App中,往往需要通过与用户交互展现地理信息。ArcGIS Runtime 中提供的Identify方法则允许识别用户所点击的要素。

通过代码来看怎么实现:
在MainWindow主函数中,先注册Mapview的点击事件。
MyMapView.GeoViewTapped += OnMapViewTapped;OnMapViewTapped事件响应如下:
private async void OnMapViewTapped(object sender, GeoViewInputEventArgs e)
{
var tolerance = 10d; // 设置容差
var maximumResults = 1; // 设置只返回单个要素
var onlyReturnPopups = false; // 是否只返回Popups


IdentifyGraphicsOverlayResult identifyResults = await MyMapView.IdentifyGraphicsOverlayAsync(
_polygonOverlay,//待识别的图层
e.Position,
tolerance,
onlyReturnPopups,
maximumResults);

// 如果有返回值
if (identifyResults.Graphics.Count > 0)
{
……
}
}


ArcGIS Runtime for .Net Quartz开发探秘(一):ArcGIS Runtime SDK for .Net简介及开发必要准备:http://zhihu.esrichina.com.cn/article/3501 
ArcGIS Runtime for .Net Quartz开发探秘(二):构建第一个ArcGIS Runtime WPF应用程序:http://zhihu.esrichina.com.cn/article/3497​ 
ArcGIS Runtime for .Net Quartz开发探秘(三):承接来自GIS服务器的服务:http://zhihu.esrichina.com.cn/article/3492​ 
ArcGIS Runtime for .Net Quartz开发探秘(四):加载本地文件:http://zhihu.esrichina.com.cn/article/3495​ 
ArcGIS Runtime for .Net Quartz开发探秘(五):要素符号化及渲染器:http://zhihu.esrichina.com.cn/article/3505​ 
ArcGIS Runtime for .Net Quartz开发探秘(六):空间查询与识别:http://zhihu.esrichina.com.cn/article/3491​ 
ArcGIS Runtime for .Net Quartz开发探秘(七):外业数据采集-离线数据编辑:http://zhihu.esrichina.com.cn/article/3504 
ArcGIS Runtime for .Net Quartz开发探秘(八):三维:http://zhihu.esrichina.com.cn/article/3502

文章来源:http://blog.csdn.net/a__ant/article/details/78052942

0 个评论

要回复文章请先登录注册