zoom to raster resolution
don't execute the ESRI's command, just find out and write codes to zoom to the raster resolution. Here they are, I hope they will help. Unfortunately (to you) I wrote these codes under C#. I hope you could manage the transfer these codes to VB. If not, feel free to contact me for further help. Because of this I'll write here some theory of mine too. There are two possible way to solve this question. 1. You want to run this under ArcMap (ArcCatalog) environment. 2. You want to use this under your own MapControl and ToolBarControl with a raster (picture) where the Spatial Reference wasn't set. My solutions: 1. You can work with MxDoc and you have set up Spatial Reference for the Map. Therefore you can use the IRasterOutputSettings::RasterRatio method, which will give back the necessary ratio (number). In this case you can cast (QI in VB) to this interface from IDisplayTransformation. Finally the formula here to calculate the raster resolution is: new map scale = old map scale / raster ratio. See the code later. 2. If you use a raster or a picture (in my case it was a raster from a raster field directly) and the Spatial Reference wasn't set for the layer or a map the raster ratio will give back 1, and it isn't so useful in the previous dividing formula. In this case you have to query the size of the mapcontrol, the size of the raster layer and use them in this relation formula: map control width / raster width = wanted map scale / known, FULL extent map scale. (If you want to use this later then you have to store the very first or the necessary raster full extent's scale! In the sample code below I didn't do that.) from this: wanted map scale = map control width / raster width * known, FULL extent map scale. I hope these will help. And the (C#) code cores are... |
|
1.: //get MxDocumnet, cast (QI in VB), under VBA you can use it instantly IMxDocument mxDoc = m_app.Document as IMxDocument; //get the ActiveView IActiveView pActiveView = mxDoc.ActiveView; //get the DisplayTransformation IDisplayTransformation pDisplayTransformation = pActiveView.ScreenDisplay.DisplayTransformation; //the scale of the map (the IMap::MapScale is a shortcut to this method) double mapScale = pDisplayTransformation.ScaleRatio; //get the RasterOutputSettings, with a cast (QI in VB) from IDisplayTransformation IRasterOutputSettings pRasterOutputSettings = pDisplayTransformation as IRasterOutputSettings; //raster ratio, see the help for discussion of the ratio number double rasterRatio = pRasterOutputSettings.RasterRatio; //the formula for the raster resolution pDisplayTransformation.ScaleRatio = (mapScale / rasterRatio) //refreshing the map pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); 2.: //get the Map IMap pMap = m_HookHelper.FocusMap; //get the raster layer, with cast (QI in VB) from ILayer, in my map it was the layer at 0 index IRasterLayer pRasterLayer = pMap.get_Layer( 0 ) as IRasterLayer; //width of the MapControl control on the form int controlWidth = pMapControl.Width; //because in the formula, you have to use the width as an explicitly converted double number in C# double controlW = Convert.ToDouble( controlWidth ); //the formula for the raster resolution pMap.MapScale = (controlW / pRasterLayer.ColumnCount * pMap.MapScale) //get the ActiveView IActiveView pActiveView = m_HookHelper.ActiveView; //refreshing the map pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); |
分类:
arcgis
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
2013-04-05 C# 获取屏幕的大小
2012-04-05 ArcEngine开发——在64位操作系统下使用VS2010中开发ArcEngine应用程序的编译问题
2012-04-05 ae中gp执行 Error HRESULT E_FAIL has been returned from a call to a COM component错误
2012-04-05 C# 建立快捷方式
2012-04-05 AE编辑-点要素编辑
2012-04-05 AE编辑-线要素编辑
2012-04-05 arcmap 启动打开指定的mxd