`

How to zoom to selected features in globe

阅读更多

This article explains how to zoom to the extent of selected features in one layer or multiple layers on a globe.

 

Development licensing Deployment licensing
Engine Developer Kit Engine Runtime: 3D
ArcView: 3D Analyst ArcView: 3D Analyst
ArcEditor: 3D Analyst ArcEditor: 3D Analyst
ArcInfo: 3D Analyst ArcInfo: 3D Analyst

 

In this topic


[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
);
  1. 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:
 


[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.
  1. 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.
  2. 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#]

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;
  1. 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();
  1. To loop through the layers, use the while loop. If no layers are present, break out of the code. See the following code example:
 


[C#]

ESRI.ArcGIS.Carto.ILayer layer;

while
 ((layer = enumLayer.Next()) != null
)
{
if
 (layer == null
)
 break
;
  1. 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.
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.
 


[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
); 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

    How to animate the camera along a path (line feature) in globe

    在本文中,我们将探讨如何在三维地球(Globe)中沿着路径(线特征)动画化相机。这个功能主要涉及到ArcGIS的3D分析扩展,使用C#编程语言实现。在开始之前,确保已经包含了以下ESRI.ArcGIS相关的程序集: 1. ESRI....

    Apress.Beginning.Joomla.From.Novice.to.Professional.Jul.2007

    Beginning Joomla!: From Novice to Professional (c) by Apress The type of the release is: eBook In the PDF format with ISBN: 1590598482 and Pub Date...how to extend Joomla! by creating your own plug-ins.

    SkylineGlobe JavaScript开发示例代码

    SkylineGlobe是一款强大的3D地球可视化平台,它允许开发者创建互动式的、高度逼真的地球模型,用于数据可视化、地理信息系统(GIS)以及各种在线地图应用。本示例代码主要展示了如何利用JavaScript来操作和集成...

    Optimized C++(O'Reilly,2016)

    In today's fast and competitive world, a program's performance is just as important to customers as the features it provides. This practical guide teaches developers performance-tuning principles that...

    Docker-in-Action.pdf

    made earlier that day to hundreds of machines spread all over the globe. If big tech firms had an engineering advantage over the rest of the corporate landscape, this was it. Early in 2013, I wanted ...

    Web Performance in Action

    The content of the web is maturing and increasing in complexity, but internet infrastructure quality varies widely across the globe. People are browsing the web through a greater variety of devices ...

    World Map - Globe Edition 2 14.9

    World Political Map - Globe Edition 2 adds to your scene a beautiful and interactive 3D world map with just a couple of clicks. Drag the globe prefab to your scene and customize the look & feel. ...

    菲律宾Globe(运营商)华为替换项目参数继承策略

    Inter RNC Cell Update" UE Behaviors in Idle Mode Qqualmin Min quality level The minimum required quality threshold corresponding to CPICH Ec/No. The UE can camp on the cell only when the measured ...

    Globe 3D地球仪 2.2

    《Globe 3D地球仪 2.2:探索世界的华丽界面与多功能应用》 Globe 3D地球仪 2.2是一款专为用户提供全方位地球信息的软件,以其独特的3D显示技术,将地球的全貌以细腻、生动的方式展现出来。这款应用不仅在视觉效果上...

    Learning Apache Spark 2

    Based out of London, Asif has vast experience in consulting for major organizations & industries across the globe, and running proof-of-concepts across various industries including but not limited to ...

    GPU Pro 360 Guide to Geometry Manipulation pdf2018

    They also show how to simulate erosion in real time. The chapter “Vertex Shader Tessellation” by Holger Gruen presents a method to implement tessellation using only the vertex shader. It requires ...

    Globe - Data Visualizer.unitypackage

    This package uses TextMeshPro, Please Import it in your project in order to make this package works properly This project is Unity3D implementation for WebGL-Globe created by Google Data Arts Team.

    Optimized C++ 2016新书 无水印pdf 0分

    You’ll learn how to make code that already embodies best practices of C++ design run faster and consume fewer resources on any computer—whether it’s a watch, phone, workstation, supercomputer, or ...

    SkylineGlobe v7.0最新产品技术白皮书

    SkylineGlobe v7.0是一款由泰瑞天际科技(北京)有限公司推出的三维地理信息云服务平台产品,它代表了当前三维空间数据可视化技术的先进水平。SkylineGlobe v7.0集成了应用程序、工具和服务,旨在帮助用户创建和发布...

    Skyline Globe Server下载(中文)

    Skyline Globe Server是一款专业的地理信息系统(GIS)服务器软件,它为用户提供了一个强大的平台来管理和分发地理空间数据。这款软件的核心功能是支持大规模三维地球模型的实时渲染和交互,广泛应用于城市规划、...

    Modern.Python.Cookbook.epub

    The recipes take a problem-solution approach to resolve issues commonly faced by Python programmers across the globe. You will be armed with the knowledge of creating applications with flexible ...

    Packt.Containers.in.OpenStack.1788394380 ePub

    OpenStack gets tremendous traction as it is used by many organizations across the globe and as containers gain in popularity and become complex, it’s necessary for OpenStack to provide various ...

    Research Advances in Cloud Computing-Springer(2017).pdf

    Their key challenge is to manage resources in an optimal way and to estimate how physical and logical failures can impact on users’ perception. The second chapter on “Highly Available Clouds: ...

Global site tag (gtag.js) - Google Analytics