ArcGIS图层和要素的过滤显示

摘要:
//ArcGISDynamicMapServiceLayer初始化函数privatevoidArcGISDsynamicMapServicesLayer_Initialized{//获得ArcGISDSynamicMapService层。这里是第一层。根据实际情况,可以通过Map.Layers[“layer ID”]//myArcGISDynomicMapServiceLayer.VisibleLayers=myVisibleLayers2;//显示的层IDint[]myVisibleLayers=myArcGISDynamicMapServiceLayer VisibleLayers;如果(myVisibleLayers!=null){stringmyVisibleLayer Text=“NumberVisibleLayers:”+myVisibleLayers.Length.ToString();stringmyVisbleLayersText2=“”;inti=0;对于{myVisibleLayoutsText2=myVisibleLayersText2+“”+myVisableLayers[i].ToString();}TextBlock_VisibleLayers.Text=myVisibleLayers Text+“.VisibleLayersID:”+myVisibleLayer Text2;}否则{TextBlock_VisibleLayers.Text=“[VisibleLayersnotset Meaningall layers reviewable.]”;}}2.根据现场条件将图层设置为过滤显示。如果不显示图层的所有特征,而是根据特定条件“过滤显示”,则可以通过设置图层定义来实现。LayerDefinition可以通过XAML代码设置:˂!

ArcGIS可以设置动态地图服务(ArcGISDynamicMapServiceLayer)显示哪些图层,也可以设置每个图层根据某个属性字段的某些条件来进行过滤显示。

1、设置显示的图层

主要是通过ArcGISDynamicMapServiceLayer的VisibleLayers属性来设置或得到当前显示的图层,C#代码如下:

代码中Map1和TextBlock_VisibleLayers是已经定义好的地图和TextBlock控件。

//ArcGISDynamicMapServiceLayer初始化函数
private void ArcGISDynamicMapServiceLayer_Initialized(object sender, System.EventArgs e)
{
    //得到ArcGISDynamicMapServiceLayer,这里是第一个图层,根据实际情况,可以通过Map.Layers["图层的ID"]来得到 
    ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = (ArcGISDynamicMapServiceLayer)Map1.Layers[0];
  
    //VisibleLayers的读写
  
    //下面注释的代码:设置myArcGISDynamicMapServiceLayer第二和第三个图层显示 
    //int[] myVisibleLayers2 = { 1, 2 }; 
    //myArcGISDynamicMapServiceLayer.VisibleLayers = myVisibleLayers2;
  
    //得到显示的图层ID
    int[] myVisibleLayers = myArcGISDynamicMapServiceLayer.VisibleLayers;
    if (myVisibleLayers != null)
    {
        string myVisibleLayersText = "Number VisibleLayers: " + myVisibleLayers.Length.ToString();
        string myVisibleLayersText2 = "";
        int i = 0;
        for (i = 0; i < myVisibleLayers.Length; ++i)
        {
            myVisibleLayersText2 = myVisibleLayersText2 + " " + myVisibleLayers[i].ToString();
        }
        TextBlock_VisibleLayers.Text = myVisibleLayersText + ". VisibleLayers ID's: " + myVisibleLayersText2;
    }
    else
    {
        TextBlock_VisibleLayers.Text = "[VisibleLayers not set - Meaning all layers are visible.]";
    }
}

2、设置图层根据字段条件过滤显示

如果不全部显示一个图层的所有要素,而是根据某些条件来“过滤显示”,则可以通过设置LayerDefinition来实现。

LayerDefinition的设置可以通过XAML代码实现:

