資源共享] IDL開發(fā)專題-IDL下的坐標系及示例
本帖最后由 lianyi_dyq 于 2009-12-23 11:27 編輯
IDL下常用的坐標系有下面三種: %設備坐標體系(顯示屏幕、打印機紙張) %規(guī)一化坐標體系 %數(shù)據(jù)坐標體系 無論采用任何的坐標系,顯示對象的坐標都要統(tǒng)一到當前坐標范圍內(nèi),只有統(tǒng)一了坐標才能正確的顯示數(shù)據(jù)。 下面的例子源碼說明了如何應用這三個坐標系。
PRO test_idlcoord ; oWindow = OBJ_NEW('IDLgrWindow', $ retain =2, $ DIMENSIONS = [800,400]) ;顯示體系結(jié)構(gòu) oView = OBJ_NEW('IDLgrView') shapeModel = OBJ_NEW('IDLgrModel') imageModel= OBJ_NEW('IDLgrModel') oTopModel= OBJ_NEW('IDLgrModel') oTopModel->add,[imageModel,shapeModel] oView->add,oTopModel ;讀取數(shù)據(jù) file = filepath( 'day.jpg', SUBDIRECTORY=['examples','data'] ) READ_JPEG, file,imageData ; Resize the image data imageData = congrid(imageData,3,360,180) oImage = OBJ_NEW('IDLgrImage', $ imageData) imageModel->add,oImage ;讀取矢量文件 shpFilename = filepath( 'shape\continents.shp', SUBDIRECTORY=['resource','maps'] ) shapeFile = OBJ_NEW('IDLffShape', shpFileName) shapeFile->getproperty, N_Entities = nEntities FOR i=0, nEntities-1 DO BEGIN entitie = shapeFile->getentity(i) IF PTR_VALID(entitie.parts) NE 0 THEN BEGIN cuts = [*entitie.parts, entitie.n_vertices] FOR j=0, entitie.n_parts-1 DO BEGIN tempLon = (*entitie.vertices)[0,cuts[j]:cuts[j+1] - 1] tempLat = (*entitie.vertices)[1,cuts[j]:cuts[j+1] - 1] ;轉(zhuǎn)換到當前圖像坐標下 tempLon = (REFORM(tempLon) -(-180)) tempLat = (REFORM(tempLat) -(-90)) ; num = N_ELEMENTS(tempLon) polylines = LINDGEN(num+1)-1 polylines[0] = num tempPlot = OBJ_NEW('IDLgrPolyline', $ tempLon, $ tempLat, $ Polylines = polyLines , $ Alpha_Channel = 1, $ color = [255,0,0]) shapeModel->add,tempPlot ENDFOR ENDIF shapeFile->destroyentity, entitie ENDFOR ; ; 圖像坐標顯示 oView->setproperty, viewPlane_Rect = [0,0,800,400] oWindow->SetProperty, title ='圖像坐標顯示' oWindow->draw,oView ;停頓兩秒 wait,2 ;歸一化坐標顯示 ;銷毀原來的 OBJ_DESTROY,oTopModel ;建立新的 shapeModel = OBJ_NEW('IDLgrModel') imageModel= OBJ_NEW('IDLgrModel') oTopModel= OBJ_NEW('IDLgrModel') oTopModel->add,[imageModel,shapeModel] oView->add,oTopModel ; oImage = OBJ_NEW('IDLgrImage', $ imageData) imageModel->add,oImage ;獲取當前圖像對象的X、Y方向的范圍 oImage->getproperty, xRange = xRange,yRange = yRange ;求出歸一化系數(shù) xr = norm_coord(xRange) ;解析:xrange =[0,360],xr是兩個參數(shù),[-0.00000000 ,0.0027777778],通過設置該參數(shù), ;那么轉(zhuǎn)換后x方向的原數(shù)據(jù)坐標為xr[0]+xr[1]*xrange[0]= -0+0.002777*0 = 0 ; xr[0]+xr[1]*xRange[1]= -0+0.002777*360 =1 ; 可測試 Norm_Coord([-100,100]) = [0.500000 , 0.00500000] ; yr = norm_coord(yRange) oImage->setproperty, xCoord_conv = xr, $ yCoord_conv = yr ; shapeFile = OBJ_NEW('IDLffShape', shpFileName) shapeFile->getproperty, N_Entities = nEntities FOR i=0, nEntities-1 DO BEGIN entitie = shapeFile->getentity(i) IF PTR_VALID(entitie.parts) NE 0 THEN BEGIN cuts = [*entitie.parts, entitie.n_vertices] FOR j=0, entitie.n_parts-1 DO BEGIN tempLon = (*entitie.vertices)[0,cuts:cuts[i+1] - 1] tempLat = (*entitie.vertices)[1,cuts[j]:cuts[j+1] - 1] ; ;轉(zhuǎn)換到歸一化的坐標系下顯示 tempLon = FLOAT((REFORM(tempLon) -(-180))) /360. tempLat = FLOAT((REFORM(tempLat) -(-90)))/180. ; num = N_ELEMENTS(tempLon) polylines = LINDGEN(num+1)-1 polylines[0] = num tempPlot = OBJ_NEW('IDLgrPolyline', $ tempLon, $ tempLat, $ Polylines = polyLines , $ Alpha_Channel = 1, $ color = [255,0,0]) shapeModel->add,tempPlot ENDFOR ENDIF shapeFile->destroyentity, entitie ENDFOR ; ; 設置顯示區(qū)域坐標 oView->setproperty, viewPlane_Rect = [0,0,1,1] oWindow->SetProperty, title ='歸一化坐標顯示' oWindow->draw,oView ;停頓兩秒 wait,2 ;地理坐標顯示 ;銷毀原來的 OBJ_DESTROY,oTopModel ;建立新的 sMap = map_proj_init('Interrupted Goode') ; 或用下面的投影 ; ;全球的“等距圓柱投影” ; sMap = Map_Proj_Init('Equirectangular' , $ ; Limit = [-90,-180,90,180] , $ ; Center_Longitude = 0 ) shapeModel = OBJ_NEW('IDLgrModel') imageModel= OBJ_NEW('IDLgrModel') oTopModel= OBJ_NEW('IDLgrModel') oTopModel->add,[imageModel,shapeModel] oView->add,oTopModel ; ;對圖像進行糾正 ; red= REFORM(imageData[0,*,*]) green= REFORM(imageData[1,*,*]) blue= REFORM(imageData[2,*,*]) red1 = map_proj_image( red, MAP_STRUCTURE=sMap, MASK=mask, $ UVRANGE=uvrange, XINDEX=xindex, YINDEX=yindex ) green1 = map_proj_image( green, XINDEX=xindex, YINDEX=yindex ) blue1 = map_proj_image( blue, XINDEX=xindex, YINDEX=yindex ) imageData = BYTARR(4,360,180) imageData[0,*,*] = red1 imageData[1,*,*] = green imageData[2,*,*] = blue ;設置掩膜 imageData[3,*,*] = mask*255b ; uRange = uvRange[2]-uvRange[0] vRange = uvRange[3]-uvRange[1] oImage = OBJ_NEW('IDLgrImage', $ imageData, $ BLEND_FUNCTION = [3, 4], $ dimensions=[uRange,vRange], $ ;維數(shù)--大地坐標 location=uvRange[0:1] ) ;位置--大地坐標 imageModel->add,oImage ; ; shapeFile = OBJ_NEW('IDLffShape', shpFileName) shapeFile->getproperty, N_Entities = nEntities FOR i=0, nEntities-1 DO BEGIN entitie = shapeFile->getentity(i) IF PTR_VALID(entitie.parts) NE 0 THEN BEGIN cuts = [*entitie.parts, entitie.n_vertices] FOR j=0, entitie.n_parts-1 DO BEGIN tempLon = (*entitie.vertices)[0,cuts[j]:cuts[j+1] - 1] tempLat = (*entitie.vertices)[1,cuts[j]:cuts[j+1] - 1] ; ;轉(zhuǎn)換到m制坐標系下顯示 vert = MAP_PROJ_FORWARD([tempLon,tempLat], $ Map_Structure = sMap, $ Polylines = polyLines) ; tempPlot = OBJ_NEW('IDLgrPolyline', $ vert[0,*], $ vert[1,*], $ Polylines = polyLines , $ Alpha_Channel = 1, $ color = [255,0,0]) shapeModel->add,tempPlot ENDFOR ENDIF shapeFile->destroyentity, entitie ENDFOR ; ; 設置顯示區(qū)域坐標 oView->setproperty, viewPlane_Rect = [uvrange[0],uvrange[1],uRange,vRange] oWindow->SetProperty, title ='Interrupted Goode 投影下m制坐標顯示' oWindow->draw,oView
|
|