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);
时间: 2024-10-11 01:25:03

zoom to raster resolution的相关文章

openlayers-热地图加载(完整版及代码)

//地圖加載function mapInit(data){ //底图// var raster = new ol.layer.Tile({// source: new ol.source.Stamen({// layer: 'toner'// })// }); var projection = new ol.proj.Projection({ code: 'EPSG:4326',// ||mapdata.code, extent: [data.map.minX, data.map.minY, d

瓦片切图工具gdal2tiles.py改写为纯c++版本

gdal2tiles.py是GDAL库中用于生成TMS瓦片的python代码,支持谷歌墨卡托EPSG:3857与经纬度EPSG:4326两种瓦片,输出png格式图像. gdal2tiles.py More info at: http://wiki.osgeo.org/wiki/Tile_Map_Service_Specificationhttp://wiki.osgeo.org/wiki/WMS_Tiling_Client_Recommendationhttp://msdn.microsoft.

矢量转栅格

#!/usr/bin/env python # -*- coding: utf-8 -*- from osgeo import ogr from osgeo import gdal # set pixel size pixel_size = 0.00002 no_data_value = -9999 # Shapefile input name # input projection must be in cartesian system in meters # input wgs 84 or E

完整版openlayer的例子及中文注释(完整中文版)

//@sourceURL=PersonLocation.jsvar window_temp = { onbeforeunload: null, DEBUG_MODE: false, MAPLIST: null, MAPLIST_CACHE: {}, MAP: null, MAP_LAYERS: null, LAYER: ['basic', 'area', 'device', 'person', 'single', 'building'], MAP_CTRLS: null, CTRLS: ['sc

栅格那点儿事(一)---Raster是个啥子东西

Raster是个啥子东西 现如今,不仅是在遥感应用中能看到花花绿绿的影像了,在GIS应用中也能随处看到她们的身影.在各种在线地图中,卫星影像作为底图与矢量的道路层叠加:高程DEM作为高程来源实现地形的山影效果.相信大家对影像这个词,应该一点儿也不感到陌生. 那么栅格呢?相对与我们熟悉的影像,这俩只是名词上的区别么? 栅格(Raster)和影像(Images/Imagery)在GIS应用中经常被相互指代.如果非要区别一下呢,影像是指通过各种遥感设备,传感器,或者照相机得到的电子的或者纸质的图片,栅

百度地图API一:根据标注点坐标范围计算显示缩放级别zoom自适应显示地图

百度地图中根据页面中的point,自动设置缩放级别和视图中心,将所有的point在视图范围内展示. var points = [point1, point2,point3]; var view = map.getViewport(eval(points)); var mapZoom = view.zoom; var centerPoint = view.center; map.centerAndZoom(centerPoint,mapZoom);

css中zoom:1以及z-index的作用

一.CSS中zoom:1的作用在做IE6.IE7.IE8浏览器兼容的时候,经常会遇到一些问题,可以使用zoom:1来解决,有如下作用:1.触发IE浏览器的haslayout2.解决IE下的浮动,margin重叠等一些问题. 二.z-index:auto|number; ◆auto遵从其父对象的定位 ◆number无单位的整数值.可为负数CSS样式,把z-index设置为999或很大,是什么意思?z-index是针对网页显示中的一个特殊属性.因为显示器是显示的图案是一个二维平面,拥有x轴和y轴来表

栅格数据处理 RasterDataset RasterLayer Raster RasterBandCollection

1 IRasterLayer myrasterlayer = MapControl.Map.Layer[index] as IRasterLayer;2 IRaster myRaster = myrasterlayer.Raster;3 IRasterBandCollection myRasterBandCollection = myRaster as IRasterBandCollection;4 IRasterBand myRasterBand = myRasterBandCollectio

HTML CSS——zoom的学习

上大学做阶段项目时遇到了一个很奇特的现象:kindEditor上传图片功能失效,但是把jsp所引用的样式去掉就好用,这说明样式有问题,于是删一个样式测试一下,就这样罪魁祸首落在了zoom身上,这是我们第一次"相识",今天周末,难得的清闲,现总结一下: 首先说一下zoom的作用:zoom用来设置对象的缩放比例: zoom属性值:normal | <number> | <percentage> 一.normal: 代码1-1如下: <!DOCTYPE html