1. 程式人生 > 其它 >通過點獲取柵格值

通過點獲取柵格值

/// <summary>
/// 通過點獲取柵格值
/// </summary>
/// <param name="raster">柵格物件</param>
/// <param name="point">點物件</param>
/// <returns></returns>
public static double GetHeigtByPoint(IRaster raster, double x, double y)
{
return 0;
double height;
IPoint point = new PointClass();
point.X = x;
point.Y = y;
try
{
IGeoDataset geoDt = raster as IGeoDataset;
ISpatialReference spatialreference = geoDt.SpatialReference;
IRasterSurface rasterSurface = new RasterSurfaceClass();
rasterSurface.PutRaster(raster, 0);
ISurface surface = rasterSurface as ISurface;
if (point.SpatialReference == null)
{
point.Project(spatialreference);
//ptX = point.X;
//ptY = point.Y;
//獲取高程
height = surface.GetElevation(point);
}
else
{
//ptX = point.X;
//ptY = point.Y;
//獲取高程
point.Project(spatialreference);
height = surface.GetElevation(point);
}
return height;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}