本文整理汇总了C#中OSGeo.GDAL.Dataset.SetProjection方法的典型用法代码示例。如果您正苦于以下问题:C# Dataset.SetProjection方法的具体用法?C# Dataset.SetProjection怎么用?C# Dataset.SetProjection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OSGeo.GDAL.Dataset
的用法示例。
在下文中一共展示了Dataset.SetProjection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertFeatureToRaster
public static void ConvertFeatureToRaster(Layer layer, out Dataset outputDataset, double rasterCellSize, string fieldName)
{
DriverUtils.RegisterGdalOgrDrivers();
Envelope envelope = new Envelope();
layer.GetExtent(envelope, 0);
//Compute the out raster cell resolutions
int x_res = Convert.ToInt32((envelope.MaxX - envelope.MinX) / rasterCellSize);
int y_res = Convert.ToInt32((envelope.MaxY - envelope.MinY) / rasterCellSize);
//Console.WriteLine("Extent: " + envelope.MaxX + " " + envelope.MinX + " " + envelope.MaxY + " " + envelope.MinY);
//Console.WriteLine("X resolution: " + x_res);
//Console.WriteLine("X resolution: " + y_res);
//Create new tiff in disk
string tempRaster = "tempZoneRaster.tif";
if (File.Exists(tempRaster))
{
File.Delete(tempRaster);
}
OSGeo.GDAL.Driver outputDriver = Gdal.GetDriverByName("GTiff");
outputDataset = outputDriver.Create(tempRaster, x_res, y_res, 1, DataType.GDT_Int32, null);
//Extrac srs from input feature
string inputShapeSrs;
SpatialReference spatialRefrence = layer.GetSpatialRef();
spatialRefrence.ExportToWkt(out inputShapeSrs);
//Assign input feature srs to outpur raster
outputDataset.SetProjection(inputShapeSrs);
//Geotransform
double[] argin = new double[] { envelope.MinX, rasterCellSize, 0, envelope.MaxY, 0, -rasterCellSize };
outputDataset.SetGeoTransform(argin);
//Set no data
Band band = outputDataset.GetRasterBand(1);
//band.SetNoDataValue(GdalUtilConstants.NoDataValue);
band.Fill(GdalUtilConstants.NoDataValue, 0.0);
//Feature to raster rasterize layer options
//No of bands (1)
int[] bandlist = new int[] { 1 };
//Values to be burn on raster (10.0)
double[] burnValues = new double[] { 10.0 };
//Dataset myDataset = Gdal.Open(outputRasterFile, Access.GA_Update);
//additional options
string[] rasterizeOptions;
//rasterizeOptions = new string[] { "ALL_TOUCHED=TRUE", "ATTRIBUTE=" + fieldName }; //To set all touched pixels into raster pixel
rasterizeOptions = new string[] { "ATTRIBUTE=" + fieldName };
//Rasterize layer
//Gdal.RasterizeLayer(myDataset, 1, bandlist, layer, IntPtr.Zero, IntPtr.Zero, 1, burnValues, null, null, null); // To burn the given burn values instead of feature attributes
//Gdal.RasterizeLayer(outputDataset, 1, bandlist, layer, IntPtr.Zero, IntPtr.Zero, 1, burnValues, rasterizeOptions, new Gdal.GDALProgressFuncDelegate(ProgressFunc), "Raster conversion");
Gdal.RasterizeLayer(outputDataset, 1, bandlist, layer, IntPtr.Zero, IntPtr.Zero, 1, burnValues, rasterizeOptions, null, null);
}