2,143
社区成员
发帖
与我相关
我的任务
分享
//三点配准
{
IRasterLayerPtr pLayer(CLSID_RasterLayer);
BSTR wPath = A2BSTR(path.c_str());
HRESULT hr = pLayer->CreateFromFilePath(wPath);
::SysFreeString(wPath);
if(!SUCCEEDED(hr))
continue;
IGeoReferencePtr pGeoRef;
hr = pLayer.QueryInterface(__uuidof(IGeoReference), &pGeoRef);
if(!SUCCEEDED(hr))
continue;
VARIANT_BOOL canGeoRef = false;
hr = pGeoRef->get_CanGeoRef(&canGeoRef);
if(!SUCCEEDED(hr) || !canGeoRef)
continue;
IRasterPtr pRaster;
hr = pLayer->get_Raster(&pRaster);
if(!SUCCEEDED(hr))
continue;
IRasterPropsPtr pRasterProps;
hr = pRaster.QueryInterface(__uuidof(IRasterProps), &pRasterProps);
if(!SUCCEEDED(hr))
continue;
long width, height;
hr = pRasterProps->get_Width(&width);
if(!SUCCEEDED(hr))
continue;
hr = pRasterProps->get_Height(&height);
if(!SUCCEEDED(hr))
continue;
IPointCollectionPtr fromPts(CLSID_Polyline);
IPointPtr fromPointLeftTop(CLSID_Point);
hr = fromPointLeftTop->PutCoords(0, 0);
hr = fromPts->AddPoint(fromPointLeftTop);
IPointPtr fromPointLeftButtom(CLSID_Point);
hr = fromPointLeftButtom->PutCoords(0, height);
hr = fromPts->AddPoint(fromPointLeftTop);
IPointPtr fromPointRightButtom(CLSID_Point);
hr = fromPointRightButtom->PutCoords(width, height);
hr = fromPts->AddPoint(fromPointRightButtom);
IPointCollectionPtr toPts(CLSID_Polyline);
IPointPtr toPointLeftTop(CLSID_Point);
hr = toPointLeftTop->PutCoords(0, 0);
hr = toPts->AddPoint(toPointLeftTop);
IPointPtr toPointLeftButtom(CLSID_Point);
hr = toPointLeftButtom->PutCoords(0, 1);
hr = toPts->AddPoint(toPointLeftButtom);
IPointPtr toPointRightButtom(CLSID_Point);
hr = toPointRightButtom->PutCoords(1, 1);
hr = toPts->AddPoint(toPointRightButtom);
hr = pGeoRef->Warp(fromPts, toPts, 0);
if(!SUCCEEDED(hr))
continue;
hr = pGeoRef->Register();
if(!SUCCEEDED(hr))
continue;
}
hr = pGeoRef->Register();
if(!SUCCEEDED(hr))
continue;
IRasterGeometryProcPtr pRasterGProc(CLSID_RasterGeometryProc);
hr = pRasterGProc->Warp(fromPts, toPts, esriGeoTransPolyOrder1,pRaster);
if(!SUCCEEDED(hr))
continue;
hr = pRasterGProc->Register(pRaster);
if(!SUCCEEDED(hr))
continue;
hr = pGeoRef->Register();
if(!SUCCEEDED(hr))
continue;
IMapControl4Ptr smpMapControl = GetView()->GetMapControl()->GetIMapControl4Ptr();
smpMapControl->AddLayer(pLayer, 0);