arcengine C# 按行政区范围加载图层数据

  1. 大家可能在平时开发中可能会遇到按行政区加载图层数据的需求,比方说整个国土资源部有某一类型专题数据有若干图层,每个图层数据的范围是整个中国,这时国土资源部开发一套系统可能有这个需求,每个省只能加载本省的数据。以下函数即为按按行政区范围创建行政区范围的图层。   
  2. 比方说我想获取河南省的数据只需传入行政区图层中河南省图元的Geometry即可。另外如果如果遇到行政区层必须用 esriSpatialRelEnum.esriSpatialRelContains这个参数,否则行政区这个图层就不能只获取河南这个省份,它会把河南省的周围省份,河北,湖北,安徽,陕西,山东,山西等省份的图元也添加创建到新图层。   
  3.         /// <summary>   
  4.         /// 按行政区范围创建行政区范围的图层   
  5.         /// </summary>   
  6.         /// <param name="pFeatureLayer">源数据图层</param>   
  7.         /// <param name="pGeometry">行政区范围</param>   
  8.         /// <param name="bXZQ">图层是否为行政区</param>   
  9.         /// <returns>新创建的图层</returns>   
  10.         private IFeatureLayer  GetSelectionLayer(IFeatureLayer pFeatureLayer, IGeometry pGeometry,bool bXZQ)   
  11.         {   
  12.             try  
  13.             {   
  14.                 if (pFeatureLayer != null && pGeometry != null)   
  15.                 {   
  16.                     IQueryFilter pQueryFilter;   
  17.                     ISpatialFilter pSpatialFilter = new SpatialFilterClass();   
  18.                     IFeatureSelection pFeatureSelection = pFeatureLayer as IFeatureSelection;   
  19.                     pSpatialFilter.GeometryField = pFeatureLayer.FeatureClass.ShapeFieldName;   
  20.                     pFeatureSelection.Clear();                     
  21.                     if (!bXZQ)   
  22.                     {   
  23.                         pSpatialFilter.Geometry = pGeometry;                         
  24.                         pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;   
  25.                         pQueryFilter = pSpatialFilter;                          
  26.                         pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);   
  27.                     }   
  28.                     else  
  29.                     {   
  30.                         pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;   
  31.                         pQueryFilter = pSpatialFilter;                          
  32.                         if(pGeometry is IGeometryCollection)   
  33.                         {   
  34.                             for (int i = 0; i < (pGeometry as IGeometryCollection).GeometryCount; i++)   
  35.                             {   
  36.                                 pSpatialFilter.Geometry = (pGeometry as IGeometryCollection).get_Geometry(i);    
  37.                                 pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultAdd, false);   
  38.                             }   
  39.                         }   
  40.                     }                    
  41.                     IFeatureLayerDefinition pFLDefinition = pFeatureLayer as IFeatureLayerDefinition;   
  42.                     IFeatureLayer pNewFeatureLayer = pFLDefinition.CreateSelectionLayer(pFeatureLayer.Name ,truenullnull);   
  43.                     pNewFeatureLayer.MaximumScale = pFeatureLayer.MaximumScale;   
  44.                     pNewFeatureLayer.MinimumScale = pFeatureLayer.MinimumScale;   
  45.                     pNewFeatureLayer.Selectable = pFeatureLayer.Selectable;   
  46.                     pNewFeatureLayer.Visible = pFeatureLayer.Visible;   
  47.                     pNewFeatureLayer.ScaleSymbols = pFeatureLayer.ScaleSymbols;   
  48.                     return pNewFeatureLayer;   
  49.                 }   
  50.                 else  
  51.                 {   
  52.                     return null;   
  53.                 }   
  54.             }   
  55.             catch (Exception Err)   
  56.             {   
  57.                 MessageBox.Show(Err.Message, "获取SelectionLayer", MessageBoxButtons.OK, MessageBoxIcon.Information);   
  58.                 return null;   
  59.             }   
  60.         }   
  61.            
  62.     }

你可能感兴趣的:(ArcEngine)