本文整理汇总了C#中IRaster.ProjToCell方法的典型用法代码示例。如果您正苦于以下问题:C# IRaster.ProjToCell方法的具体用法?C# IRaster.ProjToCell怎么用?C# IRaster.ProjToCell使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRaster
的用法示例。
在下文中一共展示了IRaster.ProjToCell方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RasterMath
public bool RasterMath(IRaster input1, IRaster input2, IRaster output, ICancelProgressHandler cancelProgressHandler)
{
// Validates the input and output data
if (input1 == null || input2 == null || output == null)
{
return false;
}
Extent envelope = UnionEnvelope(input1, input2);
// Figures out which raster has smaller cells
IRaster smallestCellRaster = input1.CellWidth < input2.CellWidth ? input1 : input2;
// Given the envelope of the two rasters we calculate the number of columns / rows
int noOfCol = Convert.ToInt32(Math.Abs(envelope.Width / smallestCellRaster.CellWidth));
int noOfRow = Convert.ToInt32(Math.Abs(envelope.Height / smallestCellRaster.CellHeight));
// create output raster
output = Raster.CreateRaster(
output.Filename, string.Empty, noOfCol, noOfRow, 1, typeof(int), new[] { string.Empty });
RasterBounds bound = new RasterBounds(noOfRow, noOfCol, envelope);
output.Bounds = bound;
output.NoDataValue = input1.NoDataValue;
RcIndex v1;
RcIndex v2;
int previous = 0;
int max = output.Bounds.NumRows + 1;
for (int i = 0; i < output.Bounds.NumRows; i++)
{
for (int j = 0; j < output.Bounds.NumColumns; j++)
{
Coordinate cellCenter = output.CellToProj(i, j);
v1 = input1.ProjToCell(cellCenter);
double val1;
if (v1.Row <= input1.EndRow && v1.Column <= input1.EndColumn && v1.Row > -1 && v1.Column > -1)
{
val1 = input1.Value[v1.Row, v1.Column];
}
else
{
val1 = input1.NoDataValue;
}
v2 = input2.ProjToCell(cellCenter);
double val2;
if (v2.Row <= input2.EndRow && v2.Column <= input2.EndColumn && v2.Row > -1 && v2.Column > -1)
{
val2 = input2.Value[v2.Row, v2.Column];
}
else
{
val2 = input2.NoDataValue;
}
if (val1 == input1.NoDataValue && val2 == input2.NoDataValue)
{
output.Value[i, j] = output.NoDataValue;
}
else if (val1 != input1.NoDataValue && val2 == input2.NoDataValue)
{
output.Value[i, j] = output.NoDataValue;
}
else if (val1 == input1.NoDataValue && val2 != input2.NoDataValue)
{
output.Value[i, j] = output.NoDataValue;
}
else
{
output.Value[i, j] = Operation(val1, val2);
}
if (cancelProgressHandler.Cancel)
{
return false;
}
}
int current = Convert.ToInt32(Math.Round(i * 100D / max));
// only update when increment in persentage
if (current > previous)
{
cancelProgressHandler.Progress(string.Empty, current, current + TextStrings.progresscompleted);
}
previous = current;
}
// output = Temp;
output.Save();
return true;
}
示例2: Execute
/// <summary>
/// Executes the ReSample Opaeration tool programaticaly
/// Ping deleted the static property for external testing
/// </summary>
/// <param name="input1">The input raster</param>
/// <param name="oldCellSize">The size of the cells Hight</param>
/// <param name="newCellSize">The size of the cells Width</param>
/// <param name="output">The output raster</param>
/// <param name="cancelProgressHandler">The progress handler</param>
/// <returns></returns>
public bool Execute(IRaster input1, double newCellHeight, double newCellWidth, IRaster output, ICancelProgressHandler cancelProgressHandler)
{
//Validates the input and output data
if (input1 == null || newCellWidth == 0 || output == null)
{
return false;
}
IEnvelope envelope = input1.Bounds.Envelope;
//Calculate new number of columns and rows
int noOfCol = Convert.ToInt32(Math.Abs(envelope.Width / newCellWidth));
int noOfRow = Convert.ToInt32(Math.Abs(envelope.Height / newCellHeight));
int previous = 0;
//************OLD Method
////Create the new raster with the appropriate dimensions
//Raster Temp = new Raster();
////Temp.CreateNew(output.Filename, noOfRow, noOfCol, input1.DataType);
//Temp.CreateNew(output.Filename, "", noOfCol, noOfRow, 1, input1.DataType, new string[] { "" });
//Temp.CellWidth = newCellSize;
//Temp.CellHeight = oldCellSize;
//Temp.Xllcenter = input1.Bounds.Envelope.Minimum.X + (Temp.CellWidth / 2);
//Temp.Yllcenter = input1.Bounds.Envelope.Minimum.Y + (Temp.CellHeight / 2);
//***************
//create output raster
output = Raster.Create(output.Filename, "", noOfCol, noOfRow, 1, input1.DataType, new[] { "" });
RasterBounds bound = new RasterBounds(noOfRow, noOfCol, envelope);
output.Bounds = bound;
output.NoDataValue = input1.NoDataValue;
RcIndex index1;
//Loop throug every cell for new value
int max = (output.Bounds.NumRows + 1);
for (int i = 0; i < output.Bounds.NumRows; i++)
{
for (int j = 0; j < output.Bounds.NumColumns; j++)
{
//Projet the cell position to Map
Coordinate cellCenter = output.CellToProj(i, j);
index1=input1.ProjToCell(cellCenter);
double val;
if (index1.Row <= input1.EndRow && index1.Column <= input1.EndColumn && index1.Row > -1 && index1.Column > -1)
{
if (input1.Value[index1.Row, index1.Column] == input1.NoDataValue)
val = output.NoDataValue;
else
val = input1.Value[index1.Row, index1.Column];
}
else
val = output.NoDataValue;
output.Value[i, j] = val;
if (cancelProgressHandler.Cancel)
return false;
}
int current = Convert.ToInt32(Math.Round(i * 100D / max));
//only update when increment in persentage
if (current > previous)
cancelProgressHandler.Progress("", current, current + TextStrings.progresscompleted);
previous = current;
}
//output = Temp;
output.Save();
return true;
}
示例3: Execute
/// <summary>
/// Executes the Erase Opaeration tool programaticaly.
/// Ping deleted static for external testing 01/2010
/// </summary>
/// <param name="input1">The input raster.</param>
/// <param name="input2">The input raster.</param>
/// <param name="output">The output raster.</param>
/// <param name="cancelProgressHandler">The progress handler.</param>
/// <returns></returns>
public bool Execute(IRaster input1, IFeatureSet input2, IRaster output, ICancelProgressHandler cancelProgressHandler)
{
//Validates the input and output data
if (input1 == null || input2 == null || output == null)
{
return false;
}
double cellWidth = input1.CellWidth;
double cellHeight = input1.CellHeight;
//Calculate the Intersect Envelope
IEnvelope envelope1 = input1.Bounds.Envelope;
IEnvelope envelope2 = input2.Envelope;
envelope1 = envelope1.Intersection(envelope2);
int noOfCol = Convert.ToInt32(envelope1.Height / cellHeight);
int noOfRow = Convert.ToInt32(envelope1.Width / cellWidth);
//create output raster
output = Raster.Create(output.Filename, "", noOfCol, noOfRow, 1, typeof(int), new[] { "" });
RasterBounds bound = new RasterBounds(noOfRow, noOfCol, envelope1);
output.Bounds = bound;
output.NoDataValue = input1.NoDataValue;
RcIndex v1;
// MapWindow.Analysis.Topology.Algorithm.PointLocator pointLocator1 = new MapWindow.Analysis.Topology.Algorithm.PointLocator();
int previous = 0;
int max = (output.Bounds.NumRows + 1);
for (int i = 0; i < output.Bounds.NumRows; i++)
{
for (int j = 0; j < output.Bounds.NumColumns; j++)
{
Coordinate cellCenter = output.CellToProj(i, j);
//test if the coordinate is inside of the polygon
bool isInside = false;
IFeature pointFeat = new Feature(new Point(cellCenter));
foreach (IFeature f in input2.Features)
{
if (f.Contains(pointFeat))
{
//output.Value[i, j] = val1;
isInside = true;
break;
}
}
if (isInside)
{
v1 = input1.ProjToCell(cellCenter);
double val1;
if (v1.Row <= input1.EndRow && v1.Column <= input1.EndColumn && v1.Row > -1 && v1.Column > -1)
val1 = input1.Value[v1.Row, v1.Column];
else
val1 = output.NoDataValue;
output.Value[i, j] = val1;
}
else
{
output.Value[i, j] = output.NoDataValue;
}
if (cancelProgressHandler.Cancel)
return false;
}
int current = Convert.ToInt32(Math.Round(i * 100D / max));
//only update when increment in percentage
if (current > previous)
cancelProgressHandler.Progress("", current, current + TextStrings.progresscompleted);
previous = current;
}
//output = Temp;
output.Save();
return true;
}
示例4: Execute
/// <summary>
/// Executes the Erase Opaeration tool programaticaly.
/// </summary>
/// <param name="input1">The input raster.</param>
/// <param name="input2">The input raster.</param>
/// <param name="output">The output raster.</param>
/// <param name="cancelProgressHandler">The progress handler.</param>
/// <returns></returns>
public bool Execute(IRaster input1, IFeatureSet input2, IRaster output, MapWindow.Tools.ICancelProgressHandler cancelProgressHandler)
{
//Validates the input and output data
if (input1 == null || input2 == null || output == null)
{
return false;
}
int noOfCol = input1.NumColumns;
int noOfRow = input1.NumRows;
//Calculate the Intersect Envelope
IEnvelope envelope1 = new Envelope() as IEnvelope;
IEnvelope envelope2 = new Envelope() as IEnvelope;
envelope1 = input1.Bounds.Envelope;
envelope2 = input2.Envelope;
envelope1 = envelope1.Intersection(envelope2);
//Create the new raster with the appropriate dimensions
IRaster Temp = Raster.Create(output.Filename, "", noOfCol, noOfRow, 1, input1.DataType, new string[] { });
//Temp.CreateNew(output.Filename, noOfRow, noOfCol, input1.DataType);
Temp.CellWidth = input1.CellWidth;
Temp.CellHeight = input1.CellHeight;
Temp.Xllcenter = envelope1.Minimum.X + (Temp.CellWidth / 2);
Temp.Yllcenter = envelope1.Minimum.Y + (Temp.CellHeight / 2);
MapWindow.Geometries.ICoordinate I1 = new MapWindow.Geometries.Coordinate() as MapWindow.Geometries.ICoordinate;
RcIndex v1 = new RcIndex();
// MapWindow.Analysis.Topology.Algorithm.PointLocator pointLocator1 = new MapWindow.Analysis.Topology.Algorithm.PointLocator();
double val1;
int previous = 0;
int current = 0;
int max = (Temp.Bounds.NumRows + 1);
for (int i = 0; i < Temp.Bounds.NumRows; i++)
{
for (int j = 0; j < Temp.Bounds.NumColumns; j++)
{
I1 = Temp.CellToProj(i, j);
v1 = input1.ProjToCell(I1);
if (v1.Row <= input1.EndRow && v1.Column <= input1.EndColumn && v1.Row > -1 && v1.Column > -1)
val1 = input1.Value[v1.Row, v1.Column];
else
val1 = Temp.NoDataValue;
//test if the coordinate is inside of the polygon
bool isInside = false;
IFeature pointFeat = new Feature(new Point(I1)) as IFeature;
foreach (IFeature f in input2.Features)
{
if (f.Contains(pointFeat))
{
Temp.Value[i, j] = val1;
isInside = true;
break;
}
}
if (isInside == false)
{
Temp.Value[i, j] = Temp.NoDataValue;
}
if (cancelProgressHandler.Cancel == true)
return false;
}
current = Convert.ToInt32(Math.Round(i * 100D / max));
//only update when increment in percentage
if (current > previous)
cancelProgressHandler.Progress("", current, current.ToString() + "% progress completed");
previous = current;
}
output = Temp;
output.Save();
return true;
}
示例5: fillTrackGrid
private void fillTrackGrid(IRaster gridTrack, IFeatureSet polyOut, int idxToFill)
{
int rowStart;
int rowStop;
int colStart;
int colStop;
RcIndex start;
RcIndex stop;
ICoordinate I;
start = gridTrack.ProjToCell(polyOut.Features[idxToFill].Envelope.Minimum.X, polyOut.Features[idxToFill].Envelope.Maximum.Y);
stop = gridTrack.ProjToCell(polyOut.Features[idxToFill].Envelope.Maximum.X, polyOut.Features[idxToFill].Envelope.Minimum.Y);
rowStart = start.Row;
colStart = start.Column;
rowStop = stop.Row;
colStop = stop.Column;
for (int rowcell = rowStart; rowcell <= rowStop; rowcell++)
{
for (int colcell = colStart; colcell <= colStop; colcell++)
{
I = gridTrack.CellToProj(rowcell, colcell);
Point pt = new Point(I);
if (polyOut.Features[idxToFill].Covers(pt))
{
gridTrack.Value[rowcell, colcell] = 1;
}
}
}
}
示例6: Execute
/// <summary>
/// Executes the Erase Opaeration tool programaticaly
/// </summary>
/// <param name="input1">The input raster</param>
/// <param name="input2">The input raster</param>
/// <param name="output">The output raster</param>
/// <param name="cancelProgressHandler">The progress handler</param>
/// <returns></returns>
public bool Execute(IRaster input1, IRaster input2, IRaster output, MapWindow.Tools.ICancelProgressHandler cancelProgressHandler)
{
//Validates the input and output data
if (input1 == null || input2 == null || output == null)
{
return false;
}
IEnvelope envelope = new Envelope() as IEnvelope;
envelope = UnionEnvelope(input1, input2);
int noOfCol;
int noOfRow;
//Figures out which raster has smaller cells
IRaster smallestCellRaster;
if (input1.CellWidth < input2.CellWidth) smallestCellRaster = input1;
else smallestCellRaster = input2;
//Given the envelope of the two rasters we calculate the number of columns / rows
noOfCol = Convert.ToInt32(Math.Abs(envelope.Width / smallestCellRaster.CellWidth));
noOfRow = Convert.ToInt32(Math.Abs(envelope.Height / smallestCellRaster.CellHeight));
//Create the new raster with the appropriate dimensions
Raster Temp = new Raster();
//Temp.CreateNew(output.Filename, noOfRow, noOfCol, input1.DataType);
Temp.CreateNew(output.Filename, "", noOfCol, noOfRow, 1, input1.DataType, new string[] { "" });
Temp.CellWidth = smallestCellRaster.CellWidth;
Temp.CellHeight = smallestCellRaster.CellHeight;
Temp.Xllcenter = envelope.Minimum.X + (Temp.CellWidth / 2);
Temp.Yllcenter = envelope.Minimum.Y + (Temp.CellHeight / 2);
MapWindow.Geometries.ICoordinate I1 = new MapWindow.Geometries.Coordinate() as MapWindow.Geometries.ICoordinate;
RcIndex v1 = new RcIndex();
RcIndex v2 = new RcIndex();
double val1;
double val2;
int previous=0;
int current=0;
int max = (Temp.Bounds.NumRows + 1);
for (int i = 0; i < Temp.Bounds.NumRows; i++)
{
for (int j = 0; j < Temp.Bounds.NumColumns; j++)
{
I1 = Temp.CellToProj(i, j);
v1 = input1.ProjToCell(I1);
if (v1.Row <= input1.EndRow && v1.Column <= input1.EndColumn && v1.Row > -1 && v1.Column > -1)
val1 = input1.Value[v1.Row, v1.Column];
else
val1 = input1.NoDataValue;
v2 = input2.ProjToCell(I1);
if (v2.Row <= input2.EndRow && v2.Column <= input2.EndColumn && v2.Row > -1 && v2.Column > -1)
val2 = input2.Value[v2.Row, v2.Column];
else
val2 = input2.NoDataValue;
if (val1 == input1.NoDataValue && val2 == input2.NoDataValue)
{
Temp.Value[i, j] = Temp.NoDataValue;
}
else if (val1 != input1.NoDataValue && val2 == input2.NoDataValue)
{
Temp.Value[i, j] = val1;
}
else if (val1 == input1.NoDataValue && val2 != input2.NoDataValue)
{
Temp.Value[i, j] = val2;
}
else
{
Temp.Value[i, j] = val1;
}
if (cancelProgressHandler.Cancel == true)
return false;
}
current = Convert.ToInt32(Math.Round(i * 100D / max));
//only update when increment in persentage
if(current>previous)
cancelProgressHandler.Progress("", current, current.ToString() + "% progress completed");
previous = current;
}
output = Temp;
output.Save();
return true;
}
示例7: GetStreamElevationPoints
//.........这里部分代码省略.........
// if (UpstreamCount == UpstreamFinishedCount) //all upstreams finished
// {
// if (currUS1ID != -2 && currUS2ID != -2) //It has two upstream, have to do a double sum
// {
// Hyd_Stor_Num++;
// InFlow_Num1 = currUS1ID;
// InFlow_Num2 = curridx + 1;
// fig.Write("add 5{0,6:G6}{1,6:G6}{2,6:G6}\n", Hyd_Stor_Num, InFlow_Num1, InFlow_Num2);
// Hyd_Stor_Num++;
// InFlow_Num1 = currUS2ID;
// InFlow_Num2 = Hyd_Stor_Num - 1;
// fig.Write("add 5{0,6:G6}{1,6:G6}{2,6:G6}\n", Hyd_Stor_Num, InFlow_Num1, InFlow_Num2);
// }
// else if (currUS1ID != -2) //It only has one upstream, check if it's 1
// {
// Hyd_Stor_Num++;
// InFlow_Num1 = currUS1ID;
// InFlow_Num2 = curridx + 1;
// fig.Write("add 5{0,6:G6}{1,6:G6}{2,6:G6}\n", Hyd_Stor_Num, InFlow_Num1, InFlow_Num2);
// }
// else if (currUS2ID != -2) //It only has one upstream, check if it's 2
// {
// Hyd_Stor_Num++;
// InFlow_Num1 = currUS2ID;
// InFlow_Num2 = curridx + 1;
// fig.Write("add 5{0,6:G6}{1,6:G6}{2,6:G6}\n", Hyd_Stor_Num, InFlow_Num1, InFlow_Num2);
// }
// //After summing, create the route and possibly reservoir
// Hyd_Stor_Num++;
// InFlow_Num1 = Hyd_Stor_Num - 1;
// fig.Write("route 2{0,6:G6}{1,6:G6}{2,6:G6}\n {1,5:D5}0000.rte{1,5:D5}0000.swq\n", Hyd_Stor_Num, curridx + 1, InFlow_Num1);
// subIDs[curridx] = Hyd_Stor_Num;
// if (sf.get_CellValue(ReservoirFieldNum, curridx).ToString() == "1")
// {
// Hyd_Stor_Num++;
// Res_Num++;
// InFlow_Num1 = Hyd_Stor_Num - 1;
// InFlow_ID = curridx + 1;
// fig.Write("routres 3{0,6:G6}{1,6:G6}{2,6:G6}{3,6:G6}\n {3,5:D5}0000.res{3,5:D5}0000.lwq\n", Hyd_Stor_Num, Res_Num, InFlow_Num1, InFlow_ID);
// subIDs[curridx] = Hyd_Stor_Num;
// }
// }
// else //There are upstream items that need to still be processed before this one
// {
// substack.Push(curridx);
// if (currUS1idx != -1 && currUS1ID == -1)
// {
// substack.Push(currUS1idx);
// }
// if (currUS2idx != -1 && currUS2ID == -1)
// {
// substack.Push(currUS2idx);
// }
// }
// }
// }
// //Write out the saveconc and finish commands
// int SaveFile_Num = 1;
// int Print_Freq = 0; //0 for daily, 1 for hourly
// fig.Write("saveconc 14{0,6:G6}{1,6:G6}{2,6:G6}\n watout.dat\n", Hyd_Stor_Num, SaveFile_Num, Print_Freq);
// fig.WriteLine("finish 0");
// fig.Close();
// sf.Close();
// return true;
// }
// #endregion
// #region "Hydrology Private Helper Functions"
private static void GetStreamElevationPoints(int sindx, IFeatureSet streamShape, IRaster demGrid, out double elevLow, out double elevHigh)
{
var shapePoints = streamShape.get_Shape(sindx).NumPoints;
elevLow = 10000000;
elevHigh = -1000000;
for (var i = 0; i < shapePoints; i += 2)
{
var pt = streamShape.get_Shape(sindx).Coordinates[i];
RcIndex position = demGrid.ProjToCell(pt.X, pt.Y);
if (position.IsEmpty()) continue;
double currVal = demGrid.Value[position.Row, position.Column];
if (currVal < elevLow)
{
elevLow = currVal;
}
if (currVal > elevHigh)
{
elevHigh = currVal;
}
}
}
示例8: Resample
/// <summary>
/// This will resample the cells.
/// If the cell size is zero, this will default to the shorter of the width or height
/// divided by 256.
/// </summary>
/// <param name="input1">the input raster.</param>
/// <param name="cellHeight">The new cell height or null.</param>
/// <param name="cellWidth">The new cell width or null.</param>
/// <param name="outputFileName">The string name of the output raster.</param>
/// <param name="progressHandler">An interface for handling the progress messages.</param>
/// <returns>The resampled raster.</returns>
public static IRaster Resample(IRaster input1, double cellHeight, double cellWidth, string outputFileName,
IProgressHandler progressHandler)
{
if (input1 == null)
{
return null;
}
Extent envelope = input1.Bounds.Extent;
if (cellHeight == 0)
{
cellHeight = envelope.Height / 256;
}
if (cellWidth == 0)
{
cellWidth = envelope.Width / 256;
}
//Calculate new number of columns and rows
int noOfCol = Convert.ToInt32(Math.Abs(envelope.Width / cellWidth));
int noOfRow = Convert.ToInt32(Math.Abs(envelope.Height / cellHeight));
IRaster output = Raster.CreateRaster(outputFileName, string.Empty, noOfCol, noOfRow, 1, input1.DataType,
new[] { string.Empty });
RasterBounds bound = new RasterBounds(noOfRow, noOfCol, envelope);
output.Bounds = bound;
output.NoDataValue = input1.NoDataValue;
RcIndex index1;
int max = (output.Bounds.NumRows);
ProgressMeter pm = new ProgressMeter(progressHandler, "ReSize Cells", max);
//Loop through every cell for new value
for (int i = 0; i < max; i++)
{
for (int j = 0; j < output.Bounds.NumColumns; j++)
{
//Project the cell position to Map
Coordinate cellCenter = output.CellToProj(i, j);
index1 = input1.ProjToCell(cellCenter);
double val;
if (index1.Row <= input1.EndRow && index1.Column <= input1.EndColumn && index1.Row > -1 &&
index1.Column > -1)
{
val = input1.Value[index1.Row, index1.Column] == input1.NoDataValue
? output.NoDataValue
: input1.Value[index1.Row, index1.Column];
}
else
{
val = output.NoDataValue;
}
output.Value[i, j] = val;
}
pm.CurrentValue = i;
}
output.Save();
pm.Reset();
return output;
}