<StackPanel Name="StackPanel1" Height="400" Width="400" Margin="0,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" >
    <esri:Map Background="White" Name="Map1" Height="200" Width="400">
         
         <!-- Set the LayerDefinition for the ArcGISDynamicMapServiceLayer. -->
         <!-- By default no LayerDefinition is set unless explicitly set on the server. -->
         <esri:ArcGISDynamicMapServiceLayer 
              Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/Since_1970/MapServer" />
              <esri:ArcGISDynamicMapServiceLayer.LayerDefinitions>
                  
                  <!-- LayerID="0" is the Earthquakes1970 layer. The Definition only displays earth quakes that have a
                          Magnitude greater than 6. The field Magnitude is of type esriFieldTypeDouble. -->
                  <esri:LayerDefinition LayerID="0" Definition="Magnitude > 6" />
                  
                  <!-- LayerID="0" is the Earthquakes1970 layer. The Definition only displays earth quakes that have a
                          Magnitude greater than 3 and less than 6. The field Magnitude is of type esriFieldTypeDouble. -->
                  <!-- <esri:LayerDefinition LayerID="0" Definition="Magnitude > 3 AND Magnitude &lt; 6" /> -->
                  
                  <!-- Another example where the Name of the earth quake event is to contains the letters 'CHINA'.
                          Note: the Definition is case sensitive. The field Name is of type esriFieldTypeString. -->
                  <!-- <esri:LayerDefinition LayerID="0" Definition="Name LIKE 'CHINA'" /> -->
                  
                  <!-- Another example where the Name of the earth quake event is exactly matches the letters 'VENEZUELA'.
                          Note: the Definition is case sensitive. The field Name is of type esriFieldTypeString. -->
                  <!-- <esri:LayerDefinition LayerID="0" Definition="Name = 'VENEZUELA'" /> -->
                  
                  <!-- Another example where the earth quake events are displayed if they occured after January 15, 2000. 
                          The field Date_ is of type esriFieldTypeDate. -->
                  <!-- <esri:LayerDefinition LayerID="0" Definition="Date_ > DATE '1/15/2000'" />-->
                
              </esri:ArcGISDynamicMapServiceLayer.LayerDefinitions>
         </esri:ArcGISDynamicMapServiceLayer>
    </esri:Map>
    
    <!-- LayerDefinitions Property (Read) -->
    <TextBlock Height="23" Name="TextBlock_LayerDefinitions" 
        Text="{Binding ElementName=Map1, Path=Layers[0].LayerDefinitions[0].Definition}" />
</StackPanel>

也可以通过代码来实现,C#代码如下:

//ArcGISDynamicMapServiceLayer初始化函数
private void ArcGISDynamicMapServiceLayer_Initialized(object sender, System.EventArgs e)
{
    //得到ArcGISDynamicMapServiceLayer,这里是第一个图层,根据实际情况,可以通过Map.Layers["图层的ID"]来得到 
    ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = (ArcGISDynamicMapServiceLayer)Map1.Layers[0];
            
    //LayerDefinition的读写
    
    //设置图层的LayerDefinition,默认情况下LayerDefinition是没有设置的
    //得到图层的LayerDefinition 
    ESRI.ArcGIS.Client.LayerDefinition myDefinition = new ESRI.ArcGIS.Client.LayerDefinition();
    myDefinition.LayerID = 0;
    
    //设置LayerDefinition,属性字段“Magnitude”属于ID为0的图层
    //LayerDefinition的设置语句和Query中的Where语句一样
    //字段Magnitude的类型是esriFieldTypeDouble.
    myDefinition.Definition = "Magnitude > 6";
    
    // The Definition only displays earth quakes that have a Magnitude greater than 3 and less that 6. 
    // The field Magnitude is of type esriFieldTypeDouble.
    // myDefinition.Definition = "Magnitude > 3 AND Magnitude < 6";
             
    // Another example where the Name of the earth quake event is to contains the letters 'CHINA'.
    // Note: the Definition is case sensitive. The field Name is of type esriFieldTypeString.
    //myDefinition.Definition = "Name LIKE 'CHINA'";
    
    // Another example where the Name of the earth quake event is exactly matches the letters 'VENEZUELA'.
    // Note: the Definition is case sensitive. The field Name is of type esriFieldTypeString.
    //myDefinition.Definition = "Name = 'VENEZUELA'";
    
    // Another example where the earth quake events are displayed if they occured after January 15, 2000. 
    // The field Date_ is of type esriFieldTypeDate.
    //myDefinition.Definition = "Date_ > DATE '1/15/2000'";
    
    //创建一个ObservableCollection,add设置的LayerDefinition
    System.Collections.ObjectModel.ObservableCollection<LayerDefinition> myObservableCollection2 = 
       new System.Collections.ObjectModel.ObservableCollection<LayerDefinition>();
    myObservableCollection2.Add(myDefinition);
    
    //启动设置的LayerDefinition
    myArcGISDynamicMapServiceLayer.LayerDefinitions = myObservableCollection2;
    
    //得到已经存在的LayerDefinitions collection.
    System.Collections.ObjectModel.ObservableCollection<LayerDefinition> myObservableCollection = 
        myArcGISDynamicMapServiceLayer.LayerDefinitions;
                
    if (myObservableCollection.Count > 0)
    {
        //得到第一个LayerDefinition 
        ESRI.ArcGIS.Client.LayerDefinition myLayerDefinition = myObservableCollection[0];
        
        //得到LayerDefinition的信息
        TextBlock_LayerDefinitions.Text = "For Layer: " + myLayerDefinition.LayerID.ToString() + 
            ". The Defintion is: " + myLayerDefinition.Definition;
    }
    else
    {
        TextBlock_LayerDefinitions.Text = "[NO LayerDefinitions SET]";
    }
}

