• MapObjects的查询


    MapObjects组件中的MapLayerClass中提供了三种方法查询:

    Recordset SearchByDistance(object shape, double distance, string expression);    //范围查询,shape形状对象,distance 范围,expression 表达式,可以为空    
    Recordset SearchExpression(string expression);    //表达式查询
    Recordset SearchShape(object shape, SearchMethodConstants searchMethod, string expression);  //形状查询

    对于查询得到的结果,系统具有统计功能。MapObjects 中的Statistics对象提供了简单的统计功能 ,可以选择任意一个数值字段,统计出对应查询结果的最大值、最小值、平均值、标准值、总和等。

    以下分别介绍这三种查询方法在C#中使用的例子

     MapObjects2.Rectangle rect;     //范围
     MapObjects2.MapLayer lyr;       //图层
    MapObjects2.Recordset rest;     //图元集合

    rect = axMap1.TrackRectangle();  //得到当前选择的范围
    lyr= axMap1.Layers.Item(0) as MapObjects2.MapLayer; // 获取当前选择的图层(只在0层图层中查)

    //rest = lyr.SearchByDistance(rect, axMap1.ToMapDistance(50f), string.Empty);   //范围查询

    rest = lyr.SearchShape(rect, MapObjects2.SearchMethodConstants.moAreaIntersect, string.Empty);  //形状查询

    由于表达式查询比较复杂,这里给它封装了一个方法       

       /// <summary>
            /// 通过图层属性数据查找数据  表达式查询
            /// </summary>
            /// <param name="fieldName"></param>
            /// <param name="value"></param>
            /// <param name="layer"></param>
            /// <returns></returns>
            public MapObjects2.Recordset SeachDataForField(string fieldName, string fieldValue, MapObjects2.MapLayer layer)
            {
                string expression = string.Empty;
                //field = layer.Records.Fields.Item(<地图属性的字段>);
                MapObjects2.Field field = layer.Records.Fields.Item(fieldName);           
                switch (field.Type)
                {
                    case MapObjects2.FieldTypeConstants.moLong:
                    case MapObjects2.FieldTypeConstants.moDouble:
                        {
                            //expression = string.Format("{0}={1}", <地图属性的字段>, <属性值>);  
                            expression = string.Format("{0}={1}", fieldName, fieldValue);
                            break;
                        }
                    case MapObjects2.FieldTypeConstants.moString:
                        {
                            //expression = string.Format("{0}='{1}'", <地图属性的字段>, <属性值>);
                            expression = string.Format("{0}={1}", fieldName, fieldValue);
                            break;
                        }
                    default:
                        {
                            expression = string.Empty;
                            break;
                        }
                }

                if (expression == string.Empty)
                {
                    return null;              
                }
                MapObjects2.Recordset recs = layer.SearchExpression(expression);            
                return recs;
            }

    地图的属性字段 通过MapObjects2.Recordset类的get_FieldName得到,如获取图层的全部属性字段

            /// <summary>
            /// 获取图层属性字段数组
            /// </summary>
            /// <param name="layer">图层</param>
            /// <returns></returns>
            public string[] GetFieldNames(MapObjects2.MapLayer layer)
            {
                MapObjects2.TableDesc tableDesc;
                tableDesc = layer.Records.TableDesc;
                string[] fieldNames = new string[tableDesc.FieldCount];           
                for (short k = 0; k < tableDesc.FieldCount; k++)
                {
                    fieldNames[k] = tableDesc.get_FieldName(k);
                }
                return fieldNames;
            }

    OK,到这里,MapObjects的三种查询方式已经介绍完了,统计的例子由于时间关系,我这里就不举例子了

    对于找到的数据源,有时候我们需要对它闪烁几下来突出它的位置,这里可以用AxMapObjects提供void FlashShape(object shape, short nTimes);方法实现。参考代码:

     axMap1.FlashShape(restTemp.Fields.Item("shape").Value, 3); //restTemp为MapObjects2.Recordset 对象,使该位置闪烁3下

    上面闪烁能对简单的单个图元进行突出显示,对于选择的是多个图元或点,需要图元或点的合并,这里将在下一次介绍,MapObjects的合并,交,差等操作

  • 相关阅读:
    PHP之PHPExcel X
    Docker之基础(一) X
    Django Admin之常用功能汇总 X
    pycharm中配置启动Django项目 X
    银联支付接入新一代 X
    pycharm集成Jupyter Notebook X
    Django之model外键 X
    Django之添加prometheus监控 X
    Yii2 中配置方法汇总 X
    python常用模块汇总 X
  • 原文地址:https://www.cnblogs.com/tqlin/p/1675751.html
Copyright © 2020-2023  润新知