How to zoom to selected features in globe
2013-07-18 22:21
357 查看
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);
相关文章推荐
- 【20091012-01】How to zoom to selected features in globe
- 在ArcGlobe中如何聚焦到选择的图元(How to zoom to selected features in globe)
- Zoom to Selected Globe Features
- 如何在ArcGlobe中实现zoomtolayer (How to zoom to layer in globe)
- Zoom to Selected Globe Features
- Zoom to Selected Globe Features
- Zoom to Selected Globe Features
- Zoom to Selected Globe Features
- 如何在ArcGlobe中实现zoomtolayer (How to zoom to layer in globe)
- How to access the features in an in-memory output layer using an IFeatureCursor
- arcengine 放大到选择集,Zoom to selected features using ArcObject
- How to enable zoom in UIScrollView
- Zoom to selected features using ArcObjects
- How to combine the features in the DefaultSelection
- How to pass selected records from form to dilog in AX 2012
- how to enable compile features in cmake
- How to Capture the Row Selected on Search Page In a Variable?
- how to zoom in/out in mac
- 转载:How to use Multi-touch in Android 2: Part 6, Implementing the Pinch Zoom Gesture
- How to get and set the drawing order of layers in globe(获取并设置Globe图层的叠加次序:)