windows编程入门之第一个程序
2009-04-10 09:42
519 查看
This article explains how to zoom to theextent of selected features in one layer or multiple layers on a globe.
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
Zoomingto selected features in globePointfeature datasetsScenariooneScenariotwoZooming to selected features in globe
Get all the layers present in the current globe document.Once you have a handle to the layers, loop through the layers and getall the features that are selected on the globe. See the following codeexample:[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);Get a handle to the globe camera. The globe camera will beused to zoom to the extent of the selected features on the globe. Seethe 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.The extent of the layers is stored in an envelope andbasically defines the area you need to zoom to. Make the envelopez-aware in cases when the features in the data have z-values or aredraped on an elevation surface.Keep track of the extent of the layer where features areselected. This is important when zooming to selected point features.Getting the extent of the point features is shown in the following codeexample: [C#]
ESRI.ArcGIS.Geometry.IEnvelope envelopeCls = newEnvelopeClass();envelopeCls.SetEmpty();ESRI.ArcGIS.Geometry.IEnvelope layersExtentCls = newEnvelopeClass();layersExtentCls.SetEmpty();ESRI.ArcGIS.Geometry.IZAware ZAware = (ESRI.ArcGIS.Geometry.IZAware)envelopeCls; // Explicit cast.ZAware.ZAware = (true);ESRI.ArcGIS.Geodatabase.ISpatialFilter spatialFilterCls = newESRI.ArcGIS.Geodatabase.SpatialFilterClass();ESRI.ArcGIS.Geometry.ISpatialReference spatialReference = scene.SpatialReference;Before looping through all the layers, define a Boolean tokeep track of any selected features in the layers and reset the counterto get the first layer stored in IEnumLayer. See the following codeexample: [C#]
boolhaveFeatures = false;enumLayer.Reset();To loop through the layers, use the whileloop. Ifno layers are present, break out of the code. See the following codeexample: [C#]
ESRI.ArcGIS.Carto.ILayer layer;while((layer = enumLayer.Next()) != null){if(layer == null)break;For each layer, get the feature selection set as shown inthe following code example. After getting the selection set, loopthrough individual features using the feature cursor and store thegeometry in the envelope.The important thing to note is that you are trying to zoom toa number of selected features. If there are multiple features in thesame feature class, keep updating the envelope of the extent by usingthe 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 CastESRI.ArcGIS.Geodatabase.ISelectionSet selectionSet = featureSelection.SelectionSet;ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureLayer.FeatureClass;stringshapeField = featureClass.ShapeFieldName;spatialFilterCls.GeometryField = shapeField;spatialFilterCls.set_OutputSpatialReference(shapeField, spatialReference);ESRI.ArcGIS.Geodatabase.ICursor cursor;selectionSet.Search(spatialFilterCls, true, outcursor);ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = (ESRI.ArcGIS.Geodatabase.IFeatureCursor)cursor; // Explicit cast.boolgetLayerExtent = 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 apoint is very small—use a special scenario so that you can zoom incloser to the point geometry. You can have the following specialscenarios:ScenariooneScenariotwo Scenario one—You can havethe width and height of the envelope equal to zero. To do this, zoom tothe 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 toenvelope is centered at the point selected. See the following codeexample: [C#]doublewidth = envelopeCls.Width;doubleheight = envelopeCls.Height;if(width == 0.0 && height == 0.0){doubledim = 1.0;boolbEmpty = layersExtentCls.IsEmpty;if(!bEmpty){doublelayerWidth = layersExtentCls.Width;doublelayerHeight = layersExtentCls.Height;doublelayerDim = System.Math.Max(layerWidth, layerHeight) * 0.05;if(layerDim > 0.0)dim = System.Math.Min(1.0, layerDim);}doublexMin = envelopeCls.XMin;doubleyMin = envelopeCls.YMin;ESRI.ArcGIS.Geometry.IPoint pointCls = newESRI.ArcGIS.Geometry.PointClass();pointCls.X = xMin;pointCls.Y = yMin;envelopeCls.Width = dim;envelopeCls.Height = dim;envelopeCls.CenterAt(pointCls);}Scenario two—You canhave the width or height of the envelope equal to zero. To do this, setthe width and height of the envelope's zoom equal to the greater of thewidth or height of the extent of the selected point feature. See thefollowing code example: [C#]
elseif(width == 0.0 || height == 0.0){doublemaxDim = System.Math.Max(width, height);envelopeCls.Width = maxDim;envelopeCls.Height = maxDim;}Once you have the extent of all the selected features, usethe IGlobeCamera.SetToZoomToExtents() method. Here, you can pass theextent and the active viewer as the parameters. See the following codeexample: [C#]
globeCamera.SetToZoomToExtents(envelopeCls, globe, sceneViewer);sceneViewer.Redraw(true);
相关文章推荐
- windows驱动编程入门(第一个程序)
- windows编程--第一个WinMain程序
- CUDA下的GPU编程入门--第一个CUDA程序
- Windows网络编程入门:简单的客户端和服务器通信程序调试
- Windows编程C++之第一个Windows程序
- Windows编程入门-创建第一个Window窗口
- Windows网络编程入门:简单的客户端和服务器通信程序调试
- C/C++_log2000_windows编程之第一个控制台程序项目part2
- GPU 编程入门到精通(二)之 运行第一个程序
- GPU 编程入门到精通(二)之 运行第一个程序
- Windows网络编程入门:简单的客户端和服务器通信程序调试
- Windows编程(1)-第一个程序
- Windows编程入门程序详解
- Windows编程入门程序详解
- 【C#入门】第一个C#下windows程序
- Windows网络编程入门:简单的客户端和服务器通信程序调试
- VC#初学入门:第一个Windows程序
- MFC入门(一)-- 第一个简单的windows图形化界面小程序(打开计算器,记事本,查IP)
- SHELL 编程入门与提高(一)第一个shell程序
- 【Window编程】Step.1 我的第一个Windows程序