在ArcGlobe中如何聚焦到选择的图元(How to zoom to selected features in globe)

Zooming to selected features in globe

1.Get all the layers present in the current globe document. Once you have a handle to the layers, loop through the layers and get all the features that are selected on the globe. See the following code example:

在当前globe文件中得到所有存在的图层。一旦你有一个图层的句柄的话,循环整个图层,得到在globe中选中的图元。看下面的代码例子。
[C#]
ESRI.ArcGIS.GlobeCore.IGlobeDisplay globeDisplay  =  globe.GlobeDisplay;
ESRI.ArcGIS.Analyst3D.IScene scene 
=  globeDisplay.Scene;
ESRI.ArcGIS.Carto.IEnumLayer enumLayer 
=  scene.get_Layers( null true );

2.Get a handle to the globe camera. The globe camera will be used to zoom to the extent of the selected features on the globe. See the following code example:

 得到一个globe camera的句柄。globe camera将被用来聚焦到globe中选择的图元的范围。看下面的代码实例。

[C#]
ESRI.ArcGIS.Analyst3D.ISceneViewer sceneViewer  =  globeDisplay.ActiveViewer;
ESRI.ArcGIS.Analyst3D.ICamera camera 
=  sceneViewer.Camera;
ESRI.ArcGIS.GlobeCore.IGlobeCamera globeCamera 
=  (ESRI.ArcGIS.GlobeCore.IGlobeCamera)camera;  //  Explicit cast.

3.The extent of the layers is stored in an envelope and basically defines the area you need to zoom to. Make the envelope z-aware in cases when the features in the data have z-values or are draped on an elevation surface.

图层的范围保存在一个envelope里主要定义了你要聚焦的区域。让envelope具有z属性,万了万一图元在数据中有z值,或者是覆盖在高程图层的表面。

4.Keep track of the extent of the layer where features are selected. This is important when zooming to selected point features. Getting the extent of the point features is shown in the following code example:

     当聚焦到选中的点图元时,记录被选中的图元所在图层的范围是很重要的。得到点图元的范围的代码如下:

[C#]

5.Before looping through all the layers, define a Boolean to keep track of any selected features in the layers and reset the counter to get the first layer stored in IEnumLayer. See the following code example:

在循环所有图层之前, 定义一个布尔型去追踪图层中被选中图元还有重置计算器去得到图层集中的第一个图层。

[C#]
  
  
bool  haveFeatures  =   false ;
enumLayer.Reset();

6.To loop through the layers, use the whileloop. If no layers are present, break out of the code. See the following code example:

用while循环 去循环所有图层。如果当前没有图层,中断循环。

[C#]
  
  
ESRI.ArcGIS.Carto.ILayer layer;
while  ((layer  =  enumLayer.Next())  !=   null )
{
if (layer == null)
 
break;

7.For each layer, get the feature selection set as shown in the following code example. After getting the selection set, loop through individual features using the feature cursor and store the geometry in the envelope.

对于每一个图层,得到选择图元的几何代码如下。当得到选择的几何之后,用feature cursor去循环其中的单个图元,在envelope中保存其几何形状。

The important thing to note is that you are trying to zoom to a number of selected features. If there are multiple features in the same feature class, keep updating the envelope of the extent by using the IEnvelope.Union method.
 最主要注意的东西是你想要去聚焦到许多选择的图元。如果有多重的图元在相同的图元图元class中,通过IEnvelope.Union 的方法来保持更新envelope 的范围。

[C#]
ESRI.ArcGIS.Carto.IFeatureLayer featureLayer  =  (ESRI.ArcGIS.Carto.IFeatureLayer)layer;  //  Explicit cast.
ESRI.ArcGIS.Carto.IFeatureSelection featureSelection  =  (ESRI.ArcGIS.Carto.IFeatureSelection)layer;  //  Explicit Cast
ESRI.ArcGIS.Geodatabase.ISelectionSet selectionSet  =  featureSelection.SelectionSet;
ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass 
=  featureLayer.FeatureClass;
string  shapeField  =  featureClass.ShapeFieldName;
spatialFilterCls.GeometryField 
=  shapeField;
spatialFilterCls.set_OutputSpatialReference(shapeField, spatialReference);
ESRI.ArcGIS.Geodatabase.ICursor cursor;
selectionSet.Search(spatialFilterCls, 
true out  cursor);
ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor 
=  (ESRI.ArcGIS.Geodatabase.IFeatureCursor)cursor;  //  Explicit cast.
bool  getLayerExtent  =   true ;
ESRI.ArcGIS.Geodatabase.IFeature feature;
while  ((feature  =  featureCursor.NextFeature())  !=   null )
{
ESRI.ArcGIS.Geometry.IGeometry geometry 
= feature.Shape;
ESRI.ArcGIS.Geometry.IEnvelope featureExtent 
= geometry.Envelope;
envelopeCls.Union(featureExtent);
haveFeatures 
= true;
if (getLayerExtent)
{
  ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset 
= (ESRI.ArcGIS.Geodatabase.IGeoDataset)featureLayer; // Explicit cast.
  if (geoDataset != null)
  
{
    ESRI.ArcGIS.Geometry.IEnvelope layerExtent 
= geoDataset.Extent;
    layersExtentCls.Union(layerExtent);
  }

getLayerExtent 
= false;
}

}

}

Point feature datasets

In cases of point feature datasets—since the extent of a point is very small—use a special scenario so that you can zoom in closer to the point geometry. You can have the following special scenarios:
 
Scenario one—You can have the width and height of the envelope equal to zero. To do this, zoom to the layer extent and multiply it by a zoom factor (for example, 0.05) that reduces the extent of the zoom. Make sure that the zoom to envelope is centered at the point selected. See the following code example:
 

[C#]  
double  width  =  envelopeCls.Width;
double  height  =  envelopeCls.Height;

if  (width  ==   0.0   &&  height  ==   0.0
{
 
double dim = 1.0;
 
bool bEmpty = layersExtentCls.IsEmpty;

 
if (!bEmpty)
 
{
   
double layerWidth = layersExtentCls.Width;
   
double layerHeight = layersExtentCls.Height;
   
double layerDim = System.Math.Max(layerWidth, layerHeight) * 0.05;
  
    
if (layerDim > 0.0)
    dim 
= System.Math.Min(1.0, layerDim);
 }


 
double xMin = envelopeCls.XMin;
 
double yMin = envelopeCls.YMin;

 ESRI.ArcGIS.Geometry.IPoint pointCls 
= new ESRI.ArcGIS.Geometry.PointClass();
 pointCls.X 
= xMin;
 pointCls.Y 
= yMin;
 envelopeCls.Width 
= dim;
 envelopeCls.Height 
= dim;
 envelopeCls.CenterAt(pointCls);
}
 
Scenario two—You can have the width or height of the envelope equal to zero. To do this, set the width and height of the envelope's zoom equal to the greater of the width or height of the extent of the selected point feature. See the following code example:
 

[C#]
else   if  (width  ==   0.0   ||  height  ==   0.0 )
{
double maxDim = System.Math.Max(width, height);
envelopeCls.Width 
= maxDim;
envelopeCls.Height 
= maxDim;
}
 
Once you have the extent of all the selected features, use the IGlobeCamera.SetToZoomToExtents() method. Here, you can pass the extent and the active viewer as the parameters. See the following code example:
 

[C#]   
globeCamera.SetToZoomToExtents(envelopeCls, globe, sceneViewer); 
sceneViewer.Redraw(
true ); 

ESRI.ArcGIS.Geometry.IEnvelope envelopeCls  =   new  EnvelopeClass();
envelopeCls.SetEmpty();
ESRI.ArcGIS.Geometry.IEnvelope layersExtentCls 
=   new  EnvelopeClass();
layersExtentCls.SetEmpty();
ESRI.ArcGIS.Geometry.IZAware ZAware 
=  (ESRI.ArcGIS.Geometry.IZAware)envelopeCls;  //  Explicit cast.
ZAware.ZAware  =  ( true );
ESRI.ArcGIS.Geodatabase.ISpatialFilter spatialFilterCls 
=   new  ESRI.ArcGIS.Geodatabase.SpatialFilterClass();
ESRI.ArcGIS.Geometry.ISpatialReference spatialReference 
=  scene.SpatialReference;
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值