zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    Cordova4.0 系列 -- 基本环境搭建(1)
    随便写写2015创业记(三)
    有哪些好用的数据分析工具?
    文字检测识别系统好用吗?都针对什么进行识别?
    用户奖励体系有哪些反作弊的机制?
    1月第2周业务风控关注|“扫黄打非”部门查处互动作业、纳米盒等20多个学习类App
    一个docker容器中运行多个服务还是弄一堆docker容器运行?
    手机app有了短信验证码还有没必要有图片验证码?
    2019年微服务实践第一课,网易&谐云&蘑菇街&奥思技术大咖深度分享
    1月第1周业务风控关注| 国家网信办启动专项行动 剑指12类违法违规互联网信息
  • 原文地址:https://www.cnblogs.com/gisoracle/p/4393987.html
Copyright © 2011-2022 走看看