上面ArcGISDynamicMapServiceLayer_Initialized(object sender, System.EventArgs e)函数是订阅到ArcGISDynamicMapServiceLayer.Initialized的,也就是在图层加载的时候就设置了“过滤”条件,如果要在后期在某个响应事件中动态的刷新地图,需要在设置LayerDefinition后,调用ArcGISDynamicMapServiceLayer.Refresh()函数来刷新地图才能看到效果。

参考:

http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer~VisibleLayers.html

http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer~LayerDefinitions.html

免责声明:文章转载自《ArcGIS图层和要素的过滤显示》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Redis AOF重写Apache 负载均衡 端口转发 配置下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

[转帖]ArcGIS标注 [VBScript] Joe

ArcGIS标注 [VBScript] 分数形式标注要素: 首先将分母和分子的内容分别放在两个字段中,然后在标注的时候,标注内容选择用表达式标注,在表达式的输入框中输入"<UND>" & [分子的字段] & "</UND>" & vbNewLine & [分母的字段],即可实现分数形式的标注。...

arcgis 如何改变字段的别名

public void ChangeFieldAliasName(ITable pTable, string pOriFieldName, string pDesFieldName){IClassSchemaEdit pClassSchemaEdit = (IClassSchemaEdit)pTable;//给对象加上锁ISchemaLock pSchem...

leaflet实现风场图

前言 leaflet 入门开发系列环境知识点了解: leaflet api文档介绍,详细介绍 leaflet 每个类的函数以及属性等等 leaflet 在线例子 leaflet 插件,leaflet 的插件库,非常有用 内容概览 leaflet 实现风场图,实现效果来自此参考文献:https://github.com/danwild/wind-...

ArcGIS空间参考概述

摘要:在地理数据库中,坐标系和其他相关空间属性被定义为各数据集的空间参考的一部分。空间参考是用于存储各要素类和栅格数据集,以及其他坐标属性(例如,x,y 坐标的坐标分辨率及可选的 z 坐标和测量 (m) 坐标)的坐标系。如果需要,可使用表示表面高程的 z 坐标为数据集定义一个垂直坐标系。 任何特定区域的地理数据都存储在独立的图层中。例如,道路存储在一个图...

C# AE 合并要素/合并图形/merger功能

功能描述 合并功能,准确的说是merge、union。 这两者在ArcMap中的差别就是:merger保留相同字段属性;union是可以选择创建新的合并图形还是直接用原始要素合并,合并属性不保留。 接口和使用方法 1. ITopologicalOperator接口,其下的ConstructUnion属性能够一次放入多个几何(ConstructUnion属性...

【转】ArcGIS投影转换与坐标转换

1 ArcGIS中的投影方法(从一种投影转换成另一种投影;在已有投影的情况才能用;有些转换限制) 投影的方法可以使带某种坐标信息数据源进行向另一坐标系统做转换,并对源数据中的X和Y值进行修改。我们生产实践中一个典型的例子是利用该方法修正某些旧地图数据中X,Y值前加了带数和分带方法的数值。 操作方法:运行ArcGIS9中的ArcMap,打开ArcTool...