AE 配准栅格图片

落花浮王杯 提交于 2019-11-27 04:48:32

背景:我有n副不同时间段的太平洋地区的bmp图片,想加载到axmapcontrol中,但是不想一幅幅手动配准生成bpw,工作量太大。

原理:将需要配准的图片放到axmapcontrol中,得到它的初始范围,接着定下配准范围(定死,太平洋),最后源文件下后配准文件了,重新加载图片即可。

代码:

        private void Adjust_Click(object sender, EventArgs e)
        {
            double pX, pY;
            IRasterDataset2 rasterDataset = new RasterDatasetClass();

            object obj = Type.Missing;

            IRasterLayer pRasterLayer = (IRasterLayer)this.axMapControl1.Map.get_Layer(0);//找到bmp图

            IRaster pRaster = pRasterLayer.Raster;

            rasterDataset.OpenFromFile(pRasterLayer.Name);

            IGeoDataset pGeoDataset = (IGeoDataset)pRaster;

            IEnvelope2 pEnv2 = new EnvelopeClass();//得到bmp在axmapcontrol中的范围

            pEnv2 = (IEnvelope2)pGeoDataset.Extent;

            IPoint pPoint = pEnv2.UpperLeft;//bmp左上角点坐标

           
            IPointCollection sourcePoints = new MultipointClass();
            IPointCollection targetPoints = new MultipointClass();
            
            IPoint pPoint1 = new PointClass();//定义6个控制点
            IPoint pPoint2 = new PointClass();
            IPoint pPoint3 = new PointClass();
            IPoint pPoint4 = new PointClass();
            IPoint pPoint5 = new PointClass();
            IPoint pPoint6 = new PointClass();

            pPoint1.X = pEnv2.XMin;//图片左上角原始位置
            pPoint1.Y = pEnv2.YMax;
            pPoint2.X = pEnv2.XMax;//图片右下角原始位置
            pPoint2.Y = pEnv2.YMin;
            pPoint3.X = 20;//图片左上角配准后位置
            pPoint3.Y = 90;
            pPoint4.X = 380;//图片右下角配准后位置
            pPoint4.Y = -90;
            pPoint5.X = pEnv2.XMin;//图片左下角原始位置
            pPoint5.Y = pEnv2.YMin;
            pPoint6.X = 20;//图片左下角配准后位置
            pPoint6.Y = -90;
            sourcePoints.AddPoint(pPoint1, ref obj, ref obj);
            sourcePoints.AddPoint(pPoint2, ref obj, ref obj);
            sourcePoints.AddPoint(pPoint5, ref obj, ref obj);
            targetPoints.AddPoint(pPoint3, ref obj, ref obj);
            targetPoints.AddPoint(pPoint4, ref obj, ref obj);
            targetPoints.AddPoint(pPoint6, ref obj, ref obj);
            GeoreferenceRaster(rasterDataset, sourcePoints, targetPoints); //配准
        }

        /// <summary>
        /// 配准
        /// </summary>
        /// <param name="rasterDataset"></param>
        /// <param name="sourcePoints"></param>
        /// <param name="targetPoints"></param>
        public static void GeoreferenceRaster(IRasterDataset2 rasterDataset, IPointCollection sourcePoints, IPointCollection targetPoints)
        {
            IRasterGeometryProc rasterPropc = new RasterGeometryProcClass();
            IRaster raster = rasterDataset.CreateDefaultRaster();  //set the transformatin
            rasterPropc.Warp(sourcePoints, targetPoints, esriGeoTransTypeEnum.esriGeoTransPolyOrder1, raster);//核心,wrap事件
            rasterPropc.Register(raster);//注册,生成配准文件处。。此时在源文件目录下
            //rasterPropc.Rectify(@"d:\georeferencing_output.img", "IMAGINE Image", raster);//另存为
        }

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!