• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

gisoracle

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

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

posted on 2015-04-05 12:50  gisai  阅读(716)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3