AE按行政区范围加载图层数据(转载)

简介:
大家可能在平时开发中可能会遇到按行政区加载图层数据的需求,比方说整个国土资源部有某一类型专题数据有若干图层,每个图层数据的范围是整个中国,这时国土资源部开发一套系统可能有这个需求,每个省只能加载本省的数据。以下函数即为按按行政区范围创建行政区范围的图层。
比方说我想获取河南省的数据只需传入行政区图层中河南省图元的Geometry即可。另外如果如果遇到行政区层必须用 esriSpatialRelEnum.esriSpatialRelContains这个参数,否则行政区这个图层就不能只获取河南这个省份,它会把河南省的周围省份,河北,湖北,安徽,陕西,山东,山西等省份的图元也添加创建到新图层。
    
ContractedBlock.gif ExpandedBlockStart.gif Code
   /// <summary>
        
/// 按行政区范围创建行政区范围的图层
        
/// </summary>
        
/// <param name="pFeatureLayer">源数据图层</param>
        
/// <param name="pGeometry">行政区范围</param>
        
/// <param name="bXZQ">图层是否为行政区</param>
        
/// <returns>新创建的图层</returns>
        private IFeatureLayer  GetSelectionLayer(IFeatureLayer pFeatureLayer, IGeometry pGeometry,bool bXZQ)
        {
            
try
            {
                
if (pFeatureLayer != null && pGeometry != null)
                {
                    IQueryFilter pQueryFilter;
                    ISpatialFilter pSpatialFilter 
= new SpatialFilterClass();
                    IFeatureSelection pFeatureSelection 
= pFeatureLayer as IFeatureSelection;
                    pSpatialFilter.GeometryField 
= pFeatureLayer.FeatureClass.ShapeFieldName;
                    pFeatureSelection.Clear();                  
                    
if (!bXZQ)
                    {
                        pSpatialFilter.Geometry 
= pGeometry;                      
                        pSpatialFilter.SpatialRel 
= esriSpatialRelEnum.esriSpatialRelIntersects;
                        pQueryFilter 
= pSpatialFilter;                       
                        pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, 
false);
                    }
                    
else
                    {
                        pSpatialFilter.SpatialRel 
= esriSpatialRelEnum.esriSpatialRelContains;
                        pQueryFilter 
= pSpatialFilter;                       
                        
if(pGeometry is IGeometryCollection)
                        {
                            
for (int i = 0; i < (pGeometry as IGeometryCollection).GeometryCount; i++)
                            {
                                pSpatialFilter.Geometry 
= (pGeometry as IGeometryCollection).get_Geometry(i); 
                                pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultAdd, 
false);
                            }
                        }
                    }                 
                    IFeatureLayerDefinition pFLDefinition 
= pFeatureLayer as IFeatureLayerDefinition;
                    IFeatureLayer pNewFeatureLayer 
= pFLDefinition.CreateSelectionLayer(pFeatureLayer.Name ,truenullnull);
                    pNewFeatureLayer.MaximumScale 
= pFeatureLayer.MaximumScale;
                    pNewFeatureLayer.MinimumScale 
= pFeatureLayer.MinimumScale;
                    pNewFeatureLayer.Selectable 
= pFeatureLayer.Selectable;
                    pNewFeatureLayer.Visible 
= pFeatureLayer.Visible;
                    pNewFeatureLayer.ScaleSymbols 
= pFeatureLayer.ScaleSymbols;
                    
return pNewFeatureLayer;
                }
                
else
                {
                    
return null;
                }
            }
            
catch (Exception Err)
            {
                MessageBox.Show(Err.Message, 
"获取SelectionLayer", MessageBoxButtons.OK, MessageBoxIcon.Information);
                
return null;
            }
        }
        
    }
原文地址: http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=34165&extra=&page=1
版权说明

  如果标题未标有<转载、转>等字则属于作者原创,欢迎转载,其版权归作者和博客园共有。
  作      者:温景良
  文章出处:http://wenjl520.cnblogs.com/  或  http://www.cnblogs.com/

posted @ 2009-03-17 09:11 温景良(Jason) Views( 711) Comments( 0) Edit 收藏
 

公告

 
本文转自 我的程序人生博客园博客,原文链接: http://www.cnblogs.com/wenjl520/archive/2009/03/17/1413911.html,如需转载请自行联系原作者
 
相关文章
|
小程序 C# 数据库
C#编程学习(20):对比两个mdb文件的图层包含的要素数目是否一致
C#编程学习(20):对比两个mdb文件的图层包含的要素数目是否一致
C#编程学习(20):对比两个mdb文件的图层包含的要素数目是否一致
|
定位技术 NoSQL 数据库