/// <summary> /// 配准 后面两个参数是保存的文件和类型 /// </summary> /// <param name="pFromPoint"></param> /// <param name="pTPoint"></param> /// <param name="pRasterLayer"></param> /// <param name="pSaveFile"></param> /// <param name="pType"></param> public bool GeoReferencing(IPointCollection pFromPoint, IPointCollection pTPoint, IRasterLayer pRasterLayer, ISpatialReference pSr, string pSaveFile, string pType) { IGeoReference pGeoreference; pGeoreference = (IGeoReference)pRasterLayer; IRaster pRaster = pRasterLayer.Raster; //判断是否可以配准 if (pGeoreference.CanGeoRef == true) { IRasterGeometryProc pRasterGProc = new RasterGeometryProcClass(); pRasterGProc.Warp(pFromPoint, pTPoint, esriGeoTransTypeEnum.esriGeoTransPolyOrder2, pRaster); pRasterGProc.Register(pRaster); IRasterProps pRasterPro = pRaster as IRasterProps; pRasterPro.SpatialReference = pSr;//定义投影 if (File.Exists(pSaveFile)) { File.Delete(pSaveFile); } pRasterGProc.Rectify(pSaveFile, pType, pRaster);//路径和格式(String) return(true); } else { return(false); } }
private void DrawRaster(string file) { try { Logger.Debug("Start drawing tile" + file + "..."); IRasterLayer rl = new RasterLayerClass(); rl.CreateFromFilePath(file); var props = (IRasterProps)rl.Raster; props.SpatialReference = _dataSpatialReference; if (_needReproject) { IRasterGeometryProc rasterGeometryProc = new RasterGeometryProcClass(); var missing = Type.Missing; rasterGeometryProc.ProjectFast(_layerSpatialReference, rstResamplingTypes.RSP_NearestNeighbor, ref missing, rl.Raster); } // Fix for issue "Each 256x256 tile rendering differently causing blockly effect." // In 10.1 the StrecthType for rasters seems to have changed from esriRasterStretch_NONE to "Percent Clip", // giving color problems with 24 or 32 bits tiles. // http://arcbrutile.codeplex.com/workitem/11207 var image = new Bitmap(file, true); var format = image.PixelFormat; if (format == PixelFormat.Format24bppRgb || format == PixelFormat.Format32bppArgb || format == PixelFormat.Format32bppRgb) { var rasterRGBRenderer = new RasterRGBRendererClass(); ((IRasterStretch2)rasterRGBRenderer).StretchType = esriRasterStretchTypesEnum.esriRasterStretch_NONE; rl.Renderer = rasterRGBRenderer; } rl.Renderer.ResamplingType = rstResamplingTypes.RSP_BilinearInterpolation; // Now set the spatial reference to the dataframe spatial reference! // Do not remove this line... rl.SpatialReference = _layerSpatialReference; //rl.Draw(ESRI.ArcGIS.esriSystem.esriDrawPhase.esriDPGeography, (IDisplay)activeView.ScreenDisplay, null); rl.Draw(esriDrawPhase.esriDPGeography, _display, null); //activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, trackCancel, env); Logger.Debug("End drawing tile."); } // ReSharper disable once EmptyGeneralCatchClause catch (Exception) { // what to do now... // just try to load next tile... } }
public override void Draw(esriDrawPhase drawPhase, IDisplay display, ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel) { var file = @"D:\aaa\strava_issue\2016_1350.png"; var rl = new RasterLayerClass(); rl.CreateFromFilePath(file); var props = (IRasterProps)rl.Raster; props.SpatialReference = new SpatialReferences().GetSpatialReference("urn: ogc:def: crs:EPSG: 6.18.3:3857"); IRasterGeometryProc3 rasterGeometryProc = new RasterGeometryProcClass(); var missing = Type.Missing; var layerSpatialReference = sp; rasterGeometryProc.ProjectFast(layerSpatialReference, rstResamplingTypes.RSP_NearestNeighbor, ref missing, rl.Raster); // fix 9/10/2015: with projected tiles color changes and transparency is ignored. var image = new Bitmap(file, true); // image.MakeTransparent(Color.White); //image.Save(@"D:\aaa\strava_issue\2018_1350.png"); var format = image.PixelFormat; if (format == PixelFormat.Format24bppRgb | format == PixelFormat.Format32bppArgb) { var rasterRgbRenderer = new RasterRGBRendererClass(); ((IRasterStretch2)rasterRgbRenderer).StretchType = esriRasterStretchTypesEnum.esriRasterStretch_NONE; // ((IRasterStretch3)rasterRgbRenderer).UseGamma = true; ((IRasterStretch2)rasterRgbRenderer).Background = true; ((IRasterStretch3)rasterRgbRenderer).UseGamma = true; var r = new RgbColorClass(); r.Red = 49; r.Green = 0; r.Blue = 38; ((IRasterStretch2)rasterRgbRenderer).BackgroundColor = r; //((IRasterStretch2)rasterRgbRenderer).BackgroundColor = r; rl.Renderer = rasterRgbRenderer; } // end fix 9/10/2015: with projected tiles color changes and transparency is ignored. rl.Draw(esriDrawPhase.esriDPGeography, display, null); }
/// <summary> /// 地理配准 /// </summary> /// <param name="pFromPoint">采集点集</param> /// <param name="pTPoint">输入点集</param> /// <param name="pRaster">栅格图层</param> /// <param name="pSr">参考坐标系</param> /// <param name="pSaveFile">输出路径</param> /// <param name="pType">格式</param> /// <returns></returns> public bool GeoReferencing(IPointCollection pFromPoint, IPointCollection pTPoint, IRaster pRaster, ISpatialReference pSr, string pSaveFile, string pType) { try { IRasterGeometryProc pRasterGProc = new RasterGeometryProcClass(); pRasterGProc.Warp(pFromPoint, pTPoint, esriGeoTransTypeEnum.esriGeoTransPolyOrder1, pRaster); pRasterGProc.Register(pRaster); IRasterProps pRasterPro = pRaster as IRasterProps; pRasterPro.SpatialReference = pSr;//定义投影 if (File.Exists(pSaveFile)) { File.Delete(pSaveFile); } pRasterGProc.Rectify(pSaveFile, pType, pRaster);//路径和格式(String) } catch (System.Exception ex) { return(false); } return(true); }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { // TODO: Add CmdRasterResample.OnClick implementation IMapControl2 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2; if (pMapCtr != null) { m_frmRasterResample = new FrmRasterResample(); IRasterProps pRasterProps = pRasterLayer.Raster as IRasterProps; m_frmRasterResample.Cellsize = pRasterProps.MeanCellSize().X; if (m_frmRasterResample.ShowDialog() == DialogResult.OK) { IGeoDataset pGeodataset = pRasterLayer.Raster as IGeoDataset; IRasterGeometryProc pRasterGeometryProc = new RasterGeometryProcClass(); ITransformationOp pTransOP = new RasterTransformationOpClass(); string name = pRasterLayer.Name; if (m_frmRasterResample.resampleType == 0) { IGeoDataset pGeodataset2 = pTransOP.Resample(pGeodataset, m_frmRasterResample.Cellsize, esriGeoAnalysisResampleEnum.esriGeoAnalysisResampleNearest); pRasterLayer.CreateFromDataset(pGeodataset2 as IRasterDataset); pRasterLayer.Name = name; } if (m_frmRasterResample.resampleType == 1) { IGeoDataset pGeodataset2 = pTransOP.Resample(pGeodataset, m_frmRasterResample.Cellsize, esriGeoAnalysisResampleEnum.esriGeoAnalysisResampleBilinear); pRasterLayer.CreateFromDataset(pGeodataset2 as IRasterDataset); pRasterLayer.Name = name; } if (m_frmRasterResample.resampleType == 2) { IGeoDataset pGeodataset2 = pTransOP.Resample(pGeodataset, m_frmRasterResample.Cellsize, esriGeoAnalysisResampleEnum.esriGeoAnalysisResampleCubic); pRasterLayer.CreateFromDataset(pGeodataset2 as IRasterDataset); pRasterLayer.Name = name; } pMapCtr.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, null, null); } } }
/// <summary> /// 配准 后面两个参数是保存的文件和类型 /// </summary> /// <param name="pFromPoint"></param> /// <param name="pTPoint"></param> /// <param name="pRasterLayer"></param> /// <param name="pSaveFile"></param> /// <param name="pType"></param> public bool GeoReferencing(IPointCollection pFromPoint, IPointCollection pTPoint, IRasterLayer pRasterLayer, ISpatialReference pSr, string pSaveFile, string pType) { IGeoReference pGeoreference; pGeoreference = (IGeoReference)pRasterLayer; IRaster pRaster = pRasterLayer.Raster; //判断是否可以配准 if (pGeoreference.CanGeoRef == true) { IRasterGeometryProc pRasterGProc = new RasterGeometryProcClass(); pRasterGProc.Warp(pFromPoint, pTPoint, esriGeoTransTypeEnum.esriGeoTransPolyOrder2, pRaster); pRasterGProc.Register(pRaster); IRasterProps pRasterPro = pRaster as IRasterProps; pRasterPro.SpatialReference = pSr;//定义投影 if (File.Exists(pSaveFile)) { File.Delete(pSaveFile); } pRasterGProc.Rectify(pSaveFile, pType, pRaster);//路径和格式(String) return true; } else { return false; } }
private static void DrawRaster(string file) { try{ Stopwatch timer = new Stopwatch(); timer.Start(); IRasterLayer rl; if (!layers.ContainsKey(file)){ Logger.Debug("Start drawing tile" + file + "..."); rl = new RasterLayerClass(); rl.CreateFromFilePath(file); var props = (IRasterProps) rl.Raster; props.SpatialReference = _dataSpatialReference; if (_needReproject){ IRasterGeometryProc rasterGeometryProc = new RasterGeometryProcClass(); var missing = Type.Missing; rasterGeometryProc.ProjectFast(_layerSpatialReference, rstResamplingTypes.RSP_NearestNeighbor, ref missing, rl.Raster); } // Fix for issue "Each 256x256 tile rendering differently causing blockly effect." // In 10.1 the StrecthType for rasters seems to have changed from esriRasterStretch_NONE to "Percent Clip", // giving color problems with 24 or 32 bits tiles. // http://arcbrutile.codeplex.com/workitem/11207 var image = new Bitmap(file, true); var format = image.PixelFormat; if (format == PixelFormat.Format24bppRgb || format == PixelFormat.Format32bppRgb){ var rasterRGBRenderer = new RasterRGBRendererClass(); ((IRasterStretch2) rasterRGBRenderer).StretchType = esriRasterStretchTypesEnum.esriRasterStretch_NONE; rl.Renderer = rasterRGBRenderer; } rl.Renderer.ResamplingType = rstResamplingTypes.RSP_BilinearInterpolation; // Now set the spatial reference to the dataframe spatial reference! // Do not remove this line... rl.SpatialReference = _layerSpatialReference; timer.Stop(); Logger.Debug(file + "读取花费时间:" + timer.Elapsed.Milliseconds); layers.Add(file,rl); layerNames.Enqueue(file); if (layerNames.Count > 100){ string tempname = layerNames.Dequeue(); layers.Remove(tempname); } } else{ layers.TryGetValue(file, out rl); timer.Stop(); Logger.Debug(file+"查询花费时间:" + timer.Elapsed.Milliseconds); } timer.Reset(); //rl.Draw(ESRI.ArcGIS.esriSystem.esriDrawPhase.esriDPGeography, (IDisplay)activeView.ScreenDisplay, null); rl.Draw(esriDrawPhase.esriDPGeography, _display, null); //activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, trackCancel, env); timer.Stop(); Logger.Debug(file + "绘制花费时间:" + timer.Elapsed.Milliseconds); //Logger.Debug("End drawing tile."); } // ReSharper disable once EmptyGeneralCatchClause catch (Exception) { // what to do now... // just try to load next tile... } }
private void DrawRasterNew(string file, TileInfo tileInfo) { if (_needReproject) { var rl = new RasterLayerClass(); rl.CreateFromFilePath(file); var props = (IRasterProps)rl.Raster; props.SpatialReference = _dataSpatialReference; var rasterGeometryProc = new RasterGeometryProcClass(); var missing = Type.Missing; rasterGeometryProc.ProjectFast(_layerSpatialReference, rstResamplingTypes.RSP_NearestNeighbor, ref missing, rl.Raster); // fix 9/10/2015: with projected tiles color changes and transparency is ignored. var image = new Bitmap(file, true); var format = image.PixelFormat; if (format == PixelFormat.Format24bppRgb | format == PixelFormat.Format32bppArgb) { var rasterRgbRenderer = new RasterRGBRendererClass(); ((IRasterStretch2)rasterRgbRenderer).StretchType = esriRasterStretchTypesEnum.esriRasterStretch_NONE; ((IRasterStretch2)rasterRgbRenderer).Background = true; rl.Renderer = rasterRgbRenderer; } // end fix 9/10/2015: with projected tiles color changes and transparency is ignored. rl.Draw(esriDrawPhase.esriDPGeography, _display, null); } else { using (var fs = new System.IO.FileStream(file, FileMode.Open, FileAccess.Read)) { if (fs.Length > 100) { var img1 = Image.FromStream(fs, true); { // add check if tile needs to be clipped if (ClipTilesEnvelope != null) { if (tileInfo.Extent.MinX <ClipTilesEnvelope.XMin | tileInfo.Extent.MaxX> ClipTilesEnvelope.XMax | tileInfo.Extent.MinY <ClipTilesEnvelope.YMin | tileInfo.Extent.MaxY> ClipTilesEnvelope.YMax) { img1 = ImageProcessor.CropImage(img1, tileInfo, ClipTilesEnvelope); } } if (img1 != null) { var ms = new MemoryStream(); img1.Save(ms, ImageFormat.Png); var bytes1 = ms.ToArray(); var ul = new PointClass() { X = tileInfo.Extent.MinX, Y = tileInfo.Extent.MaxY }; var lr = new PointClass() { X = tileInfo.Extent.MaxX, Y = tileInfo.Extent.MinY }; ImageDrawer.Draw(_display, bytes1, ul, lr); img1.Dispose(); } } } } } }
/// <summary> /// performs a x and y shift of the input raster /// </summary> /// <param name="inRaster">IRaster, IRasterDataset, string path</param> /// <param name="shiftX">number of cells to shift positive number move to the east negative number move to the west</param> /// <param name="shiftY">number of cells to shift positive number move north negative number move south</param> /// <returns></returns> public IFunctionRasterDataset shiftRasterFunction(object inRaster, double shiftX, double shiftY) { IRaster2 rs = (IRaster2)returnRaster(inRaster); IRasterGeometryProc3 geoP3 = new RasterGeometryProcClass(); geoP3.Shift(shiftX,shiftY,(IRaster)rs); //System.Windows.Forms.MessageBox.Show(shiftX.ToString() + "\n" + shiftY.ToString()); return createIdentityRaster(rs); }
public IFunctionRasterDataset RotateRasterFunction(object inRaster,double rotationAngle) { IRaster2 rs = (IRaster2)returnRaster(inRaster); IRasterGeometryProc3 geoP3 = new RasterGeometryProcClass(); IPoint pPoint = new PointClass(); IEnvelope env = ((IRasterProps)rs).Extent; double hX = (env.Width/2)+env.XMin; double hY = (env.Height / 2) + env.YMin; pPoint.X = hX; pPoint.Y = hY; geoP3.Rotate(pPoint,rotationAngle,(IRaster)rs);//.Resample(reSampleType, outCellSize, (IRaster)rs); return createIdentityRaster(rs); }
public IFunctionRasterDataset reSampleRasterFunction(object inRaster, double outCellSize) { IRaster2 rs = (IRaster2)returnRaster(inRaster); IRasterGeometryProc3 geoP3 = new RasterGeometryProcClass(); geoP3.Resample(rstResamplingTypes.RSP_NearestNeighbor, outCellSize, (IRaster)rs); return createIdentityRaster(rs); }
public IFunctionRasterDataset reprojectRasterFunction(object inRaster,ISpatialReference spatialReference) { IRaster2 rs = (IRaster2)returnRaster(inRaster); IRasterGeometryProc3 geoP3 = new RasterGeometryProcClass(); object cellSize = Type.Missing; geoP3.ProjectFast(spatialReference,rstResamplingTypes.RSP_NearestNeighbor,cellSize,(IRaster)rs); return createIdentityRaster(rs); }
public IFunctionRasterDataset flipRasterFunction(object inRaster) { IRaster2 rs = (IRaster2)returnRaster(inRaster); IRasterGeometryProc3 geoP3 = new RasterGeometryProcClass(); geoP3.Flip((IRaster)rs); return createIdentityRaster(rs); }