您的位置:首页 > 其它

在ArcGlobe三维环境中进行数据查询2(模型定位显示)

2014-01-03 15:18 405 查看
代码如下:

void dataGridView1_CellClick(object sender,DataGridViewCellEventArgs e)

{

//取查询条件

StringstrCode = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();

if (strCode== String.Empty)

{

return;

}

//取查询图层名称

StringLayerName = this.comboBox1.SelectedItem.ToString();

//获得当前视图

IScene scene= this.axGlobe.Globe.GlobeDisplay.Scene;

IQueryFilter pQueryFilter = new QueryFilterClass();

IActiveViewpActiveView;

pActiveView= (IActiveView)scene;

//清空上一次选择

scene.ClearSelection();

IFeatureLayer pFeatureLayer;

pFeatureLayer= (IFeatureLayer)scene.get_Layer(GetLayerId(LayerName, scene));

pQueryFilter.WhereClause = “NAME=”" + strCode + “”";

IFeatureCursor pFeatureCursor;

pFeatureCursor = pFeatureLayer.FeatureClass.Search(pQueryFilter, false);

IFeaturepFeature;

pFeature =pFeatureCursor.NextFeature();

while(pFeature != null)

{

scene.SelectFeature(pFeatureLayer, pFeature);

pFeature = pFeatureCursor.NextFeature();

}

ESRI.ArcGIS.Carto.ILayer layer =(ESRI.ArcGIS.Carto.ILayer)scene.get_Layer(GetLayerId(LayerName, scene));

// Get theline feature selected in the layer

ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = (ESRI.ArcGIS.Carto.IFeatureLayer)layer;

ESRI.ArcGIS.Carto.IFeatureSelection featureSelection =(ESRI.ArcGIS.Carto.IFeatureSelection)layer;

ESRI.ArcGIS.Geodatabase.ISelectionSet selectionSet =featureSelection.SelectionSet;

ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureLayer.FeatureClass;

stringshapeField = featureClass.ShapeFieldName;

ESRI.ArcGIS.Geodatabase.ISpatialFilter spatialFilterCls = newESRI.ArcGIS.Geodatabase.SpatialFilterClass();

ESRI.ArcGIS.Geometry.ISpatialReference spatialReference =scene.SpatialReference;

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;

ESRI.ArcGIS.Geodatabase.IFeature SFeature;

SFeature =featureCursor.NextFeature();

ESRI.ArcGIS.Geometry.IEnvelope envelope = SFeature.Shape.Envelope;

ESRI.ArcGIS.Analyst3D.ICamera camera =this.axGlobe.Globe.GlobeDisplay.ActiveViewer.Camera;

ESRI.ArcGIS.GlobeCore.IGlobeCamera globeCamera =(ESRI.ArcGIS.GlobeCore.IGlobeCamera)camera;

ESRI.ArcGIS.Analyst3D.ISceneViewer sceneViewer =this.axGlobe.Globe.GlobeDisplay.ActiveViewer;

globeCamera.OrientationMode =esriGlobeCameraOrientationMode.esriGlobeCameraOrientationGlobal;

IPointtarget = new PointClass();

target.PutCoords(0, 0);

target.Z =0;

axGlobe.Globe.GlobeDisplay.ActiveViewer.Camera.Target = target;

axGlobe.Globe.GlobeDisplay.ActiveViewer.Camera.ViewingDistance = 1.5;

axGlobe.Globe.GlobeDisplay.ActiveViewer.Camera.ViewFieldAngle = 8.5;

axGlobe.Globe.GlobeDisplay.ActiveViewer.Camera.RollAngle = 0.0;

axGlobe.Globe.GlobeDisplay.ActiveViewer.Camera.RecalcUp();

//定位

globeCamera.SetToZoomToExtents(envelope, this.axGlobe.Globe, sceneViewer);

//显示比例调整

double vfa =this.axGlobe.Globe.GlobeDisplay.ActiveViewer.Camera.ViewFieldAngle;

axGlobe.Globe.GlobeDisplay.ActiveViewer.Camera.ViewFieldAngle = vfa * 6;

axGlobe.Globe.GlobeDisplay.ActiveViewer.Redraw(false);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: