本文整理汇总了C#中OSGeo.GetGeoTransform方法的典型用法代码示例。如果您正苦于以下问题:C# OSGeo.GetGeoTransform方法的具体用法?C# OSGeo.GetGeoTransform怎么用?C# OSGeo.GetGeoTransform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OSGeo
的用法示例。
在下文中一共展示了OSGeo.GetGeoTransform方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GeoTransform
/// <summary>
/// Constructor
/// </summary>
/// <param name="gdalDataset">The gdal dataset</param>
public GeoTransform(OSGeo.GDAL.Dataset gdalDataset)
{
if (gdalDataset == null)
throw new ArgumentException("GeoTransform constructor invoked with null dataset.", "gdalDataset");
var array = new double[6];
gdalDataset.GetGeoTransform(array);
_transform = array;
ComputeInverse();
}
示例2: GetPreview
private void GetPreview(OSGeo.GDAL.Dataset dataset, System.Drawing.Size size, Graphics g, IEnvelope bbox)
{
double[] geoTrans = new double[6];
dataset.GetGeoTransform(geoTrans);
GeoTransform GT = new GeoTransform(geoTrans);
int DsWidth = dataset.RasterXSize;
int DsHeight = dataset.RasterYSize;
Bitmap bitmap = new Bitmap(size.Width, size.Height, PixelFormat.Format24bppRgb);
int iPixelSize = 3; //Format24bppRgb = byte[b,g,r]
if (dataset != null)
{
/*
if ((float)size.Width / (float)size.Height > (float)DsWidth / (float)DsHeight)
size.Width = size.Height * DsWidth / DsHeight;
else
size.Height = size.Width * DsHeight / DsWidth;
*/
double left = Math.Max(bbox.MinX, _Envelope.MinX);
double top = Math.Min(bbox.MaxY, _Envelope.MaxY);
double right = Math.Min(bbox.MaxX, _Envelope.MaxX);
double bottom = Math.Max(bbox.MinY, _Envelope.MinY);
int x1 = (int)GT.PixelX(left);
int y1 = (int)GT.PixelY(top);
int x1width = (int)GT.PixelXwidth(right - left);
int y1height = (int)GT.PixelYwidth(bottom - top);
bitmap = new Bitmap(size.Width, size.Height, PixelFormat.Format24bppRgb);
BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, size.Width, size.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
try
{
unsafe
{
for (int i = 1; i <= (dataset.RasterCount > 3 ? 3 : dataset.RasterCount); ++i)
{
byte[] buffer = new byte[size.Width * size.Height];
OSGeo.GDAL.Band band = dataset.GetRasterBand(i);
//band.ReadRaster(x1, y1, x1width, y1height, buffer, size.Width, size.Height, (int)GT.HorizontalPixelResolution, (int)GT.VerticalPixelResolution);
band.ReadRaster(x1, y1, x1width, y1height, buffer, size.Width, size.Height, 0, 0);
int p_indx = 0;
int ch = 0;
//#warning Check correspondance between enum and integer values
if (band.GetRasterColorInterpretation() == OSGeo.GDAL.ColorInterp.GCI_BlueBand) ch = 0;
if (band.GetRasterColorInterpretation() == OSGeo.GDAL.ColorInterp.GCI_GreenBand) ch = 1;
if (band.GetRasterColorInterpretation() == OSGeo.GDAL.ColorInterp.GCI_RedBand) ch = 2;
if (band.GetRasterColorInterpretation() != OSGeo.GDAL.ColorInterp.GCI_PaletteIndex)
{
for (int y = 0; y < size.Height; y++)
{
byte* row = (byte*)bitmapData.Scan0 + (y * bitmapData.Stride);
for (int x = 0; x < size.Width; x++, p_indx++)
{
row[x * iPixelSize + ch] = buffer[p_indx];
}
}
}
else //8bit Grayscale
{
for (int y = 0; y < size.Height; y++)
{
byte* row = (byte*)bitmapData.Scan0 + (y * bitmapData.Stride);
for (int x = 0; x < size.Width; x++, p_indx++)
{
row[x * iPixelSize] = buffer[p_indx];
row[x * iPixelSize + 1] = buffer[p_indx];
row[x * iPixelSize + 2] = buffer[p_indx];
}
}
}
}
}
}
finally
{
bitmap.UnlockBits(bitmapData);
}
}
g.DrawImage(bitmap, new System.Drawing.Point(0, 0));
}