ArcEngine获取栅格图层的四角平面坐标:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Carto;
using System.Windows.Forms;
using ESRI.ArcGIS.Editor;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.GISClient;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Output;
using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.DataSourcesRaster;
using ESRI.ArcGIS.DataSourcesGDB;
public static void GetRasterXY(IRasterLayer raster, ISpatialReference
project,out IPoint zuoshang,out IPoint youshang,out IPoint zuoxia,out IPoint
youxia)//project的作用为:如果栅格是地理坐标系,则用project计算平面坐标,输出四
个角的IPoint
{
IRasterProps pRasterProps = (IRasterProps)raster.Raster;
ESRI.ArcGIS.Geometry.IPoint pzuoshang = new PointClass();
ESRI.ArcGIS.Geometry.IPoint pyoushang = new PointClass();
ESRI.ArcGIS.Geometry.IPoint pzuoxia = new PointClass();
ESRI.ArcGIS.Geometry.IPoint pyouxia = new PointClass();
if (pRasterProps.Extent.SpatialReference is
IGeographicCoordinateSystem)
{
double xmax,xmin,ymax,ymin;
GeoXYproject(pRasterProps.Extent.XMax, pRasterProps.Extent.YMin,
project, pRasterProps.Extent.SpatialReference, out xmax, out ymin);
GeoXYproject(pRasterProps.Extent.XMin, pRasterProps.Extent.YMax,
project, pRasterProps.Extent.SpatialReference, out xmin, out ymax);
pzuoshang.SpatialReference = project;
pzuoshang.PutCoords(xmax,ymin);
pyoushang.SpatialReference = project;
pyoushang.PutCoords(xmax, ymax);
pzuoxia.SpatialReference = project;
pzuoxia.PutCoords(xmin, ymin);
pyouxia.SpatialReference = project;
pyouxia.PutCoords(xmin, ymax);
}
else
{
pzuoshang.SpatialReference =
pRasterProps.Extent.SpatialReference;
pzuoshang.PutCoords(pRasterProps.Extent.XMax,
pRasterProps.Extent.YMin);
pyoushang.SpatialReference =
pRasterProps.Extent.SpatialReference;
pyoushang.PutCoords(pRasterProps.Extent.XMax,
pRasterProps.Extent.YMax);
pzuoxia.SpatialReference = pRasterProps.Extent.SpatialReference;
pzuoxia.PutCoords(pRasterProps.Extent.XMin,
pRasterProps.Extent.YMin);
pyouxia.SpatialReference = pRasterProps.Extent.SpatialReference;
pyouxia.PutCoords(pRasterProps.Extent.XMin,
pRasterProps.Extent.YMax);
}
zuoshang = pzuoshang;
youshang = pyoushang;
zuoxia = pzuoxia;
youxia = pyouxia;
}
public static void GeoXYproject(double X, double Y, ISpatialReference
project, ISpatialReference geo, out double ox, out double oy)//第一个方法的辅助
方法,如果栅格是地理坐标系则调用这个方法转换坐标,project代表投影坐标,geo代表栅
格的地理坐标
{
ESRI.ArcGIS.Geometry.IPoint point = new PointClass();
point.SpatialReference = geo;
point.PutCoords(X, Y);
point.Project(project);
point.QueryCoords(out ox, out oy);
}